UNW_SET_REG(3libunwind)

πŸ“¦
version 1.8.3 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, epel 10, epel 9, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0

✨ UNW_SET_REG ✨

okay bestie, welcome to the libunwind corner of the 3libunwind manual, where we're talking about unw_set_reg β€” yes, it does exactly what it sounds like, it sets register contents πŸ’…


🌸 NAME 🌸

unw_set_reg -- set register contents. that's it, that's the vibe. you're writing a value into a register. iconic behavior, honestly.


πŸŽ€ SYNOPSIS πŸŽ€

#include <libunwind.h>

int unw_set_reg(unw_cursor_t *cp, unw_regnum_t reg, unw_word_t val);

like, three args, no drama. we love a low-maintenance signature 🫢


πŸ’– DESCRIPTION πŸ’–

so here's the tea: unw_set_reg() sets the value of register reg in the stack frame identified by cursor cp to the value passed in val. that's the whole plot. no plot twist. slay ✨

the register numbering is target dependent, and it's described in separate manual pages (for example, libunwind-ia64(3libunwind) for the IA-64 target). so like, don't assume the numbers mean the same thing everywhere, bestie, go read your target's page 😭

also?? the exact set of accessible registers may depend on the type of frame that cp is referring to. for ordinary stack frames, it is normally possible to access only the preserved (``callee-saved'') registers and frame-related registers (such as the stack pointer). but for signal frames (see unw_is_signal_frame(3libunwind)), it is usually possible to access all registers. so signal frames are the ones with main character energy and full access, and ordinary frames are the ones gatekeeping their register list πŸ™ˆ

not me being the bearer of bad news but: unw_set_reg() can only write the contents of registers whose values fit in a single word. see unw_set_fpreg(3libunwind) for a way to write registers which do not fit this constraint. one word. that's the limit. periodt πŸ’€

🌈 RETURN VALUE 🌈

on successful completion, unw_set_reg() returns 0. otherwise, the negative value of one of the error codes below is returned. yes, negative. keep an eye on that sign, bestie, it's giving "surprise" if you don't πŸ”₯


πŸ¦‹ THREAD AND SIGNAL SAFETY πŸ¦‹

unw_set_reg() is thread-safe as well as safe to use from a signal handler. fully unbothered, moisturized, in her lane, thriving πŸ‘‘


πŸ‘‘ ERRORS πŸ‘‘

  • UNW_EUNSPEC β€” an unspecified error occurred. like, we don't know what happened either. mystery era πŸ’€
  • UNW_EBADREG β€” an attempt was made to write a register that is either invalid or not accessible in the current frame. girl said no ❌
  • UNW_EREADONLY β€” an attempt was made to write to a read-only register. read-only means read-only, babes, respect the boundary 🚫

in addition, unw_set_reg() may return any error returned by the access_mem(), access_reg(), and access_fpreg() callbacks (see unw_create_addr_space(3libunwind)). so like, the callback squad can also hand you an error. checks out 🫑


⭐ SEE ALSO ⭐

go read them, iykyk πŸ’œ


πŸ’œ AUTHOR πŸ’œ

David Mosberger-Tang Email: dmosberger@gmail.com WWW: http://www.nongnu.org/libunwind/


and that's the whole page bestie!! this one's from the Programming Library era, dated 29 August 2023, and it lives under UNW_SET_REG(3libunwind). go set some registers responsibly, mwah πŸŽ€βœ¨πŸ’–