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