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