Commit Graph

14192 Commits

Author SHA1 Message Date
Andrew Kelley 6a5bb3ede3 std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
David Rubin 938efe4aab compiler-rt: fix f80 ceil/floor optimization
Our implementation did the classic add-sub rounding trick `(y = x +/- C =+ C - x)`
with `C = 1 / eps(T) = 2^(mantissa - 1)`. This approach only works for values whose
magnitude is below the rounding capacity of the constant. For a 64-bit mantissa
(like f80 has), `C = 2^63` only rounds for `|x| < 2^63`. Before we allowed this to
be ran on `e < bias + 64` aka `|x| < 2^64`. And because it isn't large enough,
we lose a bit to rounding.

For reference, the musl implementation does the same thing, using `mantissa - 1`:
https://git.musl-libc.org/cgit/musl/tree/src/math/ceill.c#n18
where `LDBL_MANT_DIG` is 64 for `long double` on x86.

This commit also combines the floor and ceil implementations into one generic one.
2026-01-08 00:45:52 +01:00
Steven Casper 52e0f78706 byteSwapAllFieldsAligned: use std.mem.Alignment API (#30724)
Following up on #30571

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30724
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Steven Casper <sebastiancasper3@gmail.com>
Co-committed-by: Steven Casper <sebastiancasper3@gmail.com>
2026-01-08 00:44:08 +01:00
GasInfinity 335c0fcba1 feat(libzigc): add div, ldiv, lldiv and imaxdiv
* also remove musl implementation
2026-01-07 21:53:40 +01:00
Andrew Kelley 006afece53 std.crypto.tls.Client.Options: expose entropy_len 2026-01-07 11:03:37 -08:00
Andrew Kelley 5d0929c40d std.Io.Threaded.randomSecure: eliminate dead code 2026-01-07 11:03:37 -08:00
Andrew Kelley 1ddae8585a std.Io.Threaded: add procfs fallback for fileHardLink
oof what a clunky set of functionality we have here
2026-01-07 11:03:37 -08:00
Andrew Kelley 7e8c7e5696 std.Io: fix AT_SYMLINK_FOLLOW flags
hard linking has the backwards default, which uses a different flag
2026-01-07 11:03:37 -08:00
Andrew Kelley ee574f665c std.Io.Dir: introduce renamePreserve and use it in File.Atomic.link
breaking change: the error for renaming over a non-empty directory now
returns error.DirNotEmpty rather than error.PathAlreadyExists.
2026-01-07 11:03:37 -08:00
Andrew Kelley 8e1850e277 std.Io.Threaded: tweak logic for use_dev_urandom 2026-01-07 11:03:37 -08:00
Andrew Kelley 0529fe3411 std.Io.Threaded: fix implementation of getRandomFd 2026-01-07 11:03:37 -08:00
Andrew Kelley 1eddc1737c std: add test coverage for Io.File.Atomic.link 2026-01-07 11:03:37 -08:00
Andrew Kelley a136890acc std.Io.random: clarify doc comments 2026-01-07 11:03:37 -08:00
Andrew Kelley 90f0d7d0da std.Io.Threaded: implement random seed fallback for WASI 2026-01-07 11:03:37 -08:00
Andrew Kelley 7bd033275e std.Io.Threaded: implement Windows random seed fallback 2026-01-07 11:03:37 -08:00
Andrew Kelley 1f1381a866 update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
Andrew Kelley 81a35a86ea std.Io: introduce random and randomSecure
and use a thread-local CSPRNG for the former.
2026-01-07 11:03:36 -08:00
Andrew Kelley e3e9c7c33c std.Build.Step.Compile: take advantage of std lib atomic files 2026-01-07 11:03:36 -08:00
Andrew Kelley 2f639a45b4 std.Io.Threaded: implement windows random with \Device\CNG 2026-01-07 11:03:36 -08:00
Andrew Kelley 42ca9e5d8e std.Build: remove no longer needed workaround
now that definitions of networking addresses are arch-independent
2026-01-07 11:03:36 -08:00
Andrew Kelley 3bc22dbd94 std.Build.Step.Options: exploit Io.File.Atomic 2026-01-07 11:03:36 -08:00
Andrew Kelley 816565dd07 std: move entropy to Io 2026-01-07 11:03:36 -08:00
Matthew Lugg cd963ba38d Io.Threaded: fix bad assertion
Resolves: https://codeberg.org/ziglang/zig/issues/30717
2026-01-07 11:27:21 +01:00
mlugg 1bef876636 Merge pull request 'std.Thread: mask all signals before unmapping stack' (#30713) from detached-thread-exit-signal-race into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30713
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-07 01:11:25 +01:00
GasInfinity fa625e878f feat(libzigc): add qsort
* also remove musl implementation
2026-01-07 00:06:57 +01:00
ptrstr 764764465b std.os.emscripten: make emscripten_run_script_string return optional
Signed-off-by: ptrstr <ptrstr@protonmail.com>
2026-01-06 23:49:29 +01:00
Andrew Kelley 5e002910df Merge pull request '@extern: add support for SPIR-V locations and descriptors' (#30570) from ashpil/zig:extern-bindings-locations into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30570
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-01-06 23:44:10 +01:00
pentuppup c475f1fcd5 Ast: disallow bit alignment on many-item and C pointers 2026-01-06 23:40:01 +01:00
David Rubin 8b71ec6db7 crypto: correctly disallow non-digits in time
Previously these functions made the assumption that
when performing a  on the input digits,
there could be no collisions between the less
significant digits being larger than '9', and the
upper digits being small enough to get past the
 checks.

Now we perform a correct check across all of the
digits to ensure they're in between '0'-'9', at
a minimal cost, since all digits are checked in
parallel.
2026-01-06 23:37:43 +01:00
Kristoffer 9c55776d25 std.crypto: mem.trimLeft -> mem.trimStart 2026-01-06 23:28:01 +01:00
Alex Rønne Petersen e226df2ed5 Merge pull request 'add OpenBSD libc cross-compilation support' (#30064) from alexrp/zig:openbsd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30064
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2026-01-06 16:12:54 +01:00
Matthew Lugg be0a77efd2 std: re-enable some disabled tests
I believe these tests may have been flaky as a result of the bug fixed
in the previous commit. A big hint is that they were all crashing with
SIGSEGV with no stack trace. I suspect that some lingering SIGIOs from
cancelations were being delivered to a thread after its `munmap` call,
which was happening because the test runner called `Io.Threaded.deinit`
to cause all of the (detached) worker threads to exit.

If this passes, I'll re-run the x86_64-linux CI jobs on this commit a
few times before merge to try and be sure there are no lingering
failures.

Resolves: https://codeberg.org/ziglang/zig/issues/30096
Resolves: https://codeberg.org/ziglang/zig/issues/30592
Resolves: https://codeberg.org/ziglang/zig/issues/30682
2026-01-06 11:15:47 +00:00
Matthew Lugg 073ef0f393 std.Thread: mask all signals before unmapping stack
As the comment explains, if a signal were to arrive between a detached
thread's `munmap` and `exit` calls, the signal handler would immediately
trigger SIGSEGV due to the stack being unmapped. To solve this, we need
to block all signals before entering this logic. The musl implementation
which this logic was ported from does this exact thing; that logic was
just lost when porting.

Notably, this would lead to a crash with no stack trace, because the
SIGSEGV handler would itself crash due to the missing stack.
2026-01-06 11:15:33 +00:00
Matthew Lugg 1111655131 std: block cancelation in default panic and segfault handlers
It doesn't make any sense for a task to be canceled while it's
panicking.

As a happy accident, this also solves some cases where safety panics in
`Io.Threaded` would cause stack traces not to print due to invalid
thread-local state: when cancelation is blocked, `Io.Threaded` doesn't
consult said thread-local state at all. For instance, try inserting a
panic just after a call to `Syscall.start()` in `Io.Threaded`, and then
call the `Io` function in question from a `concurrent` task. Before this
PR, the stack trace fails to print, because the panic handler sees the
thread-local cancelation state in an unexpected state, leading to a
recursive panic. After this PR, the stack trace prints fine.
2026-01-06 10:50:45 +00:00
Alex Rønne Petersen 9d08eba2e1 std.crypto.argon2: skip flaky argon2d test
https://codeberg.org/ziglang/zig/issues/30074
2026-01-06 10:02:09 +01:00
Alex Rønne Petersen b0da914ae6 std.crypto.argon2: disable flaky phc format hasher test
https://codeberg.org/ziglang/zig/issues/30682
2026-01-06 10:01:16 +01:00
Andrew Kelley 06130c5e61 std.Io.Threaded: set O_DIRECTORY along with O_TMPFILE 2026-01-05 20:31:31 -08:00
Andrew Kelley f9a5b34e67 std.Io.Threaded: fix compilation on s390x, hexagon, or1k, m68k
Apparently the O_TMPFILE flag is split across two bits on these
architectures and missing on m68k.
2026-01-05 20:28:58 -08:00
Andrew Kelley 3859250c4d std.Io.Threaded: only linux supports fileHardLink 2026-01-05 20:28:58 -08:00
Andrew Kelley 39605bd6bc compiler: update to new createFileAtomic API 2026-01-05 20:28:58 -08:00
Andrew Kelley 4365b0df88 std.Io.Threaded: add File.hardLink 2026-01-05 20:28:58 -08:00
Andrew Kelley 81bfd28974 std.Io.Dir: rework atomic file 2026-01-05 20:28:58 -08:00
Michael Dusan 6ab1159e81 netbsd: use correct symbol for lwp_park 2026-01-06 05:27:54 +01:00
Andrew Kelley d3d6761e43 std: depend on NtDll rather than advapi32.dll for entropy 2026-01-05 12:16:54 -08:00
Alex Rønne Petersen 25e348973a std.zig.target: add openbsd libc support 2026-01-05 16:50:46 +01:00
Alex Rønne Petersen 50422d5c37 Merge pull request 'libc: remove most symbols already present in compiler_rt' (#30648) from mercenary/zig:2879-rt into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30648
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-01-05 15:49:55 +01:00
Alex Rønne Petersen 4d3a847cd1 libc: add openbsd libc startup code for 7.8 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen 2c42b85529 std.zig.target: handle openbsd libc names 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen 395145d3b0 std.zig.LibCDirs: add openbsd support 2026-01-05 14:52:48 +01:00
Alex Rønne Petersen 504de5c887 std.Target: bump baseline openbsd version from 7.7 to 7.8
Since this is the first version we support cross-compiling for.
2026-01-05 14:52:48 +01:00