zig/lib/std
mlugg a18fd41064
std: rework/remove ucontext_t
Our usage of `ucontext_t` in the standard library was kind of
problematic. We unnecessarily mimiced libc-specific structures, and our
`getcontext` implementation was overkill for our use case of stack
tracing.

This commit introduces a new namespace, `std.debug.cpu_context`, which
contains "context" types for various architectures (currently x86,
x86_64, ARM, and AARCH64) containing the general-purpose CPU registers;
the ones needed in practice for stack unwinding. Each implementation has
a function `current` which populates the structure using inline
assembly. The structure is user-overrideable, though that should only be
necessary if the standard library does not have an implementation for
the *architecture*: that is to say, none of this is OS-dependent.

Of course, in POSIX signal handlers, we get a `ucontext_t` from the
kernel. The function `std.debug.cpu_context.fromPosixSignalContext`
converts this to a `std.debug.cpu_context.Native` with a big ol' target
switch.

This functionality is not exposed from `std.c` or `std.posix`, and
neither are `ucontext_t`, `mcontext_t`, or `getcontext`. The rationale
is that these types and functions do not conform to a specific ABI, and
in fact tend to get updated over time based on CPU features and
extensions; in addition, different libcs use different structures which
are "partially compatible" with the kernel structure. Overall, it's a
mess, but all we need is the kernel context, so we can just define a
kernel-compatible structure as long as we don't claim C compatibility by
putting it in `std.c` or `std.posix`.

This change resulted in a few nice `std.debug` simplifications, but
nothing too noteworthy. However, the main benefit of this change is that
DWARF unwinding---sometimes necessary for collecting stack traces
reliably---now requires far less target-specific integration.

Also fix a bug I noticed in `PageAllocator` (I found this due to a bug
in my distro's QEMU distribution; thanks, broken QEMU patch!) and I
think a couple of minor bugs in `std.debug`.

Resolves: #23801
Resolves: #23802
2025-09-30 13:44:54 +01:00
..
Build std: fixes 2025-09-30 13:44:51 +01:00
builtin start adding big endian RISC-V support 2025-08-25 16:15:17 +02:00
c std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
compress lzma2: fix premature finish 2025-09-03 01:48:46 -07:00
crypto coerce vectors to arrays rather than inline for 2025-09-20 18:33:00 -07:00
debug std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
dwarf fix compiler ftbfs from std.macho and std.dwarf changes 2025-09-30 13:44:51 +01:00
fmt
fs use copy_file_range syscall on linux 2025-09-24 03:08:12 +02:00
hash Remove usages of deprecatedWriter 2025-09-18 22:39:33 -07:00
heap std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
http std.http.Client.Connection: make host() public 2025-09-06 19:23:27 -07:00
Io Merge pull request #25302 from ziglang/growCapacity 2025-09-21 04:55:39 -07:00
json Merge pull request #25302 from ziglang/growCapacity 2025-09-21 04:55:39 -07:00
math std.math.modf: disable vector test on LoongArch with LSX 2025-09-18 12:42:24 +02:00
mem Add allocator that always fails 2025-09-03 21:46:01 -07:00
meta
net std.net.Ip6Address: format numerical scope id 2025-09-15 10:45:35 +01:00
os std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
posix std.posix: remove bogus assert that SIGRTMAX < NSIG 2025-09-22 01:37:32 +02:00
process std: always allow spawning processes when an env map is explicitly provided (#25092) 2025-09-24 03:12:28 +02:00
Random Remove usages of deprecatedWriter 2025-09-18 22:39:33 -07:00
sort std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253) 2025-09-17 19:54:15 -07:00
tar std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
Target std.Target: adjustments to LoongArch CPU models 2025-09-18 12:42:24 +02:00
testing fix compile errors and minor bugs 2025-09-30 13:44:54 +01:00
Thread
time
tz
unicode Remove usages of deprecatedWriter 2025-09-18 22:39:33 -07:00
valgrind
zig Merge pull request #25342 from ziglang/fuzz-limit 2025-09-26 05:28:46 -07:00
zon coerce vectors to arrays rather than inline for 2025-09-20 18:33:00 -07:00
array_hash_map.zig std: introduce orderedRemoveMany 2025-08-11 13:32:12 -07:00
array_list.zig std: remove loop from growCapacity 2025-09-20 14:34:18 -07:00
ascii.zig std.fmt: delete deprecated APIs 2025-08-31 12:49:18 -07:00
atomic.zig start adding big endian RISC-V support 2025-08-25 16:15:17 +02:00
base64.zig std.Io: delete GenericWriter 2025-08-28 18:30:57 -07:00
bit_set.zig
BitStack.zig std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
buf_map.zig
buf_set.zig
Build.zig replace usages of old std.debug APIs 2025-09-30 13:44:51 +01:00
builtin.zig replace usages of old std.debug APIs 2025-09-30 13:44:51 +01:00
c.zig std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
coff.zig change one million things 2025-09-30 13:44:49 +01:00
compress.zig std.compress: rework flate to new I/O API 2025-07-31 22:10:11 -07:00
crypto.zig Merge pull request #25249 from jedisct1/siv 2025-09-17 20:05:23 -07:00
debug.zig std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
deque.zig std: remove loop from growCapacity 2025-09-20 14:34:18 -07:00
DoublyLinkedList.zig
dwarf.zig
dynamic_library.zig link.Elf: fix static PIE 2025-09-30 13:44:53 +01:00
elf.zig std: fix 32-bit build and some unsafe casts 2025-09-30 13:44:53 +01:00
enums.zig std.enums: fix EnumIndexer branch quota 2025-07-31 22:10:22 +01:00
fmt.zig std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260) 2025-09-19 05:02:22 +00:00
fs.zig std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260) 2025-09-19 05:02:22 +00:00
gpu.zig
hash.zig simplify std.hash.Adler32 2025-07-31 22:10:11 -07:00
hash_map.zig use pointer subtraction 2025-09-11 00:18:37 -07:00
heap.zig std.c.darwin: cleanup, expose everything in std.c 2025-08-20 18:21:32 +02:00
http.zig http.BodyWriter: improve clarity of chunked state machine 2025-08-17 14:42:57 +02:00
Io.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
json.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
leb128.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
log.zig Remove usages of deprecatedWriter 2025-09-18 22:39:33 -07:00
macho.zig std: fixes 2025-09-30 13:44:51 +01:00
math.zig std: skip some failing tests on hexagon 2025-08-30 06:36:41 +02:00
mem.zig std.mem: add cutLast and cutScalarLast 2025-09-25 11:38:38 -07:00
meta.zig coerce vectors to arrays rather than inline for 2025-09-20 18:33:00 -07:00
multi_array_list.zig std: remove loop from growCapacity 2025-09-20 14:34:18 -07:00
net.zig std.net.Ip6Address: format numerical scope id 2025-09-15 10:45:35 +01:00
once.zig
os.zig std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260) 2025-09-19 05:02:22 +00:00
pdb.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
pie.zig std.pie: fix register constraint in getDynamicSymbol() for s390x (#25327) 2025-09-22 18:36:47 +02:00
posix.zig std: rework/remove ucontext_t 2025-09-30 13:44:54 +01:00
priority_dequeue.zig std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
priority_queue.zig
process.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
Progress.zig std.Progress: avoid problematic catch syntax 2025-09-20 18:33:00 -07:00
Random.zig
SemanticVersion.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
simd.zig std.simd: suggest more sensible vector sizes across the board 2025-09-19 04:01:08 +02:00
SinglyLinkedList.zig
sort.zig
start.zig std.start: also don't print error trace targeting .other 2025-09-30 13:44:54 +01:00
static_string_map.zig
std.zig std: delete SegmentedList again 2025-09-19 16:40:00 -07:00
tar.zig std.tar: update to new I/O API 2025-07-22 09:41:44 -07:00
Target.zig compiler: require comptime vector indexes 2025-09-20 18:33:00 -07:00
testing.zig coerce vectors to arrays rather than inline for 2025-09-20 18:33:00 -07:00
Thread.zig std: fixes 2025-09-30 13:44:51 +01:00
time.zig std.os.uefi.tables: ziggify boot and runtime services (#23441) 2025-07-12 17:18:53 +00:00
treap.zig std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
tz.zig std.tz: fix redundant endian handling 2025-08-28 18:30:57 -07:00
unicode.zig std.fmt: delete deprecated APIs 2025-08-31 12:49:18 -07:00
Uri.zig std.fmt: delete deprecated APIs 2025-08-31 12:49:18 -07:00
valgrind.zig remove condition codes 2025-07-16 10:27:39 -07:00
wasm.zig
zig.zig move translate-c helpers 2025-09-24 20:01:18 -07:00
zip.zig std.Io: delete GenericReader 2025-08-29 17:14:26 -07:00
zon.zig zon: Add anonymous struct literal in the example 2025-08-15 23:35:16 +02:00