CASU(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

🌸 CASU(9) 🌸

okay bestie, pull up a chair, because this is the casu(9) page from the Kernel Developer's Manual and we're gonna get into it πŸ’…


✨ NAME ✨

casueword, casueword32, casuword, casuword32 β€” fetch, compare and store data from user-space 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/types.h>
#include <sys/systm.h>

int
casueword(volatile u_long *base, u_long oldval, u_long *oldvalp,
    u_long newval);

int
casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp,
    uint32_t newval);

u_long
casuword(volatile u_long *base, u_long oldval, u_long newval);

uint32_t
casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval);

πŸ’– DESCRIPTION πŸ’–

so the casueword functions are literally built to do an atomic compare-and-swap on a value sitting in the usermode memory of the current process. main character energy tbh πŸ”₯

Here's the vibe: the casueword routines read the value from user memory at address base, then compare what they read against oldval. If those two are equal β€” slay, match β€” then newval gets written into *base. πŸ’«

And for casueword32() and casueword(), that old value gets stored into the kernel-mode variable pointed to by *oldvalp. Don't forget that part, it's important πŸŽ€

⚠️ the userspace value must be naturally aligned. no cap. if it isn't, that's on you bestie 😭

Also real talk: callers of casuword() and casuword32() literally cannot tell the difference between a -1 that was actually read from userspace and a -1 that means the function failed. it's giving ambiguous πŸ’€ keep that in mind.


🌈 RETURN VALUES 🌈

  • casuword() and casuword32() β€” return the data that was fetched, or -1 on failure ✨
  • casueword() and casueword32() β€” return 0 on success, -1 on failure to access memory, and 1 when the comparison or the store failed πŸ‘‘

and lowkey important: the store can fail on load-linked/store-conditional architectures. that's just how those chips do πŸ¦‹


πŸ” SEE ALSO πŸ”


that's the whole page bestie, you ate that πŸ“ stay iconic, go read your other manpages, and remember β€” Debian, April 19, 2019, mwah πŸ’œ

πŸ“¦ where this page comes from