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