Commit Graph

12675 Commits

Author SHA1 Message Date
Matthew Lugg b4ee54b580 std.Io: reimplement Mutex and Condition atop futex
This work was partially cherry-picked from Andrew's WIP std.fs branch.
However, I also analyzed and simplified the Mutex and Condition
implementations, and brought them in line with modern Zig style.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-12-21 13:07:03 +00:00
Matthew Lugg 6ed5b62050 std.Io: introduce futex primitives
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-12-21 13:07:03 +00:00
Andrew Kelley 5fa7f13082 Merge pull request 'Windows: Avoid ever-expanding DeviceIoControl error set, handle NOT_A_REPARSE_POINT in ReadLink' (#30186) from squeek502/zig:win-deviceiocontrol into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30186
2025-12-19 18:50:27 +01:00
Alex Rønne Petersen a6c22c5edb std.os.linux.test: disable fallocate on mips64*-linux-*abin32
https://codeberg.org/ziglang/zig/issues/30220
2025-12-18 12:56:28 +01:00
Alex Rønne Petersen 0437decca9 std.http.test: disable redirect to different connection on mips*-linux w/o libc
https://codeberg.org/ziglang/zig/issues/30216
2025-12-18 01:46:31 +01:00
Alex Rønne Petersen 00903d35b1 std.Target: openbsd's landisk port is only little endian 2025-12-16 06:27:25 +01:00
Alex Rønne Petersen b675223eb5 std: disable tests that depend on getFdPath on openbsd 2025-12-16 06:25:27 +01:00
Alex Rønne Petersen 215b250e6b std.posix.test: fix sigset tests on openbsd (no rt signals) 2025-12-16 06:25:21 +01:00
Alex Rønne Petersen 914005105e std.fs: fix build error in selfExePath() on openbsd 2025-12-16 06:25:10 +01:00
Alex Rønne Petersen 707e389f38 std.Io.Threaded: apply netbsd todo hacks to openbsd
https://codeberg.org/ziglang/zig/issues/30063
2025-12-16 06:25:07 +01:00
Alex Rønne Petersen 18db762bb8 std.c: openbsd does not have SIGRTMIN/SIGRTMAX 2025-12-16 06:24:58 +01:00
Alex Rønne Petersen 56add8374c std.c: remove comptime asserts of siginfo_t size
These serve no purpose other than to verify that the compiler is doing layout
correctly, and this is clearly not the place for that.
2025-12-16 06:24:54 +01:00
Alex Rønne Petersen 0564f83978 std.zig.target: remove two unused consts 2025-12-16 06:24:24 +01:00
Alex Rønne Petersen 9f58931193 std.http: disable all tests on non-Debug powerpc64
https://github.com/llvm/llvm-project/issues/171879
2025-12-16 06:23:14 +01:00
Alex Rønne Petersen 647866dd63 std.math: disable hypot tests on non-Debug powerpc64
https://github.com/llvm/llvm-project/issues/171869
2025-12-16 06:23:11 +01:00
Andrew Kelley 80b5917fad Merge pull request 'Bigint improvements' (#30100) from unplanned/zig:bigint-improvements into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30100
Reviewed-by: jedisct1 <jedisct1@noreply.codeberg.org>
2025-12-15 01:05:50 +01:00
Ryan Liptak 36cb5ea5f4 windows.ReadLink: handle NOT_A_REPARSE_POINT and add test 2025-12-14 07:12:38 -08:00
Ryan Liptak ea7512084b Make windows.DeviceIoControl return NTSTATUS instead of a Zig error
The number of possible errors in the theoretical error set of this function is very large, while each individual call to the function is only concerned with a (potentially small) subset of those errors that are specific to the control code being used. This commit makes the callers determine which statuses they are interested in to avoid an ever-ballooning error set and ever-growing switch cases at each call site that throw away most of those errors.
2025-12-14 07:12:38 -08:00
Stephen Gregoratto aec7bfb092 Linux: Dedupe generic decls
Commit #fc7a5f2 moved many of the `_t` types up a level, but didn't
remove them from arch_bits. Since `Stat` is gone, all but `time_t` can
be removed.
2025-12-14 01:41:47 +01:00
Stephen Gregoratto 6216922a9d Linux: Nuke Stat bits in favour of statx
Maintaining the POSIX `stat` bits for Zig is a pain. The order and
bit-length of members differ between all architectures, and int types
can be signed or unsigned. The libcs deal with this by introducing the
own version of `struct stat` and copying the kernel structure members to
it. In the case of glibc, they did it twice thanks to the largefile
transition!

In practice, the project needs to maintain three versions of `struct
stat`:
- What the kernel defines.
- What musl wants for `struct stat`.
- What glibc wants for `struct stat64`. Make sure to use `fstatat64`!

This isn't as simple as running `zig translate-c`. In #21440 I had to:
- Compile toolchains for each arch+glibc/musl combo.
- Create a test `fstat` program with/without `FILE_OFFSET_BITS=64`.
- Dump the value for `struct stat`.
- Stare at `std.os.linux`/`std.c` and cry.
- Add some missing padding.

The fact that so many target checks in the `linux` and `posix` tests
exist is most likely due to writing to padding bits and failing later.

The solution to this madness is `statx(2)`:
- It takes a single structure that is the same for all arches AND libcs.
- It uses a custom timestamp format, but it is 64-bit ready.
- It gives the same info as `fstatat(2)` and more!
- Unlike `fstatat(2)`, you can request a subset of the info required
  based on passing a mask.

It's so good that modern Linux arches (e.g. riscv) don't even implement
`stat`, with the libcs using a generic `struct stat` and copying from
`struct statx`.

Therefore, this commit rips out all the `stat` bits from `std.os.linux`
and `std.c`. `std.posix.Stat` is now `void`, and calling
`std.posix.*stat` is an compile-time error. A wrapper around `statx` has
been added to `std.os.linux`, and callers have been upgraded to use it.
Tests have also been updated to use `statx` where possible.

While I was here, I converted the mask and file attributes to be packed
struct bitfields. A nice side effect is checking that you actually
recieved the members you asked for via `Statx.mask`, which I have used
by adding `assert`s at specific callsites.
2025-12-14 01:41:47 +01:00
Stephen Gregoratto ff3fd950a7 Linux: Update Statx structure
Also removes the blank lines between members, and a comptime sizeOf
check.
2025-12-14 01:41:47 +01:00
Jacob Young c13857e504 windows: type safety improvements and more ntdll functions 2025-12-12 01:58:21 -05:00
Andrew Kelley 1608e31ca1 std: disable flaky tests
tracked by https://codeberg.org/ziglang/zig/issues/30141
2025-12-09 10:58:55 -08:00
jedisct1 d27c804d9f Merge pull request 'crypto.mlkem: return J(z||c) on implicit rejection' (#30155) from jedisct1/zig:mlkemrej into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30155
2025-12-09 16:28:14 +01:00
Frank Denis a0e9130b89 crypto.mlkem: return J(z||c) on implicit rejection
The ML-KEM decapsulation was returning z directly when implicit
rejection was triggered, but FIPS 203 specifies it should return
J(z || c) = SHAKE256(z || c).
2025-12-09 00:55:59 +01:00
David Rubin ae21089b97 crypto: add missing sha2 arm early clobber 2025-12-09 00:41:23 +04:00
Alex Rønne Petersen 81c52fd621 std.Target: bump max freebsd version to 15.0 2025-12-07 09:48:19 +01:00
Alex Rønne Petersen c1862ce642 drop support for powerpc-freebsd-eabihf
FreeBSD 15 dropped this target. It also dropped x86-freebsd-none, but since that
target remains buildable and usable with the 32-bit compat layer, we keep it for
now.
2025-12-07 09:29:54 +01:00
Matthew Lugg b5ff96b4d2 std.heap: remove raw_c_allocator
After https://codeberg.org/ziglang/zig/pulls/30103, `raw_c_allocator` is
redundant. It existed to avoid overhead when you could assert that all
of your `Allocator` usage was going to be compatible with the C `malloc`
API, but the standard `c_allocator` is now able to avoid that overhead
*in the case* that your usage is compatible (and use the less efficient
path in the rare case where it's not), so there's no need for the raw
version anymore. Leaving it in `std.heap` at this point seems like it
would just be a footgun.
2025-12-06 22:08:40 +01:00
Matthew Lugg 65922a2d43 std: make stack unwinding faster on macOS
https://github.com/ziglang/zig/issues/26027#issuecomment-3571227050
tracked some bad performance in `DebugAllocator` on macOS down to a
function in dyld which `std.debug.SelfInfo` was calling into. It turns
out `dladdr`'s symbol lookup logic is horrendously slow (looking at its
source code, it appears to be doing a *linear scan* over all symbols in
the image?!). However, we don't actually need the symbol, so we want to
try and avoid this logic.

Luckily, dyld has more precise APIs for what we need! Unluckily, Apple,
in their infinite wisdom, decided they should be deprecated in favour of
`dladdr`, despite the latter being several times slower (and by "several
times", I have measured a 50x slowdown on repeated calls to `dladdr`
compared to the other API). But luckily again, the deprecated APIs are
still exposed.

So, after a careful analysis of the situation (reading dyld code and
cursing Apple engineers), I think it makes sense to just use these
deprecated APIs for now. If they ever go away, we can write our own
cache for this data to bypass Apple's awfully slow code, but I suspect
these functions will stick around for the foreseeable future.

Uh, and if `_dyld_get_image_header_containing_address` goes away,
there's also `dyld_image_header_containing_address`, which is a
seemingly identical function, exported by dyld just the same, but with a
separate (functionally identical) implementation, and not documented in
the public header file. Apple work in mysterious ways, I guess.
2025-12-06 10:41:42 +00:00
pentuppup 28c5cc390c detect comptime var references in asm input/output and improve errors 2025-12-06 09:42:51 +01:00
mlugg dbb4c8d151 Merge pull request 'Remove things deprecated during the 0.15 release cycle' (#30018) from linus/zig:remove-deprecated-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30018
2025-12-06 08:51:15 +01:00
Alex Rønne Petersen d41c16930d Merge pull request 'link: support --dependency-file linker option' (#30073) from alexrp/zig:elf-depfile into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30073
Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2025-12-06 08:32:25 +01:00
Matthew Lugg 4ce7b57e86 std.heap: rework c_allocator
The main goal here was to avoid allocating padding and header space if
`malloc` already guarantees the alignment we need via `max_align_t`.
Previously, the compiler was using `std.heap.raw_c_allocator` as its GPA
in some cases depending on `std.c.max_align_t`, but that's pretty
fragile (it meant we had to encode our alignment requirements into
`src/main.zig`!). Perhaps more importantly, that solution is
unnecessarily restrictive: since Zig's `Allocator` API passes the
`Alignment` not only to `alloc`, but also to `free` etc, we are able to
use a different strategy depending on its value. So `c_allocator` can
simply compare the requested align to `Alignment.of(std.c.max_align_t)`,
and use a raw `malloc` call (no header needed!) if it will guarantee a
suitable alignment (which, in practice, will be true the vast majority
of the time).

So in short, this makes `std.heap.c_allocator` more memory efficient,
and probably removes any incentive to use `std.heap.raw_c_allocator`.

I also refactored the `c_allocator` implementation while doing this,
just to neaten things up a little.
2025-12-06 00:16:33 +01:00
Matthew Lugg ea94ac52c5 std.debug: skip manage resources correctly with cbe 2025-12-05 15:10:58 +01:00
Adrià Arrufat 02c5f05e2f std: replace usages of std.mem.indexOf with std.mem.find 2025-12-05 14:31:27 +01:00
Adrià Arrufat 1a420a8dca std.ascii: rename indexOf functions to find
This aligns with the recent changes in std.mem.find
2025-12-05 14:31:27 +01:00
Aidan Welch 032e3c9254 std.Io.Timestamp: when creating a Clock.Timestamp actually set .raw instead of the non-existant .nanoseconds 2025-12-05 14:14:01 +01:00
Luna Schwalbe adc5a39de2 Change github links to codeberg 2025-12-05 14:12:39 +01:00
Loris Cro 58e3c2cefd make Io.net.sendMany compile 2025-12-05 11:50:04 +01:00
Alex Rønne Petersen d22231c039 Compilation: track indirect file system inputs from clang's depfile
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-12-05 11:22:10 +01:00
unplanned 688af04725 math.big: stronger asserts to reduce risks of aliasing 2025-12-04 10:28:42 +01:00
unplanned 73e82332d0 big.Mutable.setString optimization and simplification 2025-12-04 10:28:31 +01:00
Alex Rønne Petersen 44543800a5 std.process.Child: enable rusage collection for dragonfly, netbsd, openbsd 2025-12-04 03:46:36 +01:00
Alex Rønne Petersen 2659fadb95 std.c: add rusage for dragonfly, netbsd, openbsd 2025-12-04 03:46:36 +01:00
Alex Rønne Petersen 9eed87f93e std.process.Child: enable rusage collection for freebsd, illumos, serenity 2025-12-04 03:46:36 +01:00
unplanned c6a1444864 std.math.big.int.int_test: replace mem.eql by expectEqualSlices 2025-12-04 01:12:50 +01:00
unplanned ded4e12559 big.Const.dump: fixed error 2025-12-04 01:12:34 +01:00
jedisct1 d73fbcc3ae Merge pull request 'Argon2: use the std.Io interface' (#30084) from jedisct1/zig:argon2 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30084
2025-12-03 12:18:09 +01:00
Zihad cb115cf73a std.process.ArgIteratorWasi: fix no-args deinit 2025-12-03 08:35:24 +01:00