8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / man / man3c / shm_open.3c
blob4f19f0defb5b0587db3556ea17a60c89d59f4fbc
1 '\" te
2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH SHM_OPEN 3C "Feb 5, 2008"
13 .SH NAME
14 shm_open \- open a shared memory object
15 .SH SYNOPSIS
16 .LP
17 .nf
18 #include <sys/mman.h>
20 \fBint\fR \fBshm_open\fR(\fBconst char *\fR\fIname\fR, \fBint\fR \fIoflag\fR, \fBmode_t\fR \fImode\fR);
21 .fi
23 .SH DESCRIPTION
24 .sp
25 .LP
26 The \fBshm_open()\fR function establishes a connection between a shared memory
27 object and a file descriptor. It creates an open file description that refers
28 to the shared memory object and a file descriptor that refers to that open file
29 description. The file descriptor is used by other functions to refer to that
30 shared memory object. The \fIname\fR argument points to a string naming a
31 shared memory object. It is unspecified whether the name appears in the file
32 system and is visible to other functions that take pathnames as arguments. The
33 \fIname\fR argument conforms to the construction rules for a pathname. The
34 first character of  \fIname\fR must be a slash  (/) character and the remaining
35 characters of  \fIname\fR cannot include any slash characters.  For maximum
36 portability,  \fIname\fR should include no more than 14 characters, but this
37 limit is not enforced.
38 .sp
39 .LP
40 If successful, \fBshm_open()\fR returns a file descriptor for the shared memory
41 object that is the lowest numbered file descriptor not currently open for that
42 process. The open file description is new, and therefore the file descriptor
43 does not share it with any other processes. It is unspecified whether the file
44 offset is set. The \fBFD_CLOEXEC\fR file descriptor flag associated with the
45 new file descriptor is set.
46 .sp
47 .LP
48 The file status flags and file access modes of the open file description are
49 according to the value of \fIoflag\fR. The \fIoflag\fR argument is the bitwise
50 inclusive OR of the following flags defined in the header <\fBfcntl.h\fR>.
51 Applications specify exactly one of the first two values (access modes) below
52 in the value of \fIoflag\fR:
53 .sp
54 .ne 2
55 .na
56 \fB\fBO_RDONLY\fR \fR
57 .ad
58 .RS 13n
59 Open for read access only.
60 .RE
62 .sp
63 .ne 2
64 .na
65 \fB\fBO_RDWR\fR \fR
66 .ad
67 .RS 13n
68 Open for read or write access.
69 .RE
71 .sp
72 .LP
73 Any combination of the remaining flags may be specified in the value of
74 \fIoflag\fR:
75 .sp
76 .ne 2
77 .na
78 \fB\fBO_CREAT\fR \fR
79 .ad
80 .RS 12n
81 If the shared memory object exists, this flag has no effect, except as noted
82 under \fBO_EXCL\fR below. Otherwise the shared memory object is created; the
83 user \fBID\fR of the shared memory object will be set to the effective user
84 \fBID\fR of the process; the group \fBID\fR of the shared memory object will be
85 set to a system default group \fBID\fR or to the effective group \fBID\fR of
86 the process. The permission bits of the shared memory object will be set to the
87 value of the \fImode\fR argument except those set in the file mode creation
88 mask of the process. When bits in \fImode\fR other than the file permission
89 bits are set, the effect is unspecified. The \fImode\fR argument does not
90 affect whether the shared memory object is opened for reading, for writing, or
91 for both. The shared memory object has a size of zero.
92 .RE
94 .sp
95 .ne 2
96 .na
97 \fB\fBO_EXCL\fR \fR
98 .ad
99 .RS 12n
100 If \fBO_EXCL\fR and \fBO_CREAT\fR are set, \fBshm_open()\fR fails if the shared
101 memory object exists. The check for the existence of the shared memory object
102 and the creation of the object if it does not exist is atomic with respect to
103 other processes executing \fBshm_open()\fR naming the same shared memory object
104 with \fBO_EXCL\fR and \fBO_CREAT\fR set. If \fBO_EXCL\fR is set and
105 \fBO_CREAT\fR is not set, the result is undefined.
109 .ne 2
111 \fB\fBO_TRUNC\fR \fR
113 .RS 12n
114 If the shared memory object exists, and it is successfully opened \fBO_RDWR\fR,
115 the object will be truncated to zero length and the mode and owner will be
116 unchanged by this function call. The result of using \fBO_TRUNC\fR with
117 \fBO_RDONLY\fR is undefined.
122 When a shared memory object is created, the state of the shared memory object,
123 including all data associated with the shared memory object, persists until the
124 shared memory object is unlinked and all other references are gone. It is
125 unspecified whether the name and shared memory object state remain valid after
126 a system reboot.
127 .SH RETURN VALUES
130 Upon successful completion, the \fBshm_open()\fR function returns a
131 non-negative integer representing the lowest numbered unused file descriptor.
132 Otherwise, it returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error
133 condition.
134 .SH ERRORS
137 The \fBshm_open()\fR function will fail if:
139 .ne 2
141 \fB\fBEACCES\fR \fR
143 .RS 17n
144 The shared memory object exists and the permissions specified by \fIoflag\fR
145 are denied, or the shared memory object does not exist and permission to create
146 the shared memory object is denied, or \fBO_TRUNC\fR is specified and write
147 permission is denied.
151 .ne 2
153 \fB\fBEEXIST\fR \fR
155 .RS 17n
156 \fBO_CREAT\fR and \fBO_EXCL\fR are set and the named shared memory object
157 already exists.
161 .ne 2
163 \fB\fBEINTR\fR \fR
165 .RS 17n
166 The \fBshm_open()\fR operation was interrupted by a signal.
170 .ne 2
172 \fB\fBEINVAL\fR \fR
174 .RS 17n
175 The \fBshm_open()\fR operation is not supported for the given name.
179 .ne 2
181 \fB\fBEMFILE\fR \fR
183 .RS 17n
184 Too many file descriptors are currently in use by this process.
188 .ne 2
190 \fB\fBENAMETOOLONG\fR \fR
192 .RS 17n
193 The length of the \fIname\fR string exceeds \fBPATH_MAX\fR, or a pathname
194 component is longer than \fINAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
195 effect.
199 .ne 2
201 \fB\fBENFILE\fR \fR
203 .RS 17n
204 Too many shared memory objects are currently open in the system.
208 .ne 2
210 \fB\fBENOENT\fR \fR
212 .RS 17n
213 \fBO_CREAT\fR is not set and the named shared memory object does not exist.
217 .ne 2
219 \fB\fBENOSPC\fR \fR
221 .RS 17n
222 There is insufficient space for the creation of the new shared memory object.
226 .ne 2
228 \fB\fBENOSYS\fR \fR
230 .RS 17n
231 The \fBshm_open()\fR function is not supported by the system.
234 .SH ATTRIBUTES
237 See \fBattributes\fR(5) for descriptions of the following attributes:
242 box;
243 c | c
244 l | l .
245 ATTRIBUTE TYPE  ATTRIBUTE VALUE
247 Interface Stability     Committed
249 MT-Level        MT-Safe
251 Standard        See \fBstandards\fR(5).
254 .SH SEE ALSO
257 \fBclose\fR(2), \fBdup\fR(2), \fBexec\fR(2), \fBfcntl\fR(2), \fBmmap\fR(2),
258 \fBumask\fR(2), \fBshm_unlink\fR(3C), \fBsysconf\fR(3C), \fBfcntl.h\fR(3HEAD),
259 \fBattributes\fR(5), \fBstandards\fR(5)
260 .SH NOTES
263 Solaris 2.6 was the first release to support the Asynchronous Input and Output
264 option. Prior to this release, this function always returned \fB\(mi1\fR and
265 set \fBerrno\fR to \fBENOSYS\fR.