]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/sem.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / sys / sem.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */
29
30/*
31 * SVID compatible sem.h file
32 *
33 * Author: Daniel Boulet
9bccf70c
A
34 * John Bellardo modified the implementation for Darwin. 12/2000
35 */
1c79356b
A
36
37#ifndef _SYS_SEM_H_
38#define _SYS_SEM_H_
39
1c79356b 40
91447636
A
41#include <sys/cdefs.h>
42#include <sys/_types.h>
1c79356b
A
43
44/*
91447636
A
45 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined
46 * when this header is included
1c79356b 47 */
91447636 48#include <sys/ipc.h>
1c79356b 49
1c79356b 50
9bccf70c 51/*
91447636
A
52 * [XSI] The pid_t, time_t, key_t, and size_t types shall be defined as
53 * described in <sys/types.h>.
54 *
55 * NOTE: The definition of the key_t type is implicit from the
56 * inclusion of <sys/ipc.h>
9bccf70c 57 */
91447636
A
58#ifndef _PID_T
59typedef __darwin_pid_t pid_t;
60#define _PID_T
9bccf70c 61#endif
9bccf70c 62
91447636
A
63#ifndef _TIME_T
64#define _TIME_T
65typedef __darwin_time_t time_t;
9bccf70c
A
66#endif
67
91447636
A
68#ifndef _SIZE_T
69#define _SIZE_T
70typedef __darwin_size_t size_t;
71#endif
1c79356b
A
72
73/*
91447636
A
74 * Technically, we should force all code references to the new structure
75 * definition, not in just the standards conformance case, and leave the
76 * legacy interface there for binary compatibility only. Currently, we
77 * are only forcing this for programs requesting standards conformance.
1c79356b 78 */
91447636
A
79#if defined(__POSIX_C_SOURCE) || defined(kernel) || defined(__LP64__)
80/*
81 * Structure used internally.
82 *
83 * This structure is exposed because standards dictate that it is used as
84 * the semun union member 'buf' as the fourth argment to semctl() when the
85 * third argument is IPC_STAT or IPC_SET.
86 *
87 * Note: only the fields sem_perm, sem_nsems, sem_otime, and sem_ctime
88 * are meaningful in user space.
89 */
90struct __semid_ds_new {
91 struct __ipc_perm_new sem_perm; /* [XSI] operation permission struct */
92 __int32_t sem_base; /* 32 bit base ptr for semaphore set */
93 unsigned short sem_nsems; /* [XSI] number of sems in set */
94 time_t sem_otime; /* [XSI] last operation time */
95 __int32_t sem_pad1; /* RESERVED: DO NOT USE! */
96 time_t sem_ctime; /* [XSI] last change time */
97 /* Times measured in secs since */
98 /* 00:00:00 GMT, Jan. 1, 1970 */
99 __int32_t sem_pad2; /* RESERVED: DO NOT USE! */
100 __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
101};
102#define semid_ds __semid_ds_new
103#else /* !_POSIX_C_SOURCE */
104#define semid_ds __semid_ds_old
105#endif /* !_POSIX_C_SOURCE */
106
107#if !defined(__POSIX_C_SOURCE) && !defined(__LP64__)
108struct __semid_ds_old {
109 struct __ipc_perm_old sem_perm; /* [XSI] operation permission struct */
110 __int32_t sem_base; /* 32 bit base ptr for semaphore set */
111 unsigned short sem_nsems; /* [XSI] number of sems in set */
112 time_t sem_otime; /* [XSI] last operation time */
113 __int32_t sem_pad1; /* RESERVED: DO NOT USE! */
114 time_t sem_ctime; /* [XSI] last change time */
115 /* Times measured in secs since */
116 /* 00:00:00 GMT, Jan. 1, 1970 */
117 __int32_t sem_pad2; /* RESERVED: DO NOT USE! */
118 __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
1c79356b 119};
91447636 120#endif /* !_POSIX_C_SOURCE */
1c79356b
A
121
122/*
91447636 123 * Possible values for the third argument to semctl()
1c79356b 124 */
91447636
A
125#define GETNCNT 3 /* [XSI] Return the value of semncnt {READ} */
126#define GETPID 4 /* [XSI] Return the value of sempid {READ} */
127#define GETVAL 5 /* [XSI] Return the value of semval {READ} */
128#define GETALL 6 /* [XSI] Return semvals into arg.array {READ} */
129#define GETZCNT 7 /* [XSI] Return the value of semzcnt {READ} */
130#define SETVAL 8 /* [XSI] Set the value of semval to arg.val {ALTER} */
131#define SETALL 9 /* [XSI] Set semvals from arg.array {ALTER} */
1c79356b 132
1c79356b 133
91447636
A
134/* A semaphore; this is an anonymous structure, not for external use */
135struct sem {
136 unsigned short semval; /* semaphore value */
137 pid_t sempid; /* pid of last operation */
138 unsigned short semncnt; /* # awaiting semval > cval */
139 unsigned short semzcnt; /* # awaiting semval == 0 */
140};
141
1c79356b
A
142
143/*
91447636 144 * Structure of array element for second argument to semop()
1c79356b 145 */
91447636
A
146struct sembuf {
147 unsigned short sem_num; /* [XSI] semaphore # */
148 short sem_op; /* [XSI] semaphore operation */
149 short sem_flg; /* [XSI] operation flags */
150};
1c79356b 151
9bccf70c 152/*
91447636 153 * Possible flag values for sem_flg
9bccf70c 154 */
91447636
A
155#define SEM_UNDO 010000 /* [XSI] Set up adjust on exit entry */
156
157
158#ifndef _POSIX_C_SOURCE
1c79356b 159
9bccf70c 160/*
91447636
A
161 * System imposed limit on the value of the third parameter to semop().
162 * This is arbitrary, and the standards unfortunately do not provide a
163 * way for user applications to retrieve this value (e.g. via sysconf()
164 * or from a manifest value in <unistd.h>). The value shown here is
165 * informational, and subject to change in future revisions.
9bccf70c 166 */
91447636 167#define MAX_SOPS 5 /* maximum # of sembuf's per semop call */
1c79356b 168
1c79356b
A
169
170/*
91447636
A
171 * Union used as the fourth argment to semctl() in all cases. Specific
172 * member values are used for different values of the third parameter:
173 *
174 * Command Member
175 * ------------------------------------------- ------
176 * GETALL, SETALL array
177 * SETVAL val
178 * IPC_STAT, IPC_SET buf
9bccf70c 179 *
91447636
A
180 * The union definition is intended to be defined by the user application
181 * in conforming applications; it is provided here for two reasons:
182 *
183 * 1) Historical source compatability for non-conforming applications
184 * expecting this header to declare the union type on their behalf
185 *
186 * 2) Documentation; specifically, 64 bit applications that do not pass
187 * this structure for 'val', or, alternately, a 64 bit type, will
188 * not function correctly
9bccf70c 189 */
91447636
A
190union semun {
191 int val; /* value for SETVAL */
192 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
193 unsigned short *array; /* array for GETALL & SETALL */
194};
195typedef union semun semun_t;
9bccf70c 196
1c79356b
A
197
198/*
91447636 199 * Permissions
1c79356b 200 */
91447636
A
201#define SEM_A 0200 /* alter permission */
202#define SEM_R 0400 /* read permission */
1c79356b 203
91447636 204#endif /* !_POSIX_C_SOURCE */
9bccf70c 205
9bccf70c 206
1c79356b
A
207
208#ifndef KERNEL
1c79356b
A
209
210__BEGIN_DECLS
91447636
A
211#ifndef _POSIX_C_SOURCE
212int semsys(int, ...);
213#endif /* !_POSIX_C_SOURCE */
214int semctl(int, int, int, ...) __DARWIN_ALIAS(semctl);
215int semget(key_t, int, int);
216int semop(int, struct sembuf *, size_t);
1c79356b 217__END_DECLS
91447636 218
1c79356b
A
219#endif /* !KERNEL */
220
221#endif /* !_SEM_H_ */