LIBUNWIND-SETJMP(3libunwind)
β¨ LIBUNWIND-SETJMP π
okay bestie, so this is a page from the Programming Library manual, section 3libunwind β it's all about libunwind-setjmp, the glow-up version of non-local gotos. sit down, hydrate, let's get into it π«Ά
πΈ NAME πΈ
libunwind-setjmp β libunwind-based non-local gotos. yeah. the jumpy jumpy but make it β¨libunwindβ¨.
π SYNOPSIS π
#include <setjmp.h>
int setjmp(jmp_buf env);
void longjmp(jmp_buf env, int val);
int _setjmp(jmp_buf env);
void _longjmp(jmp_buf env, int val);
int sigsetjmp(sigjmp_buf env, int savemask);
void siglongjmp(sigjmp_buf env, int val);
π DESCRIPTION π
so the unwind-setjmp library is a libunwind-based implementation of non-local gotos. and the whole point? it's meant to be a drop-in replacement for the normal, system-provided routines with the exact same names. like, it just slides into the spot. no cap.
the main advantage of using the unwind-setjmp library is that setting up a non-local goto via one of the setjmp() routines is very fast. typically, just 2 or 3 words need to be saved in the jump-buffer β plus one call to sigprocmask(2) in the case of sigsetjmp. that's it. tiny. cute. minimal. π
on the other hand π executing a non-local goto by calling one of the longjmp() routines tends to be much slower than with the system-provided routines. and it's not a flat cost either β the time spent on a longjmp() will be proportional to the number of call frames that exist between the points where setjmp() and longjmp() were called. so the deeper you are, the more it hurts. the way that math works is honestly giving stack traversal π
for this reason, the unwind-setjmp library is beneficial primarily in applications that frequently call setjmp() but only rarely call longjmp(). if that's your vibe, this is your library. if notβ¦ bestie, maybe reconsider π§
β οΈ CAVEATS β οΈ
read this part. i'm serious. this is the "don't text your ex" section of the manpage.
- the correct operation of this library depends on the presence of correct unwind information. on newer platforms, this is rarely an issue. on older platforms, care needs to be taken to ensure that each of the functions whose stack frames may have to be unwound during a
longjmp()have correct unwind information β and on those platforms, there is usually a compiler-switch, such as-funwind-tables, to request the generation of unwind information. so like, turn it on. please. π - the contents of
jmp_bufandsigjmp_bufas setup and used by these routines is completely different from the ones used by the system-provided routines. thus, a jump-buffer created by the libunwind-basedsetjmp()/_setjmpmay only be used in a call to the libunwind-basedlongjmp()/_longjmp(). the analogous applies forsigjmp_bufwithsigsetjmp()andsiglongjmp(). basically: no mixing brands. keep your jump-buffers in their own lane or it's over π
π¦ FILES π¦
-lunwind-setjmpβ the library an application should be linked against to ensure it uses the libunwind-based non-local goto routines. link this. that's the one. π
π SEE ALSO π
go read those too, iykyk π
π AUTHOR π
David Mosberger-Tang
- Email:
dmosberger@gmail.com - WWW:
http://www.nongnu.org/libunwind/
and that's the whole page, bestie π huge shoutout to the Programming Library for publishing this one, dated 29 August 2023, and to LIBUNWIND-SETJMP(3libunwind) for being the moment. periodt. πβ¨π«Ά
π¦ where this page comes from
- debian trixie: libunwind-dev 1.8.1-0.1 Β· MIT
- ubuntu questing: libunwind-dev 1.8.1-0.1ubuntu1
- ubuntu resolute: libunwind-dev 1.8.3-0ubuntu1 Β· MIT
- ubuntu stonking: libunwind-dev 1.8.3-0ubuntu1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms