1.\"	$OpenBSD: shm_open.3,v 1.5 2015/05/05 06:29:15 guenther Exp $
2.\"
3.\" Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: May 5 2015 $
18.Dt SHM_OPEN 3
19.Os
20.Sh NAME
21.Nm shm_open ,
22.Nm shm_unlink ,
23.Nm shm_mkstemp
24.Nd create and destroy shared memory objects
25.Sh SYNOPSIS
26.In sys/mman.h
27.Ft int
28.Fn shm_open "const char *path" "int flags" "mode_t mode"
29.Ft int
30.Fn shm_unlink "const char *path"
31.Ft int
32.Fn shm_mkstemp "char *template"
33.Sh DESCRIPTION
34The
35.Fn shm_open
36function opens a shared memory object and returns a file descriptor suitable
37for use with
38.Xr mmap 2 .
39The
40.Fa flags
41argument has the same meaning as provided to
42.Xr open 2
43and must include at least
44.Dv O_RDONLY
45or
46.Dv O_RDWR
47and may also include a combination of
48.Dv O_CREAT , O_EXCL , O_CLOEXEC , O_NOFOLLOW ,
49or
50.Dv O_TRUNC .
51This implementation forces the
52.Fa mode
53to be 0600 or 0400, and prohibits sharing between different UIDs.
54.Pp
55.Fn shm_unlink
56is used to remove a shared memory object.
57The object is not freed until all references to it have been released via
58.Xr close 2 .
59.Pp
60If a temporary shared memory object is desired, the
61.Fn shm_mkstemp
62function should be preferred as it avoids several possible security
63holes that tend to appear in programs trying to create their own unique
64temporary names.
65The
66.Fa template
67argument is a string with at least six trailing Xs as described in
68.Xr mkstemp 3 .
69.Sh RETURN VALUES
70.Fn shm_open
71and
72.Fn shm_mkstemp
73return a file descriptor on successful completion.
74They may fail for any of the reasons listed in
75.Xr open 2 .
76.Sh SEE ALSO
77.Xr mmap 2
78.Sh STANDARDS
79.Fn shm_open
80and
81.Fn shm_unlink
82appear in
83.St -p1003.1-2001 .
84Using
85.Dv O_CLOEXEC
86or
87.Dv O_NOFOLLOW
88with
89.Fn shm_open
90is an extension to that standard.
91This implementation deviates from the standard by permitting less sharing.
92.Pp
93.Fn shm_mkstemp
94is an extension.
95.Sh HISTORY
96The
97.Fn shm_open ,
98.Fn shm_unlink ,
99and
100.Fn shm_mkstemp
101functions have been available since
102.Ox 5.4 .
103.Sh AUTHORS
104.An Ted Unangst Aq Mt tedu@openbsd.org .
105