1 /* $FreeBSD: src/sys/kern/sysv_sem.c,v 1.24.2.8 2002/10/22 20:45:03 fjoe Exp $ */
4 * Implementation of SVID semaphores
6 * Author: Daniel Boulet
8 * This software is provided ``AS IS'' without any warranties of any kind.
11 #include "opt_sysvipc.h"
13 #include <sys/param.h>
14 #include <sys/systm.h>
15 #include <sys/sysproto.h>
16 #include <sys/kernel.h>
19 #include <sys/sysent.h>
20 #include <sys/sysctl.h>
21 #include <sys/malloc.h>
24 static MALLOC_DEFINE(M_SEM, "sem", "SVID compatible semaphores");
26 static void seminit __P((void *));
28 #ifndef _SYS_SYSPROTO_H_
30 int __semctl __P((struct proc *p, struct __semctl_args *uap));
32 int semget __P((struct proc *p, struct semget_args *uap));
34 int semop __P((struct proc *p, struct semop_args *uap));
37 static struct sem_undo *semu_alloc __P((struct proc *p));
38 static int semundo_adjust __P((struct proc *p, struct sem_undo **supptr,
39 int semid, int semnum, int adjval));
40 static void semundo_clear __P((int semid, int semnum));
42 /* XXX casting to (sy_call_t *) is bogus, as usual. */
43 static sy_call_t *semcalls[] = {
44 (sy_call_t *)__semctl, (sy_call_t *)semget,
48 static int semtot = 0;
49 static struct semid_ds *sema; /* semaphore id pool */
50 static struct sem *sem; /* semaphore pool */
51 static struct sem_undo *semu_list; /* list of active undo structures */
52 static int *semu; /* undo structure pool */
55 u_short semval; /* semaphore value */
56 pid_t sempid; /* pid of last operation */
57 u_short semncnt; /* # awaiting semval > cval */
58 u_short semzcnt; /* # awaiting semval = 0 */
62 * Undo structure (one per process)
65 struct sem_undo *un_next; /* ptr to next active undo structure */
66 struct proc *un_proc; /* owner of this structure */
67 short un_cnt; /* # of active entries */
69 short un_adjval; /* adjust on exit values */
70 short un_num; /* semaphore # */
71 int un_id; /* semid */
72 } un_ent[1]; /* undo entries */
76 * Configuration parameters
79 #define SEMMNI 10 /* # of semaphore identifiers */
82 #define SEMMNS 60 /* # of semaphores in system */
85 #define SEMUME 10 /* max # of undo entries per process */
88 #define SEMMNU 30 /* # of undo structures in system */
91 /* shouldn't need tuning */
93 #define SEMMAP 30 /* # of entries in semaphore map */
96 #define SEMMSL SEMMNS /* max # of semaphores per id */
99 #define SEMOPM 100 /* max # of operations per semop call */
102 #define SEMVMX 32767 /* semaphore maximum value */
103 #define SEMAEM 16384 /* adjust on exit max value */
106 * Due to the way semaphore memory is allocated, we have to ensure that
107 * SEMUSZ is properly aligned.
110 #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
112 /* actual size of an undo structure */
113 #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
116 * Macro to find a particular sem_undo vector
118 #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
121 * semaphore info struct
123 struct seminfo seminfo = {
124 SEMMAP, /* # of entries in semaphore map */
125 SEMMNI, /* # of semaphore identifiers */
126 SEMMNS, /* # of semaphores in system */
127 SEMMNU, /* # of undo structures in system */
128 SEMMSL, /* max # of semaphores per id */
129 SEMOPM, /* max # of operations per semop call */
130 SEMUME, /* max # of undo entries per process */
131 SEMUSZ, /* size in bytes of undo structure */
132 SEMVMX, /* semaphore maximum value */
133 SEMAEM /* adjust on exit max value */
136 TUNABLE_INT("kern.ipc.semmap", &seminfo.semmap);
137 TUNABLE_INT("kern.ipc.semmni", &seminfo.semmni);
138 TUNABLE_INT("kern.ipc.semmns", &seminfo.semmns);
139 TUNABLE_INT("kern.ipc.semmnu", &seminfo.semmnu);
140 TUNABLE_INT("kern.ipc.semmsl", &seminfo.semmsl);
141 TUNABLE_INT("kern.ipc.semopm", &seminfo.semopm);
142 TUNABLE_INT("kern.ipc.semume", &seminfo.semume);
143 TUNABLE_INT("kern.ipc.semusz", &seminfo.semusz);
144 TUNABLE_INT("kern.ipc.semvmx", &seminfo.semvmx);
145 TUNABLE_INT("kern.ipc.semaem", &seminfo.semaem);
147 SYSCTL_DECL(_kern_ipc);
148 SYSCTL_INT(_kern_ipc, OID_AUTO, semmap, CTLFLAG_RW, &seminfo.semmap, 0, "");
149 SYSCTL_INT(_kern_ipc, OID_AUTO, semmni, CTLFLAG_RD, &seminfo.semmni, 0, "");
150 SYSCTL_INT(_kern_ipc, OID_AUTO, semmns, CTLFLAG_RD, &seminfo.semmns, 0, "");
151 SYSCTL_INT(_kern_ipc, OID_AUTO, semmnu, CTLFLAG_RD, &seminfo.semmnu, 0, "");
152 SYSCTL_INT(_kern_ipc, OID_AUTO, semmsl, CTLFLAG_RW, &seminfo.semmsl, 0, "");
153 SYSCTL_INT(_kern_ipc, OID_AUTO, semopm, CTLFLAG_RD, &seminfo.semopm, 0, "");
154 SYSCTL_INT(_kern_ipc, OID_AUTO, semume, CTLFLAG_RD, &seminfo.semume, 0, "");
155 SYSCTL_INT(_kern_ipc, OID_AUTO, semusz, CTLFLAG_RD, &seminfo.semusz, 0, "");
156 SYSCTL_INT(_kern_ipc, OID_AUTO, semvmx, CTLFLAG_RW, &seminfo.semvmx, 0, "");
157 SYSCTL_INT(_kern_ipc, OID_AUTO, semaem, CTLFLAG_RW, &seminfo.semaem, 0, "");
160 RO seminfo.semmap /* SEMMAP unused */
163 RO seminfo.semmnu /* undo entries per system */
165 RO seminfo.semopm /* SEMOPM unused */
167 RO seminfo.semusz /* param - derived from SEMUME for per-proc sizeof */
168 RO seminfo.semvmx /* SEMVMX unused - user param */
169 RO seminfo.semaem /* SEMAEM unused - user param */
178 sem = malloc(sizeof(struct sem) * seminfo.semmns, M_SEM, M_WAITOK);
180 panic("sem is NULL");
181 sema = malloc(sizeof(struct semid_ds) * seminfo.semmni, M_SEM, M_WAITOK);
183 panic("sema is NULL");
184 semu = malloc(seminfo.semmnu * seminfo.semusz, M_SEM, M_WAITOK);
186 panic("semu is NULL");
188 for (i = 0; i < seminfo.semmni; i++) {
189 sema[i].sem_base = 0;
190 sema[i].sem_perm.mode = 0;
192 for (i = 0; i < seminfo.semmnu; i++) {
193 register struct sem_undo *suptr = SEMU(i);
194 suptr->un_proc = NULL;
198 SYSINIT(sysv_sem, SI_SUB_SYSV_SEM, SI_ORDER_FIRST, seminit, NULL)
201 * Entry point for all SEM calls
206 /* XXX actually varargs. */
207 struct semsys_args /* {
216 if (!jail_sysvipc_allowed && p->p_prison != NULL)
219 if (uap->which >= sizeof(semcalls)/sizeof(semcalls[0]))
221 return ((*semcalls[uap->which])(p, &uap->a2));
225 * Allocate a new sem_undo structure for a process
226 * (returns ptr to structure or NULL if no more room)
229 static struct sem_undo *
234 register struct sem_undo *suptr;
235 register struct sem_undo **supptr;
239 * Try twice to allocate something.
240 * (we'll purge any empty structures after the first pass so
241 * two passes are always enough)
244 for (attempt = 0; attempt < 2; attempt++) {
246 * Look for a free structure.
247 * Fill it in and return it if we find one.
250 for (i = 0; i < seminfo.semmnu; i++) {
252 if (suptr->un_proc == NULL) {
253 suptr->un_next = semu_list;
262 * We didn't find a free one, if this is the first attempt
263 * then try to free some structures.
267 /* All the structures are in use - try to free some */
268 int did_something = 0;
271 while ((suptr = *supptr) != NULL) {
272 if (suptr->un_cnt == 0) {
273 suptr->un_proc = NULL;
274 *supptr = suptr->un_next;
277 supptr = &(suptr->un_next);
280 /* If we didn't free anything then just give-up */
285 * The second pass failed even though we freed
286 * something after the first pass!
287 * This is IMPOSSIBLE!
289 panic("semu_alloc - second attempt failed");
296 * Adjust a particular entry for a particular proc
300 semundo_adjust(p, supptr, semid, semnum, adjval)
301 register struct proc *p;
302 struct sem_undo **supptr;
306 register struct sem_undo *suptr;
307 register struct undo *sunptr;
310 /* Look for and remember the sem_undo if the caller doesn't provide
315 for (suptr = semu_list; suptr != NULL;
316 suptr = suptr->un_next) {
317 if (suptr->un_proc == p) {
325 suptr = semu_alloc(p);
333 * Look for the requested entry and adjust it (delete if adjval becomes
336 sunptr = &suptr->un_ent[0];
337 for (i = 0; i < suptr->un_cnt; i++, sunptr++) {
338 if (sunptr->un_id != semid || sunptr->un_num != semnum)
341 sunptr->un_adjval = 0;
343 sunptr->un_adjval += adjval;
344 if (sunptr->un_adjval == 0) {
346 if (i < suptr->un_cnt)
348 suptr->un_ent[suptr->un_cnt];
353 /* Didn't find the right entry - create it */
356 if (suptr->un_cnt != seminfo.semume) {
357 sunptr = &suptr->un_ent[suptr->un_cnt];
359 sunptr->un_adjval = adjval;
360 sunptr->un_id = semid; sunptr->un_num = semnum;
367 semundo_clear(semid, semnum)
370 register struct sem_undo *suptr;
372 for (suptr = semu_list; suptr != NULL; suptr = suptr->un_next) {
373 register struct undo *sunptr = &suptr->un_ent[0];
376 while (i < suptr->un_cnt) {
377 if (sunptr->un_id == semid) {
378 if (semnum == -1 || sunptr->un_num == semnum) {
380 if (i < suptr->un_cnt) {
382 suptr->un_ent[suptr->un_cnt];
395 * Note that the user-mode half of this passes a union, not a pointer
397 #ifndef _SYS_SYSPROTO_H_
398 struct __semctl_args {
409 register struct __semctl_args *uap;
411 int semid = uap->semid;
412 int semnum = uap->semnum;
414 union semun *arg = uap->arg;
415 union semun real_arg;
416 struct ucred *cred = p->p_ucred;
418 struct semid_ds sbuf;
419 register struct semid_ds *semaptr;
422 printf("call to semctl(%d, %d, %d, 0x%x)\n", semid, semnum, cmd, arg);
425 if (!jail_sysvipc_allowed && p->p_prison != NULL)
428 semid = IPCID_TO_IX(semid);
429 if (semid < 0 || semid >= seminfo.semmni)
432 semaptr = &sema[semid];
433 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
434 semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
442 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_M)))
444 semaptr->sem_perm.cuid = cred->cr_uid;
445 semaptr->sem_perm.uid = cred->cr_uid;
446 semtot -= semaptr->sem_nsems;
447 for (i = semaptr->sem_base - sem; i < semtot; i++)
448 sem[i] = sem[i + semaptr->sem_nsems];
449 for (i = 0; i < seminfo.semmni; i++) {
450 if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
451 sema[i].sem_base > semaptr->sem_base)
452 sema[i].sem_base -= semaptr->sem_nsems;
454 semaptr->sem_perm.mode = 0;
455 semundo_clear(semid, -1);
456 wakeup((caddr_t)semaptr);
460 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_M)))
462 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
464 if ((eval = copyin(real_arg.buf, (caddr_t)&sbuf,
467 semaptr->sem_perm.uid = sbuf.sem_perm.uid;
468 semaptr->sem_perm.gid = sbuf.sem_perm.gid;
469 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
470 (sbuf.sem_perm.mode & 0777);
471 semaptr->sem_ctime = time_second;
475 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
477 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
479 eval = copyout((caddr_t)semaptr, real_arg.buf,
480 sizeof(struct semid_ds));
484 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
486 if (semnum < 0 || semnum >= semaptr->sem_nsems)
488 rval = semaptr->sem_base[semnum].semncnt;
492 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
494 if (semnum < 0 || semnum >= semaptr->sem_nsems)
496 rval = semaptr->sem_base[semnum].sempid;
500 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
502 if (semnum < 0 || semnum >= semaptr->sem_nsems)
504 rval = semaptr->sem_base[semnum].semval;
508 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
510 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
512 for (i = 0; i < semaptr->sem_nsems; i++) {
513 eval = copyout((caddr_t)&semaptr->sem_base[i].semval,
514 &real_arg.array[i], sizeof(real_arg.array[0]));
521 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
523 if (semnum < 0 || semnum >= semaptr->sem_nsems)
525 rval = semaptr->sem_base[semnum].semzcnt;
529 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W)))
531 if (semnum < 0 || semnum >= semaptr->sem_nsems)
533 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
535 semaptr->sem_base[semnum].semval = real_arg.val;
536 semundo_clear(semid, semnum);
537 wakeup((caddr_t)semaptr);
541 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W)))
543 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
545 for (i = 0; i < semaptr->sem_nsems; i++) {
546 eval = copyin(&real_arg.array[i],
547 (caddr_t)&semaptr->sem_base[i].semval,
548 sizeof(real_arg.array[0]));
552 semundo_clear(semid, -1);
553 wakeup((caddr_t)semaptr);
561 p->p_retval[0] = rval;
565 #ifndef _SYS_SYSPROTO_H_
576 register struct semget_args *uap;
580 int nsems = uap->nsems;
581 int semflg = uap->semflg;
582 struct ucred *cred = p->p_ucred;
585 printf("semget(0x%x, %d, 0%o)\n", key, nsems, semflg);
588 if (!jail_sysvipc_allowed && p->p_prison != NULL)
591 if (key != IPC_PRIVATE) {
592 for (semid = 0; semid < seminfo.semmni; semid++) {
593 if ((sema[semid].sem_perm.mode & SEM_ALLOC) &&
594 sema[semid].sem_perm.key == key)
597 if (semid < seminfo.semmni) {
599 printf("found public key\n");
601 if ((eval = ipcperm(p, &sema[semid].sem_perm,
604 if (nsems > 0 && sema[semid].sem_nsems < nsems) {
606 printf("too small\n");
610 if ((semflg & IPC_CREAT) && (semflg & IPC_EXCL)) {
612 printf("not exclusive\n");
621 printf("need to allocate the semid_ds\n");
623 if (key == IPC_PRIVATE || (semflg & IPC_CREAT)) {
624 if (nsems <= 0 || nsems > seminfo.semmsl) {
626 printf("nsems out of range (0<%d<=%d)\n", nsems,
631 if (nsems > seminfo.semmns - semtot) {
633 printf("not enough semaphores left (need %d, got %d)\n",
634 nsems, seminfo.semmns - semtot);
638 for (semid = 0; semid < seminfo.semmni; semid++) {
639 if ((sema[semid].sem_perm.mode & SEM_ALLOC) == 0)
642 if (semid == seminfo.semmni) {
644 printf("no more semid_ds's available\n");
649 printf("semid %d is available\n", semid);
651 sema[semid].sem_perm.key = key;
652 sema[semid].sem_perm.cuid = cred->cr_uid;
653 sema[semid].sem_perm.uid = cred->cr_uid;
654 sema[semid].sem_perm.cgid = cred->cr_gid;
655 sema[semid].sem_perm.gid = cred->cr_gid;
656 sema[semid].sem_perm.mode = (semflg & 0777) | SEM_ALLOC;
657 sema[semid].sem_perm.seq =
658 (sema[semid].sem_perm.seq + 1) & 0x7fff;
659 sema[semid].sem_nsems = nsems;
660 sema[semid].sem_otime = 0;
661 sema[semid].sem_ctime = time_second;
662 sema[semid].sem_base = &sem[semtot];
664 bzero(sema[semid].sem_base,
665 sizeof(sema[semid].sem_base[0])*nsems);
667 printf("sembase = 0x%x, next = 0x%x\n", sema[semid].sem_base,
672 printf("didn't find it and wasn't asked to create it\n");
678 p->p_retval[0] = IXSEQ_TO_IPCID(semid, sema[semid].sem_perm);
682 #ifndef _SYS_SYSPROTO_H_
693 register struct semop_args *uap;
695 int semid = uap->semid;
696 u_int nsops = uap->nsops;
697 struct sembuf sops[MAX_SOPS];
698 register struct semid_ds *semaptr;
699 register struct sembuf *sopptr;
700 register struct sem *semptr;
701 struct sem_undo *suptr = NULL;
703 int do_wakeup, do_undos;
706 printf("call to semop(%d, 0x%x, %u)\n", semid, sops, nsops);
709 if (!jail_sysvipc_allowed && p->p_prison != NULL)
712 semid = IPCID_TO_IX(semid); /* Convert back to zero origin */
714 if (semid < 0 || semid >= seminfo.semmni)
717 semaptr = &sema[semid];
718 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
720 if (semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
723 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W))) {
725 printf("eval = %d from ipaccess\n", eval);
730 if (nsops > MAX_SOPS) {
732 printf("too many sops (max=%d, nsops=%u)\n", MAX_SOPS, nsops);
737 if ((eval = copyin(uap->sops, &sops, nsops * sizeof(sops[0]))) != 0) {
739 printf("eval = %d from copyin(%08x, %08x, %u)\n", eval,
740 uap->sops, &sops, nsops * sizeof(sops[0]));
746 * Loop trying to satisfy the vector of requests.
747 * If we reach a point where we must wait, any requests already
748 * performed are rolled back and we go to sleep until some other
749 * process wakes us up. At this point, we start all over again.
751 * This ensures that from the perspective of other tasks, a set
752 * of requests is atomic (never partially satisfied).
759 for (i = 0; i < nsops; i++) {
762 if (sopptr->sem_num >= semaptr->sem_nsems)
765 semptr = &semaptr->sem_base[sopptr->sem_num];
768 printf("semop: semaptr=%x, sem_base=%x, semptr=%x, sem[%d]=%d : op=%d, flag=%s\n",
769 semaptr, semaptr->sem_base, semptr,
770 sopptr->sem_num, semptr->semval, sopptr->sem_op,
771 (sopptr->sem_flg & IPC_NOWAIT) ? "nowait" : "wait");
774 if (sopptr->sem_op < 0) {
775 if (semptr->semval + sopptr->sem_op < 0) {
777 printf("semop: can't do it now\n");
781 semptr->semval += sopptr->sem_op;
782 if (semptr->semval == 0 &&
786 if (sopptr->sem_flg & SEM_UNDO)
788 } else if (sopptr->sem_op == 0) {
789 if (semptr->semval > 0) {
791 printf("semop: not zero now\n");
796 if (semptr->semncnt > 0)
798 semptr->semval += sopptr->sem_op;
799 if (sopptr->sem_flg & SEM_UNDO)
805 * Did we get through the entire vector?
811 * No ... rollback anything that we've already done
814 printf("semop: rollback 0 through %d\n", i-1);
816 for (j = 0; j < i; j++)
817 semaptr->sem_base[sops[j].sem_num].semval -=
821 * If the request that we couldn't satisfy has the
822 * NOWAIT flag set then return with EAGAIN.
824 if (sopptr->sem_flg & IPC_NOWAIT)
827 if (sopptr->sem_op == 0)
833 printf("semop: good night!\n");
835 eval = tsleep((caddr_t)semaptr, (PZERO - 4) | PCATCH,
838 printf("semop: good morning (eval=%d)!\n", eval);
841 suptr = NULL; /* sem_undo may have been reallocated */
846 printf("semop: good morning!\n");
850 * Make sure that the semaphore still exists
852 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
853 semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
857 * The semaphore is still alive. Readjust the count of
860 if (sopptr->sem_op == 0)
868 * Process any SEM_UNDO requests.
871 for (i = 0; i < nsops; i++) {
873 * We only need to deal with SEM_UNDO's for non-zero
878 if ((sops[i].sem_flg & SEM_UNDO) == 0)
880 adjval = sops[i].sem_op;
883 eval = semundo_adjust(p, &suptr, semid,
884 sops[i].sem_num, -adjval);
889 * Oh-Oh! We ran out of either sem_undo's or undo's.
890 * Rollback the adjustments to this point and then
891 * rollback the semaphore ups and down so we can return
892 * with an error with all structures restored. We
893 * rollback the undo's in the exact reverse order that
894 * we applied them. This guarantees that we won't run
895 * out of space as we roll things back out.
897 for (j = i - 1; j >= 0; j--) {
898 if ((sops[j].sem_flg & SEM_UNDO) == 0)
900 adjval = sops[j].sem_op;
903 if (semundo_adjust(p, &suptr, semid,
904 sops[j].sem_num, adjval) != 0)
905 panic("semop - can't undo undos");
908 for (j = 0; j < nsops; j++)
909 semaptr->sem_base[sops[j].sem_num].semval -=
913 printf("eval = %d from semundo_adjust\n", eval);
916 } /* loop through the sops */
917 } /* if (do_undos) */
919 /* We're definitely done - set the sempid's */
920 for (i = 0; i < nsops; i++) {
922 semptr = &semaptr->sem_base[sopptr->sem_num];
923 semptr->sempid = p->p_pid;
926 /* Do a wakeup if any semaphore was up'd. */
929 printf("semop: doing wakeup\n");
931 wakeup((caddr_t)semaptr);
933 printf("semop: back from wakeup\n");
937 printf("semop: done\n");
944 * Go through the undo structures for this process and apply the adjustments to
951 register struct sem_undo *suptr;
952 register struct sem_undo **supptr;
958 * Go through the chain of undo vectors looking for one
959 * associated with this process.
962 for (supptr = &semu_list; (suptr = *supptr) != NULL;
963 supptr = &suptr->un_next) {
964 if (suptr->un_proc == p)
972 printf("proc @%08x has undo structure with %d entries\n", p,
977 * If there are any active undo elements then process them.
979 if (suptr->un_cnt > 0) {
982 for (ix = 0; ix < suptr->un_cnt; ix++) {
983 int semid = suptr->un_ent[ix].un_id;
984 int semnum = suptr->un_ent[ix].un_num;
985 int adjval = suptr->un_ent[ix].un_adjval;
986 struct semid_ds *semaptr;
988 semaptr = &sema[semid];
989 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
990 panic("semexit - semid not allocated");
991 if (semnum >= semaptr->sem_nsems)
992 panic("semexit - semnum out of range");
995 printf("semexit: %08x id=%d num=%d(adj=%d) ; sem=%d\n",
996 suptr->un_proc, suptr->un_ent[ix].un_id,
997 suptr->un_ent[ix].un_num,
998 suptr->un_ent[ix].un_adjval,
999 semaptr->sem_base[semnum].semval);
1003 if (semaptr->sem_base[semnum].semval < -adjval)
1004 semaptr->sem_base[semnum].semval = 0;
1006 semaptr->sem_base[semnum].semval +=
1009 semaptr->sem_base[semnum].semval += adjval;
1011 wakeup((caddr_t)semaptr);
1013 printf("semexit: back from wakeup\n");
1019 * Deallocate the undo vector.
1022 printf("removing vector\n");
1024 suptr->un_proc = NULL;
1025 *supptr = suptr->un_next;