]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/sem.h
xnu-6153.41.3.tar.gz
[apple/xnu.git] / bsd / sys / sem.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 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>
5ba3f43e 43#include <machine/types.h> /* __int32_t */
1c79356b
A
44
45/*
91447636
A
46 * [XSI] All of the symbols from <sys/ipc.h> SHALL be defined
47 * when this header is included
1c79356b 48 */
91447636 49#include <sys/ipc.h>
1c79356b 50
1c79356b 51
9bccf70c 52/*
91447636
A
53 * [XSI] The pid_t, time_t, key_t, and size_t types shall be defined as
54 * described in <sys/types.h>.
55 *
56 * NOTE: The definition of the key_t type is implicit from the
57 * inclusion of <sys/ipc.h>
9bccf70c 58 */
39236c6e
A
59#include <sys/_types/_pid_t.h>
60#include <sys/_types/_time_t.h>
61#include <sys/_types/_size_t.h>
1c79356b
A
62
63/*
91447636
A
64 * Technically, we should force all code references to the new structure
65 * definition, not in just the standards conformance case, and leave the
66 * legacy interface there for binary compatibility only. Currently, we
67 * are only forcing this for programs requesting standards conformance.
1c79356b 68 */
2d21ac55
A
69#if __DARWIN_UNIX03 || defined(KERNEL)
70#pragma pack(4)
91447636
A
71/*
72 * Structure used internally.
0a7de745 73 *
91447636
A
74 * This structure is exposed because standards dictate that it is used as
75 * the semun union member 'buf' as the fourth argment to semctl() when the
76 * third argument is IPC_STAT or IPC_SET.
77 *
78 * Note: only the fields sem_perm, sem_nsems, sem_otime, and sem_ctime
79 * are meaningful in user space.
80 */
2d21ac55
A
81#if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
82struct semid_ds
83#else
0a7de745 84#define semid_ds __semid_ds_new
2d21ac55
A
85struct __semid_ds_new
86#endif
87{
0a7de745
A
88 struct __ipc_perm_new sem_perm; /* [XSI] operation permission struct */
89 __int32_t sem_base; /* 32 bit base ptr for semaphore set */
90 unsigned short sem_nsems; /* [XSI] number of sems in set */
91 time_t sem_otime; /* [XSI] last operation time */
92 __int32_t sem_pad1; /* RESERVED: DO NOT USE! */
93 time_t sem_ctime; /* [XSI] last change time */
94 /* Times measured in secs since */
95 /* 00:00:00 GMT, Jan. 1, 1970 */
96 __int32_t sem_pad2; /* RESERVED: DO NOT USE! */
97 __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
91447636 98};
2d21ac55 99#pragma pack()
0a7de745
A
100#else /* !__DARWIN_UNIX03 */
101#define semid_ds __semid_ds_old
102#endif /* __DARWIN_UNIX03 */
91447636 103
2d21ac55 104#if !__DARWIN_UNIX03
91447636 105struct __semid_ds_old {
0a7de745
A
106 struct __ipc_perm_old sem_perm; /* [XSI] operation permission struct */
107 __int32_t sem_base; /* 32 bit base ptr for semaphore set */
108 unsigned short sem_nsems; /* [XSI] number of sems in set */
109 time_t sem_otime; /* [XSI] last operation time */
110 __int32_t sem_pad1; /* RESERVED: DO NOT USE! */
111 time_t sem_ctime; /* [XSI] last change time */
112 /* Times measured in secs since */
113 /* 00:00:00 GMT, Jan. 1, 1970 */
114 __int32_t sem_pad2; /* RESERVED: DO NOT USE! */
115 __int32_t sem_pad3[4]; /* RESERVED: DO NOT USE! */
1c79356b 116};
0a7de745 117#endif /* !__DARWIN_UNIX03 */
1c79356b
A
118
119/*
91447636 120 * Possible values for the third argument to semctl()
1c79356b 121 */
0a7de745
A
122#define GETNCNT 3 /* [XSI] Return the value of semncnt {READ} */
123#define GETPID 4 /* [XSI] Return the value of sempid {READ} */
124#define GETVAL 5 /* [XSI] Return the value of semval {READ} */
125#define GETALL 6 /* [XSI] Return semvals into arg.array {READ} */
126#define GETZCNT 7 /* [XSI] Return the value of semzcnt {READ} */
127#define SETVAL 8 /* [XSI] Set the value of semval to arg.val {ALTER} */
128#define SETALL 9 /* [XSI] Set semvals from arg.array {ALTER} */
1c79356b 129
1c79356b 130
91447636
A
131/* A semaphore; this is an anonymous structure, not for external use */
132struct sem {
0a7de745
A
133 unsigned short semval; /* semaphore value */
134 pid_t sempid; /* pid of last operation */
135 unsigned short semncnt; /* # awaiting semval > cval */
136 unsigned short semzcnt; /* # awaiting semval == 0 */
91447636
A
137};
138
1c79356b
A
139
140/*
91447636 141 * Structure of array element for second argument to semop()
1c79356b 142 */
91447636 143struct sembuf {
0a7de745
A
144 unsigned short sem_num; /* [XSI] semaphore # */
145 short sem_op; /* [XSI] semaphore operation */
146 short sem_flg; /* [XSI] operation flags */
91447636 147};
1c79356b 148
9bccf70c 149/*
91447636 150 * Possible flag values for sem_flg
9bccf70c 151 */
0a7de745 152#define SEM_UNDO 010000 /* [XSI] Set up adjust on exit entry */
91447636
A
153
154
2d21ac55 155#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1c79356b 156
1c79356b 157/*
91447636
A
158 * Union used as the fourth argment to semctl() in all cases. Specific
159 * member values are used for different values of the third parameter:
0a7de745 160 *
91447636
A
161 * Command Member
162 * ------------------------------------------- ------
163 * GETALL, SETALL array
164 * SETVAL val
165 * IPC_STAT, IPC_SET buf
9bccf70c 166 *
91447636
A
167 * The union definition is intended to be defined by the user application
168 * in conforming applications; it is provided here for two reasons:
0a7de745 169 *
91447636
A
170 * 1) Historical source compatability for non-conforming applications
171 * expecting this header to declare the union type on their behalf
172 *
173 * 2) Documentation; specifically, 64 bit applications that do not pass
174 * this structure for 'val', or, alternately, a 64 bit type, will
175 * not function correctly
9bccf70c 176 */
91447636 177union semun {
0a7de745
A
178 int val; /* value for SETVAL */
179 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
180 unsigned short *array; /* array for GETALL & SETALL */
91447636
A
181};
182typedef union semun semun_t;
9bccf70c 183
1c79356b
A
184
185/*
91447636 186 * Permissions
1c79356b 187 */
0a7de745
A
188#define SEM_A 0200 /* alter permission */
189#define SEM_R 0400 /* read permission */
1c79356b 190
0a7de745 191#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
9bccf70c 192
9bccf70c 193
1c79356b
A
194
195#ifndef KERNEL
1c79356b
A
196
197__BEGIN_DECLS
2d21ac55 198#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745 199int semsys(int, ...);
2d21ac55 200#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
0a7de745
A
201int semctl(int, int, int, ...) __DARWIN_ALIAS(semctl);
202int semget(key_t, int, int);
203int semop(int, struct sembuf *, size_t);
1c79356b 204__END_DECLS
91447636 205
1c79356b
A
206#endif /* !KERNEL */
207
208#endif /* !_SEM_H_ */