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