]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
91447636 | 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. | |
8f6c56a5 | 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. | |
17 | * | |
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. | |
8f6c56a5 | 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 | ||
60 | struct user_semid_ds { | |
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! */ | |
71 | }; | |
72 | ||
73 | union user_semun { | |
74 | user_addr_t buf; /* buffer for IPC_STAT & IPC_SET */ | |
75 | user_addr_t array; /* array for GETALL & SETALL */ | |
76 | }; | |
77 | typedef union user_semun user_semun_t; | |
78 | ||
79 | #if __DARWIN_ALIGN_NATURAL | |
80 | #pragma options align=reset | |
81 | #endif | |
82 | ||
83 | ||
84 | /* | |
85 | * Kernel implementation stuff | |
86 | */ | |
87 | #define SEMVMX 32767 /* semaphore maximum value */ | |
88 | #define SEMAEM 16384 /* adjust on exit max value */ | |
89 | ||
90 | /* | |
91 | * Configuration parameters. SEMMNI, SEMMNS, and SEMMNU are hard limits. | |
92 | * The code dynamically allocates enough memory to satisfy the current | |
93 | * demand in even increments of SEMMNI_INC, SEMMNS_INC, and SEMMNU_INC. | |
94 | * The code will never allocate more than the hard limits. The *_INC's | |
95 | * are defined in the kernel section of the header. | |
96 | */ | |
97 | /* | |
98 | * Configuration parameters | |
99 | */ | |
100 | #ifndef SEMMNS /* # of semaphores in system */ | |
101 | #define SEMMNS (1048576/sizeof(struct sem)) | |
102 | #endif /* no more than 1M of semaphore data */ | |
103 | #ifndef SEMMNI /* # of semaphore identifiers */ | |
104 | #define SEMMNI SEMMNS /* max of 1 for each semaphore */ | |
105 | #endif | |
106 | #ifndef SEMUME | |
107 | #define SEMUME 10 /* max # of undo entries per process */ | |
108 | #endif | |
109 | #ifndef SEMMNU /* # of undo structures in system */ | |
110 | #define SEMMNU SEMMNS /* 1 for each semaphore. This is quite large */ | |
111 | #endif /* This should be max 1 for each process */ | |
112 | ||
113 | /* shouldn't need tuning */ | |
114 | #ifndef SEMMAP | |
115 | #define SEMMAP 30 /* # of entries in semaphore map */ | |
116 | #endif | |
117 | #ifndef SEMMSL | |
118 | #define SEMMSL SEMMNS /* max # of semaphores per id */ | |
119 | #endif | |
120 | #ifndef SEMOPM | |
121 | #define SEMOPM 100 /* max # of operations per semop call */ | |
122 | #endif | |
123 | ||
124 | ||
125 | /* | |
126 | * Undo structure (internal: one per process) | |
127 | */ | |
128 | struct sem_undo { | |
2d21ac55 | 129 | int un_next_idx; /* index of next active undo structure */ |
91447636 A |
130 | struct proc *un_proc; /* owner of this structure */ |
131 | short un_cnt; /* # of active entries */ | |
132 | struct undo { | |
133 | short une_adjval; /* adjust on exit values */ | |
134 | short une_num; /* semaphore # */ | |
135 | int une_id; /* semid */ | |
136 | struct undo *une_next; /* next undo entry */ | |
137 | } *un_ent; /* undo entries */ | |
138 | }; | |
139 | ||
140 | /* | |
141 | * semaphore info struct (internal; for administrative limits and ipcs) | |
142 | */ | |
143 | struct seminfo { | |
144 | int semmap, /* # of entries in semaphore map */ | |
145 | semmni, /* # of semaphore identifiers */ | |
146 | semmns, /* # of semaphores in system */ | |
147 | semmnu, /* # of undo structures in system */ | |
148 | semmsl, /* max # of semaphores per id */ | |
149 | semopm, /* max # of operations per semop call */ | |
150 | semume, /* max # of undo entries per process */ | |
151 | semusz, /* size in bytes of undo structure */ | |
152 | semvmx, /* semaphore maximum value */ | |
153 | semaem; /* adjust on exit max value */ | |
154 | }; | |
155 | extern struct seminfo seminfo; | |
156 | ||
2d21ac55 A |
157 | /* |
158 | * Kernel wrapper for the user-level structure | |
159 | */ | |
160 | struct semid_kernel { | |
161 | struct user_semid_ds u; | |
162 | struct label *label; /* MAC framework label */ | |
163 | }; | |
164 | ||
165 | ||
91447636 A |
166 | /* internal "mode" bits */ |
167 | #define SEM_ALLOC 01000 /* semaphore is allocated */ | |
168 | #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ | |
169 | ||
170 | #define SEMMNI_INC 8 /* increment value for semaphore identifiers */ | |
171 | #define SEMMNS_INC 64 /* increment value for semaphores */ | |
172 | #define SEMMNU_INC 32 /* increment value for undo structures */ | |
173 | ||
174 | /* | |
175 | * Due to the way semaphore memory is allocated, we have to ensure that | |
176 | * SEMUSZ is properly aligned. | |
177 | * | |
178 | * We are not doing strange semaphore memory allocation anymore, so | |
179 | * these macros are no longer needed. | |
180 | */ | |
181 | ||
182 | /* | |
183 | * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1)) | |
184 | */ | |
185 | ||
186 | /* actual size of an undo structure */ | |
187 | /* | |
188 | * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME])) | |
189 | */ | |
190 | #define SEMUSZ sizeof(struct sem_undo) | |
191 | ||
2d21ac55 | 192 | extern struct semid_kernel *sema; /* semaphore id pool */ |
91447636 A |
193 | extern struct sem *sem_pool; /* semaphore pool */ |
194 | /* This is now a struct sem_undo with the new memory allocation | |
195 | * extern int *semu; // undo structure pool | |
196 | */ | |
197 | extern struct sem_undo *semu; /* undo structure pool */ | |
198 | ||
199 | /* | |
200 | * Macro to find a particular sem_undo vector | |
201 | */ | |
202 | /* Until we can initialize seminfo.semusz to SEMUSZ, we hard code the size macro | |
203 | * in SEMU. This should be fixed when (if) we implement dynamic pool sizes | |
204 | * | |
205 | * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz)) | |
206 | */ | |
207 | /* | |
208 | * This macro doesn't work because we are using a staticly allocated array | |
209 | * for semu now. | |
210 | * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ)) | |
211 | */ | |
212 | #define SEMU(ix) (&semu[ix]) | |
213 | ||
214 | ||
215 | /* | |
216 | * Process sem_undo vectors at proc exit. | |
217 | */ | |
218 | void semexit(struct proc *p); | |
219 | ||
91447636 | 220 | #endif /* !_SYS_SEM__INTERNALH_ */ |