]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem_internal.h
296d6dbf1825ca55e147d53d8a2827e5bd3a5520
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
33 * SVID compatible sem_internal.h file
35 * Author: Daniel Boulet
38 * John Bellardo modified the implementation for Darwin. 12/2000
41 #ifndef _SYS_SEM__INTERNALH_
42 #define _SYS_SEM__INTERNALH_
45 #include <sys/cdefs.h>
49 * This structure is variant for 64 bits because of sem_otime and sem_ctime.
52 #if __DARWIN_ALIGN_NATURAL
53 #pragma options align=natural
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! */
70 user_addr_t buf
; /* buffer for IPC_STAT & IPC_SET */
71 user_addr_t array
; /* array for GETALL & SETALL */
73 typedef union user_semun user_semun_t
;
75 #if __DARWIN_ALIGN_NATURAL
76 #pragma options align=reset
81 * Kernel implementation stuff
83 #define SEMVMX 32767 /* semaphore maximum value */
84 #define SEMAEM 16384 /* adjust on exit max value */
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.
94 * Configuration parameters
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 */
103 #define SEMUME 10 /* max # of undo entries per process */
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 */
109 /* shouldn't need tuning */
111 #define SEMMAP 30 /* # of entries in semaphore map */
114 #define SEMMSL SEMMNS /* max # of semaphores per id */
117 #define SEMOPM 100 /* max # of operations per semop call */
122 * Undo structure (internal: one per process)
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 */
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 */
137 * semaphore info struct (internal; for administrative limits and ipcs)
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 */
151 extern struct seminfo seminfo
;
153 /* internal "mode" bits */
154 #define SEM_ALLOC 01000 /* semaphore is allocated */
155 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
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 */
162 * Due to the way semaphore memory is allocated, we have to ensure that
163 * SEMUSZ is properly aligned.
165 * We are not doing strange semaphore memory allocation anymore, so
166 * these macros are no longer needed.
170 * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
173 /* actual size of an undo structure */
175 * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
177 #define SEMUSZ sizeof(struct sem_undo)
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
184 extern struct sem_undo
*semu
; /* undo structure pool */
187 * Macro to find a particular sem_undo vector
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
192 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
195 * This macro doesn't work because we are using a staticly allocated array
197 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ))
199 #define SEMU(ix) (&semu[ix])
203 * Process sem_undo vectors at proc exit.
205 void semexit(struct proc
*p
);
207 #endif /* !_SYS_SEM__INTERNALH_ */