xref: /illumos-gate/usr/src/uts/common/sys/sem_impl.h (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /*	  All Rights Reserved	*/
29 
30 #ifndef	_SYS_SEM_IMPL_H
31 #define	_SYS_SEM_IMPL_H
32 
33 #include <sys/ipc_impl.h>
34 #if defined(_KERNEL) || defined(_KMEMUSER)
35 #include <sys/sem.h>
36 #include <sys/t_lock.h>
37 #include <sys/avl.h>
38 #include <sys/list.h>
39 #endif
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Argument vectors for the various flavors of semsys().
47  */
48 
49 #define	SEMCTL	0
50 #define	SEMGET	1
51 #define	SEMOP	2
52 #define	SEMIDS	3
53 #define	SEMTIMEDOP	4
54 
55 #if defined(_KERNEL) || defined(_KMEMUSER)
56 
57 /*
58  * There is one semaphore id data structure (semid_ds) for each set of
59  * semaphores in the system.
60  */
61 typedef struct ksemid {
62 	kipc_perm_t	sem_perm;	/* operation permission struct */
63 	struct sem	*sem_base;	/* ptr to first semaphore in set */
64 	ushort_t	sem_nsems;	/* # of semaphores in set */
65 	time_t		sem_otime;	/* last semop time */
66 	time_t		sem_ctime;	/* last change time */
67 	int		sem_binary;	/* flag indicating semaphore type */
68 	int		sem_maxops;	/* maximum number of operations */
69 	list_t		sem_undos;	/* list of undo structures */
70 } ksemid_t;
71 
72 /*
73  * There is one semaphore structure (sem) for each semaphore in the system.
74  */
75 struct sem {
76 	ushort_t	semval;		/* semaphore value */
77 	pid_t		sempid;		/* pid of last operation */
78 	ushort_t	semncnt;	/* # awaiting semval > cval */
79 	ushort_t	semzcnt;	/* # awaiting semval = 0 */
80 	kcondvar_t	semncnt_cv;
81 	kcondvar_t	semzcnt_cv;
82 };
83 
84 /*
85  * There is one undo structure per process in the system.
86  */
87 struct sem_undo {
88 	avl_node_t	un_avl;		/* node in per-process avl tree */
89 	list_node_t	un_list;	/* ptr to next active undo structure */
90 	proc_t		*un_proc;	/* back-pointer to process */
91 	ksemid_t	*un_sp;		/* back-pointer to semaphore */
92 	int 		un_aoe[1];	/* adjust on exit values */
93 };
94 #endif	/* _KERNEL */
95 
96 #if defined(_SYSCALL32)
97 /*
98  * LP64 view of the ILP32 semid_ds structure
99  */
100 struct semid_ds32 {
101 	struct ipc_perm32 sem_perm;	/* operation permission struct */
102 	caddr32_t	sem_base;	/* ptr to first semaphore in set */
103 	uint16_t	sem_nsems;	/* # of semaphores in set */
104 	time32_t	sem_otime;	/* last semop time */
105 	int32_t		sem_pad1;	/* reserved for time_t expansion */
106 	time32_t	sem_ctime;	/* last semop time */
107 	int32_t		sem_pad2;	/* reserved for time_t expansion */
108 	int32_t		sem_binary;	/* flag indicating semaphore type */
109 	int32_t		sem_pad3[3];	/* reserve area */
110 };
111 #endif
112 
113 #ifdef _KERNEL
114 extern void semexit(proc_t *);
115 #endif
116 
117 #ifdef	__cplusplus
118 }
119 #endif
120 
121 #endif	/* _SYS_SEM_IMPL_H */
122