CASU(9)
πΈ 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()andcasuword32()β return the data that was fetched, or-1on failure β¨casueword()andcasueword32()β return0on success,-1on failure to access memory, and1when 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
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2014, 2019 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms