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