arphaman added a comment.

In https://reviews.llvm.org/D27827#625438, @erik.pilkington wrote:

> I seem to remember that mapping from kernel versions to marketing versions 
> was tossed around as a potential alternative to Gestalt. I think that the 
> problem was Apple sometimes introduces (or reserves the right to introduce) 
> new SDKs in a patch release (ie, Z in X.Y.Z), which wouldn't necessary imply 
> a new kernel version, and would still need to be queried by @available. This 
> makes it impossible to use kernel version in the general case (Or at least I 
> think, it would be nice if someone internal to Apple could confirm this?). 
> This rules out using `sysctl()` and the like.


This sounds like a legitimate concern, I'll try to get some information about 
this.

> AFAIK this just leaves `Gestalt()` and Objective-C's `NSProcessInfo`, the 
> latter would mean pulling in the Objective-C runtime, which would be 
> unfortunate for C users (using the `__builtin_available` spelling). I don't 
> think `Gestalt()` is in any danger of actually being removed, so we might as 
> well use it. The only alternative I know of to those would be manually 
> parsing the `SystemVersion.plist` XML file, but I think that might cause 
> problems with sandboxed processes (right?). Any thoughts here would be much 
> appreciated, `Gestalt()` is by no means a perfect solution.

Sandboxed applications are allowed to read that PLIST file, since 
https://developer.apple.com/library/content/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html
 states the applications are permitted to read files that are world readable in 
`/System`. I confirmed that with a test sandboxed app as well. It would seem 
that reading that PLIST file is a good solution if we can get access to the 
PLIST APIs from compiler-rt (+ we can always fallback to `Gestalt`/`sysctl` if 
something goes wrong).

> Compiler-rt does seem like a good place it put this, should I move the 
> runtime code there instead?

Yes, please.

Btw, compiler-rt already has code that checks which version of macOS it's 
running on 
(https://github.com/llvm-project/compiler-rt/blob/master/lib/sanitizer_common/sanitizer_mac.cc#L410).
 It uses `sysctl` as well. I'm not sure if we can somehow refactor and reuse 
this code or not (since ours will be in builtins), but at least it's a good 
starting point.

> Thanks for taking a look!
> Erik


https://reviews.llvm.org/D27827



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to