You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Darwin, lock access to the environ block. (#403)
This PR adds calls to Darwin's internal libc functions
`environ_lock_np()` and `environ_unlock_np()` when directly accessing
the `environ` block (via the CRT function `_NSGetEnviron()`.)
These calls are necessary because direct access to `environ` is not
thread-safe by default. The standard library guards accesses to
`getenv()` and `setenv()`, but `environ` is a global variable and
neither it nor `_NSGetEnviron()` can be made thread-safe internally.
This change does not prevent data races when using the result of
`getenv()`, but short of a new `copyenv_np()` or `getenv_r()` function,
there's not much we can do about it. This change has no effect on Linux
since it doesn't have these non-portable functions, but if equivalents
are added in the future, we can add support too. Windows'
`GetEnvironmentStringsW()` API returns a copy of the environment block,
so it doesn't need a lock.
Compare Foundation's use
[here](https://github.com/apple/swift-foundation/blob/main/Sources/_CShims/platform_shims.c).
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
0 commit comments