DriverKit

RSS for tag

Develop device drivers that run in user space using DriverKit.

DriverKit Documentation

Posts under DriverKit tag

71 Posts
Sort by:
Post not yet marked as solved
1 Replies
421 Views
I declare a structure type in swift, name as CmdStruct struct CmdStruct { var cmd:[UInt8] init() { cmd = [UInt8](repeating: 0, count:16) } } In the case that the connection has been obtained. In sendCmd function, declare a variable which name as input which type of CmdStruct. After set data to input, call a DriverKit function IOConnectCallStructMethod. Here xcode shows a warning tip for the parameter 'input' for call IOConnectCallStructMethod: <Forming 'UnsafeRawPointer' to a variable of type 'CmdStruct'; this is likely incorrect because 'CmdStruct' may contain an object reference.> func sendCmd() { var ret:kern_return_t = kIOReturnSuccess var input = cmdStruct() var output:[UInt8] = [UInt8](repeating:0, count: 16) var inputSize = MemoryLayout<CmdStruct>.size // print value 8 var outputSize = output.count // print value 16 input.cmd[0] = 0x12 input.cmd[1] = 0x34 ret = IOConnectCallStructMethod(Connection, selector, &input, inputSize, &output, &outputSize) } In C file, driverkit function ExternalMethod will receive the parameter from swift side. And check the value of input->cmd[0] and input->cmd[1] in console. However, the values are not the expected 0x12 and 0x34. struct CmdStruct { uint8_t cmd[16]; }; kern_return_t myTest::ExternalMethod(uint64_t selector, IOUserClientMethodArguments* arguments, const IOuserClientMethodDispatch* dispatch, OSObject* target, void* reference) { int i = 0; CmdStruct* input = nullptr; if (arguments == nullptr) { ret = KIOReturnBadArgument; } if (arguments->structureInput != nullptr) { input = (CmdStruct*)arguments->structureInput->getBytestNoCopy(); } /* Here to print input->cmd[0] and input->cmd[1] data to console. */ } I expect that the correct value of input will be show on the driverkit side. I'm not sure which part is wrong. Here, I list some factors that may lead to incorrect value. How to fix the warning tip for parameter 'input' when call IOConnectCallStructMethod in swift. I get the inputSize value 8 by using MemoryLayout.size. But this structure contains a 16 bytes array. How to get the correct struct size in swift In C file side, using (CmdStruct*)arguments->structureInput->getBytestNoCopy() to transform data to C struct is correct?
Posted
by JMicron.
Last updated
.
Post marked as solved
2 Replies
715 Views
Hey! I'am trying to write my own driver for usb serial device. I'am trying to subclass from IOUserUSBSerial #include <DriverKit/IOService.iig> #include <USBSerialDriverKit/IOUserUSBSerial.iig> class NewDriver: public IOUserUSBSerial { public:     virtual kern_return_t     Start(IOService * provider) override; }; but get a lot of errors such as   "IOUserUSBSerial::handleRxPacket(unsigned char*&, unsigned int&)", referenced from:       vtable for NewDriver in NewDriver.iig.o   "IOUserUSBSerial::handleInterruptPacket(unsigned char const*, unsigned int)", referenced from:       vtable for NewDriver in NewDriver.iig.o   "IOUserUSBSerial::free()", referenced from:       vtable for NewDriver in NewDriver.iig.o   "IOUserUSBSerial::init()", referenced from:       vtable for NewDriver in NewDriver.iig.o   "IOUserUSBSerial::initWith(IOBufferMemoryDescriptor*)", referenced from:       vtable for NewDriver in NewDriver.iig.o   "IOUserUSBSerial::_Dispatch(IOUserUSBSerial*, IORPC)", referenced from:       NewDriver::Start_Impl(IOService*) in NewDriver-e6d71af2158103084ce0c1eba7c6088d.o       NewDriver::_Dispatch(NewDriver*, IORPC) in NewDriver.iig.o   "vtable for IOUserSerial", referenced from:       IOUserSerial::IOUserSerial() in NewDriver.iig.o   NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.   "vtable for IOUserUSBSerial", referenced from:       IOUserUSBSerial::IOUserUSBSerial() in NewDriver.iig.o   NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.   "non-virtual thunk to IOUserUSBSerial::free()", referenced from:       vtable for NewDriver in NewDriver.iig.o   "non-virtual thunk to IOUserUSBSerial::init()", referenced from:       vtable for NewDriver in NewDriver.iig.o   "non-virtual thunk to IOUserUSBSerial::initWith(IOBufferMemoryDescriptor*)", referenced from:       vtable for NewDriver in NewDriver.iig.o   "non-virtual thunk to IOUserUSBSerial::handleRxPacket(unsigned char*&, unsigned int&)", referenced from:       vtable for NewDriver in NewDriver.iig.o   "non-virtual thunk to IOUserUSBSerial::handleInterruptPacket(unsigned char const*, unsigned int)", referenced from:       vtable for NewDriver in NewDriver.iig.o ld: symbol(s) not found for architecture x86_64 If I making any implementations of this methods errors staying on. What Im doing wrong? Is there anywhere examples for USBSerialDriverKit? Didn't find anything on github
Posted
by svedm.
Last updated
.
Post not yet marked as solved
2 Replies
1.1k Views
I'm working on a DriverKit driver. I have it running on macOS, including a very simple client app written in SwiftUI. Everything is working fine there. I've added iPadOS as a destination for the app as demonstrated in the WWDC video on DriverKit for iPadOS. The app builds and runs on my iPad, as expected (after a little work to conditionalize out my use of SystemExtensions.framework for installation on macOS). However, after installing and running the app on an iPad, the driver does not show up in Settings->General, nor in the app-specific settings pane triggered by the inclusion of a settings bundle in the app. I've confirmed that the dext is indeed being included in the app bundle when built for iPadOS (in MyApp.app/SystemExtensions/com.me.MyApp.MyDriver.dext). I also can see in the build log that there's a validation step for the dext, and that seems to be succeeding. I don't know why the app isn't being discovered -- or in any case surfaced to the user -- when the app is installed on the iPad. Has anyone faced this problem and solved it? Are there ways to troubleshoot installation/discovery of an embedded DriverKit extensions on iOS? Unlike on macOS, I don't really see any relevant console messages.
Posted
by armadsen.
Last updated
.
Post not yet marked as solved
3 Replies
472 Views
In a project, I'm using the DriverKit(and HIDDriverKit) framework. I have encountered a problem in the connection between the client app and the driver, which is implemented by the "IOKit" framework. By calling the function "IOServiceGetMatchingServices" the value of "iterator" returns correctly and then communication with the driver is done. However, after releasing the version on the TestFlight, on some systems, the value of the "iterator" returned 0 and it is not possible to communicate with the driver. I checked the status of the activated driver with the command "systemextensionsctl list" and there are no problems on the driver side and the values of "Enabled" and "Active" are starred. AppSandbox = True, SIP: enable ret = IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceNameMatching(dextIdentifier), &iterator); if (ret != kIOReturnSuccess) { goto fail; } while ((service = IOIteratorNext(iterator)) != IO_OBJECT_NULL) { ret = IOServiceOpen(service, mach_task_self(), 0, &connection); if(ret == kIOReturnSuccess) { break; } else { syslog(LOG_WARNING, "IDmelonLog LIB: Can't open service"); } IOObjectRelease(service); }
Posted
by Jafar96.
Last updated
.
Post not yet marked as solved
2 Replies
460 Views
I am currently in the process of developing a DEXT for a USB based external mass storage device using the USBDriverKit framework. IOUSBHostInterface is used as the provider to communicate with the interface's endpoints and I am successful in it. As per the IOUSBHostInterface documentation, To use a host interface object, call Open to create a new session between the interface and your driver. After successfully opening your session, you can request information from the interface and set up pipes to communicate with the interface's endpoints. Remember to close the session you opened in the Stop method of your driver. However, calling Open gains exclusive access to the USB interface and does not allow other services to access the interface. Also, to let go of the exclusive access, Close method can be called but in the Stop method which is called only once during the lifecycle of the extension (when the DEXT is unloaded). As a result of this, Apple's mass storage related KEXTs (media and partition related specifically) do not match the interface and so the filesystem of the drive in question does not get mounted whenever the DEXT has matched the interface. Is this exclusive access a limitation of USBDriverkit or is there any way to get around this issue in this case?
Posted Last updated
.
Post marked as solved
1 Replies
672 Views
I have a dext target in a project which fails to install on my iPad because "the code signature version is no longer supported". Indeed, when I look at the built dext (before or after is has been copied into the hosting app's System Extensions folder), codesign -dv tells me that it has CodeDirectory = 20200. The hosting app has CodeDirectory = 20400. Curiously, in the same workspace, I have another iOS app which hosts another version of the driver (using the same source code files). The other app is a minimal test app. It is signed with CodeDirectory = 20500 and the driver has CodeDirectory = 20400 inside this minimal app. In both the more complex target and the simple target, the codesign invocation has the same options. Only the provisioning profile and the name of the dext differs between the working and non-working version. Here are the options, on multiple lines to make them easier to read /usr/bin/codesign --force --sign D0...A0F (same for both) -o runtime --entitlements <path to driver>.dext.xcent --timestamp\=none --generate-entitlement-der <path to driver.dext> I've searched high and low for a solution to this problem, but found none. It has come up before, in particular here https://developer.apple.com/forums/thread/683214?answerId=679712022#679712022 I'm using Xcode 15 on macOS Sonoma 14.0. I've thrown away the Derived Data for the project, I've thrown away the ModuleCache.index and the SymbolCache.index I've restarted my Mac. I've restarted the iPad. There's no legacy code here. This is all new, newly built and signed by a new version of Xcode. But I don't seem to have any control over what version of signature Xcode chooses to use - what influences that? Obviously there's some difference, perhaps in the hosting app or target, between the environment where everything works and where nothing works. If it helps, the more complex app was already built, signed and deployed to the App Store without a driver. The driver is under development, and it is a new addition to the target, so the existing Identifier, Certificate and Profile for the app pre-date the addition of the embedded driver target. Any ideas. Anyone?
Posted
by ssmith_c.
Last updated
.
Post not yet marked as solved
2 Replies
324 Views
In my application, I have used DriverKit USB Transport - VendorID. Now whenever I am trying to install my application using driver kit development profile, it throws me error that profile is not valid. Now, If I try to install the app using Adhoc profile, then I am able to install it. Can you update us, is there any changes are there in 17.1 OS with development profile.
Posted
by Rushita.
Last updated
.
Post marked as solved
1 Replies
354 Views
I'm trying to find extension by name with following code: static const char* dextIdentifier = "someDextName"; CFMutableDictionaryRef cfd = IOServiceNameMatching(dextIdentifier); int nMatch = (int)CFDictionaryGetCount(cfd); printf("nMatch=%d\n",nMatch); const void *keys[nMatch], *values[nMatch]; CFDictionaryGetKeysAndValues(cfd, keys, values); for(int e=0; e < nMatch; e++) { char key[100] = "", value[100] = ""; if(CFStringGetCString(reinterpret_cast<CFStringRef>(keys[e]), key, sizeof(key), kCFStringEncodingASCII)) { printf("Key: %s\n",key); } if(CFStringGetCString(reinterpret_cast<CFStringRef>(values[e]), value, sizeof(value), kCFStringEncodingASCII)) { printf("Value: %s\n",key); } } Regardless of dextIdentifier value IOServiceNameMatching always returns single record (nMatch = 1), where key = "IONameMatch" and value = It doesn't matter whether the specified extension name exists or not There is the single extension in the system, according to 'systemextensionsctl list' command
Posted
by Farquaad.
Last updated
.
Post not yet marked as solved
0 Replies
332 Views
I have created a USB filter using Mac DriverKit, but the filter is unable to retrieve configuration information during startup. After the USB filter has started and registered the service, my app can send the configuration information to the filter. Therefore, I would like to know if there is a way to exit the USB filter and allow the system to take control of the USB device once the filter has exited. I have tried calling Terminate(0), but it did not work as even after the USB filter exited, the Finder still couldn't display the USB device.
Posted
by emerys.
Last updated
.
Post marked as solved
7 Replies
4.3k Views
Xcode version : 14.0 Beta 3 macOS version : 13 Beta 3(22A5295i) Hi, I'm signing the DriverKit in Developer ID Application type profile with Developer ID Application (With Kext) type certificate on Xcode. But status shows error with"Xcode 14 and later requires a DriverKit development profile enabled for IOS and macOS.Visit the developer website to create or download a DriverKit profile" I have downloaded all profiles and Certificates to my Mac and installed all of them, then checked the website. I'm wondering what's different between "Development type" &amp; "Developer ID Application type" profile ? and the reason why "2022-07-22 14:41:54.162815+0800 0x22ee2    Error       0x0                  138    0    kernelmanagerd: Error occurred while handling request "DextLaunch(arguments: Optional(["Driver Extension Server Name": com.asix.dext.usbdevice, "Check In Token": 371, "Driver Extension Server Tag": 4294975444, "CFBundleIdentifier": com.asix.dext.usbdevice, "DriverKit Reslide Shared Cache": 0, "kOSBundleDextUniqueIdentifier": &lt;222f1e51 f5e890f7 b467c2a0 da761dbd 9b14dc5f 1bf56ff6 4eeab6b2 fed9683c&gt;]))": Error Domain=NSPOSIXErrorDomain Code=8 "Exec format error" error code show on when I starting the app. I'll appreciate that someone can give me some idea or suggestions. Thanks a lot.
Posted
by asix.
Last updated
.
Post not yet marked as solved
0 Replies
336 Views
I want to use DriverKit to develop a USBDriver, which serves as a bridge between USB devices and the system. All messages between USB devices and the system will be forwarded through the USBDriver. Can anyone give me some tips or suggestions? What API should I use? I couldn't find anything like this in the documentation or sample code. class MyUSBDriver: public IOUserClient { public: virtual bool init() override; virtual kern_return_t Start(IOService * provider) override; virtual kern_return_t Stop(IOService * provider) override; virtual void free() override; virtual kern_return_t GetRegistryEntryID(uint64_t * registryEntryID) override; virtual kern_return_t NewUserClient(uint32_t type, IOUserClient** userClient) override; virtual kern_return_t ExternalMethod(uint64_t selector, IOUserClientMethodArguments* arguments, const IOUserClientMethodDispatch* dispatch, OSObject* target, void* reference) override; }; I am now able to retrieve the device descriptor in the Start method IOUSBHostDevice *device = OSDynamicCast(IOUSBHostDevice, provider); if (device) { const IOUSBDeviceDescriptor *deviceDescriptor = device->CopyDeviceDescriptor(); if (deviceDescriptor) { uint16_t idVendor = deviceDescriptor->idVendor; uint16_t idProduct = deviceDescriptor->idProduct; uint8_t iSerialNumber = deviceDescriptor->iSerialNumber; IOUSBHostFreeDescriptor(deviceDescriptor); } }
Posted
by emerys.
Last updated
.
Post marked as solved
4 Replies
733 Views
Hi , I am trying to write dext code for my existing Kext , i see "IOMemoryDescriptor::withAddress" being used , I dont find any alternatives in "DriverKit", Is there any others ways to achieve this, Any input is appriciated , Thanks, revan
Posted
by revancse2.
Last updated
.
Post not yet marked as solved
4 Replies
2.0k Views
My application installs a system extension. When I try to remove the app from the Applications folder (cmd + backspace) I get an error message: "The operation can’t be completed right now because another operation is in progress, such as moving or copying an item or emptying the Bin." According to systemextensionsctl the extension state is "terminating for uninstall but still running". I can see an error in the console logs: kernelmanagerd Failed to terminate dext com.my.driver-dk, error: Kernel request failed: (os/kern) invalid address (1) sysextd a category delegate declined to terminate extension with identifier: com.my.driver-dk sysextd failed to terminate extension with identifier: com.my.driver-dk: Optional(Error Domain=kernelmanagerd.KMError Code=38 "(null)") Issue occurs with macOS 13 - works fine with macOS 12 and macOS 11 What is the problem here? Have there been any changes in macOS in that regard?
Posted Last updated
.
Post not yet marked as solved
0 Replies
329 Views
Hi, I'm working on a project that requires porting my KEXT driver to DriverKit system extension ( DEXT ). I've managed to re-write most of functions using DriverKit but I couldn't found a function for cancelling a scheduled timer. What I try to make is waiting for an interrupt with a timeout period. And if the interrupt arrives in certain time period I need to cancel timeout timer and send async response to the user app. I'm also open to the suggestions. Here is the code fragment for IOKit that I need to convert to DriverKit // ... initialization code fragment ( error handling parts deleted ) m_timeout_timer = IOTimerEventSource::timerEventSource(this, timer_fired_pc_recv); IOReturn result = m_workLoop->addEventSource(timer); // ... starting the timeout counter m_timeout_timer->setTimeoutMS(timeout_in_ms); // ... some time later (cancel part) m_timeout_timer->cancelTimeout(); And equivalent code in DriverKit // ... initialization code fragment ( error handling parts deleted ) ret = IOTimerDispatchSource::Create(ivars->default_dispatch_queue, &ivars->timer_dispatchSource); // starting timer timer_dispatchSource->WakeAtTime(kIOTimerClockMonotonicRaw, currentTime + fiveSecondsInNanoSeconds, twoSecondsInNanoSeconds); // missing part here I did see the member method Cancel in IOTimerDispatchSource but it is kind of termination to the lifetime of IOTimerDispatchSource
Posted
by KivancG.
Last updated
.
Post not yet marked as solved
4 Replies
1.8k Views
Hello, I am porting a PCI driver written with IOKit to the new PCIDriverKit framework. I am able to perform DMA with a contiguous buffer allocated inside the dext (with IOBufferMemoryDescriptor::Create). But I would also like to perform DMA to and from a buffer allocated by an application. What I exactly want to do is: Allocate an aligned buffer in the app (with e.g. posix_memalign) Send the pointer to this buffer to the dext In the dext, retrieve the list of pages descriptors to be able to perform DMA without copy into (or from) this buffer. In IOKit, we can use methods such IOMemoryDescriptor::withAddressRange and IODMACommand::gen64IOVMSegments to map and retrieve the scatter gather list but I cannot find any information on how to do this in a dext with the PCIDriverKit framework. Can anybody help me on how to do that?
Posted
by Benoit55.
Last updated
.
Post not yet marked as solved
2 Replies
556 Views
Hi All, Is there a limit on the data size of input and output in IOConnectCallStructMethod? I am working with CommunicatingBetweenADriverKitExtensionAndAClientApp. It seems there a buffer size limit in OversizedDataStruct in the sample code. typedef struct { uint64_t foo; uint64_t bar; uint64_t largeArray[511]; } OversizedDataStruct; If I tested by changing 511 to 0x1E00000(30MB), I got below error. Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f20fff8) I need to get large image data(over 30 MBytes) from driver(dext) to user client application. How can I transfer more than 30MB of data from driver to App with IOConnectCallStructMethod? Or is there any other way without using IOConnectCallStructMethod? Please help.
Posted
by daqsystem.
Last updated
.
Post not yet marked as solved
0 Replies
430 Views
For those of us working on drivers for DriverKit, much of the example documentation is confusing, outdated, or just not an actual working example of the latest DriverKit feature set. This post might be of some help to you. I have published a fully working client sample app example that adds iPadOS support alongside macOS and updates to the latest driverkit version: https://github.com/DanBurkhardt/DriverKitUserClientSample This should be immediately runnable, but you will have to ensure you disable SIP and enable developer mode, as per the original README (this is required without DriverKit entitlement permission from Apple). You will also need to, of course, change the bundle ID to your own name (replace "gigabitelabs" with something that is specific to your dev account / business). Lmk if you have any issues, I'm happy to help you get this running so you can get the initial part of DriverKit testing out of the way. Happy hacking, Dan
Posted Last updated
.
Post not yet marked as solved
0 Replies
236 Views
By default Driver kit is disabled in settings app when my app is first installed. I want to show notification to user to enable driverkit whenever i detect driverkit is not enabled or disabled. How do my app know whether driverkit is enabled or disabled? Any pointer for above question will be very helpful.
Posted Last updated
.
Post not yet marked as solved
2 Replies
696 Views
Failed to verify code signature of /var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.yOSaDQ/extracted/SimpleAudio.app/SystemExtensions/com.xreal.nrsdk.driver.demo.Driver.dext : 0xe8008015 (A valid provisioning profile for this executable was not found.) Verify that the Developer App certificate for your account is trusted on your device. Open Settings on the device and navigate to General -> VPN & Device Management, then select your Developer App certificate to trust it.
Posted
by pxhero.
Last updated
.