xref: /xnu-8792.81.2/bsd/sys/shm.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1*19c3b8c2SApple OSS Distributions /*
2*19c3b8c2SApple OSS Distributions  * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3*19c3b8c2SApple OSS Distributions  *
4*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*19c3b8c2SApple OSS Distributions  *
6*19c3b8c2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*19c3b8c2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*19c3b8c2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*19c3b8c2SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*19c3b8c2SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*19c3b8c2SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*19c3b8c2SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*19c3b8c2SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*19c3b8c2SApple OSS Distributions  *
15*19c3b8c2SApple OSS Distributions  * Please obtain a copy of the License at
16*19c3b8c2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*19c3b8c2SApple OSS Distributions  *
18*19c3b8c2SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*19c3b8c2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*19c3b8c2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*19c3b8c2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*19c3b8c2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*19c3b8c2SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*19c3b8c2SApple OSS Distributions  * limitations under the License.
25*19c3b8c2SApple OSS Distributions  *
26*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*19c3b8c2SApple OSS Distributions  */
28*19c3b8c2SApple OSS Distributions /*	$NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $	*/
29*19c3b8c2SApple OSS Distributions 
30*19c3b8c2SApple OSS Distributions /*
31*19c3b8c2SApple OSS Distributions  * Copyright (c) 1994 Adam Glass
32*19c3b8c2SApple OSS Distributions  * All rights reserved.
33*19c3b8c2SApple OSS Distributions  *
34*19c3b8c2SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
35*19c3b8c2SApple OSS Distributions  * modification, are permitted provided that the following conditions
36*19c3b8c2SApple OSS Distributions  * are met:
37*19c3b8c2SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
38*19c3b8c2SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
39*19c3b8c2SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
40*19c3b8c2SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
41*19c3b8c2SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
42*19c3b8c2SApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
43*19c3b8c2SApple OSS Distributions  *    must display the following acknowledgement:
44*19c3b8c2SApple OSS Distributions  *      This product includes software developed by Adam Glass.
45*19c3b8c2SApple OSS Distributions  * 4. The name of the author may not be used to endorse or promote products
46*19c3b8c2SApple OSS Distributions  *    derived from this software without specific prior written permission
47*19c3b8c2SApple OSS Distributions  *
48*19c3b8c2SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
49*19c3b8c2SApple OSS Distributions  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50*19c3b8c2SApple OSS Distributions  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51*19c3b8c2SApple OSS Distributions  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
52*19c3b8c2SApple OSS Distributions  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53*19c3b8c2SApple OSS Distributions  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54*19c3b8c2SApple OSS Distributions  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55*19c3b8c2SApple OSS Distributions  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56*19c3b8c2SApple OSS Distributions  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
57*19c3b8c2SApple OSS Distributions  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58*19c3b8c2SApple OSS Distributions  */
59*19c3b8c2SApple OSS Distributions 
60*19c3b8c2SApple OSS Distributions /*
61*19c3b8c2SApple OSS Distributions  * As defined+described in "X/Open System Interfaces and Headers"
62*19c3b8c2SApple OSS Distributions  *                         Issue 4, p. XXX
63*19c3b8c2SApple OSS Distributions  */
64*19c3b8c2SApple OSS Distributions 
65*19c3b8c2SApple OSS Distributions #ifndef _SYS_SHM_H_
66*19c3b8c2SApple OSS Distributions #define _SYS_SHM_H_
67*19c3b8c2SApple OSS Distributions 
68*19c3b8c2SApple OSS Distributions #include <sys/cdefs.h>
69*19c3b8c2SApple OSS Distributions #include <sys/_types.h>
70*19c3b8c2SApple OSS Distributions 
71*19c3b8c2SApple OSS Distributions /*
72*19c3b8c2SApple OSS Distributions  * [XSI]	All of the symbols from <sys/ipc.h> SHALL be defined
73*19c3b8c2SApple OSS Distributions  *		when this header is included
74*19c3b8c2SApple OSS Distributions  */
75*19c3b8c2SApple OSS Distributions #include <sys/ipc.h>
76*19c3b8c2SApple OSS Distributions 
77*19c3b8c2SApple OSS Distributions /*
78*19c3b8c2SApple OSS Distributions  * [XSI] The pid_t, time_t, key_t, and size_t types shall be defined as
79*19c3b8c2SApple OSS Distributions  * described in <sys/types.h>.
80*19c3b8c2SApple OSS Distributions  *
81*19c3b8c2SApple OSS Distributions  * NOTE:	The definition of the key_t type is implicit from the
82*19c3b8c2SApple OSS Distributions  *		inclusion of <sys/ipc.h>
83*19c3b8c2SApple OSS Distributions  */
84*19c3b8c2SApple OSS Distributions #include <sys/_types/_pid_t.h>
85*19c3b8c2SApple OSS Distributions #include <sys/_types/_time_t.h>
86*19c3b8c2SApple OSS Distributions #include <sys/_types/_size_t.h>
87*19c3b8c2SApple OSS Distributions 
88*19c3b8c2SApple OSS Distributions /*
89*19c3b8c2SApple OSS Distributions  * [XSI] The unsigned integer type used for the number of current attaches
90*19c3b8c2SApple OSS Distributions  * that MUST be able to store values at least as large as a type unsigned
91*19c3b8c2SApple OSS Distributions  * short.
92*19c3b8c2SApple OSS Distributions  */
93*19c3b8c2SApple OSS Distributions typedef unsigned short  shmatt_t;
94*19c3b8c2SApple OSS Distributions 
95*19c3b8c2SApple OSS Distributions 
96*19c3b8c2SApple OSS Distributions /*
97*19c3b8c2SApple OSS Distributions  * Possible flag values which may be OR'ed into the third argument to
98*19c3b8c2SApple OSS Distributions  * shmat()
99*19c3b8c2SApple OSS Distributions  */
100*19c3b8c2SApple OSS Distributions #define SHM_RDONLY      010000  /* [XSI] Attach read-only (else read-write) */
101*19c3b8c2SApple OSS Distributions #define SHM_RND         020000  /* [XSI] Round attach address to SHMLBA */
102*19c3b8c2SApple OSS Distributions 
103*19c3b8c2SApple OSS Distributions /*
104*19c3b8c2SApple OSS Distributions  * This value is symbolic, and generally not expected to be sed by user
105*19c3b8c2SApple OSS Distributions  * programs directly, although such ise is permitted by the standard.  Its
106*19c3b8c2SApple OSS Distributions  * value in our implementation is equal to the number of bytes per page.
107*19c3b8c2SApple OSS Distributions  *
108*19c3b8c2SApple OSS Distributions  * NOTE:	We DO NOT obtain this value from the appropriate system
109*19c3b8c2SApple OSS Distributions  *		headers at this time, to avoid the resulting namespace
110*19c3b8c2SApple OSS Distributions  *		pollution, which is why we discourages its use.
111*19c3b8c2SApple OSS Distributions  */
112*19c3b8c2SApple OSS Distributions #if __arm64__
113*19c3b8c2SApple OSS Distributions #define SHMLBA      (16*1024)   /* [XSI] Segment low boundary address multiple*/
114*19c3b8c2SApple OSS Distributions #else /* __arm64__ */
115*19c3b8c2SApple OSS Distributions #define SHMLBA      4096        /* [XSI] Segment low boundary address multiple*/
116*19c3b8c2SApple OSS Distributions #endif /* __arm64__ */
117*19c3b8c2SApple OSS Distributions 
118*19c3b8c2SApple OSS Distributions /* "official" access mode definitions; somewhat braindead since you have
119*19c3b8c2SApple OSS Distributions  *  to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */
120*19c3b8c2SApple OSS Distributions #define SHM_R       (IPC_R)
121*19c3b8c2SApple OSS Distributions #define SHM_W       (IPC_W)
122*19c3b8c2SApple OSS Distributions 
123*19c3b8c2SApple OSS Distributions #pragma pack(4)
124*19c3b8c2SApple OSS Distributions 
125*19c3b8c2SApple OSS Distributions /*
126*19c3b8c2SApple OSS Distributions  * Technically, we should force all code references to the new structure
127*19c3b8c2SApple OSS Distributions  * definition, not in just the standards conformance case, and leave the
128*19c3b8c2SApple OSS Distributions  * legacy interface there for binary compatibility only.  Currently, we
129*19c3b8c2SApple OSS Distributions  * are only forcing this for programs requesting standards conformance.
130*19c3b8c2SApple OSS Distributions  */
131*19c3b8c2SApple OSS Distributions #if __DARWIN_UNIX03 || defined(KERNEL)
132*19c3b8c2SApple OSS Distributions /*
133*19c3b8c2SApple OSS Distributions  * Structure used internally.
134*19c3b8c2SApple OSS Distributions  *
135*19c3b8c2SApple OSS Distributions  * This structure is exposed because standards dictate that it is used as
136*19c3b8c2SApple OSS Distributions  * the third argment to shmctl().
137*19c3b8c2SApple OSS Distributions  *
138*19c3b8c2SApple OSS Distributions  * NOTE:	The field shm_internal is not meaningful in user space,
139*19c3b8c2SApple OSS Distributions  *		and must not be used there.
140*19c3b8c2SApple OSS Distributions  */
141*19c3b8c2SApple OSS Distributions #if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
142*19c3b8c2SApple OSS Distributions struct shmid_ds
143*19c3b8c2SApple OSS Distributions #else
144*19c3b8c2SApple OSS Distributions #define shmid_ds        __shmid_ds_new
145*19c3b8c2SApple OSS Distributions struct __shmid_ds_new
146*19c3b8c2SApple OSS Distributions #endif
147*19c3b8c2SApple OSS Distributions {
148*19c3b8c2SApple OSS Distributions 	struct __ipc_perm_new shm_perm; /* [XSI] Operation permission value */
149*19c3b8c2SApple OSS Distributions 	size_t          shm_segsz;      /* [XSI] Size of segment in bytes */
150*19c3b8c2SApple OSS Distributions 	pid_t           shm_lpid;       /* [XSI] PID of last shared memory op */
151*19c3b8c2SApple OSS Distributions 	pid_t           shm_cpid;       /* [XSI] PID of creator */
152*19c3b8c2SApple OSS Distributions 	shmatt_t        shm_nattch;     /* [XSI] Number of current attaches */
153*19c3b8c2SApple OSS Distributions 	time_t          shm_atime;      /* [XSI] Time of last shmat() */
154*19c3b8c2SApple OSS Distributions 	time_t          shm_dtime;      /* [XSI] Time of last shmdt() */
155*19c3b8c2SApple OSS Distributions 	time_t          shm_ctime;      /* [XSI] Time of last shmctl() change */
156*19c3b8c2SApple OSS Distributions 	void            *shm_internal;  /* reserved for kernel use */
157*19c3b8c2SApple OSS Distributions };
158*19c3b8c2SApple OSS Distributions #else   /* !__DARWIN_UNIX03 */
159*19c3b8c2SApple OSS Distributions #define shmid_ds        __shmid_ds_old
160*19c3b8c2SApple OSS Distributions #endif  /* !__DARWIN_UNIX03 */
161*19c3b8c2SApple OSS Distributions 
162*19c3b8c2SApple OSS Distributions #if !__DARWIN_UNIX03
163*19c3b8c2SApple OSS Distributions struct __shmid_ds_old {
164*19c3b8c2SApple OSS Distributions 	struct __ipc_perm_old shm_perm; /* [XSI] Operation permission value */
165*19c3b8c2SApple OSS Distributions 	size_t          shm_segsz;      /* [XSI] Size of segment in bytes */
166*19c3b8c2SApple OSS Distributions 	pid_t           shm_lpid;       /* [XSI] PID of last shared memory op */
167*19c3b8c2SApple OSS Distributions 	pid_t           shm_cpid;       /* [XSI] PID of creator */
168*19c3b8c2SApple OSS Distributions 	shmatt_t        shm_nattch;     /* [XSI] Number of current attaches */
169*19c3b8c2SApple OSS Distributions 	time_t          shm_atime;      /* [XSI] Time of last shmat() */
170*19c3b8c2SApple OSS Distributions 	time_t          shm_dtime;      /* [XSI] Time of last shmdt() */
171*19c3b8c2SApple OSS Distributions 	time_t          shm_ctime;      /* [XSI] Time of last shmctl() change */
172*19c3b8c2SApple OSS Distributions 	void            *shm_internal;  /* reserved for kernel use */
173*19c3b8c2SApple OSS Distributions };
174*19c3b8c2SApple OSS Distributions #endif  /* !__DARWIN_UNIX03 */
175*19c3b8c2SApple OSS Distributions 
176*19c3b8c2SApple OSS Distributions #pragma pack()
177*19c3b8c2SApple OSS Distributions 
178*19c3b8c2SApple OSS Distributions #ifndef KERNEL
179*19c3b8c2SApple OSS Distributions 
180*19c3b8c2SApple OSS Distributions __BEGIN_DECLS
181*19c3b8c2SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
182*19c3b8c2SApple OSS Distributions int     shmsys(int, ...);
183*19c3b8c2SApple OSS Distributions #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
184*19c3b8c2SApple OSS Distributions void    *shmat(int, const void *, int);
185*19c3b8c2SApple OSS Distributions int     shmctl(int, int, struct shmid_ds *) __DARWIN_ALIAS(shmctl);
186*19c3b8c2SApple OSS Distributions int     shmdt(const void *);
187*19c3b8c2SApple OSS Distributions int     shmget(key_t, size_t, int);
188*19c3b8c2SApple OSS Distributions __END_DECLS
189*19c3b8c2SApple OSS Distributions 
190*19c3b8c2SApple OSS Distributions #endif /* !KERNEL */
191*19c3b8c2SApple OSS Distributions 
192*19c3b8c2SApple OSS Distributions #endif /* !_SYS_SHM_H_ */
193