本文整理汇总了C++中IOMalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ IOMalloc函数的具体用法?C++ IOMalloc怎么用?C++ IOMalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOMalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}