-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use the new macOS kernel detach feature for non-root user #1014
Comments
Apple documentation on USB driver development is very poor. And the documentation for the entitlement is also very poor. https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_vm_device-access You configure entitlements for your app by declaring capabilities for a target in Xcode. Xcode records capabilities that you add in a property list file with the .entitlements extension. You can also edit the entitlements file directly. When code signing your app, Xcode combines the entitlements file, information from your developer account, and other project information to apply a final set of entitlements to your app. |
#911 (comment)
Please tell what you have done and what is the outcome. Thanks. |
@llinshenzhen You got the entitlement from Apple Developer support, created a provisioning profile with that entitlement, and built your app with that profile? Note that command line apps cannot use provisioning profiles and therefore cannot hold this entitlement. |
@osy Great info. I've updated the FAQ here. |
@osy Replied from Apple Developer Technical Support
I'm using libuvc for my microscope software. |
@scchn |
I'm stuck at got an Entitlement from Apple, I checked the official website and emailed them about this, still waiting reply from them. From official info as @scchn provided, it's might be not the correct solution of getting entitlement 'com.apple.vm.device-access' from Apple for those who needed to control and streaming UVC Camera inside macOS app. Kinda upset. |
I added entitlement value 'com.apple.vm.device-access', and compiled libUSB turned on debug mode and confirmed that the entitlement or sudo privilege is needed. And 'sudo' can truly solved the problem, but as macOS app I needed entitlement solution other than sudo for better experience. |
@mcuee They only told me to file a bug about it...
|
I don’t think you guys understand… you don’t “get” the entitlement without Apple granting you a provisioning profile with it. Just adding it to your entitlements and ad-hoc signing it won’t work. This is impossible without Apple’s help. |
My understanding is that this entitlement will be granted for non-VM Apps given that Apple is moving away from kernel-space drivers. If that is the case they really should change the name of the entitlement. Let us know what Apple says in their response. |
I don’t think so. Apple has always held certain entitlements close to the chest. |
@osy Apparently "com.apple.vm.device-access" works in practice. The main question is whether "com.apple.vm.device-access" is the right entitlement or not. And we need Apple's answer for this one. |
@llinshenzhen 'sudo' is probably just a work-around for testers like I since I am not an Apple developer, just a user/tester. |
Thanks, your understanding is correct. 'sudo' can stream the UVC camera and able to control it, but same as you mention, this is not good enough. This workaround is inspired by libUSB source code:
About entitlement I'm facing 2 issues, firstly, as mentioned above this entitlement is for 'the guest-operating system', and second one is that this entitlement doesn't have open entry to request, can only contact Apple by email and I have no response from them so far. Because end-users who upgraded their macOS to 12 can not control the camera we are selling, but other app like OBS can stream at least, we are facing lots of complaints. |
You can not get around the second one as you can see from the answer from osy. Please try to get the first answer from Apple. Apparently it does work. It is just whether Apple will want to grant your request or not.
You may want to check how OBS works with USB cameras under macOS. In the end, libuvc/libusb may not be the right API to use if the system has already provided the video capture APIs. It seems to be more useful under Linux. libuvc main git tree does not even compile properly under Windows. |
I was using libuvc to conveniently test real-time processing of webcam images by importing them to my mac. However, when I upgraded to macOS Monterey for other reasons, I encountered a problem, and finally came to this issue. If libusb will not be able to support macOS Monterey for a long time in the future, I will have to change my implementation to use other libraries, (but I have not been able to find a cross-platform library other than libuvc (+libusb) that can be used to import and control webcams.) Is there any chance that libusb can overcome this problem? |
Not so sure why you say libusb is not able to support macOS Monterey. It supports macOS Monterey properly. As for libusb/libuvc for the UVC compatible cameras, apparently that is an Apple issue that they grab the device for exclusive access, unlike previous version of macOS. And apparently libusb git and libuvc work with macOS Monterey if you can get the provision profile from Apple for the "com.apple.vm.device-access" entitlement. The discussion is whether it is possible to get the approval or not as some Apple support personnel think it is not the right entitlement. You need to be an Apple developer and contact Apple for help in this case. You can also file a bug report with Apple saying macOS Monterey does not work with devices previously working under earlier version of macOS. Maybe they will fix it. On the other hand, libuvc does not seem to work well under Windows. Are you using libuvc under Windows? If you are already not using libuvc under Windows, then probably it is also okay not to use libuvc under macOS. Apparently new version of OBS Studio works under macOS Monterey and it does not use libuvc. |
How do I obtain the com.apple.vm.device-access permission |
Answer from osy. |
I see. But, I'm in trouble. My App is a simple command line App for scientific experiments. Since my app is built with cmake, I can create xcproject by adding "-G Xcode" to the cmake options, and then use xcode to build it with "com.apple.vm.device-access " entitlement in xcode. |
Not sure that will help at all. cmake can generate a generic xcode project but it will take hand editing to make it work. cmake makes it seem easy but, like most things with cmake, it is far more complicated than that. I found this that may help: https://stackoverflow.com/questions/57396522/setting-entitlements-on-executables Looks like you need to create an Info.plist and embed it in your binary. |
Reiterating my comment from above
Provisioning profiles != entitlements. Some entitlements do not need a provisioning profiles. This particular entitlement does. |
@osy Ok, that makes sense. You need an embedded Info.plist to have any entitlements with a command line executable but this entitlement requires more than just that. Keeps going back to thinking that it would be nice if Apple were to create a new entitlement for our purpose. We want the ability to provide user-space interaction of user-space devices that may have a matching kernel driver. |
This should be closed, cause Apple won't grant entitlement for non-vm system as they replied. And they won't answer any third-party issue detail either, like libusb. The only way to solve this is to ask user to authorize the app when you start, but that will bring other issues like, other cam will stop stream when you authorize your app to stream from libuvc. In all, if you are looking for solution to stream and control uvc camera the same time, libuvc is not the one you looking for. |
You described that there is a self-compiled version of libuvc on the macOS12 system. Does it require root privileges? Is this done? I also encountered this problem. Could you please tell me about the latest development of libuvc&libusb under macOS12? (wuxiao1129@foxmail.com) |
There is a workaround (for older mac versions other than Monterey for this entitlement issue). When opening the UVC, don't claim the USB interface. Only claim the USB interface right before write or read the UVC property and release it right after write/read. For windows, the libuvc won't work for streaming and uvc control at same time, use Media Foundation (MF) or DirectShow (DS) instead. |
I have updated the wiki here. It does not help to sort out the issue though -- I just try to document what we have now. |
-> Test rebuild for claiming of interfaces on Windows. Note that if a macOS kernel driver (kext) has already claimed exclusive access to the device, then this will only work by detaching the kernel driver, which requires you to run octave or matlab as root. Only tested by myself with octave via "sudo octave" so far. For the hoops you have to jump through on macOS to get this working without sudo, read this FAQ: https://github.com/libusb/libusb/wiki/FAQ#how-can-i-run-libusb-applications-under-mac-os-x-if-there-is-already-a-kernel-extension-installed-for-the-device-and-claim-exclusive-access Executive summary: Give up, or be prepared to suffer greatly! Technical discussion thread which shows Apples "We don't care about this problem. Get lost!" attitude to this problem, as of macOS 12 at least: libusb/libusb#1014 => Best hope is that your USB device does not have an associated kernel driver, otherwise things get really painful, or expensive and painful on macOS if one wants to use any data transfers involving interface endpoints, e.g., USB bulk or interrupt transfers, to control USB devices.
Ultimate solution is to override the default USB video class extension
This should work. Basically it is a bit similar to previously used method -- codeless kext, now it is codeless DriverKit extension. You do need to have the valid developer signature in order to load the extension.
The main drawback compared to previous situation is that it will no longer function as a UVC camera and you can only use libuvc. It may be okay for certain use cases though. If possible, I think it is better not to use libusb/libuvc in this case. It was the same situation last time with HID device. Later HIDAPI project was launched to use native HID API under Mac OS X (now macOS). Maybe the application should use native macOS API now. |
Deprecated on macOS 10.15 and fully obsolete on macOS 11.0. |
So now there is a solution for libuvc users and there is a success story here. The idea may be similar for other types of device. I have closed $972 (specific to libuvc) but I will keep this issue open. |
The following pull request is an important new feature for libusb under macOS.
But it is not clear how to use it for non-root users. It is mentioned that "com.apple.vm.device-access" entitlement is needed. But there is no clear documentation from libusb or Apple on how to apply the entitlement
The text was updated successfully, but these errors were encountered: