FETCH(9)
πΈ FETCH β from the Kernel Developer's Manual, section 9 πΈ
okay bestie, buckle up, we're going into kernel-space and we're gonna fetch stuff from user-space π
this is the fetch family: fetch, fubyte, fuword, fuword16, fuword32, fuword64, fueword, fueword32, fueword64 β they fetch data from user-space, and they are lowkey iconic for it π«Ά
β¨ SYNOPSIS β¨
no cap, the includes come in two waves. first these:
#include <sys/types.h>
#include <sys/systm.h>
and then the whole girlband of signatures π
int
fubyte(volatile const void *base);
long
fuword(volatile const void *base);
int
fuword16(volatile const void *base);
int32_t
fuword32(volatile const void *base);
int64_t
fuword64(volatile const void *base);
int
fueword(volatile const void *base, long *val);
int
fueword32(volatile const void *base, int32_t *val);
int
fueword64(volatile const void *base, int64_t *val);
and then, plot twist, another include shows up fashionably late π
#include <sys/resourcevar.h>
π DESCRIPTION π
so the fetch functions are literally designed to copy small amounts of data from the user-space of the current process. that's the whole vibe. and if the read is successful, it is performed atomically β yes ma'am, no half-reads, we do not do partial here β¨
one thing though, and this is the main character rule: the data read must be naturally aligned. not aligned? don't talk to me π
the fetch routines each serve a different little purpose, and here's the full lineup, no skips:
fubyte()β fetches a byte of data from the user-space addressbase. the byte read is zero-extended into the results variable. tiny but mighty πfuword()β fetches a word of data (long) from the user-space addressbase.fuword16()β fetches 16 bits of data from the user-space addressbase. the half-word read is zero-extended into the results variable.fuword32()β fetches 32 bits of data from the user-space addressbase.fuword64()β fetches 64 bits of data from the user-space addressbase.fueword()β fetches a word of data (long) from the user-space addressbaseand stores the result in the variable pointed to byval.fueword32()β fetches 32 bits of data from the user-space addressbaseand stores the result in the variable pointed to byval.fueword64()β fetches 64 bits of data from the user-space addressbaseand stores the result in the variable pointed to byval.
β οΈ okay so this part is important and also a little cursed: the callers offuword(),fuword32()andfuword64()cannot distinguish between -1 read from userspace and function failure. like, a real-1and a broken-1look exactly the same. it's giving identity theft π
π RETURN VALUES π
here's the receipts:
fubyte(),fuword(),fuword16(),fuword32(), andfuword64()return the data fetched, or-1on failure.fueword(),fueword32()andfueword64()return0on success and-1on failure.
periodt π
π SEE ALSO π
go read these next bestie, they're in the same friend group:
and that's the whole page, you ate it π«Ά this was the FETCH(9) page from Debian, dated January 23, 2020 β mwah, iconic, tysm for reading, ily, go align your data πβ¨π
π¦ 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) 1996 Jason R. Thorpe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms