REEXEC_TO_MATCH_KERNEL(3)

πŸ“¦ version 73, in nixpkgs unstable

πŸ’… REEXEC_TO_MATCH_KERNEL πŸ’…

okay so bestie, buckle up β€” this is reexec_to_match_kernel(3) from the Library Functions Manual, and it's genuinely such a cute little API. no cap.


✨ NAME ✨

reexec_to_match_kernel β€” re-exec the current binary to match the ABI of the running kernel. that's it, that's the whole vibe 🫢


πŸŽ€ LIBRARY πŸŽ€

System Utilities Library, aka libutil, aka link it with -lutil. yep, that's the one. πŸ’–


🌸 SYNOPSIS 🌸

#include <libutil.h>

int
reexec_to_match_kernel(void);

int
reexec_to_match_lp64ness(bool isLP64);

look at them. two little functions. so iconic. πŸ¦‹


πŸ’… DESCRIPTION πŸ’…

so reexec_to_match_kernel() does exactly what it says on the tin: it re-executes the current binary so it matches the ABI of the running kernel. literally the whole point. πŸ”₯

like β€” if the current kernel is a 64-bit Intel kernel, it will attempt to execute the 64-bit x86_64 userspace slice of the universal binary. yes bestie, the slice. it's giving deli counter energy and i'm obsessed.

and here's the part that's actually kind of elegant: the API intentionally does not take arguments, because its use should be transparent to the program and to the user. no params, no fuss, nobody even notices. main character energy that doesn't need to announce itself. πŸ‘‘

then we have reexec_to_match_lp64ness(), which is coarser-grained (fancy way of saying it's less picky, lowkey) β€” it only attempts to match the word width that is requested. for example: if the current system defaults to executing the 64-bit x86_64 userspace slice, but the program should instead run in 32-bit i386 mode, this routine is the one you reach for. periodt. ✨

okay and now the important bit, so listen up πŸ™ˆ β€” both reexec_to_match_kernel() and reexec_to_match_lp64ness() can each be used exactly once in a program's lifetime. one and done. and in certain circumstances, it may even be desirable to use one, and then the other. so like… first one, then the other. you got this. πŸ’œ


⭐ RETURN VALUES ⭐

reexec_to_match_kernel() and reexec_to_match_lp64ness() both return 0 if re-execution was not required. slay, nothing to do, carry on. πŸŽ€

they return -1 and set errno if there was an error performing the re-execution β€” for example, if the binary is not universal, or if it doesn't contain a slice to match the running kernel's ABI. 😭 (the slice thing again. always the slice.)

and if the function succeeds? bestie, control never returns to the caller β€” the program just starts from main() again. like a little rebirth. a re-exec glow-up. 🌈 iykyk.

that's the whole page, fr fr. go forth and match that ABI. 🧚

signing off from Mac OS X, dated Apr 14, 2008, on the REEXEC_TO_MATCH_KERNEL(3) page β€” mwah πŸ’‹

πŸ“¦ where this page comes from