I'm using DriverKit in my iPadOS.
I'm trying to create a IOBufferMemoryDescriptor
and add the data I've got in an OSData
object.
I'm creating the IOBufferMemoryDescriptor
with:
ret = ivars->interface->CreateIOBuffer(kIOMemoryDirectionOut,
length,
&myBuffer);
Although I think it can be created with this too:
IOBufferMemoryDescriptor::Create(kIOMemoryDirectionOut, length, 0, &mybuffer);
How do I add the data from my OSData
object. I've seen examples of:
IOMemoryDescriptor *buffer = IOMemoryDescriptor::withAddress((void*)firmwareData->getBytesNoCopy(), firmwareData->getLength(), kIODirectionOut);
(from How to use deviceRequest of IOUSBHostDevice / IOUSBHostInterface? )
But that method doesn't seem to work in DriverKit.
I've also tried Mapping the Buffer:
uint64_t bufferAddress;
uint64_t bufferLength;
ret = myBuffer->Map(0, 0, 0, 0, &bufferAddress, &bufferLength);
and then copying the data with:
memcpy(reinterpret_cast<void*>(bufferAddress), inputOsData->getBytesNoCopy(), length);
But this would always make the driver to crash when tries to run the memcpy
Thanks