sysv_sem.c revision 1.10 1 1.10 cgd /* $NetBSD: sysv_sem.c,v 1.10 1994/10/20 04:23:17 cgd Exp $ */
2 1.9 cgd
3 1.1 cgd /*
4 1.1 cgd * Implementation of SVID semaphores
5 1.1 cgd *
6 1.1 cgd * Author: Daniel Boulet
7 1.1 cgd *
8 1.1 cgd * This software is provided ``AS IS'' without any warranties of any kind.
9 1.1 cgd */
10 1.1 cgd
11 1.3 mycroft #include <sys/param.h>
12 1.3 mycroft #include <sys/systm.h>
13 1.3 mycroft #include <sys/kernel.h>
14 1.3 mycroft #include <sys/proc.h>
15 1.3 mycroft #include <sys/sem.h>
16 1.3 mycroft #include <sys/malloc.h>
17 1.1 cgd
18 1.10 cgd #include <sys/mount.h>
19 1.10 cgd #include <sys/syscallargs.h>
20 1.10 cgd
21 1.1 cgd int semtot = 0;
22 1.1 cgd
23 1.1 cgd static struct proc *semlock_holder = NULL;
24 1.1 cgd
25 1.1 cgd int
26 1.1 cgd seminit()
27 1.1 cgd {
28 1.5 mycroft register int i;
29 1.5 mycroft vm_offset_t whocares1, whocares2;
30 1.1 cgd
31 1.5 mycroft if (sema == NULL)
32 1.5 mycroft panic("sema is NULL");
33 1.5 mycroft if (semu == NULL)
34 1.5 mycroft panic("semu is NULL");
35 1.5 mycroft
36 1.5 mycroft for (i = 0; i < seminfo.semmni; i++) {
37 1.5 mycroft sema[i].sem_base = 0;
38 1.5 mycroft sema[i].sem_perm.mode = 0;
39 1.5 mycroft }
40 1.5 mycroft for (i = 0; i < seminfo.semmnu; i++) {
41 1.5 mycroft register struct sem_undo *suptr = SEMU(i);
42 1.5 mycroft suptr->un_proc = NULL;
43 1.5 mycroft }
44 1.5 mycroft semu_list = NULL;
45 1.1 cgd }
46 1.1 cgd
47 1.1 cgd /*
48 1.1 cgd * Lock or unlock the entire semaphore facility.
49 1.1 cgd *
50 1.1 cgd * This will probably eventually evolve into a general purpose semaphore
51 1.1 cgd * facility status enquiry mechanism (I don't like the "read /dev/kmem"
52 1.1 cgd * approach currently taken by ipcs and the amount of info that we want
53 1.1 cgd * to be able to extract for ipcs is probably beyond what the capability
54 1.1 cgd * of the getkerninfo facility.
55 1.1 cgd *
56 1.1 cgd * At the time that the current version of semconfig was written, ipcs is
57 1.1 cgd * the only user of the semconfig facility. It uses it to ensure that the
58 1.1 cgd * semaphore facility data structures remain static while it fishes around
59 1.1 cgd * in /dev/kmem.
60 1.1 cgd */
61 1.1 cgd
62 1.1 cgd int
63 1.1 cgd semconfig(p, uap, retval)
64 1.1 cgd struct proc *p;
65 1.10 cgd struct semconfig_args /* {
66 1.10 cgd syscallarg(int) flag;
67 1.10 cgd } */ *uap;
68 1.10 cgd register_t *retval;
69 1.1 cgd {
70 1.5 mycroft int eval = 0;
71 1.1 cgd
72 1.10 cgd switch (SCARG(uap, flag)) {
73 1.5 mycroft case SEM_CONFIG_FREEZE:
74 1.5 mycroft semlock_holder = p;
75 1.5 mycroft break;
76 1.6 mycroft
77 1.5 mycroft case SEM_CONFIG_THAW:
78 1.5 mycroft semlock_holder = NULL;
79 1.5 mycroft wakeup((caddr_t)&semlock_holder);
80 1.5 mycroft break;
81 1.6 mycroft
82 1.5 mycroft default:
83 1.10 cgd printf(
84 1.10 cgd "semconfig: unknown flag parameter value (%d) - ignored\n",
85 1.10 cgd SCARG(uap, flag));
86 1.5 mycroft eval = EINVAL;
87 1.5 mycroft break;
88 1.5 mycroft }
89 1.1 cgd
90 1.5 mycroft *retval = 0;
91 1.5 mycroft return(eval);
92 1.1 cgd }
93 1.1 cgd
94 1.1 cgd /*
95 1.1 cgd * Allocate a new sem_undo structure for a process
96 1.1 cgd * (returns ptr to structure or NULL if no more room)
97 1.1 cgd */
98 1.1 cgd
99 1.1 cgd struct sem_undo *
100 1.5 mycroft semu_alloc(p)
101 1.5 mycroft struct proc *p;
102 1.1 cgd {
103 1.5 mycroft register int i;
104 1.5 mycroft register struct sem_undo *suptr;
105 1.5 mycroft register struct sem_undo **supptr;
106 1.5 mycroft int attempt;
107 1.1 cgd
108 1.1 cgd /*
109 1.5 mycroft * Try twice to allocate something.
110 1.5 mycroft * (we'll purge any empty structures after the first pass so
111 1.5 mycroft * two passes are always enough)
112 1.1 cgd */
113 1.1 cgd
114 1.5 mycroft for (attempt = 0; attempt < 2; attempt++) {
115 1.5 mycroft /*
116 1.5 mycroft * Look for a free structure.
117 1.5 mycroft * Fill it in and return it if we find one.
118 1.5 mycroft */
119 1.5 mycroft
120 1.5 mycroft for (i = 0; i < seminfo.semmnu; i++) {
121 1.5 mycroft suptr = SEMU(i);
122 1.5 mycroft if (suptr->un_proc == NULL) {
123 1.5 mycroft suptr->un_next = semu_list;
124 1.5 mycroft semu_list = suptr;
125 1.5 mycroft suptr->un_cnt = 0;
126 1.5 mycroft suptr->un_proc = p;
127 1.5 mycroft return(suptr);
128 1.5 mycroft }
129 1.5 mycroft }
130 1.1 cgd
131 1.5 mycroft /*
132 1.5 mycroft * We didn't find a free one, if this is the first attempt
133 1.5 mycroft * then try to free some structures.
134 1.5 mycroft */
135 1.5 mycroft
136 1.5 mycroft if (attempt == 0) {
137 1.5 mycroft /* All the structures are in use - try to free some */
138 1.5 mycroft int did_something = 0;
139 1.5 mycroft
140 1.5 mycroft supptr = &semu_list;
141 1.5 mycroft while ((suptr = *supptr) != NULL) {
142 1.5 mycroft if (suptr->un_cnt == 0) {
143 1.5 mycroft suptr->un_proc = NULL;
144 1.5 mycroft *supptr = suptr->un_next;
145 1.5 mycroft did_something = 1;
146 1.5 mycroft } else
147 1.5 mycroft supptr = &(suptr->un_next);
148 1.5 mycroft }
149 1.5 mycroft
150 1.5 mycroft /* If we didn't free anything then just give-up */
151 1.5 mycroft if (!did_something)
152 1.5 mycroft return(NULL);
153 1.5 mycroft } else {
154 1.5 mycroft /*
155 1.5 mycroft * The second pass failed even though we freed
156 1.5 mycroft * something after the first pass!
157 1.5 mycroft * This is IMPOSSIBLE!
158 1.5 mycroft */
159 1.5 mycroft panic("semu_alloc - second attempt failed");
160 1.5 mycroft }
161 1.1 cgd }
162 1.1 cgd }
163 1.1 cgd
164 1.1 cgd /*
165 1.1 cgd * Adjust a particular entry for a particular proc
166 1.1 cgd */
167 1.1 cgd
168 1.1 cgd int
169 1.5 mycroft semundo_adjust(p, supptr, semid, semnum, adjval)
170 1.5 mycroft register struct proc *p;
171 1.5 mycroft struct sem_undo **supptr;
172 1.5 mycroft int semid, semnum;
173 1.5 mycroft int adjval;
174 1.1 cgd {
175 1.5 mycroft register struct sem_undo *suptr;
176 1.5 mycroft register struct undo *sunptr;
177 1.5 mycroft int i;
178 1.1 cgd
179 1.5 mycroft /* Look for and remember the sem_undo if the caller doesn't provide
180 1.5 mycroft it */
181 1.1 cgd
182 1.5 mycroft suptr = *supptr;
183 1.4 mycroft if (suptr == NULL) {
184 1.5 mycroft for (suptr = semu_list; suptr != NULL;
185 1.5 mycroft suptr = suptr->un_next) {
186 1.5 mycroft if (suptr->un_proc == p) {
187 1.5 mycroft *supptr = suptr;
188 1.5 mycroft break;
189 1.5 mycroft }
190 1.5 mycroft }
191 1.5 mycroft if (suptr == NULL) {
192 1.5 mycroft if (adjval == 0)
193 1.5 mycroft return(0);
194 1.5 mycroft suptr = semu_alloc(p);
195 1.5 mycroft if (suptr == NULL)
196 1.5 mycroft return(ENOSPC);
197 1.5 mycroft *supptr = suptr;
198 1.5 mycroft }
199 1.1 cgd }
200 1.1 cgd
201 1.6 mycroft /*
202 1.6 mycroft * Look for the requested entry and adjust it (delete if adjval becomes
203 1.6 mycroft * 0).
204 1.6 mycroft */
205 1.6 mycroft sunptr = &suptr->un_ent[0];
206 1.5 mycroft for (i = 0; i < suptr->un_cnt; i++, sunptr++) {
207 1.6 mycroft if (sunptr->un_id != semid || sunptr->un_num != semnum)
208 1.6 mycroft continue;
209 1.6 mycroft if (adjval == 0)
210 1.6 mycroft sunptr->un_adjval = 0;
211 1.6 mycroft else
212 1.6 mycroft sunptr->un_adjval += adjval;
213 1.6 mycroft if (sunptr->un_adjval == 0) {
214 1.6 mycroft suptr->un_cnt--;
215 1.6 mycroft if (i < suptr->un_cnt)
216 1.6 mycroft suptr->un_ent[i] =
217 1.6 mycroft suptr->un_ent[suptr->un_cnt];
218 1.5 mycroft }
219 1.6 mycroft return(0);
220 1.1 cgd }
221 1.1 cgd
222 1.5 mycroft /* Didn't find the right entry - create it */
223 1.5 mycroft if (adjval == 0)
224 1.5 mycroft return(0);
225 1.5 mycroft if (suptr->un_cnt != SEMUME) {
226 1.6 mycroft sunptr = &suptr->un_ent[suptr->un_cnt];
227 1.5 mycroft suptr->un_cnt++;
228 1.5 mycroft sunptr->un_adjval = adjval;
229 1.5 mycroft sunptr->un_id = semid; sunptr->un_num = semnum;
230 1.5 mycroft } else
231 1.5 mycroft return(EINVAL);
232 1.1 cgd return(0);
233 1.1 cgd }
234 1.1 cgd
235 1.1 cgd void
236 1.5 mycroft semundo_clear(semid, semnum)
237 1.5 mycroft int semid, semnum;
238 1.1 cgd {
239 1.6 mycroft register struct sem_undo *suptr;
240 1.1 cgd
241 1.6 mycroft for (suptr = semu_list; suptr != NULL; suptr = suptr->un_next) {
242 1.6 mycroft register struct undo *sunptr = &suptr->un_ent[0];
243 1.6 mycroft register int i = 0;
244 1.6 mycroft
245 1.6 mycroft while (i < suptr->un_cnt) {
246 1.6 mycroft if (sunptr->un_id == semid) {
247 1.6 mycroft if (semnum == -1 || sunptr->un_num == semnum) {
248 1.6 mycroft suptr->un_cnt--;
249 1.6 mycroft if (i < suptr->un_cnt) {
250 1.6 mycroft suptr->un_ent[i] =
251 1.6 mycroft suptr->un_ent[suptr->un_cnt];
252 1.6 mycroft continue;
253 1.6 mycroft }
254 1.6 mycroft }
255 1.6 mycroft if (semnum != -1)
256 1.6 mycroft break;
257 1.6 mycroft }
258 1.6 mycroft i++, sunptr++;
259 1.6 mycroft }
260 1.1 cgd }
261 1.1 cgd }
262 1.1 cgd
263 1.1 cgd int
264 1.10 cgd __semctl(p, uap, retval)
265 1.1 cgd struct proc *p;
266 1.10 cgd register struct __semctl_args /* {
267 1.10 cgd syscallarg(int) semid;
268 1.10 cgd syscallarg(int) semnum;
269 1.10 cgd syscallarg(int) cmd;
270 1.10 cgd syscallarg(union semun *) arg;
271 1.10 cgd } */ *uap;
272 1.10 cgd register_t *retval;
273 1.1 cgd {
274 1.10 cgd int semid = SCARG(uap, semid);
275 1.10 cgd int semnum = SCARG(uap, semnum);
276 1.10 cgd int cmd = SCARG(uap, cmd);
277 1.10 cgd union semun *arg = SCARG(uap, arg);
278 1.6 mycroft union semun real_arg;
279 1.6 mycroft struct ucred *cred = p->p_ucred;
280 1.6 mycroft int i, rval, eval;
281 1.6 mycroft struct semid_ds sbuf;
282 1.6 mycroft register struct semid_ds *semaptr;
283 1.1 cgd
284 1.1 cgd #ifdef SEM_DEBUG
285 1.6 mycroft printf("call to semctl(%d, %d, %d, 0x%x)\n", semid, semnum, cmd, arg);
286 1.1 cgd #endif
287 1.1 cgd
288 1.6 mycroft semid = IPCID_TO_IX(semid);
289 1.6 mycroft if (semid < 0 || semid >= seminfo.semmsl)
290 1.6 mycroft return(EINVAL);
291 1.6 mycroft
292 1.6 mycroft semaptr = &sema[semid];
293 1.6 mycroft if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
294 1.10 cgd semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid)))
295 1.6 mycroft return(EINVAL);
296 1.6 mycroft
297 1.6 mycroft eval = 0;
298 1.6 mycroft rval = 0;
299 1.1 cgd
300 1.6 mycroft switch (cmd) {
301 1.6 mycroft case IPC_RMID:
302 1.8 mycroft if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)))
303 1.8 mycroft return(eval);
304 1.6 mycroft semaptr->sem_perm.cuid = cred->cr_uid;
305 1.6 mycroft semaptr->sem_perm.uid = cred->cr_uid;
306 1.6 mycroft semtot -= semaptr->sem_nsems;
307 1.6 mycroft for (i = semaptr->sem_base - sem; i < semtot; i++)
308 1.6 mycroft sem[i] = sem[i + semaptr->sem_nsems];
309 1.6 mycroft for (i = 0; i < seminfo.semmni; i++) {
310 1.6 mycroft if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
311 1.6 mycroft sema[i].sem_base > semaptr->sem_base)
312 1.6 mycroft sema[i].sem_base -= semaptr->sem_nsems;
313 1.6 mycroft }
314 1.6 mycroft semaptr->sem_perm.mode = 0;
315 1.6 mycroft semundo_clear(semid, -1);
316 1.6 mycroft wakeup((caddr_t)semaptr);
317 1.6 mycroft break;
318 1.1 cgd
319 1.6 mycroft case IPC_SET:
320 1.8 mycroft if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)))
321 1.8 mycroft return(eval);
322 1.6 mycroft if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
323 1.6 mycroft return(eval);
324 1.6 mycroft if ((eval = copyin(real_arg.buf, (caddr_t)&sbuf,
325 1.6 mycroft sizeof(sbuf))) != 0)
326 1.6 mycroft return(eval);
327 1.6 mycroft semaptr->sem_perm.uid = sbuf.sem_perm.uid;
328 1.6 mycroft semaptr->sem_perm.gid = sbuf.sem_perm.gid;
329 1.6 mycroft semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
330 1.6 mycroft (sbuf.sem_perm.mode & 0777);
331 1.6 mycroft semaptr->sem_ctime = time.tv_sec;
332 1.6 mycroft break;
333 1.1 cgd
334 1.6 mycroft case IPC_STAT:
335 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
336 1.6 mycroft return(eval);
337 1.6 mycroft if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
338 1.6 mycroft return(eval);
339 1.6 mycroft eval = copyout((caddr_t)semaptr, real_arg.buf,
340 1.6 mycroft sizeof(struct semid_ds));
341 1.6 mycroft break;
342 1.1 cgd
343 1.6 mycroft case GETNCNT:
344 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
345 1.6 mycroft return(eval);
346 1.6 mycroft if (semnum < 0 || semnum >= semaptr->sem_nsems)
347 1.6 mycroft return(EINVAL);
348 1.6 mycroft rval = semaptr->sem_base[semnum].semncnt;
349 1.6 mycroft break;
350 1.1 cgd
351 1.6 mycroft case GETPID:
352 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
353 1.6 mycroft return(eval);
354 1.6 mycroft if (semnum < 0 || semnum >= semaptr->sem_nsems)
355 1.6 mycroft return(EINVAL);
356 1.6 mycroft rval = semaptr->sem_base[semnum].sempid;
357 1.6 mycroft break;
358 1.1 cgd
359 1.6 mycroft case GETVAL:
360 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
361 1.6 mycroft return(eval);
362 1.6 mycroft if (semnum < 0 || semnum >= semaptr->sem_nsems)
363 1.6 mycroft return(EINVAL);
364 1.6 mycroft rval = semaptr->sem_base[semnum].semval;
365 1.6 mycroft break;
366 1.1 cgd
367 1.6 mycroft case GETALL:
368 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
369 1.6 mycroft return(eval);
370 1.6 mycroft if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
371 1.6 mycroft return(eval);
372 1.6 mycroft for (i = 0; i < semaptr->sem_nsems; i++) {
373 1.6 mycroft eval = copyout((caddr_t)&semaptr->sem_base[i].semval,
374 1.6 mycroft &real_arg.array[i], sizeof(real_arg.array[0]));
375 1.6 mycroft if (eval != 0)
376 1.6 mycroft break;
377 1.6 mycroft }
378 1.6 mycroft break;
379 1.1 cgd
380 1.6 mycroft case GETZCNT:
381 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
382 1.6 mycroft return(eval);
383 1.6 mycroft if (semnum < 0 || semnum >= semaptr->sem_nsems)
384 1.6 mycroft return(EINVAL);
385 1.6 mycroft rval = semaptr->sem_base[semnum].semzcnt;
386 1.6 mycroft break;
387 1.1 cgd
388 1.6 mycroft case SETVAL:
389 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
390 1.6 mycroft return(eval);
391 1.6 mycroft if (semnum < 0 || semnum >= semaptr->sem_nsems)
392 1.6 mycroft return(EINVAL);
393 1.6 mycroft if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
394 1.6 mycroft return(eval);
395 1.6 mycroft semaptr->sem_base[semnum].semval = real_arg.val;
396 1.6 mycroft semundo_clear(semid, semnum);
397 1.6 mycroft wakeup((caddr_t)semaptr);
398 1.6 mycroft break;
399 1.1 cgd
400 1.6 mycroft case SETALL:
401 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
402 1.6 mycroft return(eval);
403 1.6 mycroft if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
404 1.6 mycroft return(eval);
405 1.6 mycroft for (i = 0; i < semaptr->sem_nsems; i++) {
406 1.6 mycroft eval = copyin(&real_arg.array[i],
407 1.6 mycroft (caddr_t)&semaptr->sem_base[i].semval,
408 1.6 mycroft sizeof(real_arg.array[0]));
409 1.6 mycroft if (eval != 0)
410 1.6 mycroft break;
411 1.6 mycroft }
412 1.6 mycroft semundo_clear(semid, -1);
413 1.6 mycroft wakeup((caddr_t)semaptr);
414 1.6 mycroft break;
415 1.1 cgd
416 1.6 mycroft default:
417 1.6 mycroft return(EINVAL);
418 1.6 mycroft }
419 1.4 mycroft
420 1.6 mycroft if (eval == 0)
421 1.6 mycroft *retval = rval;
422 1.6 mycroft return(eval);
423 1.1 cgd }
424 1.1 cgd
425 1.1 cgd int
426 1.1 cgd semget(p, uap, retval)
427 1.1 cgd struct proc *p;
428 1.10 cgd register struct semget_args /* {
429 1.10 cgd syscallarg(key_t) key;
430 1.10 cgd syscallarg(int) nsems;
431 1.10 cgd syscallarg(int) semflg;
432 1.10 cgd } */ *uap;
433 1.10 cgd register_t *retval;
434 1.1 cgd {
435 1.6 mycroft int semid, eval;
436 1.10 cgd int key = SCARG(uap, key);
437 1.10 cgd int nsems = SCARG(uap, nsems);
438 1.10 cgd int semflg = SCARG(uap, semflg);
439 1.6 mycroft struct ucred *cred = p->p_ucred;
440 1.1 cgd
441 1.1 cgd #ifdef SEM_DEBUG
442 1.6 mycroft printf("semget(0x%x, %d, 0%o)\n", key, nsems, semflg);
443 1.1 cgd #endif
444 1.1 cgd
445 1.6 mycroft if (key != IPC_PRIVATE) {
446 1.6 mycroft for (semid = 0; semid < seminfo.semmni; semid++) {
447 1.6 mycroft if ((sema[semid].sem_perm.mode & SEM_ALLOC) &&
448 1.6 mycroft sema[semid].sem_perm.key == key)
449 1.6 mycroft break;
450 1.6 mycroft }
451 1.6 mycroft if (semid < seminfo.semmni) {
452 1.1 cgd #ifdef SEM_DEBUG
453 1.6 mycroft printf("found public key\n");
454 1.1 cgd #endif
455 1.7 hpeyerl if ((eval = ipcperm(cred, &sema[semid].sem_perm,
456 1.7 hpeyerl semflg & 0700)))
457 1.6 mycroft return(eval);
458 1.6 mycroft if (nsems > 0 && sema[semid].sem_nsems < nsems) {
459 1.1 cgd #ifdef SEM_DEBUG
460 1.6 mycroft printf("too small\n");
461 1.1 cgd #endif
462 1.6 mycroft return(EINVAL);
463 1.6 mycroft }
464 1.6 mycroft if ((semflg & IPC_CREAT) && (semflg & IPC_EXCL)) {
465 1.1 cgd #ifdef SEM_DEBUG
466 1.6 mycroft printf("not exclusive\n");
467 1.1 cgd #endif
468 1.6 mycroft return(EEXIST);
469 1.6 mycroft }
470 1.6 mycroft goto found;
471 1.6 mycroft }
472 1.6 mycroft }
473 1.6 mycroft
474 1.1 cgd #ifdef SEM_DEBUG
475 1.6 mycroft printf("need to allocate the semid_ds\n");
476 1.1 cgd #endif
477 1.6 mycroft if (key == IPC_PRIVATE || (semflg & IPC_CREAT)) {
478 1.6 mycroft if (nsems <= 0 || nsems > seminfo.semmsl) {
479 1.1 cgd #ifdef SEM_DEBUG
480 1.6 mycroft printf("nsems out of range (0<%d<=%d)\n", nsems,
481 1.6 mycroft seminfo.semmsl);
482 1.1 cgd #endif
483 1.6 mycroft return(EINVAL);
484 1.6 mycroft }
485 1.6 mycroft if (nsems > seminfo.semmns - semtot) {
486 1.1 cgd #ifdef SEM_DEBUG
487 1.6 mycroft printf("not enough semaphores left (need %d, got %d)\n",
488 1.6 mycroft nsems, seminfo.semmns - semtot);
489 1.1 cgd #endif
490 1.6 mycroft return(ENOSPC);
491 1.6 mycroft }
492 1.6 mycroft for (semid = 0; semid < seminfo.semmni; semid++) {
493 1.6 mycroft if ((sema[semid].sem_perm.mode & SEM_ALLOC) == 0)
494 1.6 mycroft break;
495 1.6 mycroft }
496 1.6 mycroft if (semid == seminfo.semmni) {
497 1.1 cgd #ifdef SEM_DEBUG
498 1.6 mycroft printf("no more semid_ds's available\n");
499 1.1 cgd #endif
500 1.6 mycroft return(ENOSPC);
501 1.6 mycroft }
502 1.1 cgd #ifdef SEM_DEBUG
503 1.6 mycroft printf("semid %d is available\n", semid);
504 1.1 cgd #endif
505 1.6 mycroft sema[semid].sem_perm.key = key;
506 1.6 mycroft sema[semid].sem_perm.cuid = cred->cr_uid;
507 1.6 mycroft sema[semid].sem_perm.uid = cred->cr_uid;
508 1.6 mycroft sema[semid].sem_perm.cgid = cred->cr_gid;
509 1.6 mycroft sema[semid].sem_perm.gid = cred->cr_gid;
510 1.6 mycroft sema[semid].sem_perm.mode = (semflg & 0777) | SEM_ALLOC;
511 1.6 mycroft sema[semid].sem_perm.seq =
512 1.6 mycroft (sema[semid].sem_perm.seq + 1) & 0x7fff;
513 1.6 mycroft sema[semid].sem_nsems = nsems;
514 1.6 mycroft sema[semid].sem_otime = 0;
515 1.6 mycroft sema[semid].sem_ctime = time.tv_sec;
516 1.6 mycroft sema[semid].sem_base = &sem[semtot];
517 1.6 mycroft semtot += nsems;
518 1.6 mycroft bzero(sema[semid].sem_base,
519 1.6 mycroft sizeof(sema[semid].sem_base[0])*nsems);
520 1.1 cgd #ifdef SEM_DEBUG
521 1.6 mycroft printf("sembase = 0x%x, next = 0x%x\n", sema[semid].sem_base,
522 1.6 mycroft &sem[semtot]);
523 1.1 cgd #endif
524 1.1 cgd } else {
525 1.1 cgd #ifdef SEM_DEBUG
526 1.6 mycroft printf("didn't find it and wasn't asked to create it\n");
527 1.1 cgd #endif
528 1.6 mycroft return(ENOENT);
529 1.1 cgd }
530 1.1 cgd
531 1.6 mycroft found:
532 1.6 mycroft *retval = IXSEQ_TO_IPCID(semid, sema[semid].sem_perm);
533 1.6 mycroft return(0);
534 1.1 cgd }
535 1.1 cgd
536 1.1 cgd int
537 1.1 cgd semop(p, uap, retval)
538 1.1 cgd struct proc *p;
539 1.10 cgd register struct semop_args /* {
540 1.10 cgd syscallarg(int) semid;
541 1.10 cgd syscallarg(struct sembuf *) sops;
542 1.10 cgd syscallarg(u_int) nsops;
543 1.10 cgd } */ *uap;
544 1.10 cgd register_t *retval;
545 1.1 cgd {
546 1.10 cgd int semid = SCARG(uap, semid);
547 1.10 cgd int nsops = SCARG(uap, nsops);
548 1.6 mycroft struct sembuf sops[MAX_SOPS];
549 1.6 mycroft register struct semid_ds *semaptr;
550 1.6 mycroft register struct sembuf *sopptr;
551 1.6 mycroft register struct sem *semptr;
552 1.6 mycroft struct sem_undo *suptr = NULL;
553 1.6 mycroft struct ucred *cred = p->p_ucred;
554 1.6 mycroft int i, j, eval;
555 1.6 mycroft int all_ok, do_wakeup, do_undos;
556 1.1 cgd
557 1.1 cgd #ifdef SEM_DEBUG
558 1.6 mycroft printf("call to semop(%d, 0x%x, %d)\n", semid, sops, nsops);
559 1.1 cgd #endif
560 1.1 cgd
561 1.6 mycroft semid = IPCID_TO_IX(semid); /* Convert back to zero origin */
562 1.6 mycroft
563 1.6 mycroft if (semid < 0 || semid >= seminfo.semmsl)
564 1.6 mycroft return(EINVAL);
565 1.6 mycroft
566 1.6 mycroft semaptr = &sema[semid];
567 1.6 mycroft if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
568 1.6 mycroft return(EINVAL);
569 1.10 cgd if (semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid)))
570 1.6 mycroft return(EINVAL);
571 1.6 mycroft
572 1.7 hpeyerl if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W))) {
573 1.1 cgd #ifdef SEM_DEBUG
574 1.6 mycroft printf("eval = %d from ipaccess\n", eval);
575 1.1 cgd #endif
576 1.6 mycroft return(eval);
577 1.6 mycroft }
578 1.1 cgd
579 1.6 mycroft if (nsops > MAX_SOPS) {
580 1.1 cgd #ifdef SEM_DEBUG
581 1.6 mycroft printf("too many sops (max=%d, nsops=%d)\n", MAX_SOPS, nsops);
582 1.1 cgd #endif
583 1.6 mycroft return(E2BIG);
584 1.6 mycroft }
585 1.1 cgd
586 1.10 cgd if ((eval = copyin(SCARG(uap, sops), sops, nsops * sizeof(sops[0])))
587 1.10 cgd != 0) {
588 1.6 mycroft #ifdef SEM_DEBUG
589 1.6 mycroft printf("eval = %d from copyin(%08x, %08x, %d)\n", eval,
590 1.10 cgd SCARG(uap, sops), &sops, nsops * sizeof(sops[0]));
591 1.6 mycroft #endif
592 1.6 mycroft return(eval);
593 1.6 mycroft }
594 1.1 cgd
595 1.6 mycroft /*
596 1.6 mycroft * Loop trying to satisfy the vector of requests.
597 1.6 mycroft * If we reach a point where we must wait, any requests already
598 1.6 mycroft * performed are rolled back and we go to sleep until some other
599 1.6 mycroft * process wakes us up. At this point, we start all over again.
600 1.6 mycroft *
601 1.6 mycroft * This ensures that from the perspective of other tasks, a set
602 1.6 mycroft * of requests is atomic (never partially satisfied).
603 1.6 mycroft */
604 1.6 mycroft do_undos = 0;
605 1.1 cgd
606 1.6 mycroft for (;;) {
607 1.6 mycroft do_wakeup = 0;
608 1.1 cgd
609 1.6 mycroft for (i = 0; i < nsops; i++) {
610 1.6 mycroft sopptr = &sops[i];
611 1.1 cgd
612 1.6 mycroft if (sopptr->sem_num >= semaptr->sem_nsems)
613 1.6 mycroft return(EFBIG);
614 1.1 cgd
615 1.6 mycroft semptr = &semaptr->sem_base[sopptr->sem_num];
616 1.1 cgd
617 1.1 cgd #ifdef SEM_DEBUG
618 1.6 mycroft printf("semop: semaptr=%x, sem_base=%x, semptr=%x, sem[%d]=%d : op=%d, flag=%s\n",
619 1.6 mycroft semaptr, semaptr->sem_base, semptr,
620 1.6 mycroft sopptr->sem_num, semptr->semval, sopptr->sem_op,
621 1.6 mycroft (sopptr->sem_flg & IPC_NOWAIT) ? "nowait" : "wait");
622 1.1 cgd #endif
623 1.1 cgd
624 1.6 mycroft if (sopptr->sem_op < 0) {
625 1.6 mycroft if (semptr->semval + sopptr->sem_op < 0) {
626 1.1 cgd #ifdef SEM_DEBUG
627 1.6 mycroft printf("semop: can't do it now\n");
628 1.1 cgd #endif
629 1.6 mycroft break;
630 1.6 mycroft } else {
631 1.6 mycroft semptr->semval += sopptr->sem_op;
632 1.6 mycroft if (semptr->semval == 0 &&
633 1.6 mycroft semptr->semzcnt > 0)
634 1.6 mycroft do_wakeup = 1;
635 1.6 mycroft }
636 1.6 mycroft if (sopptr->sem_flg & SEM_UNDO)
637 1.6 mycroft do_undos = 1;
638 1.6 mycroft } else if (sopptr->sem_op == 0) {
639 1.6 mycroft if (semptr->semval > 0) {
640 1.6 mycroft #ifdef SEM_DEBUG
641 1.6 mycroft printf("semop: not zero now\n");
642 1.6 mycroft #endif
643 1.6 mycroft break;
644 1.6 mycroft }
645 1.6 mycroft } else {
646 1.6 mycroft if (semptr->semncnt > 0)
647 1.6 mycroft do_wakeup = 1;
648 1.6 mycroft semptr->semval += sopptr->sem_op;
649 1.6 mycroft if (sopptr->sem_flg & SEM_UNDO)
650 1.6 mycroft do_undos = 1;
651 1.6 mycroft }
652 1.6 mycroft }
653 1.1 cgd
654 1.6 mycroft /*
655 1.6 mycroft * Did we get through the entire vector?
656 1.6 mycroft */
657 1.6 mycroft if (i >= nsops)
658 1.6 mycroft goto done;
659 1.1 cgd
660 1.6 mycroft /*
661 1.6 mycroft * No ... rollback anything that we've already done
662 1.6 mycroft */
663 1.1 cgd #ifdef SEM_DEBUG
664 1.6 mycroft printf("semop: rollback 0 through %d\n", i-1);
665 1.1 cgd #endif
666 1.6 mycroft for (j = 0; j < i; j++)
667 1.6 mycroft semaptr->sem_base[sops[j].sem_num].semval -=
668 1.6 mycroft sops[j].sem_op;
669 1.1 cgd
670 1.6 mycroft /*
671 1.6 mycroft * If the request that we couldn't satisfy has the
672 1.6 mycroft * NOWAIT flag set then return with EAGAIN.
673 1.6 mycroft */
674 1.6 mycroft if (sopptr->sem_flg & IPC_NOWAIT)
675 1.6 mycroft return(EAGAIN);
676 1.1 cgd
677 1.6 mycroft if (sopptr->sem_op == 0)
678 1.6 mycroft semptr->semzcnt++;
679 1.6 mycroft else
680 1.6 mycroft semptr->semncnt++;
681 1.1 cgd
682 1.1 cgd #ifdef SEM_DEBUG
683 1.6 mycroft printf("semop: good night!\n");
684 1.1 cgd #endif
685 1.6 mycroft eval = tsleep((caddr_t)semaptr, (PZERO - 4) | PCATCH,
686 1.6 mycroft "semwait", 0);
687 1.1 cgd #ifdef SEM_DEBUG
688 1.6 mycroft printf("semop: good morning (eval=%d)!\n", eval);
689 1.1 cgd #endif
690 1.1 cgd
691 1.6 mycroft suptr = NULL; /* sem_undo may have been reallocated */
692 1.1 cgd
693 1.6 mycroft if (eval != 0)
694 1.6 mycroft return(EINTR);
695 1.1 cgd #ifdef SEM_DEBUG
696 1.6 mycroft printf("semop: good morning!\n");
697 1.1 cgd #endif
698 1.1 cgd
699 1.6 mycroft /*
700 1.6 mycroft * Make sure that the semaphore still exists
701 1.6 mycroft */
702 1.6 mycroft if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
703 1.10 cgd semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid))) {
704 1.6 mycroft /* The man page says to return EIDRM. */
705 1.6 mycroft /* Unfortunately, BSD doesn't define that code! */
706 1.1 cgd #ifdef EIDRM
707 1.6 mycroft return(EIDRM);
708 1.1 cgd #else
709 1.6 mycroft return(EINVAL);
710 1.1 cgd #endif
711 1.6 mycroft }
712 1.1 cgd
713 1.6 mycroft /*
714 1.6 mycroft * The semaphore is still alive. Readjust the count of
715 1.6 mycroft * waiting processes.
716 1.6 mycroft */
717 1.6 mycroft if (sopptr->sem_op == 0)
718 1.6 mycroft semptr->semzcnt--;
719 1.6 mycroft else
720 1.6 mycroft semptr->semncnt--;
721 1.6 mycroft }
722 1.1 cgd
723 1.6 mycroft done:
724 1.6 mycroft /*
725 1.6 mycroft * Process any SEM_UNDO requests.
726 1.6 mycroft */
727 1.6 mycroft if (do_undos) {
728 1.5 mycroft for (i = 0; i < nsops; i++) {
729 1.6 mycroft /*
730 1.6 mycroft * We only need to deal with SEM_UNDO's for non-zero
731 1.6 mycroft * op's.
732 1.6 mycroft */
733 1.6 mycroft int adjval;
734 1.1 cgd
735 1.6 mycroft if ((sops[i].sem_flg & SEM_UNDO) == 0)
736 1.6 mycroft continue;
737 1.6 mycroft adjval = sops[i].sem_op;
738 1.6 mycroft if (adjval == 0)
739 1.6 mycroft continue;
740 1.6 mycroft eval = semundo_adjust(p, &suptr, semid,
741 1.6 mycroft sops[i].sem_num, -adjval);
742 1.6 mycroft if (eval == 0)
743 1.6 mycroft continue;
744 1.1 cgd
745 1.6 mycroft /*
746 1.6 mycroft * Oh-Oh! We ran out of either sem_undo's or undo's.
747 1.6 mycroft * Rollback the adjustments to this point and then
748 1.6 mycroft * rollback the semaphore ups and down so we can return
749 1.6 mycroft * with an error with all structures restored. We
750 1.6 mycroft * rollback the undo's in the exact reverse order that
751 1.6 mycroft * we applied them. This guarantees that we won't run
752 1.6 mycroft * out of space as we roll things back out.
753 1.6 mycroft */
754 1.6 mycroft for (j = i - 1; j >= 0; j--) {
755 1.6 mycroft if ((sops[j].sem_flg & SEM_UNDO) == 0)
756 1.6 mycroft continue;
757 1.6 mycroft adjval = sops[j].sem_op;
758 1.6 mycroft if (adjval == 0)
759 1.6 mycroft continue;
760 1.6 mycroft if (semundo_adjust(p, &suptr, semid,
761 1.6 mycroft sops[j].sem_num, adjval) != 0)
762 1.1 cgd panic("semop - can't undo undos");
763 1.6 mycroft }
764 1.1 cgd
765 1.6 mycroft for (j = 0; j < nsops; j++)
766 1.6 mycroft semaptr->sem_base[sops[j].sem_num].semval -=
767 1.6 mycroft sops[j].sem_op;
768 1.1 cgd
769 1.1 cgd #ifdef SEM_DEBUG
770 1.6 mycroft printf("eval = %d from semundo_adjust\n", eval);
771 1.1 cgd #endif
772 1.6 mycroft return(eval);
773 1.1 cgd } /* loop through the sops */
774 1.6 mycroft } /* if (do_undos) */
775 1.1 cgd
776 1.6 mycroft /* We're definitely done - set the sempid's */
777 1.6 mycroft for (i = 0; i < nsops; i++) {
778 1.1 cgd sopptr = &sops[i];
779 1.1 cgd semptr = &semaptr->sem_base[sopptr->sem_num];
780 1.1 cgd semptr->sempid = p->p_pid;
781 1.6 mycroft }
782 1.1 cgd
783 1.6 mycroft /* Do a wakeup if any semaphore was up'd. */
784 1.6 mycroft if (do_wakeup) {
785 1.1 cgd #ifdef SEM_DEBUG
786 1.1 cgd printf("semop: doing wakeup\n");
787 1.1 cgd #ifdef SEM_WAKEUP
788 1.4 mycroft sem_wakeup((caddr_t)semaptr);
789 1.1 cgd #else
790 1.4 mycroft wakeup((caddr_t)semaptr);
791 1.1 cgd #endif
792 1.1 cgd printf("semop: back from wakeup\n");
793 1.1 cgd #else
794 1.4 mycroft wakeup((caddr_t)semaptr);
795 1.1 cgd #endif
796 1.6 mycroft }
797 1.1 cgd #ifdef SEM_DEBUG
798 1.6 mycroft printf("semop: done\n");
799 1.1 cgd #endif
800 1.6 mycroft *retval = 0;
801 1.6 mycroft return(0);
802 1.1 cgd }
803 1.1 cgd
804 1.1 cgd /*
805 1.6 mycroft * Go through the undo structures for this process and apply the adjustments to
806 1.6 mycroft * semaphores.
807 1.1 cgd */
808 1.1 cgd semexit(p)
809 1.6 mycroft struct proc *p;
810 1.1 cgd {
811 1.6 mycroft register struct sem_undo *suptr;
812 1.6 mycroft register struct sem_undo **supptr;
813 1.6 mycroft int did_something;
814 1.1 cgd
815 1.6 mycroft /*
816 1.6 mycroft * If somebody else is holding the global semaphore facility lock
817 1.6 mycroft * then sleep until it is released.
818 1.6 mycroft */
819 1.6 mycroft while (semlock_holder != NULL && semlock_holder != p) {
820 1.1 cgd #ifdef SEM_DEBUG
821 1.6 mycroft printf("semaphore facility locked - sleeping ...\n");
822 1.1 cgd #endif
823 1.6 mycroft sleep((caddr_t)&semlock_holder, (PZERO - 4));
824 1.6 mycroft }
825 1.1 cgd
826 1.6 mycroft did_something = 0;
827 1.1 cgd
828 1.6 mycroft /*
829 1.6 mycroft * Go through the chain of undo vectors looking for one
830 1.6 mycroft * associated with this process.
831 1.6 mycroft */
832 1.6 mycroft
833 1.6 mycroft for (supptr = &semu_list; (suptr = *supptr) != NULL;
834 1.6 mycroft supptr = &suptr->un_next) {
835 1.6 mycroft if (suptr->un_proc == p)
836 1.6 mycroft break;
837 1.6 mycroft }
838 1.1 cgd
839 1.6 mycroft if (suptr == NULL)
840 1.6 mycroft goto unlock;
841 1.1 cgd
842 1.1 cgd #ifdef SEM_DEBUG
843 1.6 mycroft printf("proc @%08x has undo structure with %d entries\n", p,
844 1.6 mycroft suptr->un_cnt);
845 1.1 cgd #endif
846 1.1 cgd
847 1.5 mycroft /*
848 1.5 mycroft * If there are any active undo elements then process them.
849 1.5 mycroft */
850 1.5 mycroft if (suptr->un_cnt > 0) {
851 1.6 mycroft int ix;
852 1.1 cgd
853 1.6 mycroft for (ix = 0; ix < suptr->un_cnt; ix++) {
854 1.6 mycroft int semid = suptr->un_ent[ix].un_id;
855 1.6 mycroft int semnum = suptr->un_ent[ix].un_num;
856 1.6 mycroft int adjval = suptr->un_ent[ix].un_adjval;
857 1.6 mycroft struct semid_ds *semaptr;
858 1.6 mycroft
859 1.6 mycroft semaptr = &sema[semid];
860 1.6 mycroft if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
861 1.6 mycroft panic("semexit - semid not allocated");
862 1.6 mycroft if (semnum >= semaptr->sem_nsems)
863 1.6 mycroft panic("semexit - semnum out of range");
864 1.6 mycroft
865 1.6 mycroft #ifdef SEM_DEBUG
866 1.6 mycroft printf("semexit: %08x id=%d num=%d(adj=%d) ; sem=%d\n",
867 1.6 mycroft suptr->un_proc, suptr->un_ent[ix].un_id,
868 1.6 mycroft suptr->un_ent[ix].un_num,
869 1.6 mycroft suptr->un_ent[ix].un_adjval,
870 1.6 mycroft semaptr->sem_base[semnum].semval);
871 1.6 mycroft #endif
872 1.6 mycroft
873 1.6 mycroft if (adjval < 0) {
874 1.6 mycroft if (semaptr->sem_base[semnum].semval < -adjval)
875 1.6 mycroft semaptr->sem_base[semnum].semval = 0;
876 1.6 mycroft else
877 1.6 mycroft semaptr->sem_base[semnum].semval +=
878 1.6 mycroft adjval;
879 1.6 mycroft } else
880 1.6 mycroft semaptr->sem_base[semnum].semval += adjval;
881 1.1 cgd
882 1.1 cgd #ifdef SEM_WAKEUP
883 1.6 mycroft sem_wakeup((caddr_t)semaptr);
884 1.1 cgd #else
885 1.6 mycroft wakeup((caddr_t)semaptr);
886 1.1 cgd #endif
887 1.1 cgd #ifdef SEM_DEBUG
888 1.6 mycroft printf("semexit: back from wakeup\n");
889 1.1 cgd #endif
890 1.6 mycroft }
891 1.5 mycroft }
892 1.1 cgd
893 1.5 mycroft /*
894 1.5 mycroft * Deallocate the undo vector.
895 1.5 mycroft */
896 1.1 cgd #ifdef SEM_DEBUG
897 1.5 mycroft printf("removing vector\n");
898 1.1 cgd #endif
899 1.5 mycroft suptr->un_proc = NULL;
900 1.5 mycroft *supptr = suptr->un_next;
901 1.1 cgd
902 1.6 mycroft unlock:
903 1.6 mycroft /*
904 1.6 mycroft * If the exiting process is holding the global semaphore facility
905 1.6 mycroft * lock then release it.
906 1.6 mycroft */
907 1.6 mycroft if (semlock_holder == p) {
908 1.6 mycroft semlock_holder = NULL;
909 1.6 mycroft wakeup((caddr_t)&semlock_holder);
910 1.6 mycroft }
911 1.1 cgd }
912 1.10 cgd
913 1.10 cgd #if defined(COMPAT_10) && !defined(alpha)
914 1.10 cgd int
915 1.10 cgd compat_10_semsys(p, uap, retval)
916 1.10 cgd struct proc *p;
917 1.10 cgd struct compat_10_semsys_args /* {
918 1.10 cgd syscallarg(int) which;
919 1.10 cgd syscallarg(int) a2;
920 1.10 cgd syscallarg(int) a3;
921 1.10 cgd syscallarg(int) a4;
922 1.10 cgd syscallarg(int) a5;
923 1.10 cgd } */ *uap;
924 1.10 cgd register_t *retval;
925 1.10 cgd {
926 1.10 cgd struct __semctl_args /* {
927 1.10 cgd syscallarg(int) semid;
928 1.10 cgd syscallarg(int) semnum;
929 1.10 cgd syscallarg(int) cmd;
930 1.10 cgd syscallarg(union semun *) arg;
931 1.10 cgd } */ __semctl_args;
932 1.10 cgd struct semget_args /* {
933 1.10 cgd syscallarg(key_t) key;
934 1.10 cgd syscallarg(int) nsems;
935 1.10 cgd syscallarg(int) semflg;
936 1.10 cgd } */ semget_args;
937 1.10 cgd struct semop_args /* {
938 1.10 cgd syscallarg(int) semid;
939 1.10 cgd syscallarg(struct sembuf *) sops;
940 1.10 cgd syscallarg(u_int) nsops;
941 1.10 cgd } */ semop_args;
942 1.10 cgd struct semconfig_args /* {
943 1.10 cgd syscallarg(int) flag;
944 1.10 cgd } */ semconfig_args;
945 1.10 cgd
946 1.10 cgd while (semlock_holder != NULL && semlock_holder != p)
947 1.10 cgd sleep((caddr_t)&semlock_holder, (PZERO - 4));
948 1.10 cgd
949 1.10 cgd switch (SCARG(uap, which)) {
950 1.10 cgd case 0: /* __semctl() */
951 1.10 cgd SCARG(&__semctl_args, semid) = SCARG(uap, a2);
952 1.10 cgd SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
953 1.10 cgd SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
954 1.10 cgd SCARG(&__semctl_args, arg) = (union semun *)SCARG(uap, a5);
955 1.10 cgd return (__semctl(p, &__semctl_args, retval));
956 1.10 cgd
957 1.10 cgd case 1: /* semget() */
958 1.10 cgd SCARG(&semget_args, key) = SCARG(uap, a2);
959 1.10 cgd SCARG(&semget_args, nsems) = SCARG(uap, a3);
960 1.10 cgd SCARG(&semget_args, semflg) = SCARG(uap, a4);
961 1.10 cgd return (semget(p, &semget_args, retval));
962 1.10 cgd
963 1.10 cgd case 2: /* semop() */
964 1.10 cgd SCARG(&semop_args, semid) = SCARG(uap, a2);
965 1.10 cgd SCARG(&semop_args, sops) = (struct sembuf *)SCARG(uap, a3);
966 1.10 cgd SCARG(&semop_args, nsops) = SCARG(uap, a4);
967 1.10 cgd return (semop(p, &semop_args, retval));
968 1.10 cgd
969 1.10 cgd case 3: /* semconfig() */
970 1.10 cgd SCARG(&semconfig_args, flag) = SCARG(uap, a2);
971 1.10 cgd return (semconfig(p, &semconfig_args, retval));
972 1.10 cgd
973 1.10 cgd default:
974 1.10 cgd return (EINVAL);
975 1.10 cgd }
976 1.10 cgd }
977 1.10 cgd #endif /* defined(COMPAT_10) && !defined(alpha) */
978