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