CASU(9)
π CASU(9) β the kernel dev manual, but make it slay π
okay bestie, so this is the page about casueword, casueword32, casuword, and casuword32 β aka the little guys who go fetch, compare and store data from user-space. it's giving kernel-mode, it's giving atomic, it's giving "please align your pointers or perish". let's 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 girlies are literally designed to do an atomic compare-and-swap operation on the value living in the usermode memory of the current process. main character energy fr fr π
here's the tea: the casueword routines read the value from user memory at address base, and then compare the value they read with oldval. if those two are equal β slay, match β then newval gets written to *base. and for casueword32() and casueword(), the old value is stored into the (kernel-mode) variable pointed to by *oldvalp. no cap, that's just how it works β¨
okay but the way that the userspace value must be naturally aligned β like, non-negotiable, bestie. it's giving strict. it's giving boundaries. respect them π«Ά
and here's the sad part π the callers of casuword() and casuword32() cannot distinguish between -1 read from userspace and function failure. like... it's the same number either way. tragic. iconic. anyway π
β RETURN VALUES β
- the
casuword()andcasuword32()functions return the data fetched β or-1on failure. that's it, that's the whole vibe. - the
casueword()andcasueword32()functions are a lil more chatty: they return0on success,-1on failure to access memory, and1when comparison or store failed. three whole moods π - also!! the store can fail on load-linked/store-conditional architectures. so if it fails, it's not you, it's the architecture π
π SEE ALSO π
and that's the page, bestie!! this one came out of the Debian crew, dated April 19, 2019 β so like, vintage but still serving. go forth and compare-and-swap responsibly β¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2014, 2019 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms