[BACK]Return to shm_open.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / librt

File: [cvs.NetBSD.org] / src / lib / librt / shm_open.3 (download)

Revision 1.2, Fri Dec 20 13:48:45 2013 UTC (10 years, 3 months ago) by wiz
Branch: MAIN
CVS Tags: yamt-pagecache-base9, tls-maxphys-base, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, HEAD
Branch point for: yamt-pagecache, tls-maxphys
Changes since 1.1: +24 -25 lines

Sort errors.

.\" $NetBSD: shm_open.3,v 1.2 2013/12/20 13:48:45 wiz Exp $
.\"
.\" Copyright 2000 Massachusetts Institute of Technology
.\"
.\" Permission to use, copy, modify, and distribute this software and
.\" its documentation for any purpose and without fee is hereby
.\" granted, provided that both the above copyright notice and this
.\" permission notice appear in all copies, that both the above
.\" copyright notice and this permission notice appear in all
.\" supporting documentation, and that the name of M.I.T. not be used
.\" in advertising or publicity pertaining to distribution of the
.\" software without specific, written prior permission.  M.I.T. makes
.\" no representations about the suitability of this software for any
.\" purpose.  It is provided "as is" without express or implied
.\" warranty.
.\"
.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd December 19, 2013
.Dt SHM_OPEN 3
.Os
.Sh NAME
.Nm shm_open , shm_unlink
.Nd "shared memory object operations"
.Sh LIBRARY
.Lb librt
.Sh SYNOPSIS
.In sys/types.h
.In sys/mman.h
.In fcntl.h
.Ft int
.Fn shm_open "const char *name" "int flags" "mode_t mode"
.Ft int
.Fn shm_unlink "const char *name"
.Sh DESCRIPTION
The
.Fn shm_open
function creates or opens a
.Tn POSIX
shared memory object named
.Fa name .
The
.Fa flags
argument contains a subset of the flags used by
.Xr open 2 .
An access mode of either
.Dv O_RDONLY
or
.Dv O_RDWR
must be included in
.Fa flags .
The optional flags
.Dv O_CREAT ,
.Dv O_EXCL ,
and
.Dv O_TRUNC
may also be specified.
.Pp
If
.Dv O_CREAT
is specified,
then a new shared memory object named
.Fa name
will be created if it does not exist.
In this case,
the shared memory object is created with mode
.Fa mode
subject to the process' umask value.
If both the
.Dv O_CREAT
and
.Dv O_EXCL
flags are specified and a shared memory object named
.Fa path
already exists,
then
.Fn shm_open
will fail with
.Er EEXIST .
.Pp
Newly created objects start off with a size of zero.
If an existing shared memory object is opened with
.Dv O_RDWR
and the
.Dv O_TRUNC
flag is specified,
then the shared memory object will be truncated to a size of zero.
The size of the object can be adjusted via
.Xr ftruncate 2
and queried via
.Xr fstat 2 .
.Pp
The new descriptor is set to close during
.Xr execve 2
system calls;
see
.Xr close 2
and
.Xr fcntl 2 .
.Pp
The
.Fn shm_unlink
system call removes a shared memory object named
.Fa path .
.Sh RETURN VALUES
If successful,
.Fn shm_open
returns a non-negative integer,
and
.Fn shm_unlink
returns zero.
Both functions return -1 on failure, and set
.Va errno
to indicate the error.
.Sh COMPATIBILITY
The
.Fa path
argument does not necessarily represent a pathname (although it does in
most other implementations).
Two processes opening the same
.Fa path
are guaranteed to access the same shared memory object if and only if
.Fa path
begins with a slash
.Pq Ql \&/
character.
.Pp
Only the
.Dv O_RDONLY ,
.Dv O_RDWR ,
.Dv O_CREAT ,
.Dv O_EXCL ,
and
.Dv O_TRUNC
flags may be used in portable programs.
.Pp
The result of using
.Xr open 2 ,
.Xr read 2 ,
or
.Xr write 2
on a shared memory object, or on the descriptor returned by
.Fn shm_open ,
is undefined.
It is also undefined whether the shared memory object itself, or its
contents, persist across reboots.
.Sh ERRORS
The following errors are defined for
.Fn shm_open :
.Bl -tag -width Er
.It Bq Er EACCES
The required permissions (for reading or reading and writing) are denied.
.It Bq Er EEXIST
.Dv O_CREAT
and
.Dv O_EXCL
are specified and the named shared memory object does exist.
.It Bq Er EFAULT
The
.Fa path
argument points outside the process' allocated address space.
.It Bq Er EINVAL
A flag other than
.Dv O_RDONLY ,
.Dv O_RDWR ,
.Dv O_CREAT ,
.Dv O_EXCL ,
or
.Dv O_TRUNC
was included in
.Fa flags ;
or the
.Fa path
does not begin with a slash
.Pq Ql \&/
character.
.It Bq Er EMFILE
The process has already reached its limit for open file descriptors.
.It Bq Er ENAMETOOLONG
The entire pathname exceeded
.Brq Dv PATH_MAX
characters.
.It Bq Er ENFILE
The system file table is full.
.It Bq Er ENOENT
.Dv O_CREAT
is specified and the named shared memory object does not exist.
.It Bq Er ENOTSUP
Not supported, most likely due to missing or incorrect
.Pa /var/shm
mount.
.El
.Pp
The following errors are defined for
.Fn shm_unlink :
.Bl -tag -width Er
.It Bq Er EACCES
The required permissions are denied.
.Fn shm_unlink
requires write permission to the shared memory object.
.It Bq Er EFAULT
The
.Fa path
argument points outside the process' allocated address space.
.It Bq Er ENAMETOOLONG
The entire pathname exceeded
.Brq Dv PATH_MAX
characters.
.It Bq Er ENOENT
The named shared memory object does not exist.
.El
.Sh SEE ALSO
.Xr close 2 ,
.Xr fstat 2 ,
.Xr ftruncate 2 ,
.Xr mmap 2 ,
.Xr munmap 2
.Sh STANDARDS
The
.Fn shm_open
and
.Fn shm_unlink
functions are expected to conform to
.St -p1003.1b-93 .
.Sh HISTORY
These functions first appeared in
.Nx 7.0 .