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