]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/sem_internal.h
bcaa2b54abe121b60bc109f17be93f22d1e9638f
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
25 * SVID compatible sem_internal.h file
27 * Author: Daniel Boulet
30 * John Bellardo modified the implementation for Darwin. 12/2000
33 #ifndef _SYS_SEM__INTERNALH_
34 #define _SYS_SEM__INTERNALH_
37 #include <sys/cdefs.h>
41 * This structure is variant for 64 bits because of sem_otime and sem_ctime.
44 #if __DARWIN_ALIGN_NATURAL
45 #pragma options align=natural
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! */
62 user_addr_t buf
; /* buffer for IPC_STAT & IPC_SET */
63 user_addr_t array
; /* array for GETALL & SETALL */
65 typedef union user_semun user_semun_t
;
67 #if __DARWIN_ALIGN_NATURAL
68 #pragma options align=reset
73 * Kernel implementation stuff
75 #define SEMVMX 32767 /* semaphore maximum value */
76 #define SEMAEM 16384 /* adjust on exit max value */
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.
86 * Configuration parameters
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 */
95 #define SEMUME 10 /* max # of undo entries per process */
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 */
101 /* shouldn't need tuning */
103 #define SEMMAP 30 /* # of entries in semaphore map */
106 #define SEMMSL SEMMNS /* max # of semaphores per id */
109 #define SEMOPM 100 /* max # of operations per semop call */
114 * Undo structure (internal: one per process)
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 */
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 */
129 * semaphore info struct (internal; for administrative limits and ipcs)
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 */
143 extern struct seminfo seminfo
;
145 /* internal "mode" bits */
146 #define SEM_ALLOC 01000 /* semaphore is allocated */
147 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
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 */
154 * Due to the way semaphore memory is allocated, we have to ensure that
155 * SEMUSZ is properly aligned.
157 * We are not doing strange semaphore memory allocation anymore, so
158 * these macros are no longer needed.
162 * #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
165 /* actual size of an undo structure */
167 * #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
169 #define SEMUSZ sizeof(struct sem_undo)
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
176 extern struct sem_undo
*semu
; /* undo structure pool */
179 * Macro to find a particular sem_undo vector
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
184 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
187 * This macro doesn't work because we are using a staticly allocated array
189 * #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * SEMUSZ))
191 #define SEMU(ix) (&semu[ix])
195 * Process sem_undo vectors at proc exit.
197 void semexit(struct proc
*p
);
199 #endif /* !_SYS_SEM__INTERNALH_ */