Zig Version
0.15.0-dev.451+bd230215f
Steps to Reproduce and Observed Behavior
I believe the only current use of getcontext in the Zig library is in std.debug. From what I can tell, this code doesn't need a full ucontext_t (which includes a signal mask, floating point state, and a shadow stack). The existing debug code just needs the basic CPU registers. Perhaps just the mcontext_t register state would be sufficient?
I think moving away from getcontext() would make it easier to get the stack walking code working on other platforms (e.g., Android and OpenBSD don't provide a getcontext() at all, nor generally do freestanding and other targets). This also might make it simpler to get new platforms to support this debug code since they would just need a bit of arch-specific assembly to capture the basic registers.
Finally, the getcontext() API is "deprecated" (See https://man7.org/linux/man-pages/man3/getcontext.3.html: "POSIX.1-2008 removes these functions, citing portability issues, and recommending that applications be rewritten to use POSIX threads instead.") and has some hairy portability issues (it's a struct with embedded pointers that need to be fixed up when copied and its size can vary across C library versions and kernel versions).
Expected Behavior
std.debug uses locally defined assembly to capture register values, removing Zig's dependency on the getcontext() API.
Zig Version
0.15.0-dev.451+bd230215f
Steps to Reproduce and Observed Behavior
I believe the only current use of
getcontextin the Zig library is instd.debug. From what I can tell, this code doesn't need a fullucontext_t(which includes a signal mask, floating point state, and a shadow stack). The existing debug code just needs the basic CPU registers. Perhaps just themcontext_tregister state would be sufficient?I think moving away from
getcontext()would make it easier to get the stack walking code working on other platforms (e.g., Android and OpenBSD don't provide agetcontext()at all, nor generally dofreestandingandothertargets). This also might make it simpler to get new platforms to support this debug code since they would just need a bit of arch-specific assembly to capture the basic registers.Finally, the
getcontext()API is "deprecated" (See https://man7.org/linux/man-pages/man3/getcontext.3.html: "POSIX.1-2008 removes these functions, citing portability issues, and recommending that applications be rewritten to use POSIX threads instead.") and has some hairy portability issues (it's a struct with embedded pointers that need to be fixed up when copied and its size can vary across C library versions and kernel versions).Expected Behavior
std.debuguses locally defined assembly to capture register values, removing Zig's dependency on thegetcontext()API.