Missing documentation for OSMappedFile

I am working on a DriverKit project and the new class OSMappedFile sounds like something I am looking for, at least from what I understood from the description in the header file. https://developer.apple.com/documentation/driverkit/osmappedfile

I've tried different combinations, however the method OSMappedFile::createFromPath always returns an error 0xe00002bc (general error), which is not helpful at all.

Could you please provide more details about the class and how to use it? Is it possible to open an arbitrary file in an arbitrary location? Does the owner of the file matter? Does the entitlements have to be modified somehow?

Thanks for reply

I am testing it on Monterey 12.3.1, my driver is linking DriverKit 21.0, no provisioning profile, SIP is off.

Answered by in 714899022

Pulling the conversation from the comments back out to an answer for clarity. Instead of using OSMappedFile::createFromPath, try getting the file from an OSBundle like so:

OSMappedFile* myMappedFile = nullptr;
OSBundle* myBundle = OSBundle::mainBundle();
myBundle->loadResources("configfile.conf", 0, IOVMPageSize * sizeToFit, &myMappedFile);

This should work without requiring any additional entitlements, and without having to know any GUIDs.

OSMappedFile can only be used to read files in the dext's bundle. Since you are getting kIOReturnError, that means that DriverKit couldn't find the file, likely due to you not having permissions to access it. You might try to open the plist of your dext first to make sure it's working for you, and then branch out from there.

I found an error log message which confirms this is really a permission related issue. Could you please suggest how to set the permissions to make this work? Adding the bundle path to com.apple.security.temporary-exception.files.absolute-path.read-only didn't help - this entitlement is missing in the built driver, so it must have been somehow stripped during the build.

Accepted Answer

Pulling the conversation from the comments back out to an answer for clarity. Instead of using OSMappedFile::createFromPath, try getting the file from an OSBundle like so:

OSMappedFile* myMappedFile = nullptr;
OSBundle* myBundle = OSBundle::mainBundle();
myBundle->loadResources("configfile.conf", 0, IOVMPageSize * sizeToFit, &myMappedFile);

This should work without requiring any additional entitlements, and without having to know any GUIDs.

Missing documentation for OSMappedFile
 
 
Q