4 ms·
Wow, awesome find. macOS and probably iOS has an undocumented set of filesystem calls which require a "cookie." You call open() and provide a large integer of
by ridiculous_fish 7y ago
Wow, awesome find.
macOS and probably iOS has an undocumented set of filesystem calls which require a "cookie." You call open() and provide a large integer of your choice (probably random); to close the file you need to provide the same integer. This fixed a lot of crashes in CoreData, where some rando was closing its SQLite fd.
- skissane 7y ago> macOS and probably iOS has an undocumented set of filesystem calls which require a "cookie." You call open() and provide a large integer of your choice (probably random); to close the file you need to provide the same integer. I want to learn more. Is there anything I can read about this? (I tried searching but I just keep on getting stuff about HTTP cookies not this.)
- exikyut 7y agoI too am very interested in this, so tried searches with "macos", then "mach" and "xnu". This led me to tentatively conclude that it's not in XNU. On the one hand, http://newosxbook.com/src.jl?tree=xnu-1504.15.3&file=/bsd/sys/vnode.h http://newosxbook.com/src.jl?tree=xnu-1504.15.3&file=/bsd/sy... seems interesting. On the other hand, https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db01281fc08ae024145e84df927/bsd/man/man5/dir.5#L176 https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db0128... is suggested to be a red herring because of https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db01281fc08ae024145e84df927/bsd/sys/vnode_if.h#L946 https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db0128.... I have no idea if these are connected but they might be. I'm not sure if my GitHub and/or Google queries aren't finding the relevant bits of magic though; had (only) a couple minutes and got curious.
- wereHamster 7y agoPerhaps this? https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/funopen.3.html https://developer.apple.com/library/archive/documentation/Sy...
- nneonneo 7y agoNo, those are libc functions that let you use stdio (fprintf, fwrite, fscanf, etc.) with arbitrary "file" implementations. glibc has these too, but these have nothing to do with the underlying syscalls.
- saurik 7y agoguarded_open_np guarded_close_np change_fdguard_np https://opensource.apple.com/source/xnu/xnu-4903.241.1/bsd/kern/kern_guarded.c https://opensource.apple.com/source/xnu/xnu-4903.241.1/bsd/k...