xref: /freebsd/share/man/man9/zero_region.9 (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1.\" SPDX-License-Identifier: BSD-2-Clause
2.\"
3.\" Copyright (c) 2021 The FreeBSD Foundation
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd March 2, 2021
29.Dt ZERO_REGION 9
30.Os
31.Sh NAME
32.Nm zero_region
33.Nd Read-only region prefilled with zeroes
34.Sh SYNOPSIS
35.In sys/param.h
36.In sys/systm.h
37.In vm/vm_param.h
38.Vt extern const void *zero_region ;
39.Sh DESCRIPTION
40The global variable
41.Va zero_region
42points to a read-only region prefilled with zeroes.
43The size of the region is specified by the
44.Dv ZERO_REGION_SIZE
45macro.
46.Sh IMPLEMENTATION NOTES
47The region
48.Va zero_region
49points to is mapped to the same page multiple times.
50.Sh EXAMPLES
51.Bd -literal
52/*
53 * This function writes zeroes to the vnode at offset 0
54 * with ZERO_REGION_SIZE length.
55 */
56static int
57write_example(struct vnode *vp)
58{
59	struct thread *td;
60	struct iovec aiov;
61	struct uio auio;
62	int error;
63
64	td = curthread;
65
66	aiov.iov_base = __DECONST(void *, zero_region);
67	aiov.iov_len = ZERO_REGION_SIZE;
68	auio.uio_iov = &aiov;
69	auio.uio_iovcnt = 1;
70	auio.uio_offset = 0;
71	auio.uio_resid = ZERO_REGION_SIZE;
72	auio.uio_segflg = UIO_SYSSPACE;
73	auio.uio_rw = UIO_WRITE;
74	auio.uio_td = td;
75
76	error = VOP_WRITE(vp, &auio, 0, td->td_ucred);
77	return (error);
78}
79.Ed
80.Sh SEE ALSO
81.Xr pmap 9 ,
82.Xr vm_map 9
83.Sh AUTHORS
84This manual page was written by
85.An Ka Ho Ng Aq Mt khng@FreeBSDFoundation.org
86under sponsorship from the FreeBSD Foundation.
87