xref: /freebsd/sys/sys/sem.h (revision 2668e76d6e764c5c361156ffa3d39eb02ce8e5d9)
1 /*	$NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $	*/
2 
3 /*
4  * SVID compatible sem.h file
5  *
6  * Author:  Daniel Boulet
7  */
8 
9 #ifndef _SYS_SEM_H_
10 #define _SYS_SEM_H_
11 
12 #ifdef _WANT_SYSVSEM_INTERNALS
13 #define	_WANT_SYSVIPC_INTERNALS
14 #endif
15 #include <sys/ipc.h>
16 
17 #ifndef _PID_T_DECLARED
18 typedef	__pid_t		pid_t;
19 #define	_PID_T_DECLARED
20 #endif
21 
22 #ifndef _SIZE_T_DECLARED
23 typedef	__size_t	size_t;
24 #define	_SIZE_T_DECLARED
25 #endif
26 
27 #ifndef _TIME_T_DECLARED
28 typedef	__time_t	time_t;
29 #define	_TIME_T_DECLARED
30 #endif
31 
32 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
33     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
34 struct semid_ds_old {
35 	struct ipc_perm_old sem_perm;	/* operation permission struct */
36 	struct sem	*__sem_base;	/* pointer to first semaphore in set */
37 	unsigned short	sem_nsems;	/* number of sems in set */
38 	time_t		sem_otime;	/* last operation time */
39 	long		sem_pad1;	/* SVABI/386 says I need this here */
40 	time_t		sem_ctime;	/* last change time */
41     					/* Times measured in secs since */
42     					/* 00:00:00 UTC, Jan. 1, 1970, without leap seconds */
43 	long		sem_pad2;	/* SVABI/386 says I need this here */
44 	long		sem_pad3[4];	/* SVABI/386 says I need this here */
45 };
46 #endif
47 
48 struct semid_ds {
49 	struct ipc_perm	sem_perm;	/* operation permission struct */
50 	struct sem	*__sem_base;	/* pointer to first semaphore in set */
51 	unsigned short	sem_nsems;	/* number of sems in set */
52 	time_t		sem_otime;	/* last operation time */
53 	time_t		sem_ctime;	/* last change time */
54     					/* Times measured in secs since */
55     					/* 00:00:00 UTC, Jan. 1, 1970, without leap seconds */
56 };
57 
58 /*
59  * semop's sops parameter structure
60  */
61 struct sembuf {
62 	unsigned short	sem_num;	/* semaphore # */
63 	short		sem_op;		/* semaphore operation */
64 	short		sem_flg;	/* operation flags */
65 };
66 #define SEM_UNDO	010000
67 
68 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
69     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \
70     defined(_WANT_SEMUN_OLD)
71 union semun_old {
72 	int		val;		/* value for SETVAL */
73 	struct		semid_ds_old *buf; /* buffer for IPC_STAT & IPC_SET */
74 	unsigned short	*array;		/* array for GETALL & SETALL */
75 };
76 #endif
77 
78 #if defined(_KERNEL) || defined(_WANT_SEMUN)
79 /*
80  * semctl's arg parameter structure
81  */
82 union semun {
83 	int		val;		/* value for SETVAL */
84 	struct		semid_ds *buf;	/* buffer for IPC_STAT & IPC_SET */
85 	unsigned short	*array;		/* array for GETALL & SETALL */
86 };
87 #endif
88 
89 /*
90  * commands for semctl
91  */
92 #define GETNCNT	3	/* Return the value of semncnt {READ} */
93 #define GETPID	4	/* Return the value of sempid {READ} */
94 #define GETVAL	5	/* Return the value of semval {READ} */
95 #define GETALL	6	/* Return semvals into arg.array {READ} */
96 #define GETZCNT	7	/* Return the value of semzcnt {READ} */
97 #define SETVAL	8	/* Set the value of semval to arg.val {ALTER} */
98 #define SETALL	9	/* Set semvals from arg.array {ALTER} */
99 #define SEM_STAT 10	/* Like IPC_STAT but treats semid as sema-index */
100 #define SEM_INFO 11	/* Like IPC_INFO but treats semid as sema-index */
101 
102 /*
103  * Permissions
104  */
105 #define SEM_A		IPC_W	/* alter permission */
106 #define SEM_R		IPC_R	/* read permission */
107 
108 #if defined(_KERNEL) || defined(_WANT_SYSVSEM_INTERNALS)
109 /*
110  * semaphore info struct
111  */
112 struct seminfo {
113 	int	semmni;		/* # of semaphore identifiers */
114 	int	semmns;		/* # of semaphores in system */
115 	int	semmnu;		/* # of undo structures in system */
116 	int	semmsl;		/* max # of semaphores per id */
117 	int	semopm;		/* max # of operations per semop call */
118 	int	semume;		/* max # of undo entries per process */
119 	int	semusz;		/* size in bytes of undo structure */
120 	int	semvmx;		/* semaphore maximum value */
121 	int	semaem;		/* adjust on exit max value */
122 };
123 
124 /*
125  * Kernel wrapper for the user-level structure
126  */
127 struct semid_kernel {
128 	struct	semid_ds u;
129 	struct	label *label;	/* MAC framework label */
130 	struct	ucred *cred;	/* creator's credentials */
131 };
132 
133 /* internal "mode" bits */
134 #define	SEM_ALLOC	01000	/* semaphore is allocated */
135 #define	SEM_DEST	02000	/* semaphore will be destroyed on last detach */
136 #endif
137 
138 #ifdef _KERNEL
139 extern struct seminfo	seminfo;
140 /*
141  * Process sem_undo vectors at proc exit.
142  */
143 void	semexit(struct proc *p);
144 
145 int	kern_get_sema(struct thread *td, struct semid_kernel **res,
146 	    size_t *sz);
147 
148 #else /* !_KERNEL */
149 
150 __BEGIN_DECLS
151 int semctl(int, int, int, ...);
152 int semget(key_t, int, int);
153 int semop(int, struct sembuf *, size_t);
154 __END_DECLS
155 
156 #endif /* !_KERNEL */
157 
158 #endif /* !_SYS_SEM_H_ */
159