NetBSD/lib/librt/shm_open.3

241 lines
5.5 KiB
Groff
Raw Normal View History

2013-12-20 17:48:45 +04:00
.\" $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
2013-12-20 17:48:45 +04:00
.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
2013-12-20 17:48:45 +04:00
.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.
2013-12-20 17:48:45 +04:00
.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
2013-12-20 17:48:45 +04:00
.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 .