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