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