-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
I was doing some research for something I am writing and I just stumbled across this discussion from a few years ago: #47584. macOS actually happens to provide non-cancellable versions of open
& close
(+ a few other APIs), and I was thinking we should be utilising those. To utilise them, we just need to define __DARWIN_NON_CANCELABLE
to be 1
.
The non-cancellable versions ensure that EINTR
doesn't represent an indeterminate/intermediate state.
You can see this feature being implemented for these functions across a few files below:
This is set up in the same way that $INODE64
(64-bit inodes & stat structure - on by default for a long time, and no longer necessary in arm64 (but is in x64 and was in x86)) & $UNIX2003
(fully unix complaint definitions, which are no longer necessary in x64/arm64 (but was in x86)) are set up for example. The only difference is that this one is not enabled by default.
Here's an example of it being used in other stuff from a google search:
- https://chromium.googlesource.com/chromium/src/base/+/master/mac/close_nocancel.cc
- Use NOCANCEL variants for close on Mac rust-lang/libc#596
We can make it use the no-cancel ones by adding #define __DARWIN_NON_CANCELABLE 1
(which seems much simplier than what these projects did). Sadly there are not also versions of this for opendir
/closedir
.
It also exists for some other functions such as fcntl
, etc. - if we defined the thing in pal_io.c
(or in cmake somehow), we should get the reliability benefits in all the functions used in that file which could benefit.
Is this something .NET is interested in doing? I can make a PR if so :)