---
name: "casueword"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/casueword"
---

# casueword(9)

fetch, compare and store data from user-space

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

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.

## SEE ALSO

[atomic(9)](/atomic/9.md), [fetch(9)](/fetch/9.md), [store(9)](/store/9.md)
