xref: /titanic_51/usr/src/lib/libbc/inc/include/sys/sem.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1986 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*      Copyright (c) 1984 AT&T */
28 /*        All Rights Reserved   */
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  *	IPC Semaphore Facility.
34  */
35 
36 #ifndef _sys_sem_h
37 #define _sys_sem_h
38 
39 /*
40  *	Semaphore Operation Flags.
41  */
42 #define	SEM_UNDO	010000	/* set up adjust on exit entry */
43 
44 /*
45  *	Semctl Command Definitions.
46  */
47 
48 #define	GETNCNT	3	/* get semncnt */
49 #define	GETPID	4	/* get sempid */
50 #define	GETVAL	5	/* get semval */
51 #define	GETALL	6	/* get all semval's */
52 #define	GETZCNT	7	/* get semzcnt */
53 #define	SETVAL	8	/* set semval */
54 #define	SETALL	9	/* set all semval's */
55 
56 /*
57  *	Structure Definitions.
58  */
59 
60 /*
61  *	There is one semaphore id data structure for each set of semaphores
62  *		in the system.
63  */
64 
65 struct semid_ds {
66 	struct ipc_perm	sem_perm;	/* operation permission struct */
67 	struct sem	*sem_base;	/* ptr to first semaphore in set */
68 	ushort		sem_nsems;	/* # of semaphores in set */
69 	time_t		sem_otime;	/* last semop time */
70 	time_t		sem_ctime;	/* last change time */
71 };
72 
73 /*
74  *	There is one semaphore structure for each semaphore in the system.
75  */
76 
77 struct sem {
78 	ushort	semval;		/* semaphore text map address */
79 	short	sempid;		/* pid of last operation */
80 	ushort	semncnt;	/* # awaiting semval > cval */
81 	ushort	semzcnt;	/* # awaiting semval = 0 */
82 };
83 
84 /*
85  *	User semaphore template for semop system calls.
86  */
87 
88 struct sembuf {
89 	short	sem_num;	/* semaphore # */
90 	short	sem_op;		/* semaphore operation */
91 	short	sem_flg;	/* operation flags */
92 };
93 
94 /*
95  *	'arg' argument template for semctl system calls.
96  */
97 union semun {
98 	int		val;	/* value for SETVAL */
99 	struct semid_ds	*buf;	/* buffer for IPC_STAT & IPC_SET */
100 	ushort		*array;	/* array for GETALL & SETALL */
101 };
102 
103 
104 #ifdef KERNEL
105 /*
106  *	Implementation Constants.
107  */
108 
109 #define	PSEMN	(PZERO + 3)	/* sleep priority waiting for greater value */
110 #define	PSEMZ	(PZERO + 2)	/* sleep priority waiting for zero */
111 
112 #define	SEMVMX	32767		/* semaphore maximum value */
113 #define	SEMAEM	16384		/* adjust on exit max value */
114 
115 
116 /*
117  *	Permission Definitions.
118  */
119 
120 #define	SEM_A	0200	/* alter permission */
121 #define	SEM_R	0400	/* read permission */
122 
123 /*
124  *	There is one undo structure per process in the system.
125  */
126 
127 struct sem_undo {
128 	struct sem_undo	*un_np;	/* ptr to next active undo structure */
129 	short		un_cnt;	/* # of active entries */
130 	struct undo {
131 		short	un_aoe;	/* adjust on exit values */
132 		short	un_num;	/* semaphore # */
133 		int	un_id;	/* semid */
134 	}	un_ent[1];	/* (semume) undo entries (one minimum) */
135 };
136 
137 /*
138  * semaphore information structure
139  */
140 struct	seminfo	{
141 	int	semmap,		/* # of entries in semaphore map */
142 		semmni,		/* # of semaphore identifiers */
143 		semmns,		/* # of semaphores in system */
144 		semmnu,		/* # of undo structures in system */
145 		semmsl,		/* max # of semaphores per id */
146 		semopm,		/* max # of operations per semop call */
147 		semume,		/* max # of undo entries per process */
148 		semusz,		/* size in bytes of undo structure */
149 		semvmx,		/* semaphore maximum value */
150 		semaem;		/* adjust on exit max value */
151 };
152 struct seminfo	seminfo;	/* configuration parameters */
153 
154 
155 /*
156  *	Configuration Parameters
157  * These parameters are tuned by editing the system configuration file.
158  * The following lines establish the default values.
159  */
160 #ifndef	SEMMNI
161 #define	SEMMNI	10		/* # of semaphore identifiers */
162 #endif
163 #ifndef	SEMMNS
164 #define	SEMMNS	60		/* # of semaphores in system */
165 #endif
166 #ifndef	SEMUME
167 #define	SEMUME	10		/* max # of undo entries per process */
168 #endif
169 #ifndef	SEMMNU
170 #define	SEMMNU	30		/* # of undo structures in system */
171 #endif
172 
173 /* The following parameters are assumed not to require tuning */
174 #ifndef	SEMMAP
175 #define	SEMMAP	30		/* # of entries in semaphore map */
176 #endif
177 #ifndef	SEMMSL
178 #define	SEMMSL	SEMMNS		/* max # of semaphores per id */
179 #endif
180 #ifndef	SEMOPM
181 #define	SEMOPM	100		/* max # of operations per semop call */
182 #endif
183 
184 		/* size in bytes of undo structure */
185 #define	SEMUSZ	(sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
186 
187 
188 /*
189  * Structures allocated in machdep.c
190  */
191 struct semid_ds *sema;		/* semaphore id pool */
192 struct sem	*sem;		/* semaphore pool */
193 struct map	*semmap;	/* semaphore allocation map */
194 struct sem_undo	**sem_undo;	/* per process undo table */
195 int		*semu;		/* undo structure pool */
196 
197 #endif KERNEL
198 
199 #endif /*!_sys_sem_h*/
200