xref: /openbsd/lib/libc/sys/msync.2 (revision 78b63d65)
1.\"	$OpenBSD: msync.2,v 1.15 1999/06/29 14:10:10 aaron Exp $
2.\"	$NetBSD: msync.2,v 1.8 1995/10/12 15:41:09 jtc Exp $
3.\"
4.\" Copyright (c) 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"	@(#)msync.2	8.1 (Berkeley) 6/9/93
36.\"
37.Dd October 10, 1997
38.Dt MSYNC 2
39.Os
40.Sh NAME
41.Nm msync
42.Nd synchronize a mapped region
43.Sh SYNOPSIS
44.Fd #include <sys/types.h>
45.Fd #include <sys/mman.h>
46.Ft int
47.Fn msync "void *addr" "size_t len" "int flags"
48.Sh DESCRIPTION
49The
50.Fn msync
51system call writes all pages with shared modifications
52in the specified
53region of the process's address space back to permanent
54storage, and, if requested, invalidates cached data mapped
55in the region.
56If
57.Fa len
58is 0, all modified pages within the region containing
59.Fa addr
60will be flushed;
61if
62.Fa len
63is non-zero, only modified pages containing
64.Fa addr
65and
66.Fa len-1
67succeeding locations will be flushed.
68Any required synchronization of memory caches
69will also take place at this time.
70Filesystem operations on a file that is mapped for shared modifications
71are unpredictable except after an
72.Fn msync .
73.Pp
74The
75.Fa flags
76argument is formed by
77.Tn OR Ns 'ing
78the following values
79.Pp
80.Bd -literal -offset indent -compact
81MS_ASYNC	Perform asynchronous writes.
82MS_SYNC		Perform synchronous writes.
83MS_INVALIDATE	Invalidate cached data after writing.
84.Ed
85.Sh RETURN VALUES
86Upon successful completion,
87a value of 0 is returned.
88Otherwise, a value of \-1 is returned and
89.Va errno
90is set to indicate the error.
91.Sh ERRORS
92The following errors may be reported:
93.Bl -tag -width Er
94.It Bq Er EBUSY
95The
96.Dv MS_INVALIDATE
97flag was specified and a portion of the specified region
98was locked with
99.Xr mlock 2 .
100.It Bq Er EINVAL
101The specified
102.Fa flags
103argument was invalid.
104.It Bq Er EINVAL
105The
106.Fa addr
107parameter was not page aligned.
108.It Bq Er ENOMEM
109Addresses in the specified region are outside the range allowed
110for the address space of the process, or specify one or more pages
111which are unmapped.
112.It Bq Er EIO
113An I/O error occurred while writing.
114.El
115.Sh BUGS
116Writes are currently done synchronously even if the
117.Dv MS_ASYNC
118flag is specified.
119.Sh SEE ALSO
120.Xr madvise 2 ,
121.Xr mincore 2 ,
122.Xr minherit 2 ,
123.Xr mprotect 2 ,
124.Xr munmap 2
125.Sh HISTORY
126The
127.Fn msync
128function first appeared in
129.Bx 4.4 .
130It was modified to conform to
131.St -p1003.1b-93
132