FreeBSD/Linux Kernel Cross Reference
sys/sys/sem.h
1 /* $NetBSD: sem.h,v 1.22 2006/07/23 22:06:14 ad 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 /*
76 * semop's sops parameter structure
77 */
78 struct sembuf {
79 unsigned short sem_num; /* semaphore # */
80 short sem_op; /* semaphore operation */
81 short sem_flg; /* operation flags */
82 };
83 #define SEM_UNDO 010000 /* undo changes on process exit */
84
85 /*
86 * commands for semctl
87 */
88 #define GETNCNT 3 /* Return the value of semncnt {READ} */
89 #define GETPID 4 /* Return the value of sempid {READ} */
90 #define GETVAL 5 /* Return the value of semval {READ} */
91 #define GETALL 6 /* Return semvals into arg.array {READ} */
92 #define GETZCNT 7 /* Return the value of semzcnt {READ} */
93 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
94 #define SETALL 9 /* Set semvals from arg.array {ALTER} */
95
96 #ifdef _KERNEL
97 /*
98 * Kernel implementation stuff
99 */
100 #define SEMVMX 32767 /* semaphore maximum value */
101 #define SEMAEM 16384 /* adjust on exit max value */
102
103 /*
104 * Permissions
105 */
106 #define SEM_A 0200 /* alter permission */
107 #define SEM_R 0400 /* read permission */
108
109 /*
110 * Undo structure (one per process)
111 */
112 struct sem_undo {
113 struct sem_undo *un_next; /* ptr to next active undo structure */
114 struct proc *un_proc; /* owner of this structure */
115 short un_cnt; /* # of active entries */
116 struct undo {
117 short un_adjval; /* adjust on exit values */
118 short un_num; /* semaphore # */
119 int un_id; /* semid */
120 } un_ent[1]; /* undo entries */
121 };
122 #endif /* _KERNEL */
123
124 #if defined(_NETBSD_SOURCE)
125 /*
126 * semaphore info struct
127 */
128 struct seminfo {
129 int32_t semmap; /* # of entries in semaphore map */
130 int32_t semmni; /* # of semaphore identifiers */
131 int32_t semmns; /* # of semaphores in system */
132 int32_t semmnu; /* # of undo structures in system */
133 int32_t semmsl; /* max # of semaphores per id */
134 int32_t semopm; /* max # of operations per semop call */
135 int32_t semume; /* max # of undo entries per process */
136 int32_t semusz; /* size in bytes of undo structure */
137 int32_t semvmx; /* semaphore maximum value */
138 int32_t semaem; /* adjust on exit max value */
139 };
140
141 /* Warning: 64-bit structure padding is needed here */
142 struct semid_ds_sysctl {
143 struct ipc_perm_sysctl sem_perm;
144 int16_t sem_nsems;
145 int16_t pad2;
146 int32_t pad3;
147 time_t sem_otime;
148 time_t sem_ctime;
149 };
150 struct sem_sysctl_info {
151 struct seminfo seminfo;
152 struct semid_ds_sysctl semids[1];
153 };
154
155 /*
156 * Internal "mode" bits. The first of these is used by ipcs(1), and so
157 * is defined outside the kernel as well.
158 */
159 #define SEM_ALLOC 01000 /* semaphore is allocated */
160 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
161
162 #ifdef _KERNEL
163 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
164
165 /*
166 * Configuration parameters
167 */
168 #ifndef SEMMNI
169 #define SEMMNI 10 /* # of semaphore identifiers */
170 #endif
171 #ifndef SEMMNS
172 #define SEMMNS 60 /* # of semaphores in system */
173 #endif
174 #ifndef SEMUME
175 #define SEMUME 10 /* max # of undo entries per process */
176 #endif
177 #ifndef SEMMNU
178 #define SEMMNU 30 /* # of undo structures in system */
179 #endif
180
181 /* shouldn't need tuning */
182 #ifndef SEMMAP
183 #define SEMMAP 30 /* # of entries in semaphore map */
184 #endif
185 #ifndef SEMMSL
186 #define SEMMSL SEMMNS /* max # of semaphores per id */
187 #endif
188 #ifndef SEMOPM
189 #define SEMOPM 100 /* max # of operations per semop call */
190 #endif
191
192 /* actual size of an undo structure */
193 #define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
194
195 /*
196 * Structures allocated in machdep.c
197 */
198 extern struct seminfo seminfo;
199 extern struct semid_ds *sema; /* semaphore id pool */
200
201 /*
202 * Macro to find a particular sem_undo vector
203 */
204 #define SEMU(ix) ((struct sem_undo *)(((long)semu)+ix * SEMUSZ))
205
206 /*
207 * Parameters to the semconfig system call
208 */
209 #define SEM_CONFIG_FREEZE 0 /* Freeze the semaphore facility. */
210 #define SEM_CONFIG_THAW 1 /* Thaw the semaphore facility. */
211 #endif /* _KERNEL */
212
213 #ifndef _KERNEL
214 #include <sys/cdefs.h>
215
216 __BEGIN_DECLS
217 #ifndef __LIBC12_SOURCE__
218 int semctl(int, int, int, ...) __RENAME(__semctl13);
219 #endif
220 int semget(key_t, int, int);
221 int semop(int, struct sembuf *, size_t);
222 #if defined(_NETBSD_SOURCE)
223 int semconfig(int);
224 #endif
225 __END_DECLS
226 #else
227 void seminit(void);
228 void semexit(struct proc *, void *);
229
230 int semctl1(struct lwp *, int, int, int, void *, register_t *);
231 #endif /* !_KERNEL */
232
233 #endif /* !_SYS_SEM_H_ */
Cache object: 2d06ce674c07a289eed174d910b0c0e7
|