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