ZERO_REGION(9)
π ZERO_REGION(9) β zero_region π
okay bestie, welcome to the Kernel Developer's Manual corner where the page is literally ZERO_REGION(9) and the main character is a global pointer to a read-only block of zeroes. It's giving βsimple but essential,β no cap. π«Ά
β¨ NAME β¨
zero_region β read-only region prefilled with zeroes π
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/systm.h>
#include <vm/vm_param.h>
extern const void *zero_region;
π¦ DESCRIPTION π¦
The global variable zero_region points to a read-only region prefilled with zeroes. The size of the region is specified by the ZERO_REGION_SIZE macro. That's the whole vibe: you get zeroes, they're read-only, and the macro tells you how big the region is. β¨
π IMPLEMENTATION NOTES π
The region zero_region points to is mapped to the same page multiple times. Lowkey iconic implementation detail, highkey useful to know. π
π₯ EXAMPLES π₯
Here's the example straight from the page β a function that writes zeroes to the vnode at offset 0 with ZERO_REGION_SIZE length. Copy it exactly, bestie, we don't freestyle kernel code:
/*
* This function writes zeroes to the vnode at offset 0
* with ZERO_REGION_SIZE length.
*/
static int
write_example(struct vnode *vp)
{
struct thread *td;
struct iovec aiov;
struct uio auio;
int error;
td = curthread;
aiov.iov_base = __DECONST(void *, zero_region);
aiov.iov_len = ZERO_REGION_SIZE;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_offset = 0;
auio.uio_resid = ZERO_REGION_SIZE;
auio.uio_segflg = UIO_SYSSPACE;
auio.uio_rw = UIO_WRITE;
auio.uio_td = td;
error = VOP_WRITE(vp, &auio, 0, td->td_ucred);
return (error);
}
π SEE ALSO π
π AUTHORS π
This manual page was written by Ka Ho Ng <khng@FreeBSDFoundation.org> under sponsorship from the FreeBSD Foundation. Slay, and thank you for the docs, honestly. π«Ά
mwah π that's the whole page: source/version Debian, dated March 2, 2021, and the title is ZERO_REGION(9). periodt. π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- π the page's license: BSD-2-Clause
- Copyright (c) 2021 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms