xref: /freebsd/share/man/man9/zero_region.9 (revision 02e9120893770924227138ba49df1edb3896112a)
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.Dd March 2, 2021
27.Dt ZERO_REGION 9
28.Os
29.Sh NAME
30.Nm zero_region
31.Nd Read-only region prefilled with zeroes
32.Sh SYNOPSIS
33.In sys/param.h
34.In sys/systm.h
35.In vm/vm_param.h
36.Vt extern const void *zero_region ;
37.Sh DESCRIPTION
38The global variable
39.Va zero_region
40points to a read-only region prefilled with zeroes.
41The size of the region is specified by the
42.Dv ZERO_REGION_SIZE
43macro.
44.Sh IMPLEMENTATION NOTES
45The region
46.Va zero_region
47points to is mapped to the same page multiple times.
48.Sh EXAMPLES
49.Bd -literal
50/*
51 * This function writes zeroes to the vnode at offset 0
52 * with ZERO_REGION_SIZE length.
53 */
54static int
55write_example(struct vnode *vp)
56{
57	struct thread *td;
58	struct iovec aiov;
59	struct uio auio;
60	int error;
61
62	td = curthread;
63
64	aiov.iov_base = __DECONST(void *, zero_region);
65	aiov.iov_len = ZERO_REGION_SIZE;
66	auio.uio_iov = &aiov;
67	auio.uio_iovcnt = 1;
68	auio.uio_offset = 0;
69	auio.uio_resid = ZERO_REGION_SIZE;
70	auio.uio_segflg = UIO_SYSSPACE;
71	auio.uio_rw = UIO_WRITE;
72	auio.uio_td = td;
73
74	error = VOP_WRITE(vp, &auio, 0, td->td_ucred);
75	return (error);
76}
77.Ed
78.Sh SEE ALSO
79.Xr pmap 9 ,
80.Xr vm_map 9
81.Sh AUTHORS
82This manual page was written by
83.An Ka Ho Ng Aq Mt khng@FreeBSDFoundation.org
84under sponsorship from the FreeBSD Foundation.
85