]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
9bccf70c | 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ | |
26 | ||
27 | /* | |
28 | * SVID compatible sem.h file | |
29 | * | |
30 | * Author: Daniel Boulet | |
31 | */ | |
9bccf70c A |
32 | /* |
33 | * John Bellardo modified the implementation for Darwin. 12/2000 | |
34 | */ | |
1c79356b A |
35 | |
36 | #ifndef _SYS_SEM_H_ | |
37 | #define _SYS_SEM_H_ | |
38 | ||
9bccf70c | 39 | #include <sys/appleapiopts.h> |
1c79356b A |
40 | #include <sys/ipc.h> |
41 | ||
42 | struct sem { | |
43 | u_short semval; /* semaphore value */ | |
44 | pid_t sempid; /* pid of last operation */ | |
45 | u_short semncnt; /* # awaiting semval > cval */ | |
46 | u_short semzcnt; /* # awaiting semval = 0 */ | |
47 | }; | |
48 | ||
49 | struct semid_ds { | |
50 | struct ipc_perm sem_perm; /* operation permission struct */ | |
51 | struct sem *sem_base; /* pointer to first semaphore in set */ | |
52 | u_short sem_nsems; /* number of sems in set */ | |
53 | time_t sem_otime; /* last operation time */ | |
54 | long sem_pad1; /* SVABI/386 says I need this here */ | |
55 | time_t sem_ctime; /* last change time */ | |
56 | /* Times measured in secs since */ | |
57 | /* 00:00:00 GMT, Jan. 1, 1970 */ | |
58 | long sem_pad2; /* SVABI/386 says I need this here */ | |
59 | long sem_pad3[4]; /* SVABI/386 says I need this here */ | |
60 | }; | |
61 | ||
62 | /* | |
63 | * semop's sops parameter structure | |
64 | */ | |
65 | struct sembuf { | |
66 | u_short sem_num; /* semaphore # */ | |
67 | short sem_op; /* semaphore operation */ | |
68 | short sem_flg; /* operation flags */ | |
69 | }; | |
70 | #define SEM_UNDO 010000 | |
71 | ||
72 | #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */ | |
73 | ||
74 | /* | |
75 | * semctl's arg parameter structure | |
76 | */ | |
77 | union semun { | |
78 | int val; /* value for SETVAL */ | |
79 | struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ | |
80 | u_short *array; /* array for GETALL & SETALL */ | |
81 | }; | |
82 | ||
83 | /* | |
84 | * commands for semctl | |
85 | */ | |
86 | #define GETNCNT 3 /* Return the value of semncnt {READ} */ | |
87 | #define GETPID 4 /* Return the value of sempid {READ} */ | |
88 | #define GETVAL 5 /* Return the value of semval {READ} */ | |
89 | #define GETALL 6 /* Return semvals into arg.array {READ} */ | |
90 | #define GETZCNT 7 /* Return the value of semzcnt {READ} */ | |
91 | #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ | |
92 | #define SETALL 9 /* Set semvals from arg.array {ALTER} */ | |
93 | ||
94 | /* | |
95 | * Permissions | |
96 | */ | |
97 | #define SEM_A 0200 /* alter permission */ | |
98 | #define SEM_R 0400 /* read permission */ | |
99 | ||
100 | #ifdef KERNEL | |
9bccf70c | 101 | #ifdef __APPLE_API_PRIVATE |
1c79356b A |
102 | /* |
103 | * Kernel implementation stuff | |
104 | */ | |
105 | #define SEMVMX 32767 /* semaphore maximum value */ | |
106 | #define SEMAEM 16384 /* adjust on exit max value */ | |
107 | ||
9bccf70c A |
108 | /* |
109 | * Configuration parameters. SEMMNI, SEMMNS, and SEMMNU are hard limits. | |
110 | * The code dynamically allocates enough memory to satisfy the current | |
111 | * demand in even increments of SEMMNI_INC, SEMMNS_INC, and SEMMNU_INC. | |
112 | * The code will never allocate more than the hard limits. The *_INC's | |
113 | * are defined in the kernel section of the header. | |
114 | */ | |
115 | /* | |
116 | * Configuration parameters | |
117 | */ | |
118 | #ifndef SEMMNS /* # of semaphores in system */ | |
119 | #define SEMMNS (1048576/sizeof(struct sem)) | |
120 | #endif /* no more than 1M of semaphore data */ | |
121 | #ifndef SEMMNI /* # of semaphore identifiers */ | |
122 | #define SEMMNI SEMMNS /* max of 1 for each semaphore */ | |
123 | #endif | |
124 | #ifndef SEMUME | |
125 | #define SEMUME 10 /* max # of undo entries per process */ | |
126 | #endif | |
127 | #ifndef SEMMNU /* # of undo structures in system */ | |
128 | #define SEMMNU SEMMNS /* 1 for each semaphore. This is quite large */ | |
129 | #endif /* This should be max 1 for each process */ | |
130 | ||
131 | /* shouldn't need tuning */ | |
132 | #ifndef SEMMAP | |
133 | #define SEMMAP 30 /* # of entries in semaphore map */ | |
134 | #endif | |
135 | #ifndef SEMMSL | |
136 | #define SEMMSL SEMMNS /* max # of semaphores per id */ | |
137 | #endif | |
138 | #ifndef SEMOPM | |
139 | #define SEMOPM 100 /* max # of operations per semop call */ | |
140 | #endif | |
141 | ||
1c79356b A |
142 | |
143 | /* | |
144 | * Undo structure (one per process) | |
145 | */ | |
146 | struct sem_undo { | |
147 | struct sem_undo *un_next; /* ptr to next active undo structure */ | |
148 | struct proc *un_proc; /* owner of this structure */ | |
149 | short un_cnt; /* # of active entries */ | |
150 | struct undo { | |
151 | short un_adjval; /* adjust on exit values */ | |
152 | short un_num; /* semaphore # */ | |
153 | int un_id; /* semid */ | |
9bccf70c | 154 | } un_ent[SEMUME]; /* undo entries */ |
1c79356b A |
155 | }; |
156 | ||
157 | /* | |
158 | * semaphore info struct | |
159 | */ | |
160 | struct seminfo { | |
161 | int semmap, /* # of entries in semaphore map */ | |
162 | semmni, /* # of semaphore identifiers */ | |
163 | semmns, /* # of semaphores in system */ | |
164 | semmnu, /* # of undo structures in system */ | |
165 | semmsl, /* max # of semaphores per id */ | |
166 | semopm, /* max # of operations per semop call */ | |
167 | semume, /* max # of undo entries per process */ | |
168 | semusz, /* size in bytes of undo structure */ | |
169 | semvmx, /* semaphore maximum value */ | |
170 | semaem; /* adjust on exit max value */ | |
171 | }; | |
172 | extern struct seminfo seminfo; | |
173 | ||
174 | /* internal "mode" bits */ | |
175 | #define SEM_ALLOC 01000 /* semaphore is allocated */ | |
176 | #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ | |
177 | ||
9bccf70c A |
178 | #define SEMMNI_INC 8 /* increment value for semaphore identifiers */ |
179 | #define SEMMNS_INC 64 /* increment value for semaphores */ | |
180 | #define SEMMNU_INC 32 /* increment value for undo structures */ | |
1c79356b A |
181 | |
182 | /* | |
183 | * Due to the way semaphore memory is allocated, we have to ensure that | |
184 | * SEMUSZ is properly aligned. | |
9bccf70c A |
185 | * |
186 | * We are not doing strange semaphore memory allocation anymore, so | |
187 | * these macros are no longer needed. | |
1c79356b A |
188 | */ |
189 | ||
9bccf70c A |
190 | /* |
191 | * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1)) | |
192 | */ | |
1c79356b A |
193 | |
194 | /* actual size of an undo structure */ | |
9bccf70c A |
195 | /* |
196 | * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME])) | |
197 | */ | |
198 | #define SEMUSZ sizeof(struct sem_undo) | |
1c79356b A |
199 | |
200 | extern struct semid_ds *sema; /* semaphore id pool */ | |
201 | extern struct sem *sem; /* semaphore pool */ | |
9bccf70c A |
202 | /* This is now a struct sem_undo with the new memory allocation |
203 | * extern int *semu; /* undo structure pool | |
204 | */ | |
205 | extern struct sem_undo *semu; /* undo structure pool */ | |
1c79356b A |
206 | |
207 | /* | |
208 | * Macro to find a particular sem_undo vector | |
209 | */ | |
9bccf70c A |
210 | /* Until we can initialize seminfo.semusz to SEMUSZ, we hard code the size macro |
211 | * in SEMU. This should be fixed when (if) we implement dynamic pool sizes | |
212 | * | |
213 | * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz)) | |
214 | */ | |
215 | /* | |
216 | * This macro doesn't work because we are using a staticly allocated array | |
217 | * for semu now. | |
218 | * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ)) | |
219 | */ | |
220 | #define SEMU(ix) (&semu[ix]) | |
221 | ||
1c79356b A |
222 | |
223 | /* | |
224 | * Process sem_undo vectors at proc exit. | |
225 | */ | |
226 | void semexit __P((struct proc *p)); | |
227 | ||
228 | /* | |
229 | * Parameters to the semconfig system call | |
230 | */ | |
231 | typedef enum { | |
232 | SEM_CONFIG_FREEZE, /* Freeze the semaphore facility. */ | |
233 | SEM_CONFIG_THAW /* Thaw the semaphore facility. */ | |
234 | } semconfig_ctl_t; | |
9bccf70c A |
235 | |
236 | #endif /* __APPLE_API_PRIVATE */ | |
237 | ||
1c79356b A |
238 | #endif /* KERNEL */ |
239 | ||
240 | #ifndef KERNEL | |
241 | #include <sys/cdefs.h> | |
242 | ||
243 | __BEGIN_DECLS | |
244 | int semsys __P((int, ...)); | |
55e303ae | 245 | int semctl __P((int, int, int, ...)); |
1c79356b A |
246 | int semget __P((key_t, int, int)); |
247 | int semop __P((int, struct sembuf *,unsigned)); | |
248 | __END_DECLS | |
249 | #endif /* !KERNEL */ | |
250 | ||
251 | #endif /* !_SEM_H_ */ |