]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem_internal.h
d06c73fab6135dd7dab449a48fbc8b45fc9b3239
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
21 * @APPLE_LICENSE_HEADER_END@
23 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
26 * SVID compatible sem_internal.h file
28 * Author: Daniel Boulet
31 * John Bellardo modified the implementation for Darwin. 12/2000
34 #ifndef _SYS_SEM__INTERNALH_
35 #define _SYS_SEM__INTERNALH_
38 #include <sys/cdefs.h>
42 * This structure is variant for 64 bits because of sem_otime and sem_ctime.
45 #if __DARWIN_ALIGN_NATURAL
46 #pragma options align=natural
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! */
63 user_addr_t buf
; /* buffer for IPC_STAT & IPC_SET */
64 user_addr_t array
; /* array for GETALL & SETALL */
66 typedef union user_semun user_semun_t
;
68 #if __DARWIN_ALIGN_NATURAL
69 #pragma options align=reset
74 * Kernel implementation stuff
76 #define SEMVMX 32767 /* semaphore maximum value */
77 #define SEMAEM 16384 /* adjust on exit max value */
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.
87 * Configuration parameters
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 */
96 #define SEMUME 10 /* max # of undo entries per process */
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 */
102 /* shouldn't need tuning */
104 #define SEMMAP 30 /* # of entries in semaphore map */
107 #define SEMMSL SEMMNS /* max # of semaphores per id */
110 #define SEMOPM 100 /* max # of operations per semop call */
115 * Undo structure (internal: one per process)
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 */
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 */
130 * semaphore info struct (internal; for administrative limits and ipcs)
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 */
144 extern struct seminfo seminfo
;
146 /* internal "mode" bits */
147 #define SEM_ALLOC 01000 /* semaphore is allocated */
148 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
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 */
155 * Due to the way semaphore memory is allocated, we have to ensure that
156 * SEMUSZ is properly aligned.
158 * We are not doing strange semaphore memory allocation anymore, so
159 * these macros are no longer needed.
163 * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
166 /* actual size of an undo structure */
168 * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
170 #define SEMUSZ sizeof(struct sem_undo)
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
177 extern struct sem_undo
*semu
; /* undo structure pool */
180 * Macro to find a particular sem_undo vector
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
185 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
188 * This macro doesn't work because we are using a staticly allocated array
190 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ))
192 #define SEMU(ix) (&semu[ix])
196 * Process sem_undo vectors at proc exit.
198 void semexit(struct proc
*p
);
201 * Parameters to the semconfig system call
204 SEM_CONFIG_FREEZE
, /* Freeze the semaphore facility. */
205 SEM_CONFIG_THAW
/* Thaw the semaphore facility. */
209 #endif /* !_SYS_SEM__INTERNALH_ */