zero_region(9)

zero_region9

Read-only region prefilled with zeroes

Usage

#include <sys/param.h>

#include <sys/systm.h>

#include <vm/vm_param.h>

extern const void *zero_region;

Overview

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.

Implementation notes

The region zero_region points to is mapped to the same page multiple times.

Examples

/*
 * 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);
}

Releases

Unchanged in 9 releases since FreeBSD 14.0-RELEASE.

  1. 14.0–16.0

Authors

This manual page was written by Ka Ho Ng ⟨[email protected]⟩ under sponsorship from the FreeBSD Foundation.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.