• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ IOMalloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中IOMalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ IOMalloc函数的具体用法?C++ IOMalloc怎么用?C++ IOMalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IOMalloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: vm_new

VM* vm_new(int num_cpus) {
	if (num_cpus <= 0) {
		LOG_ERROR("vm_new: num_cpus <= 0");
		return NULL;		
	}
	
	VM* vm = (VM*)IOMalloc(sizeof(VM));
	if (!vm) {
		LOG_ERROR("vm_new: can't allocate VM");
		return NULL;
	}
	memset(vm, 0, sizeof(VM));
	
	vm->num_cpus = num_cpus;
	vm->cpus = (CPU**)IOMalloc(sizeof(CPU*) * num_cpus);
	if (!vm->cpus) {
		LOG_ERROR("vm_new: can't allocate cpus[]");
		vm_delete(vm);
		return NULL;
	}
	memset(vm->cpus, 0, sizeof(sizeof(CPU*) * num_cpus));
	for (int i = 0; i < vm->num_cpus; i++) {
		CPU* cpu = cpu_new();
		if (!cpu) {
			vm_delete(vm);
			return NULL;
		}
		vm->cpus[i] = cpu;
	}

	LOG("created VM");
	return vm;
}
开发者ID:cocoajunkie,项目名称:vm,代码行数:33,代码来源:VM.cpp


示例2: bcopy

bool SuperIOSensor::initWithOwner(SuperIOMonitor *aOwner, const char* aKey, const char* aType, unsigned char aSize, SuperIOSensorGroup aGroup, unsigned long aIndex)
{
	if (!OSObject::init())
		return false;
	
	if (!(owner = aOwner))
		return false;
	
	if (!(name = (char *)IOMalloc(5)))
		return false;
	
	bcopy(aKey, name, 4);
	name[5] = '\0';
	
	if (!(type = (char *)IOMalloc(5)))
		return false;
	
	bcopy(aType, type, 4);
	type[5] = '\0';
	
	size = aSize;
	group = aGroup;
	index = aIndex;
	
	return true;
}
开发者ID:Beshuta,项目名称:HWSensors,代码行数:26,代码来源:SuperIOFamily.cpp


示例3: sizeof

IOReturn IOSharedInterruptController::initInterruptController(IOInterruptController *parentController, OSData *parentSource)
{
  int      cnt, interruptType;
  IOReturn error;
  
  if (!super::init())
    return kIOReturnNoResources;
  
  // Set provider to this so enable/disable nub stuff works.
  provider = this;
  
  // Allocate the IOInterruptSource so this can act like a nub.
  _interruptSources = (IOInterruptSource *)IOMalloc(sizeof(IOInterruptSource));
  if (_interruptSources == 0) return kIOReturnNoMemory;
  _numInterruptSources = 1;
  
  // Set up the IOInterruptSource to point at this.
  _interruptSources[0].interruptController = parentController;
  _interruptSources[0].vectorData = parentSource;
  
  sourceIsLevel = false;
  error = provider->getInterruptType(0, &interruptType);
  if (error == kIOReturnSuccess) {
    if (interruptType & kIOInterruptTypeLevel)
      sourceIsLevel = true;
  }
  
  // Allocate the memory for the vectors
  numVectors = 32; // For now a constant number.
  vectors = (IOInterruptVector *)IOMalloc(numVectors * sizeof(IOInterruptVector));
  if (vectors == NULL) {
    IOFree(_interruptSources, sizeof(IOInterruptSource));
    return kIOReturnNoMemory;
  }
  bzero(vectors, numVectors * sizeof(IOInterruptVector));
  
  // Allocate the lock for the controller.
  controllerLock = IOSimpleLockAlloc();
  if (controllerLock == 0) return kIOReturnNoResources;
  
  // Allocate locks for the vectors.
  for (cnt = 0; cnt < numVectors; cnt++) {
    vectors[cnt].interruptLock = IOLockAlloc();
    if (vectors[cnt].interruptLock == NULL) {
      for (cnt = 0; cnt < numVectors; cnt++) {
	if (vectors[cnt].interruptLock != NULL)
	  IOLockFree(vectors[cnt].interruptLock);
      }
      return kIOReturnNoResources;
    }
  }
  
  vectorsRegistered = 0;
  vectorsEnabled = 0;
  controllerDisabled = 1;
  
  return kIOReturnSuccess;
}
开发者ID:OpenDarwin-CVS,项目名称:SEDarwin,代码行数:58,代码来源:IOInterruptController.cpp


示例4: round_page

Boolean IOSharedDataQueue::initWithCapacity(UInt32 size)
{
    IODataQueueAppendix *   appendix;
    vm_size_t               allocSize;

    if (!super::init()) {
        return false;
    }

    _reserved = (ExpansionData *)IOMalloc(sizeof(struct ExpansionData));
    if (!_reserved) {
        return false;
    }

    if (size > UINT32_MAX - DATA_QUEUE_MEMORY_HEADER_SIZE - DATA_QUEUE_MEMORY_APPENDIX_SIZE) {
        return false;
    }
    
    allocSize = round_page(size + DATA_QUEUE_MEMORY_HEADER_SIZE + DATA_QUEUE_MEMORY_APPENDIX_SIZE);

    if (allocSize < size) {
        return false;
    }

    dataQueue = (IODataQueueMemory *)IOMallocAligned(allocSize, PAGE_SIZE);
    if (dataQueue == 0) {
        return false;
    }
    bzero(dataQueue, allocSize);

    dataQueue->queueSize    = size;
//  dataQueue->head         = 0;
//  dataQueue->tail         = 0;

    if (!setQueueSize(size)) {
        return false;
    }
    
    appendix            = (IODataQueueAppendix *)((UInt8 *)dataQueue + size + DATA_QUEUE_MEMORY_HEADER_SIZE);
    appendix->version   = 0;

    if (!notifyMsg) {
        notifyMsg = IOMalloc(sizeof(mach_msg_header_t));
        if (!notifyMsg)
            return false;
    }
    bzero(notifyMsg, sizeof(mach_msg_header_t));

    setNotificationPort(MACH_PORT_NULL);

    return true;
}
开发者ID:argp,项目名称:xnu,代码行数:52,代码来源:IOSharedDataQueue.cpp


示例5: copySymbol

bool FakeSMCKey::init(const char * aKey, const char * aType, unsigned char aSize, const void *aValue, IOService * aHandler)
{
    if (!super::init())
        return false;

	if (!aKey || strlen(aKey) == 0 || !(key = (char *)IOMalloc(5))) 
		return false;
	
	copySymbol(aKey, key);
    
	size = aSize;
	
	if (!(type = (char *)IOMalloc(5)))
		return false;
    
	if (!aType || strlen(aType) == 0) {
		switch (size) 
		{
			case 1:
				copySymbol("ui8", type);
				break;
			case 2:
				copySymbol("ui16", type);
				break;
			case 4:
				copySymbol("ui32", type);
				break;
			default:
				copySymbol("ch8*", type);
				break;
		}
        //copySymbol("\0\0\0\0", type);
	}
	else 
        copySymbol(aType, type);
	
	if (size == 0)
		size++;
    
	if (!(value = IOMalloc(size)))
		return false;
	
	if (aValue)
		bcopy(aValue, value, size);
	else
		bzero(value, size);
	
	handler = aHandler;
	
    return true;
}
开发者ID:alexandrezia,项目名称:HWSensors,代码行数:51,代码来源:FakeSMCKey.cpp


示例6: sizeof

int VoodooI2CHIDDevice::i2c_hid_alloc_buffers(i2c_hid *ihid, UInt report_size) {
    int args_len = sizeof(UInt8) + sizeof(UInt16) + sizeof(UInt16) + report_size;
    
    ihid->inbuf = (char *)IOMalloc(report_size);
    ihid->argsbuf = (char *)IOMalloc(report_size);
    ihid->cmdbuf = (char *)IOMalloc(sizeof(union command) + args_len);
    
    if(!ihid->inbuf || !ihid->argsbuf || !ihid->cmdbuf) {
        i2c_hid_free_buffers(ihid, report_size);
        return -1;
    }
    
    ihid->bufsize = report_size;
    
    return 0;
}
开发者ID:nuudles,项目名称:VoodooI2C,代码行数:16,代码来源:VoodooI2CHIDDevice.cpp


示例7: IOLockAlloc

bool IOHIKeyboard::init(OSDictionary * properties)
{
  if (!super::init(properties))  return false;

  /*
   * Initialize minimal state.
   */

  _deviceLock   = IOLockAlloc();
  _keyMap       = 0;
  _keyStateSize = 4*((maxKeyCodes()+(EVK_BITS_PER_UNIT-1))/EVK_BITS_PER_UNIT);
  _keyState     = (UInt32 *) IOMalloc(_keyStateSize);
  _codeToRepeat = (unsigned)-1;
  
  _keyboardEventTarget        = 0;
  _keyboardEventAction        = 0;
  _keyboardSpecialEventTarget = 0;
  _keyboardSpecialEventAction = 0;
  _updateEventFlagsTarget     = 0;
  _updateEventFlagsAction     = 0;
    
  if (!_deviceLock || !_keyState)  return false;

  bzero(_keyState, _keyStateSize);
  
  return true;
}
开发者ID:MomandDad,项目名称:netbook-installer,代码行数:27,代码来源:IOHIKeyboard.cpp


示例8: CreateBufferFromData

QTOCDataFormat10Ptr
CreateBufferFromData ( OSData * theData )
{

	vm_size_t          		bufferLength	= 0;
	QTOCDataFormat10Ptr		buffer			= NULL;
	
	DebugLog ( ( "CreateBufferFromData: Entering...\n" ) );
	
	DebugAssert ( ( theData != NULL ) );
	
	if ( theData == NULL )
	{
		
		DebugLog ( ( "CreateBufferFromData: theData is NULL.\n" ) );
		return NULL;
		
	}
	
	bufferLength = theData->getLength ( );
	buffer		 = ( QTOCDataFormat10Ptr ) IOMalloc ( bufferLength );
		
	if ( buffer != NULL )
	{
		
		// Copy the bytes into the buffer
		bcopy ( theData->getBytesNoCopy ( ), buffer, bufferLength );
		
	}
	
	DebugLog ( ( "CreateBufferFromData: exiting.\n" ) );
	
	return buffer;
	
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:35,代码来源:AppleCDDAFileSystemUtilities.cpp


示例9: sizeof

bool IOFWPseudoAddressSpaceAux::createMemberVariables( void )
{
	bool success = true;
	
	if( fMembers == NULL )
	{
		// create member variables
		
		if( success )
		{
			fMembers = (MemberVariables*)IOMalloc( sizeof(MemberVariables) );
			if( fMembers == NULL )
				success = false;
		}
		
		// zero member variables
		
		if( success )
		{
			bzero( fMembers, sizeof(MemberVariables) );
		}
		
		// clean up on failure
		
		if( !success )
		{
			destroyMemberVariables();
		}
	}
	
	return success;
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:32,代码来源:IOFWPseudoAddressSpace.cpp


示例10: OSDynamicCast

bool VoodooI2CHIDDevice::probe(IOService* device) {

    
    hid_device = (I2CDevice *)IOMalloc(sizeof(I2CDevice));
    
    //hid_device->_dev = _controller->_dev;
    
    if (!super::start(device))
        return false;
    
    
    hid_device->provider = OSDynamicCast(IOACPIPlatformDevice, device);
    hid_device->provider->retain();
    
    int ret = i2c_get_slave_address(hid_device);
    if (ret < 0){
        IOLog("%s::%s::Failed to get a slave address for an I2C device, aborting.\n", getName(), _controller->_dev->name);
        IOFree(hid_device, sizeof(I2CDevice));
        return false;
    }
    
    
    IOLog("%s::%s::HID Probe called for i2c 0x%02x\n", getName(), _controller->_dev->name, hid_device->addr);
    
    initHIDDevice(hid_device);
    
    //super::stop(device);
    return 0;
}
开发者ID:nuudles,项目名称:VoodooI2C,代码行数:29,代码来源:VoodooI2CHIDDevice.cpp


示例11: QueueRead

// Queue a read on a controller
bool WirelessGamingReceiver::QueueRead(int index)
{
    IOUSBCompletion complete;
    IOReturn err;
    WGRREAD *data;
    
    data = (WGRREAD*)IOMalloc(sizeof(WGRREAD));
    if (data == NULL)
        return false;
    data->index = index;
    data->buffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task, 0, GetMaxPacketSize(connections[index].controllerIn));
    if (data->buffer == NULL)
    {
        IOFree(data, sizeof(WGRREAD));
        return false;
    }

    complete.target = this;
    complete.action = _ReadComplete;
    complete.parameter = data;
    
    err = connections[index].controllerIn->Read(data->buffer, 0, 0, data->buffer->getLength(), &complete);
    if (err == kIOReturnSuccess)
        return true;
        
    data->buffer->release();
    IOFree(data, sizeof(WGRREAD));
    
//    IOLog("read - failed to start (0x%.8x)\n", err);
    return false;
}
开发者ID:derekvanvliet,项目名称:Xbox360ControllerManager,代码行数:32,代码来源:WirelessGamingReceiver.cpp


示例12:

bool
ZFSDatasetProxy::init(OSDictionary *properties)
{
	char *str = (char *)IOMalloc(1);

	if (!str) {
		dprintf("string allocation failed\n");
		return (false);
	}
	str[0] = '\0';
	vendorString = str;
	revisionString = str;
	infoString = str;

	if (IOBlockStorageDevice::init(properties) == false) {
		dprintf("BlockStorageDevice start failed");
		goto error;
	}

	return (true);

error:
	if (str) {
		vendorString = 0;
		revisionString = 0;
		infoString = 0;
		IOFree(str, 1);
	}
	return (false);
}
开发者ID:cbreak-black,项目名称:zfs,代码行数:30,代码来源:ZFSDatasetProxy.cpp


示例13: shadowBios

bool GeforceSensors::shadowBios()
{
    struct nouveau_device *device = &card;

    //try to load bios from registry first from "vbios" property created by Chameleon boolloader
    if (OSData *vbios = OSDynamicCast(OSData, pciDevice->getProperty("vbios"))) {
        device->bios.size = vbios->getLength();
        device->bios.data = (u8*)IOMalloc(card.bios.size);
        memcpy(device->bios.data, vbios->getBytesNoCopy(), device->bios.size);
    }

    if (!device->bios.data || !device->bios.size || nouveau_bios_score(device, true) < 1) {
        if (nouveau_bios_shadow(device)) {
            //nv_info(device, "early shadow VBIOS succeeded\n");
        }
        else {
            if (device->bios.data && device->bios.size) {
                IOFree(card.bios.data, card.bios.size);
                device->bios.data = NULL;
                device->bios.size = 0;
            }
            return false;
        }
    }

    return true;
}
开发者ID:MagOO33,项目名称:HWSensors,代码行数:27,代码来源:GeforceSensors.cpp


示例14: start

bool Core99NVRAM::start(IOService *provider)
{
  IOMemoryMap        *nvramMemoryMap;
  unsigned long      gen1, gen2;
  
  // Get the base address for the nvram.
  nvramMemoryMap = provider->mapDeviceMemoryWithIndex(0);
  if (nvramMemoryMap == 0) return false;
  nvramBaseAddress = (unsigned char *)nvramMemoryMap->getVirtualAddress();
  
  // Allocte the nvram shadow.
  nvramShadow = (unsigned char *)IOMalloc(kCore99NVRAMSize);
  if (nvramShadow == 0) return false;

  // Find the current nvram partition and set the next.
  gen1 = validateGeneration(nvramBaseAddress + kCore99NVRAMAreaAOffset);
  gen2 = validateGeneration(nvramBaseAddress + kCore99NVRAMAreaBOffset);
  
  if (gen1 > gen2) {
    generation = gen1;
    nvramCurrent = nvramBaseAddress + kCore99NVRAMAreaAOffset;
    nvramNext    = nvramBaseAddress + kCore99NVRAMAreaBOffset;
  } else {
    generation = gen2;
    nvramCurrent = nvramBaseAddress + kCore99NVRAMAreaBOffset;
    nvramNext    = nvramBaseAddress + kCore99NVRAMAreaAOffset;
  }
  
  // Copy the nvram into the shadow.
  bcopy(nvramCurrent, nvramShadow, kCore99NVRAMSize);
  
  return super::start(provider);
}
开发者ID:AzerTyQsdF,项目名称:osx,代码行数:33,代码来源:Core99NVRAM.cpp


示例15: IOFree

bool FakeSMCKey::setValueFromBuffer(const void *aBuffer, UInt8 aSize)
{
	if (!aBuffer || aSize == 0) 
		return false;
	
	if (aSize != size) {
		if (value)
			IOFree(value, size);
		
		size = aSize;
		
		if (!(value = IOMalloc(size)))
			return false;
	}
	
	bcopy(aBuffer, value, size);
	
	if (handler) {       
		IOReturn result = handler->callPlatformFunction(kFakeSMCSetValueCallback, false, (void *)key, (void *)value, (void *)size, 0);
		
		if (kIOReturnSuccess != result)
			HWSensorsWarningLog("value changed event callback error for key %s, return 0x%x", key, result);
	}
	
	return true;
}
开发者ID:alexandrezia,项目名称:HWSensors,代码行数:26,代码来源:FakeSMCKey.cpp


示例16: sizeof

bool IOFWCompareAndSwapCommand::createMemberVariables( void )
{
	bool success = true;
	
	if( fMembers == NULL )
	{
		// create member variables
		
		if( success )
		{
			fMembers = (MemberVariables*)IOMalloc( sizeof(MemberVariables) );
			if( fMembers == NULL )
				success = false;
		}
		
		// zero member variables
		
		if( success )
		{
			bzero( fMembers, sizeof(MemberVariables) );
		}
		
		// clean up on failure
		
		if( !success )
		{
			destroyMemberVariables();
		}
	}
	
	return success;
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:32,代码来源:IOFWCompareAndSwapCommand.cpp


示例17: rndisSetPacketFilter

bool HoRNDIS::rndisSetPacketFilter(uint32_t filter) {
	union {
		unsigned char *buf;
		struct rndis_msg_hdr *hdr;
		struct rndis_set *set;
		struct rndis_set_c *set_c;
	} u;
	int rc;
	
	u.buf = (unsigned char *)IOMalloc(RNDIS_CMD_BUF_SZ);
	if (!u.buf) {
		LOG(V_ERROR, "out of memory?");
		return false;;
	}
	
	memset(u.buf, 0, sizeof *u.set);
	u.set->msg_type = RNDIS_MSG_SET;
	u.set->msg_len = cpu_to_le32(4 + sizeof *u.set);
	u.set->oid = OID_GEN_CURRENT_PACKET_FILTER;
	u.set->len = cpu_to_le32(4);
	u.set->offset = cpu_to_le32((sizeof *u.set) - 8);
	*(uint32_t *)(u.buf + sizeof *u.set) = filter;
	
	rc = rndisCommand(u.hdr, RNDIS_CMD_BUF_SZ);
	if (rc != kIOReturnSuccess) {
		LOG(V_ERROR, "SET not successful?");
		IOFree(u.buf, RNDIS_CMD_BUF_SZ);
		return false;
	}
	
	IOFree(u.buf, RNDIS_CMD_BUF_SZ);
	
	return true;
}
开发者ID:burnsra,项目名称:HoRNDIS,代码行数:34,代码来源:HoRNDIS.cpp


示例18: start

// Standard IOService.h function methods
bool AppleUSBAudioPlugin::start (IOService * provider) {
	if (!super::start (provider)) 
	{
		return FALSE;
	}

	reserved = (ExpansionData *)IOMalloc (sizeof(struct ExpansionData));
	if (!reserved) {
		return FALSE;
	}

	reserved->streamProvider = OSDynamicCast (AppleUSBAudioStream, provider);
	
	if (reserved->streamProvider)
	{
		// Tell AppleUSBAudioStream that we're loaded
		reserved->streamProvider->registerPlugin (this);
	}
	else
	{
		mOurProvider = OSDynamicCast (AppleUSBAudioEngine, provider);

		if (mOurProvider)
		{
			// Tell AppleUSBAudioEngine that we're loaded
			mOurProvider->registerPlugin (this);
		}
	}
	
	return TRUE;
}
开发者ID:clarkewd,项目名称:AppleUSBAudio-273.4.1,代码行数:32,代码来源:AppleUSBAudioPlugin.cpp


示例19: IOMalloc

IOReturn HoRNDIS::getHardwareAddress(IOEthernetAddress *ea) {
	UInt32	  i;
	void *buf;
	unsigned char *bp;
	int rlen = -1;
	int rv;
	
	buf = IOMalloc(RNDIS_CMD_BUF_SZ);
	if (!buf)
		return kIOReturnNoMemory;
	
	rv = rndisQuery(buf, OID_802_3_PERMANENT_ADDRESS, 48, (void **) &bp, &rlen);
	if (rv < 0) {
		LOG(V_ERROR, "getHardwareAddress OID failed?");
		IOFree(buf, RNDIS_CMD_BUF_SZ);
		return kIOReturnIOError;
	}
	LOG(V_DEBUG, "MAC Address %02x:%02x:%02x:%02x:%02x:%02x -- rlen %d",
	      bp[0], bp[1], bp[2], bp[3], bp[4], bp[5],
	      rlen);
	
	for (i=0; i<6; i++)
		ea->bytes[i] = bp[i];
	
	IOFree(buf, RNDIS_CMD_BUF_SZ);
	return kIOReturnSuccess;
}
开发者ID:burnsra,项目名称:HoRNDIS,代码行数:27,代码来源:HoRNDIS.cpp


示例20: IOFree

//==============================================================================
// IOHIDEvent::initWithCapacity
//==============================================================================
bool IOHIDEvent::initWithCapacity(IOByteCount capacity)
{
    if (!super::init())
        return false;

    if (_data && (!capacity || _capacity < capacity) ) {
        // clean out old data's storage if it isn't big enough
        IOFree(_data, _capacity);
        _data = 0;
    }

    _capacity = capacity;

    if ( !_capacity )
        return false;

    if ( !_data && !(_data = (IOHIDEventData *) IOMalloc(_capacity)))
        return false;

    bzero(_data, _capacity);
    _data->size = _capacity;
    _children = NULL;
    
    clock_get_uptime(&_creationTimeStamp);

    return true;
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:30,代码来源:IOHIDEvent.cpp



注:本文中的IOMalloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ IOMasterPort函数代码示例发布时间:2022-05-30
下一篇:
C++ IOMUX_TO_IRQ函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap