FreeBSD/Linux Kernel Cross Reference
sys/sys/sem.h
1 /* $NetBSD: sem.h,v 1.18.4.1 2005/11/05 00:47:00 tron Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * SVID compatible sem.h file
42 *
43 * Author: Daniel Boulet
44 */
45
46 #ifndef _SYS_SEM_H_
47 #define _SYS_SEM_H_
48
49 #include <sys/featuretest.h>
50
51 #include <sys/ipc.h>
52
53 #ifdef _KERNEL
54 struct __sem {
55 unsigned short semval; /* semaphore value */
56 pid_t sempid; /* pid of last operation */
57 unsigned short semncnt; /* # awaiting semval > cval */
58 unsigned short semzcnt; /* # awaiting semval = 0 */
59 };
60 #endif /* _KERNEL */
61
62 struct semid_ds {
63 struct ipc_perm sem_perm; /* operation permission structure */
64 unsigned short sem_nsems; /* number of semaphores in set */
65 time_t sem_otime; /* last semop() time */
66 time_t sem_ctime; /* last time changed by semctl() */
67
68 /*
69 * These members are private and used only in the internal
70 * implementation of this interface.
71 */
72 struct __sem *_sem_base; /* pointer to first semaphore in set */
73 };
74
75 #ifdef _KERNEL
76 struct semid_ds14 {
77 struct ipc_perm14 sem_perm; /* operation permission struct */
78 struct __sem *sem_base; /* pointer to first semaphore in set */
79 unsigned short sem_nsems; /* number of sems in set */
80 time_t sem_otime; /* last operation time */
81 long sem_pad1; /* SVABI/386 says I need this here */
82 time_t sem_ctime; /* last change time */
83 /* Times measured in secs since */
84 /* 00:00:00 GMT, Jan. 1, 1970 */
85 long sem_pad2; /* SVABI/386 says I need this here */
86 long sem_pad3[4]; /* SVABI/386 says I need this here */
87 };
88 #endif /* _KERNEL */
89
90 /*
91 * semop's sops parameter structure
92 */
93 struct sembuf {
94 unsigned short sem_num; /* semaphore # */
95 short sem_op; /* semaphore operation */
96 short sem_flg; /* operation flags */
97 };
98 #define SEM_UNDO 010000 /* undo changes on process exit */
99
100 /*
101 * commands for semctl
102 */
103 #define GETNCNT 3 /* Return the value of semncnt {READ} */
104 #define GETPID 4 /* Return the value of sempid {READ} */
105 #define GETVAL 5 /* Return the value of semval {READ} */
106 #define GETALL 6 /* Return semvals into arg.array {READ} */
107 #define GETZCNT 7 /* Return the value of semzcnt {READ} */
108 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
109 #define SETALL 9 /* Set semvals from arg.array {ALTER} */
110
111 #ifdef _KERNEL
112 /*
113 * Kernel implementation stuff
114 */
115 #define SEMVMX 32767 /* semaphore maximum value */
116 #define SEMAEM 16384 /* adjust on exit max value */
117
118 /*
119 * Permissions
120 */
121 #define SEM_A 0200 /* alter permission */
122 #define SEM_R 0400 /* read permission */
123
124 /*
125 * Undo structure (one per process)
126 */
127 struct sem_undo {
128 struct sem_undo *un_next; /* ptr to next active undo structure */
129 struct proc *un_proc; /* owner of this structure */
130 short un_cnt; /* # of active entries */
131 struct undo {
132 short un_adjval; /* adjust on exit values */
133 short un_num; /* semaphore # */
134 int un_id; /* semid */
135 } un_ent[1]; /* undo entries */
136 };
137 #endif /* _KERNEL */
138
139 #if defined(_NETBSD_SOURCE)
140 /*
141 * semaphore info struct
142 */
143 struct seminfo {
144 int32_t semmap; /* # of entries in semaphore map */
145 int32_t semmni; /* # of semaphore identifiers */
146 int32_t semmns; /* # of semaphores in system */
147 int32_t semmnu; /* # of undo structures in system */
148 int32_t semmsl; /* max # of semaphores per id */
149 int32_t semopm; /* max # of operations per semop call */
150 int32_t semume; /* max # of undo entries per process */
151 int32_t semusz; /* size in bytes of undo structure */
152 int32_t semvmx; /* semaphore maximum value */
153 int32_t semaem; /* adjust on exit max value */
154 };
155
156 /* Warning: 64-bit structure padding is needed here */
157 struct semid_ds_sysctl {
158 struct ipc_perm_sysctl sem_perm;
159 int16_t sem_nsems;
160 int16_t pad2;
161 int32_t pad3;
162 time_t sem_otime;
163 time_t sem_ctime;
164 };
165 struct sem_sysctl_info {
166 struct seminfo seminfo;
167 struct semid_ds_sysctl semids[1];
168 };
169
170 /*
171 * Internal "mode" bits. The first of these is used by ipcs(1), and so
172 * is defined outside the kernel as well.
173 */
174 #define SEM_ALLOC 01000 /* semaphore is allocated */
175 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
176
177 #ifdef _KERNEL
178 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
179
180 /*
181 * Configuration parameters
182 */
183 #ifndef SEMMNI
184 #define SEMMNI 10 /* # of semaphore identifiers */
185 #endif
186 #ifndef SEMMNS
187 #define SEMMNS 60 /* # of semaphores in system */
188 #endif
189 #ifndef SEMUME
190 #define SEMUME 10 /* max # of undo entries per process */
191 #endif
192 #ifndef SEMMNU
193 #define SEMMNU 30 /* # of undo structures in system */
194 #endif
195
196 /* shouldn't need tuning */
197 #ifndef SEMMAP
198 #define SEMMAP 30 /* # of entries in semaphore map */
199 #endif
200 #ifndef SEMMSL
201 #define SEMMSL SEMMNS /* max # of semaphores per id */
202 #endif
203 #ifndef SEMOPM
204 #define SEMOPM 100 /* max # of operations per semop call */
205 #endif
206
207 /* actual size of an undo structure */
208 #define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
209
210 /*
211 * Structures allocated in machdep.c
212 */
213 extern struct seminfo seminfo;
214 extern struct semid_ds *sema; /* semaphore id pool */
215
216 /*
217 * Macro to find a particular sem_undo vector
218 */
219 #define SEMU(ix) ((struct sem_undo *)(((long)semu)+ix * SEMUSZ))
220
221 /*
222 * Parameters to the semconfig system call
223 */
224 #define SEM_CONFIG_FREEZE 0 /* Freeze the semaphore facility. */
225 #define SEM_CONFIG_THAW 1 /* Thaw the semaphore facility. */
226 #endif /* _KERNEL */
227
228 #ifndef _KERNEL
229 #include <sys/cdefs.h>
230
231 __BEGIN_DECLS
232 #if defined(__LIBC12_SOURCE__)
233 int semctl(int, int, int, union __semun);
234 int __semctl(int, int, int, union __semun *);
235 int __semctl13(int, int, int, ...);
236 #else
237 int semctl(int, int, int, ...) __RENAME(__semctl13);
238 #endif
239 int semget(key_t, int, int);
240 int semop(int, struct sembuf *, size_t);
241 #if defined(_NETBSD_SOURCE)
242 int semconfig(int);
243 #endif
244 __END_DECLS
245 #else
246 void seminit(void);
247 void semexit(struct proc *, void *);
248
249 int semctl1(struct proc *, int, int, int, void *, register_t *);
250 #endif /* !_KERNEL */
251
252 #endif /* !_SEM_H_ */
Cache object: 02a21654333397068056358eae47d0cb
|