UNW_GETCONTEXT(3libunwind)
π« UNW_GETCONTEXT π«
okay so this is a page from the libunwind manual, section 3libunwind, and bestie we are about to get into machine-state and it's honestly kind of iconic π«Ά
β¨ NAME β¨
unw_getcontext β get initial machine-state π
πΈ SYNOPSIS πΈ
#include <libunwind.h>
int unw_getcontext(unw_context_t *ucp);
π¦ DESCRIPTION π¦
so. the unw_getcontext() routine initializes the context structure pointed to by ucp with the machine state of the call site. like, it's literally grabbing a lil snapshot of where you are right now πΈ
the exact set of registers stored by unw_getcontext() is platform-specific, but, in general, at least all preserved (``callee-saved'') and all frame-related registers, such as the stack pointer, will be stored. so basically the important ones, no cap.
π¨ real talk: this routine is normally implemented as a macro and applications should not attempt to take its address. like... do not do that. it's giving undefined and we're not about that life π
π PLATFORM-SPECIFIC NOTES π
on IA-64, unw_context_t has a layout that is compatible with that of ucontext_t and such structures can be initialized with getcontext() instead of unw_getcontext(). cute, right? β¨
however β and this is the part where you gotta pay attention bestie β the reverse is not true. it is not safe to use structures initialized by unw_getcontext() in places where a structure initialized by getcontext() is expected. π
the reason for this asymmetry is that unw_getcontext() is optimized for maximum performance and does not, for example, save the signal mask. she's fast, she's efficient, she's not doing the extra credit π
β RETURN VALUE β
- on successful completion,
unw_getcontext()returns0π - otherwise, a value of
-1is returned π
π THREAD AND SIGNAL SAFETY π
unw_getcontext() is thread safe as well as safe to use from a signal handler. yes bestie, both. she does it all π
π₯ SEE ALSO π₯
π AUTHOR π
David Mosberger-Tang Email: dmosberger@gmail.com WWW: http://www.nongnu.org/libunwind/
and that's the whole vibe check, fr fr β this was the Programming Library manual, dated 29 August 2023, page UNW_GETCONTEXT(3libunwind). slay, go init some contexts, ily π
π¦ where this page comes from
- alpine 3.22: libunwind-doc 1.8.1-r0 Β· MIT
- alpine 3.23: libunwind-doc 1.8.1-r0 Β· MIT
- alpine 3.24: libunwind-doc 1.8.3-r0 Β· MIT
- arch rolling: libunwind 1.8.3-1 Β· MIT
- epel 10: libunwind-devel 1.8.0-4.el10_0 Β· MIT
- epel 9: libunwind-devel 1.8.0-4.el9 Β· MIT
- fedora 43: libunwind-devel 1.8.1-3.fc43 Β· MIT
- fedora 43: libunwind-devel 1.8.1-3.fc43 Β· MIT
- fedora 43: libunwind-devel 1.8.3-4.fc43 Β· MIT
- fedora 43: libunwind-devel 1.8.3-4.fc43 Β· MIT
- fedora 44: libunwind-devel 1.8.3-1.fc44 Β· MIT
- fedora 44: libunwind-devel 1.8.3-1.fc44 Β· MIT
- fedora 44: libunwind-devel 1.8.3-4.fc44 Β· MIT
- fedora 44: libunwind-devel 1.8.3-4.fc44 Β· MIT
- nixpkgs unstable: libunwind 1.8.3-devman
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms