xref: /netbsd-src/lib/librt/shm_open.3 (revision f61d31bbaf84e27d1ec85da660752d2839f9b1e4)
1*f61d31bbSwiz.\" $NetBSD: shm_open.3,v 1.2 2013/12/20 13:48:45 wiz Exp $
20ec95f7aSrmind.\"
30ec95f7aSrmind.\" Copyright 2000 Massachusetts Institute of Technology
40ec95f7aSrmind.\"
50ec95f7aSrmind.\" Permission to use, copy, modify, and distribute this software and
60ec95f7aSrmind.\" its documentation for any purpose and without fee is hereby
70ec95f7aSrmind.\" granted, provided that both the above copyright notice and this
80ec95f7aSrmind.\" permission notice appear in all copies, that both the above
90ec95f7aSrmind.\" copyright notice and this permission notice appear in all
100ec95f7aSrmind.\" supporting documentation, and that the name of M.I.T. not be used
110ec95f7aSrmind.\" in advertising or publicity pertaining to distribution of the
120ec95f7aSrmind.\" software without specific, written prior permission.  M.I.T. makes
130ec95f7aSrmind.\" no representations about the suitability of this software for any
140ec95f7aSrmind.\" purpose.  It is provided "as is" without express or implied
150ec95f7aSrmind.\" warranty.
160ec95f7aSrmind.\"
170ec95f7aSrmind.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
180ec95f7aSrmind.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
190ec95f7aSrmind.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
200ec95f7aSrmind.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
210ec95f7aSrmind.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
220ec95f7aSrmind.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
230ec95f7aSrmind.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
240ec95f7aSrmind.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
250ec95f7aSrmind.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
260ec95f7aSrmind.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
270ec95f7aSrmind.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
280ec95f7aSrmind.\" SUCH DAMAGE.
290ec95f7aSrmind.\"
300ec95f7aSrmind.\" $FreeBSD$
310ec95f7aSrmind.\"
320ec95f7aSrmind.Dd December 19, 2013
330ec95f7aSrmind.Dt SHM_OPEN 3
340ec95f7aSrmind.Os
350ec95f7aSrmind.Sh NAME
360ec95f7aSrmind.Nm shm_open , shm_unlink
370ec95f7aSrmind.Nd "shared memory object operations"
380ec95f7aSrmind.Sh LIBRARY
390ec95f7aSrmind.Lb librt
400ec95f7aSrmind.Sh SYNOPSIS
410ec95f7aSrmind.In sys/types.h
420ec95f7aSrmind.In sys/mman.h
430ec95f7aSrmind.In fcntl.h
440ec95f7aSrmind.Ft int
450ec95f7aSrmind.Fn shm_open "const char *name" "int flags" "mode_t mode"
460ec95f7aSrmind.Ft int
470ec95f7aSrmind.Fn shm_unlink "const char *name"
480ec95f7aSrmind.Sh DESCRIPTION
490ec95f7aSrmindThe
500ec95f7aSrmind.Fn shm_open
510ec95f7aSrmindfunction creates or opens a
520ec95f7aSrmind.Tn POSIX
530ec95f7aSrmindshared memory object named
540ec95f7aSrmind.Fa name .
550ec95f7aSrmindThe
560ec95f7aSrmind.Fa flags
570ec95f7aSrmindargument contains a subset of the flags used by
580ec95f7aSrmind.Xr open 2 .
590ec95f7aSrmindAn access mode of either
600ec95f7aSrmind.Dv O_RDONLY
610ec95f7aSrmindor
620ec95f7aSrmind.Dv O_RDWR
630ec95f7aSrmindmust be included in
640ec95f7aSrmind.Fa flags .
650ec95f7aSrmindThe optional flags
660ec95f7aSrmind.Dv O_CREAT ,
670ec95f7aSrmind.Dv O_EXCL ,
680ec95f7aSrmindand
690ec95f7aSrmind.Dv O_TRUNC
700ec95f7aSrmindmay also be specified.
710ec95f7aSrmind.Pp
720ec95f7aSrmindIf
730ec95f7aSrmind.Dv O_CREAT
740ec95f7aSrmindis specified,
750ec95f7aSrmindthen a new shared memory object named
760ec95f7aSrmind.Fa name
770ec95f7aSrmindwill be created if it does not exist.
780ec95f7aSrmindIn this case,
790ec95f7aSrmindthe shared memory object is created with mode
800ec95f7aSrmind.Fa mode
810ec95f7aSrmindsubject to the process' umask value.
820ec95f7aSrmindIf both the
830ec95f7aSrmind.Dv O_CREAT
840ec95f7aSrmindand
850ec95f7aSrmind.Dv O_EXCL
860ec95f7aSrmindflags are specified and a shared memory object named
870ec95f7aSrmind.Fa path
880ec95f7aSrmindalready exists,
890ec95f7aSrmindthen
900ec95f7aSrmind.Fn shm_open
910ec95f7aSrmindwill fail with
920ec95f7aSrmind.Er EEXIST .
930ec95f7aSrmind.Pp
940ec95f7aSrmindNewly created objects start off with a size of zero.
950ec95f7aSrmindIf an existing shared memory object is opened with
960ec95f7aSrmind.Dv O_RDWR
970ec95f7aSrmindand the
980ec95f7aSrmind.Dv O_TRUNC
990ec95f7aSrmindflag is specified,
1000ec95f7aSrmindthen the shared memory object will be truncated to a size of zero.
1010ec95f7aSrmindThe size of the object can be adjusted via
1020ec95f7aSrmind.Xr ftruncate 2
1030ec95f7aSrmindand queried via
1040ec95f7aSrmind.Xr fstat 2 .
1050ec95f7aSrmind.Pp
1060ec95f7aSrmindThe new descriptor is set to close during
1070ec95f7aSrmind.Xr execve 2
1080ec95f7aSrmindsystem calls;
1090ec95f7aSrmindsee
1100ec95f7aSrmind.Xr close 2
1110ec95f7aSrmindand
1120ec95f7aSrmind.Xr fcntl 2 .
1130ec95f7aSrmind.Pp
1140ec95f7aSrmindThe
1150ec95f7aSrmind.Fn shm_unlink
1160ec95f7aSrmindsystem call removes a shared memory object named
1170ec95f7aSrmind.Fa path .
1180ec95f7aSrmind.Sh RETURN VALUES
1190ec95f7aSrmindIf successful,
1200ec95f7aSrmind.Fn shm_open
1210ec95f7aSrmindreturns a non-negative integer,
1220ec95f7aSrmindand
1230ec95f7aSrmind.Fn shm_unlink
1240ec95f7aSrmindreturns zero.
1250ec95f7aSrmindBoth functions return -1 on failure, and set
1260ec95f7aSrmind.Va errno
1270ec95f7aSrmindto indicate the error.
1280ec95f7aSrmind.Sh COMPATIBILITY
1290ec95f7aSrmindThe
1300ec95f7aSrmind.Fa path
1310ec95f7aSrmindargument does not necessarily represent a pathname (although it does in
1320ec95f7aSrmindmost other implementations).
1330ec95f7aSrmindTwo processes opening the same
1340ec95f7aSrmind.Fa path
1350ec95f7aSrmindare guaranteed to access the same shared memory object if and only if
1360ec95f7aSrmind.Fa path
1370ec95f7aSrmindbegins with a slash
1380ec95f7aSrmind.Pq Ql \&/
1390ec95f7aSrmindcharacter.
1400ec95f7aSrmind.Pp
1410ec95f7aSrmindOnly the
1420ec95f7aSrmind.Dv O_RDONLY ,
1430ec95f7aSrmind.Dv O_RDWR ,
1440ec95f7aSrmind.Dv O_CREAT ,
1450ec95f7aSrmind.Dv O_EXCL ,
1460ec95f7aSrmindand
1470ec95f7aSrmind.Dv O_TRUNC
1480ec95f7aSrmindflags may be used in portable programs.
1490ec95f7aSrmind.Pp
1500ec95f7aSrmindThe result of using
1510ec95f7aSrmind.Xr open 2 ,
1520ec95f7aSrmind.Xr read 2 ,
1530ec95f7aSrmindor
1540ec95f7aSrmind.Xr write 2
1550ec95f7aSrmindon a shared memory object, or on the descriptor returned by
1560ec95f7aSrmind.Fn shm_open ,
1570ec95f7aSrmindis undefined.
1580ec95f7aSrmindIt is also undefined whether the shared memory object itself, or its
1590ec95f7aSrmindcontents, persist across reboots.
1600ec95f7aSrmind.Sh ERRORS
1610ec95f7aSrmindThe following errors are defined for
1620ec95f7aSrmind.Fn shm_open :
1630ec95f7aSrmind.Bl -tag -width Er
164*f61d31bbSwiz.It Bq Er EACCES
165*f61d31bbSwizThe required permissions (for reading or reading and writing) are denied.
166*f61d31bbSwiz.It Bq Er EEXIST
167*f61d31bbSwiz.Dv O_CREAT
168*f61d31bbSwizand
169*f61d31bbSwiz.Dv O_EXCL
170*f61d31bbSwizare specified and the named shared memory object does exist.
171*f61d31bbSwiz.It Bq Er EFAULT
172*f61d31bbSwizThe
173*f61d31bbSwiz.Fa path
174*f61d31bbSwizargument points outside the process' allocated address space.
1750ec95f7aSrmind.It Bq Er EINVAL
1760ec95f7aSrmindA flag other than
1770ec95f7aSrmind.Dv O_RDONLY ,
1780ec95f7aSrmind.Dv O_RDWR ,
1790ec95f7aSrmind.Dv O_CREAT ,
1800ec95f7aSrmind.Dv O_EXCL ,
1810ec95f7aSrmindor
1820ec95f7aSrmind.Dv O_TRUNC
1830ec95f7aSrmindwas included in
184*f61d31bbSwiz.Fa flags ;
185*f61d31bbSwizor the
1860ec95f7aSrmind.Fa path
1870ec95f7aSrminddoes not begin with a slash
1880ec95f7aSrmind.Pq Ql \&/
1890ec95f7aSrmindcharacter.
190*f61d31bbSwiz.It Bq Er EMFILE
191*f61d31bbSwizThe process has already reached its limit for open file descriptors.
192*f61d31bbSwiz.It Bq Er ENAMETOOLONG
193*f61d31bbSwizThe entire pathname exceeded
194*f61d31bbSwiz.Brq Dv PATH_MAX
195*f61d31bbSwizcharacters.
196*f61d31bbSwiz.It Bq Er ENFILE
197*f61d31bbSwizThe system file table is full.
1980ec95f7aSrmind.It Bq Er ENOENT
1990ec95f7aSrmind.Dv O_CREAT
2000ec95f7aSrmindis specified and the named shared memory object does not exist.
2010ec95f7aSrmind.It Bq Er ENOTSUP
2020ec95f7aSrmindNot supported, most likely due to missing or incorrect
2030ec95f7aSrmind.Pa /var/shm
2040ec95f7aSrmindmount.
2050ec95f7aSrmind.El
2060ec95f7aSrmind.Pp
2070ec95f7aSrmindThe following errors are defined for
2080ec95f7aSrmind.Fn shm_unlink :
2090ec95f7aSrmind.Bl -tag -width Er
210*f61d31bbSwiz.It Bq Er EACCES
211*f61d31bbSwizThe required permissions are denied.
212*f61d31bbSwiz.Fn shm_unlink
213*f61d31bbSwizrequires write permission to the shared memory object.
2140ec95f7aSrmind.It Bq Er EFAULT
2150ec95f7aSrmindThe
2160ec95f7aSrmind.Fa path
2170ec95f7aSrmindargument points outside the process' allocated address space.
2180ec95f7aSrmind.It Bq Er ENAMETOOLONG
2190ec95f7aSrmindThe entire pathname exceeded
2200ec95f7aSrmind.Brq Dv PATH_MAX
2210ec95f7aSrmindcharacters.
2220ec95f7aSrmind.It Bq Er ENOENT
2230ec95f7aSrmindThe named shared memory object does not exist.
2240ec95f7aSrmind.El
2250ec95f7aSrmind.Sh SEE ALSO
2260ec95f7aSrmind.Xr close 2 ,
2270ec95f7aSrmind.Xr fstat 2 ,
2280ec95f7aSrmind.Xr ftruncate 2 ,
2290ec95f7aSrmind.Xr mmap 2 ,
2300ec95f7aSrmind.Xr munmap 2
2310ec95f7aSrmind.Sh STANDARDS
2320ec95f7aSrmindThe
2330ec95f7aSrmind.Fn shm_open
2340ec95f7aSrmindand
2350ec95f7aSrmind.Fn shm_unlink
2360ec95f7aSrmindfunctions are expected to conform to
2370ec95f7aSrmind.St -p1003.1b-93 .
2380ec95f7aSrmind.Sh HISTORY
2390ec95f7aSrmindThese functions first appeared in
2400ec95f7aSrmind.Nx 7.0 .
241