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