]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/sem_internal.h
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / sys / sem_internal.h
CommitLineData
91447636 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
30 * support for mandatory and extensible security protections. This notice
31 * is included in support of clause 2.2 (b) of the Apple Public License,
32 * Version 2.0.
91447636
A
33 */
34/* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
35
36/*
37 * SVID compatible sem_internal.h file
38 *
39 * Author: Daniel Boulet
40 */
41/*
42 * John Bellardo modified the implementation for Darwin. 12/2000
43 */
44
45#ifndef _SYS_SEM__INTERNALH_
46#define _SYS_SEM__INTERNALH_
47
48#include <sys/sem.h>
49#include <sys/cdefs.h>
50
51
52/*
53 * This structure is variant for 64 bits because of sem_otime and sem_ctime.
54 */
55
56#if __DARWIN_ALIGN_NATURAL
57#pragma options align=natural
58#endif
59
60struct user_semid_ds {
0a7de745
A
61 struct ipc_perm sem_perm; /* [XSI] operation permission struct */
62 struct sem *sem_base; /* 32 bit base ptr for semaphore set */
63 unsigned short sem_nsems; /* [XSI] number of sems in set */
64 user_time_t sem_otime; /* [XSI] last operation time */
65 __int32_t sem_pad1; /* RESERVED: DO NOT USE! */
66 user_time_t sem_ctime; /* [XSI] last change time */
67 /* Times measured in secs since */
68 /* 00:00:00 GMT, Jan. 1, 1970 */
69 __int32_t sem_pad2; /* RESERVED: DO NOT USE! */
70 __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
91447636
A
71};
72
b0d623f7
A
73#pragma pack(4)
74struct user64_semid_ds {
0a7de745
A
75 struct ipc_perm sem_perm; /* [XSI] operation permission struct */
76 int32_t sem_base; /* 32 bit base ptr for semaphore set */
77 unsigned short sem_nsems; /* [XSI] number of sems in set */
78 user64_time_t sem_otime; /* [XSI] last operation time */
79 int32_t sem_pad1; /* RESERVED: DO NOT USE! */
80 user64_time_t sem_ctime; /* [XSI] last change time */
81 /* Times measured in secs since */
82 /* 00:00:00 GMT, Jan. 1, 1970 */
83 int32_t sem_pad2; /* RESERVED: DO NOT USE! */
84 int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
b0d623f7
A
85};
86
87struct user32_semid_ds {
0a7de745
A
88 struct ipc_perm sem_perm; /* [XSI] operation permission struct */
89 int32_t sem_base; /* 32 bit base ptr for semaphore set */
90 unsigned short sem_nsems; /* [XSI] number of sems in set */
91 user32_time_t sem_otime; /* [XSI] last operation time */
92 int32_t sem_pad1; /* RESERVED: DO NOT USE! */
93 user32_time_t sem_ctime; /* [XSI] last change time */
94 /* Times measured in secs since */
95 /* 00:00:00 GMT, Jan. 1, 1970 */
96 int32_t sem_pad2; /* RESERVED: DO NOT USE! */
97 int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
b0d623f7
A
98};
99#pragma pack()
100
91447636 101union user_semun {
0a7de745
A
102 user_addr_t buf; /* buffer for IPC_STAT & IPC_SET */
103 user_addr_t array; /* array for GETALL & SETALL */
91447636
A
104};
105typedef union user_semun user_semun_t;
106
107#if __DARWIN_ALIGN_NATURAL
108#pragma options align=reset
109#endif
110
111
112/*
113 * Kernel implementation stuff
114 */
0a7de745
A
115#define SEMVMX 32767 /* semaphore maximum value */
116#define SEMAEM 16384 /* adjust on exit max value */
91447636
A
117
118/*
119 * Configuration parameters. SEMMNI, SEMMNS, and SEMMNU are hard limits.
120 * The code dynamically allocates enough memory to satisfy the current
121 * demand in even increments of SEMMNI_INC, SEMMNS_INC, and SEMMNU_INC.
122 * The code will never allocate more than the hard limits. The *_INC's
123 * are defined in the kernel section of the header.
124 */
125/*
126 * Configuration parameters
127 */
0a7de745
A
128#ifndef SEMMNS /* # of semaphores in system */
129#define SEMMNS (1048576/sizeof(struct sem))
130#endif /* no more than 1M of semaphore data */
131#ifndef SEMMNI /* # of semaphore identifiers */
132#define SEMMNI SEMMNS /* max of 1 for each semaphore */
91447636
A
133#endif
134#ifndef SEMUME
0a7de745 135#define SEMUME 10 /* max # of undo entries per process */
91447636 136#endif
0a7de745
A
137#ifndef SEMMNU /* # of undo structures in system */
138#define SEMMNU SEMMNS /* 1 for each semaphore. This is quite large */
139#endif /* This should be max 1 for each process */
91447636
A
140
141/* shouldn't need tuning */
142#ifndef SEMMAP
0a7de745 143#define SEMMAP 30 /* # of entries in semaphore map */
91447636
A
144#endif
145#ifndef SEMMSL
0a7de745 146#define SEMMSL SEMMNS /* max # of semaphores per id */
91447636
A
147#endif
148#ifndef SEMOPM
0a7de745 149#define SEMOPM 5 /* max # of operations per semop call */
91447636
A
150#endif
151
152
153/*
154 * Undo structure (internal: one per process)
155 */
156struct sem_undo {
0a7de745
A
157 int un_next_idx; /* index of next active undo structure */
158 struct proc *un_proc; /* owner of this structure */
159 short un_cnt; /* # of active entries */
91447636 160 struct undo {
0a7de745
A
161 short une_adjval; /* adjust on exit values */
162 short une_num; /* semaphore # */
163 int une_id; /* semid */
164 struct undo *une_next; /* next undo entry */
165 } *un_ent; /* undo entries */
91447636
A
166};
167
168/*
169 * semaphore info struct (internal; for administrative limits and ipcs)
170 */
171struct seminfo {
0a7de745
A
172 int semmap, /* # of entries in semaphore map */
173 semmni, /* # of semaphore identifiers */
174 semmns, /* # of semaphores in system */
175 semmnu, /* # of undo structures in system */
176 semmsl, /* max # of semaphores per id */
177 semopm, /* max # of operations per semop call */
178 semume, /* max # of undo entries per process */
179 semusz, /* size in bytes of undo structure */
180 semvmx, /* semaphore maximum value */
181 semaem; /* adjust on exit max value */
91447636 182};
0a7de745 183extern struct seminfo seminfo;
91447636 184
2d21ac55
A
185/*
186 * Kernel wrapper for the user-level structure
187 */
188struct semid_kernel {
0a7de745
A
189 struct user_semid_ds u;
190 struct label *label; /* MAC framework label */
2d21ac55
A
191};
192
193
91447636 194/* internal "mode" bits */
0a7de745
A
195#define SEM_ALLOC 01000 /* semaphore is allocated */
196#define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
91447636 197
0a7de745
A
198#define SEMMNI_INC 8 /* increment value for semaphore identifiers */
199#define SEMMNS_INC 64 /* increment value for semaphores */
200#define SEMMNU_INC 32 /* increment value for undo structures */
91447636
A
201
202/*
203 * Due to the way semaphore memory is allocated, we have to ensure that
204 * SEMUSZ is properly aligned.
205 *
206 * We are not doing strange semaphore memory allocation anymore, so
207 * these macros are no longer needed.
208 */
209
210/*
211 * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
212 */
213
214/* actual size of an undo structure */
215/*
216 * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
217 */
0a7de745 218#define SEMUSZ sizeof(struct sem_undo)
91447636 219
0a7de745
A
220extern struct semid_kernel *sema; /* semaphore id pool */
221extern struct sem *sem_pool; /* semaphore pool */
222/* This is now a struct sem_undo with the new memory allocation
91447636
A
223 * extern int *semu; // undo structure pool
224 */
0a7de745 225extern struct sem_undo *semu; /* undo structure pool */
91447636
A
226
227/*
228 * Macro to find a particular sem_undo vector
229 */
230/* Until we can initialize seminfo.semusz to SEMUSZ, we hard code the size macro
231 * in SEMU. This should be fixed when (if) we implement dynamic pool sizes
232 *
233 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
234 */
235/*
236 * This macro doesn't work because we are using a staticly allocated array
237 * for semu now.
0a7de745 238 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ))
91447636
A
239 */
240#define SEMU(ix) (&semu[ix])
241
242
243/*
244 * Process sem_undo vectors at proc exit.
245 */
0a7de745 246void semexit(struct proc *p);
91447636 247
91447636 248#endif /* !_SYS_SEM__INTERNALH_ */