FreeBSD/Linux Kernel Cross Reference
sys/sys/sem.h
1 /* $NetBSD: sem.h,v 1.27 2008/10/22 11:25:19 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * SVID compatible sem.h file
35 *
36 * Author: Daniel Boulet
37 */
38
39 #ifndef _SYS_SEM_H_
40 #define _SYS_SEM_H_
41
42 #include <sys/featuretest.h>
43
44 #include <sys/ipc.h>
45
46 #ifdef _KERNEL
47 struct __sem {
48 unsigned short semval; /* semaphore value */
49 pid_t sempid; /* pid of last operation */
50 unsigned short semncnt; /* # awaiting semval > cval */
51 unsigned short semzcnt; /* # awaiting semval = 0 */
52 };
53 #endif /* _KERNEL */
54
55 struct semid_ds {
56 struct ipc_perm sem_perm; /* operation permission structure */
57 unsigned short sem_nsems; /* number of semaphores in set */
58 time_t sem_otime; /* last semop() time */
59 time_t sem_ctime; /* last time changed by semctl() */
60
61 /*
62 * These members are private and used only in the internal
63 * implementation of this interface.
64 */
65 struct __sem *_sem_base; /* pointer to first semaphore in set */
66 };
67
68 /*
69 * semop's sops parameter structure
70 */
71 struct sembuf {
72 unsigned short sem_num; /* semaphore # */
73 short sem_op; /* semaphore operation */
74 short sem_flg; /* operation flags */
75 };
76 #define SEM_UNDO 010000 /* undo changes on process exit */
77
78 /*
79 * commands for semctl
80 */
81 #define GETNCNT 3 /* Return the value of semncnt {READ} */
82 #define GETPID 4 /* Return the value of sempid {READ} */
83 #define GETVAL 5 /* Return the value of semval {READ} */
84 #define GETALL 6 /* Return semvals into arg.array {READ} */
85 #define GETZCNT 7 /* Return the value of semzcnt {READ} */
86 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
87 #define SETALL 9 /* Set semvals from arg.array {ALTER} */
88
89 #ifdef _KERNEL
90 /*
91 * Kernel implementation stuff
92 */
93 #define SEMVMX 32767 /* semaphore maximum value */
94 #define SEMAEM 16384 /* adjust on exit max value */
95
96 /*
97 * Permissions
98 */
99 #define SEM_A 0200 /* alter permission */
100 #define SEM_R 0400 /* read permission */
101
102 /*
103 * Undo structure (one per process)
104 */
105 struct sem_undo {
106 struct sem_undo *un_next; /* ptr to next active undo structure */
107 struct proc *un_proc; /* owner of this structure */
108 short un_cnt; /* # of active entries */
109 struct undo {
110 short un_adjval; /* adjust on exit values */
111 short un_num; /* semaphore # */
112 int un_id; /* semid */
113 } un_ent[1]; /* undo entries */
114 };
115 #endif /* _KERNEL */
116
117 #if defined(_NETBSD_SOURCE)
118 /*
119 * semaphore info struct
120 */
121 struct seminfo {
122 int32_t semmap; /* # of entries in semaphore map */
123 int32_t semmni; /* # of semaphore identifiers */
124 int32_t semmns; /* # of semaphores in system */
125 int32_t semmnu; /* # of undo structures in system */
126 int32_t semmsl; /* max # of semaphores per id */
127 int32_t semopm; /* max # of operations per semop call */
128 int32_t semume; /* max # of undo entries per process */
129 int32_t semusz; /* size in bytes of undo structure */
130 int32_t semvmx; /* semaphore maximum value */
131 int32_t semaem; /* adjust on exit max value */
132 };
133
134 /* Warning: 64-bit structure padding is needed here */
135 struct semid_ds_sysctl {
136 struct ipc_perm_sysctl sem_perm;
137 int16_t sem_nsems;
138 int16_t pad2;
139 int32_t pad3;
140 time_t sem_otime;
141 time_t sem_ctime;
142 };
143 struct sem_sysctl_info {
144 struct seminfo seminfo;
145 struct semid_ds_sysctl semids[1];
146 };
147
148 /*
149 * Internal "mode" bits. The first of these is used by ipcs(1), and so
150 * is defined outside the kernel as well.
151 */
152 #define SEM_ALLOC 01000 /* semaphore is allocated */
153 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
154
155 #ifdef _KERNEL
156 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */
157
158 /*
159 * Configuration parameters
160 */
161 #ifndef SEMMNI
162 #define SEMMNI 10 /* # of semaphore identifiers */
163 #endif
164 #ifndef SEMMNS
165 #define SEMMNS 60 /* # of semaphores in system */
166 #endif
167 #ifndef SEMUME
168 #define SEMUME 10 /* max # of undo entries per process */
169 #endif
170 #ifndef SEMMNU
171 #define SEMMNU 30 /* # of undo structures in system */
172 #endif
173
174 /* shouldn't need tuning */
175 #ifndef SEMMAP
176 #define SEMMAP 30 /* # of entries in semaphore map */
177 #endif
178 #ifndef SEMMSL
179 #define SEMMSL SEMMNS /* max # of semaphores per id */
180 #endif
181 #ifndef SEMOPM
182 #define SEMOPM 100 /* max # of operations per semop call */
183 #endif
184
185 /* actual size of an undo structure */
186 #define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
187
188 /*
189 * Structures allocated in machdep.c
190 */
191 extern struct seminfo seminfo;
192 extern struct semid_ds *sema; /* semaphore id pool */
193
194 /*
195 * Parameters to the semconfig system call
196 */
197 #define SEM_CONFIG_FREEZE 0 /* Freeze the semaphore facility. */
198 #define SEM_CONFIG_THAW 1 /* Thaw the semaphore facility. */
199 #endif /* _KERNEL */
200
201 #ifndef _KERNEL
202 #include <sys/cdefs.h>
203
204 __BEGIN_DECLS
205 #ifndef __LIBC12_SOURCE__
206 int semctl(int, int, int, ...) __RENAME(__semctl13);
207 #endif
208 int semget(key_t, int, int);
209 int semop(int, struct sembuf *, size_t);
210 #if defined(_NETBSD_SOURCE)
211 int semconfig(int);
212 #endif
213 __END_DECLS
214 #else
215 void seminit(void);
216 void semexit(struct proc *, void *);
217
218 int semctl1(struct lwp *, int, int, int, void *, register_t *);
219 #define get_semctl_arg(cmd, sembuf, arg) \
220 ((cmd) == IPC_SET || (cmd) == IPC_STAT ? (void *)sembuf \
221 : (cmd) == GETALL || (cmd) == SETVAL || (cmd) == SETALL ? (void *)arg \
222 : NULL)
223 #endif /* !_KERNEL */
224
225 #endif /* !_SYS_SEM_H_ */
Cache object: 35b24a89353ed1b81d8b16afd7387e16
|