aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug/cpu_context.zig
AgeCommit message (Collapse)Author
2025-10-30std.debug.cpu_context: fix signal_ucontext_t for arm-linuxAlex Rønne Petersen
2025-10-29feat: add `x86_16` debug `cpu_context`GasInfinity
2025-10-27remove all Oracle Solaris supportAlex Rønne Petersen
There is no straightforward way for the Zig team to access the Solaris system headers; to do this, one has to create an Oracle account, accept their EULA to download the installer ISO, and finally install it on a machine or VM. We do not have to jump through hoops like this for any other OS that we support, and no one on the team has expressed willingness to do it. As a result, we cannot audit any Solaris contributions to std.c or other similarly sensitive parts of the standard library. The best we would be able to do is assume that Solaris and illumos are 100% compatible with no way to verify that assumption. But at that point, the solaris and illumos OS tags would be functionally identical anyway. For Solaris especially, any contributions that involve APIs introduced after the OS was made closed-source would also be inherently more risky than equivalent contributions for other proprietary OSs due to the case of Google LLC v. Oracle America, Inc., wherein Oracle clearly demonstrated its willingness to pursue legal action against entities that merely copy API declarations. Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in maintenance mode since, presumably to be retired completely sometime in the 2030s. For these reasons, this commit removes all Oracle Solaris support. Anyone who still wishes to use Zig on Solaris can try their luck by simply using illumos instead of solaris in target triples - chances are it'll work. But there will be no effort from the Zig team to support this use case; we recommend that people move to illumos instead.
2025-10-26std.debug.cpu_context: fix mcontext alignment for x86_64-illumosAlex Rønne Petersen
It contains a upad128_t array which increases its alignment.
2025-10-25std.debug.cpu_context: add missing signal_ucontext_t fields for ↵Stephen Gregoratto
x86_64-solaris/illumos
2025-10-23std.debug.cpu_context: add signal_ucontext_t for alpha, hppa, microblaze, shAlex Rønne Petersen
2025-10-23std.Target: add arceb and xtensaeb Cpu.Arch tagsAlex Rønne Petersen
2025-10-18std.debug.cpu_context.Sparc: fix bad use of call delay slotAlex Rønne Petersen
2025-10-18std.debug.cpu_context: let the compiler deal with clobbersAlex Rønne Petersen
Otherwise we might be restoring registers we don't even need to.
2025-10-18std.debug.cpu_context: sort context decls according to switch prongs (NFC)Alex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for arcAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for m68kAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for or1kAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for cskyAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for lanaiAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for veAlex Rønne Petersen
2025-10-15std.debug.cpu_context: add sparc*-linux context conversion supportAlex Rønne Petersen
It's not really a ucontext_t at all. Lovely stuff.
2025-10-15std.debug.cpu_context.Sparc: flush register windows in current()Alex Rønne Petersen
It's better to do this here than in StackIterator.init() so that std.debug.cpu_context.Native.current() isn't a footgun on SPARC.
2025-10-15std.debug.cpu_context: add Sparc contextAlex Rønne Petersen
2025-10-12std.debug.cpu_context: consider arm and aarch64 reserved register ranges ↵Alex Rønne Petersen
unsupported If these ever get allocated, it's most likely going to be for things that don't matter to us anyway, so completely abandoning DWARF unwinding just because we see these doesn't seem justified. We will still do so if we're actually asked to read from such a register, which is the only actually problematic case; see c23a5ccd19 for more details.
2025-10-10std.debug: greatly expand target support for segfault handling/unwindingAlex Rønne Petersen
I made a couple of decisions for this based on the fact that we don't expose the signal_ucontext_t type outside of the file: * Adding all the floating point and vector state to every ucontext_t and mcontext_t variant was way, way too much work, especially when we don't even use the stuff. So I deleted all that and kept only the bare minimum needed to reach into general-purpose registers. * There is no particularly compelling reason to stick to the naming and struct nesting used in the system headers. So we can actually unify the access patterns for almost all of these variants by taking some liberties here; as a result, fromPosixSignalContext() is now much nicer to read and extend.
2025-10-07std.debug.cpu_context: make arch-specific implementations privateAlex Rønne Petersen
2025-10-07std.debug.cpu_context: map a bunch of known registers as unsupported instead ↵Alex Rønne Petersen
of invalid
2025-10-07std.debug.cpu_context: remove support for s390x float registersAlex Rønne Petersen
Let's for the moment assume that compilers haven't lost the plot. Fingers crossed.
2025-10-07std.debug.Dwarf: use 66 as the (fake) MIPS PC registerAlex Rønne Petersen
32-63 conflict with the floating point registers. 64 and 65 are used for the ac0 hi/lo registers.
2025-10-07std.debug.Dwarf: use 67 as the (fake) PowerPC PC registerAlex Rønne Petersen
It's free real estate, as it turns out.
2025-10-07std.debug.Dwarf: use 65 as the (fake) RISC-V PC registerAlex Rønne Petersen
32-63 conflict with the floating point registers. 64 is the Alternate Frame Return Column.
2025-10-07std.debug.Dwarf: use 64 as the (fake) LoongArch PC registerAlex Rønne Petersen
32-63 conflict with the floating point registers.
2025-10-07std.debug: add unwind support for powerpc*-linuxAlex Rønne Petersen
2025-10-07std.debug: add unwind support for mips*-linuxAlex Rønne Petersen
2025-10-07std.debug.cpu_context: check for architecture, i.e. register size, not bitnessAlex Rønne Petersen
We care about the hardware here, not the ABI.
2025-10-05std.debug: add unwind support for hexagon-linuxAlex Rønne Petersen
2025-10-03std.debug: Add unwind support for serenityLinus Groh
2025-10-03std.debug: add s390x-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: add riscv32-linux and riscv64-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: add loongarch64-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: some adjustments to target handlingAlex Rønne Petersen
* driverkit handling missing in a few places. * x86-solaris is a dead target. * aarch64_be does not exist on Darwin, FreeBSD, Windows.
2025-09-30typomlugg
2025-09-30std: clarify cpu_context register order rationalemlugg
2025-09-30std: don't get CPU context when using CBE targeting MSVCmlugg
Calling `current` here causes compilation failures as the C backend currently does not emit valid MSVC inline assembly. This change means that when building for MSVC with the self-hosted C backend, only FP unwinding can be used.
2025-09-30std.debug: miscellaneous fixesmlugg
Mostly on macOS, since Loris showed me a not-great stack trace, and I spent 8 hours trying to make it better. The dyld shared cache is designed in a way which makes this really hard to do right, and documentation is non-existent, but this *seems* to work pretty well. I'll leave the ruling on whether I did a good job to CI and our users.
2025-09-30std: rework/remove ucontext_tmlugg
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