15 Commits

Author SHA1 Message Date
Andrew Kelley
7f03cfe161 std.os: more reorganization efforts
* std lib tests are passing on x86_64-linux with and without -lc
 * stage2 is building from source on x86_64-linux
 * down to 38 remaining uses of `usingnamespace`
2021-09-01 17:54:06 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
LemonBoy
ec9a44b2a5 std: Make atfork handler more robust
The atfork handler is executed even when fork()-ing threads that have
never initialized their local csprng. Handle this case gracefully
instead of raising a runtime error.

Fixes #8841
2021-05-20 15:28:59 +02:00
LemonBoy
abfe7f96dd std: Call pthread_atfork only once
Some libc implementations (glib) deduplicate identical hooks, others
(musl, macos) do not and blindly append them to an internal list.
Ensure there's only a single call to pthread_atfork to prevent unbounded
memory use when lots of threads/forks are used.
2021-05-20 15:26:17 +02:00
LemonBoy
992c02ab95 std: Fix error in tlcsprng init sequence
The fallback case was actually switched with the success one.
2021-05-20 14:43:04 +02:00
Andrew Kelley
615d45da77 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * src/codegen/spirv.zig
 * src/link/SpirV.zig

We're going to want to improve the stage2 test harness to print
the source file name when a compile error occurs otherwise std lib
contributors are going to see some confusing CI failures when they cause
stage2 AstGen compile errors.
2021-05-17 19:30:38 -07:00
LemonBoy
b7eab32f42 std: Allocate tlscsprng memory as needed
Let mmap allocate a block of memory that's wide enough to use with
MADV_WIPEONFORK, madvise granularity is the current system page size
(using a static buffer of mem.page_size bytes would be wrong, that's the
minimum page size).

As a result, we don't zero some random chunk of memory every time we
fork the process.

Fixes #7609
2021-05-17 17:16:38 -04:00
Al Hoang
c17396691c initial support for haiku sync update
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku
2021-02-25 16:41:42 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
LemonBoy
84549b4267 stage1: Fix for generic fn monomorphization
Don't use the instantiation argument types to build the function
parameter array.

f416535768fc30195cad6cd481f73fd1e80082aa worked around the problem, this
commit solves it.
2020-12-19 19:45:48 -05:00
Andrew Kelley
f416535768 work around compiler bug regarding generic function slice alignment
See #7495
2020-12-18 18:30:06 -07:00
Andrew Kelley
53987c932c 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.
2020-12-18 15:54:01 -07:00
Andrew Kelley
2e4b409f31 std: tlcsprng: cleanups & improvements
* get rid of the pointless fences
 * make seed_len 16 instead of 32, which is accurate since it was
   already padding the rest anyway; now we do 1 pad instead of 2.
 * secureZero to clear the AT_RANDOM auxval
 * add a flag root source files can use to disable the start code. This
   is in case people want to opt out of the initialization when they
   don't depend on it.
2020-12-18 12:22:46 -07:00
Andrew Kelley
013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00