FETCH(9)
π FETCH(9) β the kernel dev manual, bestie edition π
okay so this is FETCH(9) from the Kernel Developer's Manual β like, the whole "fetch data from user-space" situation. grab a strawberry drink π and let's get into it.
β¨ NAME β¨
fetch, fubyte, fuword, fuword16, fuword32, fuword64, fueword, fueword32, fueword64 β fetch data from user-space π
π SYNOPSIS π
first things first, you gotta include these:
#include <sys/types.h>
#include <sys/systm.h>
and then the whole squad of functions, literally all of them, no cap:
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);
π¦ DESCRIPTION π¦
so the fetch functions are designed to copy small amounts of data from user-space of the current process. like, little sips of data, not the whole drink. π§
here's the tea on alignment: if the user address is naturally aligned, then the operation will be performed atomically. but if it's not aligned? it may fail or be performed non-atomically, depending on the platform. so like, platform-dependent vibes, bestie. β οΈ
the fetch routines provide the following functionality:
fubyte()β fetches a byte of data from the user-space addressbase. the byte read is zero-extended into the results variable. cute and tiny. π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 byval. it's giving "put it in the group chat" energy πfueword32()β fetches 32 bits of data from the user-space addressbaseand stores the result in the variable pointed byval.fueword64()β fetches 64 bits of data from the user-space addressbaseand stores the result in the variable pointed byval.
π okay so important, lowkey a tragedy: the callers offuword(),fuword32()andfuword64()functions cannot distinguish between-1read from userspace and function failure. like, same value, two totally different meanings. iconic but also a nightmare, fr fr.
πΈ RETURN VALUES πΈ
the fubyte(), fuword(), fuword16(), fuword32(), and fuword64() functions return the data fetched or -1 on failure. slay when it works, -1 when it doesn't. π
the fueword(), fueword32() and fueword64() functions return 0 on success and -1 on failure. clean, simple, main character energy. π
π SEE ALSO π
like the other half of the friend group, iykyk π«Ά
and that's the whole page, bestie! this one's from Debian, dated July 22, 2021 β shoutout to the FETCH(9) girlies, periodt. ππ¦β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1996 Jason R. Thorpe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms