Skip to content

Consider using $NOCANCEL versions of open and close on OSX-like platforms #117299

@hamarb123

Description

@hamarb123

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:

cdefs.h:
Image
Image
Image

fcntl.h:
Image

unistd.h:
Image

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:

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 :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions