Commit | Line | Data |
---|---|---|
24fd64ab DG |
1 | /* |
2 | * SVID compatible sem.h file | |
3 | * | |
4 | * Author: Daniel Boulet | |
5 | */ | |
6 | ||
7 | #ifndef _SEM_H_ | |
8 | #define _SEM_H_ | |
9 | ||
10 | #ifdef KERNEL | |
11 | #include "ipc.h" | |
12 | #else | |
13 | #include <sys/ipc.h> | |
14 | #endif | |
15 | ||
16 | struct sem { | |
17 | ushort semval; /* semaphore value */ | |
18 | pid_t sempid; /* pid of last operation */ | |
19 | ushort semncnt; /* # awaiting semval > cval */ | |
20 | ushort semzcnt; /* # awaiting semval = 0 */ | |
21 | }; | |
22 | ||
23 | struct semid_ds { | |
24 | struct ipc_perm sem_perm; /* operation permission struct */ | |
25 | struct sem *sem_base; /* pointer to first semaphore in set */ | |
26 | ushort sem_nsems; /* number of sems in set */ | |
27 | time_t sem_otime; /* last operation time */ | |
28 | long sem_pad1; /* SVABI/386 says I need this here */ | |
29 | time_t sem_ctime; /* last change time */ | |
30 | /* Times measured in secs since */ | |
31 | /* 00:00:00 GMT, Jan. 1, 1970 */ | |
32 | long sem_pad2; /* SVABI/386 says I need this here */ | |
33 | long sem_pad3[4]; /* SVABI/386 says I need this here */ | |
34 | }; | |
35 | ||
36 | /* | |
37 | * semop's sops parameter structure | |
38 | */ | |
39 | ||
40 | struct sembuf { | |
41 | ushort sem_num; /* semaphore # */ | |
42 | short sem_op; /* semaphore operation */ | |
43 | short sem_flg; /* operation flags */ | |
44 | }; | |
45 | #define SEM_UNDO 010000 | |
46 | ||
47 | #define MAX_SOPS 5 /* maximum # of sembuf's per semop call */ | |
48 | ||
49 | /* | |
50 | * semctl's arg parameter structure | |
51 | */ | |
52 | ||
53 | union semun { | |
54 | int val; /* value for SETVAL */ | |
55 | struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ | |
56 | ushort *array; /* array for GETALL & SETALL */ | |
57 | }; | |
58 | ||
59 | /* | |
60 | * commands for semctl | |
61 | */ | |
62 | ||
63 | #define GETNCNT 3 /* Return the value of semncnt {READ} */ | |
64 | #define GETPID 4 /* Return the value of sempid {READ} */ | |
65 | #define GETVAL 5 /* Return the value of semval {READ} */ | |
66 | #define GETALL 6 /* Return semvals into arg.array {READ} */ | |
67 | #define GETZCNT 7 /* Return the value of semzcnt {READ} */ | |
68 | #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ | |
69 | #define SETALL 9 /* Set semvals from arg.array {ALTER} */ | |
70 | ||
71 | #ifdef KERNEL | |
72 | /* | |
73 | * Kernel implementation stuff | |
74 | */ | |
75 | ||
76 | #define SEMVMX 32767 /* semaphore maximum value */ | |
77 | #define SEMAEM 16384 /* adjust on exit max value */ | |
78 | ||
79 | /* | |
80 | * Permissions | |
81 | */ | |
82 | ||
83 | #define SEM_A 0200 /* alter permission */ | |
84 | #define SEM_R 0400 /* read permission */ | |
85 | ||
86 | /* | |
87 | * Undo structure (one per process) | |
88 | */ | |
89 | ||
90 | struct sem_undo { | |
91 | struct sem_undo *un_next; /* ptr to next active undo structure */ | |
92 | struct proc *un_proc; /* owner of this structure */ | |
93 | short un_cnt; /* # of active entries */ | |
94 | struct undo { | |
95 | short un_adjval; /* adjust on exit values */ | |
96 | short un_num; /* semaphore # */ | |
97 | int un_id; /* semid */ | |
98 | } un_ent[1]; /* undo entries */ | |
99 | }; | |
100 | ||
101 | /* | |
102 | * semaphore info struct | |
103 | */ | |
104 | ||
105 | struct seminfo { | |
106 | int semmap, /* # of entries in semaphore map */ | |
107 | semmni, /* # of semaphore identifiers */ | |
108 | semmns, /* # of semaphores in system */ | |
109 | semmnu, /* # of undo structures in system */ | |
110 | semmsl, /* max # of semaphores per id */ | |
111 | semopm, /* max # of operations per semop call */ | |
112 | semume, /* max # of undo entries per process */ | |
113 | semusz, /* size in bytes of undo structure */ | |
114 | semvmx, /* semaphore maximum value */ | |
115 | semaem; /* adjust on exit max value */ | |
116 | }; | |
117 | struct seminfo seminfo; | |
118 | ||
119 | /* internal "mode" bits */ | |
120 | #define SEM_ALLOC 01000 /* semaphore is allocated */ | |
121 | #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ | |
122 | ||
123 | /* | |
124 | * Configuration parameters | |
125 | */ | |
126 | ||
127 | #ifndef SEMMNI | |
128 | #define SEMMNI 10 /* # of semaphore identifiers */ | |
129 | #endif | |
130 | #ifndef SEMMNS | |
131 | #define SEMMNS 60 /* # of semaphores in system */ | |
132 | #endif | |
133 | #ifndef SEMUME | |
134 | #define SEMUME 10 /* max # of undo entries per process */ | |
135 | #endif | |
136 | #ifndef SEMMNU | |
137 | #define SEMMNU 30 /* # of undo structures in system */ | |
138 | #endif | |
139 | ||
140 | /* These shouldn't need tuning */ | |
141 | ||
142 | #ifndef SEMMAP | |
143 | #define SEMMAP 30 /* # of entries in semaphore map */ | |
144 | #endif | |
145 | #ifndef SEMMSL | |
146 | #define SEMMSL SEMMNS /* max # of semaphores per id */ | |
147 | #endif | |
148 | #ifndef SEMOPM | |
149 | #define SEMOPM 100 /* max # of operations per semop call */ | |
150 | #endif | |
151 | ||
152 | /* actual size of an undo structure */ | |
153 | #define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME) | |
154 | ||
155 | /* | |
156 | * Structures allocated in machdep.c | |
157 | */ | |
158 | ||
159 | struct semid_ds *sema; /* semaphore id pool */ | |
160 | struct sem *sem; /* semaphore pool */ | |
161 | struct map *semmap; /* semaphore allocation map */ | |
162 | struct sem_undo *semu_list; /* list of active undo structures */ | |
163 | int *semu; /* undo structure pool */ | |
164 | ||
165 | /* | |
166 | * Macro to find a particular sem_undo vector | |
167 | */ | |
168 | ||
169 | #define SEMU(ix) ((struct sem_undo *)(((long)semu)+ix * SEMUSZ)) | |
170 | ||
171 | /* | |
172 | * Parameters to the semconfig system call | |
173 | */ | |
174 | ||
175 | typedef enum { | |
176 | SEM_CONFIG_FREEZE, /* Freeze the semaphore facility. */ | |
177 | SEM_CONFIG_THAW /* Thaw the semaphore facility. */ | |
178 | } semconfig_ctl_t; | |
179 | ||
180 | #endif KERNEL | |
181 | ||
182 | #ifndef KERNEL | |
183 | #include <sys/cdefs.h> | |
184 | ||
185 | __BEGIN_DECLS | |
186 | ||
187 | int semsys __P((int, ...)); | |
188 | ||
189 | int semctl __P((int, int, int, union semun)); | |
190 | int semget __P((key_t, int, int)); | |
191 | int semop __P((int, struct sembuf *,unsigned)); | |
192 | ||
193 | __END_DECLS | |
194 | ||
195 | #endif | |
196 | ||
197 | #endif /* !_SEM_H_ */ |