# std.crypto.random: introduce fork safety · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/53987c932c9d62cc9cdae3d523fb62756ce83ca9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 53987c932c9d62cc9cdae3d523fb62756ce83ca9

Requested commit: 53987c932c9d62cc9cdae3d523fb62756ce83ca9

Commit: 53987c932c9d62cc9cdae3d523fb62756ce83ca9

Tree: 280817d390ef900cf590c40f47cca4230b354b0e

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std.crypto.random: introduce fork safety

Everybody gets what they want!

 * AT_RANDOM is completely ignored.
 * On Linux, MADV_WIPEONFORK is used to provide fork safety.
 * On pthread systems, `pthread_atfork` is used to provide fork safety.
 * For systems that do not have the capability to provide fork safety,
   the implementation falls back to calling getrandom() every time.
 * If madvise is unavailable or returns an error, or pthread_atfork
   fails for whatever reason, it falls back to calling getrandom() every
   time.
 * Applications may choose to opt-out of fork safety.
 * Applications may choose to opt-in to unconditionally calling
   getrandom() for every call to std.crypto.random.fillFn.
 * Added `std.meta.globalOption`.
 * Added `std.os.madvise` and related bits.
 * Bumped up the size of the main thread TLS buffer. See the comment
   there for justification.
 * Simpler hot path in TLS initialization.

```

## Parents

- [2b8dcc76eba92ad44bd88756218de8d2bd8a1c10](https://git.cafe/gitcafe/zig/commit/2b8dcc76eba92ad44bd88756218de8d2bd8a1c10?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/53987c932c9d62cc9cdae3d523fb62756ce83ca9?format=markdown)
