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