ZERO_REGION(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– 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