1.\" $OpenBSD: msync.2,v 1.21 2007/05/31 19:19:33 jmc 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 $Mdocdate: May 31 2007 $ 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.Bd -literal -offset indent 76MS_ASYNC Perform asynchronous writes. 77MS_SYNC Perform synchronous writes. 78MS_INVALIDATE Invalidate cached data after writing. 79.Ed 80.Sh RETURN VALUES 81Upon successful completion, 82a value of 0 is returned. 83Otherwise, a value of \-1 is returned and 84.Va errno 85is set to indicate the error. 86.Sh ERRORS 87The following errors may be reported: 88.Bl -tag -width Er 89.It Bq Er EBUSY 90The 91.Dv MS_INVALIDATE 92flag was specified and a portion of the specified region 93was locked with 94.Xr mlock 2 . 95.It Bq Er EINVAL 96The specified 97.Fa flags 98argument was invalid. 99.It Bq Er EINVAL 100The 101.Fa addr 102parameter was not page aligned or 103.Fa addr 104and 105.Fa size 106specify a region that would extend beyond the end of the address space. 107.It Bq Er ENOMEM 108Addresses in the specified region are outside the range allowed 109for the address space of the process, or specify one or more pages 110which are unmapped. 111.It Bq Er EIO 112An I/O error occurred while writing. 113.El 114.Sh SEE ALSO 115.Xr madvise 2 , 116.Xr mincore 2 , 117.Xr minherit 2 , 118.Xr mprotect 2 , 119.Xr munmap 2 120.Sh HISTORY 121The 122.Fn msync 123function first appeared in 124.Bx 4.4 . 125It was modified to conform to 126.St -p1003.1b-93 127.Sh BUGS 128Writes are currently done synchronously even if the 129.Dv MS_ASYNC 130flag is specified. 131