casueword(9)

casueword9

Fetch, compare and store data from user-space

Usage

#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);

Overview

The casueword functions are designed to perform atomic compare-and-swap operation on the value in the usermode memory of the current process.

The casueword routines reads the value from user memory with address base, and compare the value read with oldval. If the values are equal, newval is written to the *base. In case of casueword32() and casueword(), old value is stored into the (kernel-mode) variable pointed by *oldvalp. The userspace value must be naturally aligned.

The callers of casuword() and casuword32() functions cannot distinguish between -1 read from userspace and function failure.

Return values

The casuword() and casuword32() functions return the data fetched or -1 on failure. The casueword() and casueword32() functions return 0 on success, -1 on failure to access memory, and 1 when comparison or store failed. The store can fail on load-linked/store-conditional architectures.

Releases

28 releases since FreeBSD 10.2-RELEASE; the text changed 14 times.

  1. 10.2
  2. 10.3
  3. 10.4
  4. 11.0
  5. 11.1
  6. 11.2
  7. 11.3
  8. 11.4
  9. 12.0
  10. 12.1
  11. 12.2
  12. 12.3
  13. 12.4
  14. 13.0–13.2
  15. 13.3–16.0

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.