1 /* $FreeBSD: src/sys/kern/sysv_sem.c,v 1.24.2.8 2002/10/22 20:45:03 fjoe Exp $ */
2 /* $DragonFly: src/sys/kern/sysv_sem.c,v 1.2 2003/06/17 04:28:41 dillon Exp $ */
5 * Implementation of SVID semaphores
7 * Author: Daniel Boulet
9 * This software is provided ``AS IS'' without any warranties of any kind.
12 #include "opt_sysvipc.h"
14 #include <sys/param.h>
15 #include <sys/systm.h>
16 #include <sys/sysproto.h>
17 #include <sys/kernel.h>
20 #include <sys/sysent.h>
21 #include <sys/sysctl.h>
22 #include <sys/malloc.h>
25 static MALLOC_DEFINE(M_SEM, "sem", "SVID compatible semaphores");
27 static void seminit __P((void *));
29 #ifndef _SYS_SYSPROTO_H_
31 int __semctl __P((struct proc *p, struct __semctl_args *uap));
33 int semget __P((struct proc *p, struct semget_args *uap));
35 int semop __P((struct proc *p, struct semop_args *uap));
38 static struct sem_undo *semu_alloc __P((struct proc *p));
39 static int semundo_adjust __P((struct proc *p, struct sem_undo **supptr,
40 int semid, int semnum, int adjval));
41 static void semundo_clear __P((int semid, int semnum));
43 /* XXX casting to (sy_call_t *) is bogus, as usual. */
44 static sy_call_t *semcalls[] = {
45 (sy_call_t *)__semctl, (sy_call_t *)semget,
49 static int semtot = 0;
50 static struct semid_ds *sema; /* semaphore id pool */
51 static struct sem *sem; /* semaphore pool */
52 static struct sem_undo *semu_list; /* list of active undo structures */
53 static int *semu; /* undo structure pool */
56 u_short semval; /* semaphore value */
57 pid_t sempid; /* pid of last operation */
58 u_short semncnt; /* # awaiting semval > cval */
59 u_short semzcnt; /* # awaiting semval = 0 */
63 * Undo structure (one per process)
66 struct sem_undo *un_next; /* ptr to next active undo structure */
67 struct proc *un_proc; /* owner of this structure */
68 short un_cnt; /* # of active entries */
70 short un_adjval; /* adjust on exit values */
71 short un_num; /* semaphore # */
72 int un_id; /* semid */
73 } un_ent[1]; /* undo entries */
77 * Configuration parameters
80 #define SEMMNI 10 /* # of semaphore identifiers */
83 #define SEMMNS 60 /* # of semaphores in system */
86 #define SEMUME 10 /* max # of undo entries per process */
89 #define SEMMNU 30 /* # of undo structures in system */
92 /* shouldn't need tuning */
94 #define SEMMAP 30 /* # of entries in semaphore map */
97 #define SEMMSL SEMMNS /* max # of semaphores per id */
100 #define SEMOPM 100 /* max # of operations per semop call */
103 #define SEMVMX 32767 /* semaphore maximum value */
104 #define SEMAEM 16384 /* adjust on exit max value */
107 * Due to the way semaphore memory is allocated, we have to ensure that
108 * SEMUSZ is properly aligned.
111 #define SEM_ALIGN(bytes) (((bytes) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
113 /* actual size of an undo structure */
114 #define SEMUSZ SEM_ALIGN(offsetof(struct sem_undo, un_ent[SEMUME]))
117 * Macro to find a particular sem_undo vector
119 #define SEMU(ix) ((struct sem_undo *)(((intptr_t)semu)+ix * seminfo.semusz))
122 * semaphore info struct
124 struct seminfo seminfo = {
125 SEMMAP, /* # of entries in semaphore map */
126 SEMMNI, /* # of semaphore identifiers */
127 SEMMNS, /* # of semaphores in system */
128 SEMMNU, /* # of undo structures in system */
129 SEMMSL, /* max # of semaphores per id */
130 SEMOPM, /* max # of operations per semop call */
131 SEMUME, /* max # of undo entries per process */
132 SEMUSZ, /* size in bytes of undo structure */
133 SEMVMX, /* semaphore maximum value */
134 SEMAEM /* adjust on exit max value */
137 TUNABLE_INT("kern.ipc.semmap", &seminfo.semmap);
138 TUNABLE_INT("kern.ipc.semmni", &seminfo.semmni);
139 TUNABLE_INT("kern.ipc.semmns", &seminfo.semmns);
140 TUNABLE_INT("kern.ipc.semmnu", &seminfo.semmnu);
141 TUNABLE_INT("kern.ipc.semmsl", &seminfo.semmsl);
142 TUNABLE_INT("kern.ipc.semopm", &seminfo.semopm);
143 TUNABLE_INT("kern.ipc.semume", &seminfo.semume);
144 TUNABLE_INT("kern.ipc.semusz", &seminfo.semusz);
145 TUNABLE_INT("kern.ipc.semvmx", &seminfo.semvmx);
146 TUNABLE_INT("kern.ipc.semaem", &seminfo.semaem);
148 SYSCTL_DECL(_kern_ipc);
149 SYSCTL_INT(_kern_ipc, OID_AUTO, semmap, CTLFLAG_RW, &seminfo.semmap, 0, "");
150 SYSCTL_INT(_kern_ipc, OID_AUTO, semmni, CTLFLAG_RD, &seminfo.semmni, 0, "");
151 SYSCTL_INT(_kern_ipc, OID_AUTO, semmns, CTLFLAG_RD, &seminfo.semmns, 0, "");
152 SYSCTL_INT(_kern_ipc, OID_AUTO, semmnu, CTLFLAG_RD, &seminfo.semmnu, 0, "");
153 SYSCTL_INT(_kern_ipc, OID_AUTO, semmsl, CTLFLAG_RW, &seminfo.semmsl, 0, "");
154 SYSCTL_INT(_kern_ipc, OID_AUTO, semopm, CTLFLAG_RD, &seminfo.semopm, 0, "");
155 SYSCTL_INT(_kern_ipc, OID_AUTO, semume, CTLFLAG_RD, &seminfo.semume, 0, "");
156 SYSCTL_INT(_kern_ipc, OID_AUTO, semusz, CTLFLAG_RD, &seminfo.semusz, 0, "");
157 SYSCTL_INT(_kern_ipc, OID_AUTO, semvmx, CTLFLAG_RW, &seminfo.semvmx, 0, "");
158 SYSCTL_INT(_kern_ipc, OID_AUTO, semaem, CTLFLAG_RW, &seminfo.semaem, 0, "");
161 RO seminfo.semmap /* SEMMAP unused */
164 RO seminfo.semmnu /* undo entries per system */
166 RO seminfo.semopm /* SEMOPM unused */
168 RO seminfo.semusz /* param - derived from SEMUME for per-proc sizeof */
169 RO seminfo.semvmx /* SEMVMX unused - user param */
170 RO seminfo.semaem /* SEMAEM unused - user param */
179 sem = malloc(sizeof(struct sem) * seminfo.semmns, M_SEM, M_WAITOK);
181 panic("sem is NULL");
182 sema = malloc(sizeof(struct semid_ds) * seminfo.semmni, M_SEM, M_WAITOK);
184 panic("sema is NULL");
185 semu = malloc(seminfo.semmnu * seminfo.semusz, M_SEM, M_WAITOK);
187 panic("semu is NULL");
189 for (i = 0; i < seminfo.semmni; i++) {
190 sema[i].sem_base = 0;
191 sema[i].sem_perm.mode = 0;
193 for (i = 0; i < seminfo.semmnu; i++) {
194 register struct sem_undo *suptr = SEMU(i);
195 suptr->un_proc = NULL;
199 SYSINIT(sysv_sem, SI_SUB_SYSV_SEM, SI_ORDER_FIRST, seminit, NULL)
202 * Entry point for all SEM calls
207 /* XXX actually varargs. */
208 struct semsys_args /* {
217 if (!jail_sysvipc_allowed && p->p_prison != NULL)
220 if (uap->which >= sizeof(semcalls)/sizeof(semcalls[0]))
222 return ((*semcalls[uap->which])(p, &uap->a2));
226 * Allocate a new sem_undo structure for a process
227 * (returns ptr to structure or NULL if no more room)
230 static struct sem_undo *
235 register struct sem_undo *suptr;
236 register struct sem_undo **supptr;
240 * Try twice to allocate something.
241 * (we'll purge any empty structures after the first pass so
242 * two passes are always enough)
245 for (attempt = 0; attempt < 2; attempt++) {
247 * Look for a free structure.
248 * Fill it in and return it if we find one.
251 for (i = 0; i < seminfo.semmnu; i++) {
253 if (suptr->un_proc == NULL) {
254 suptr->un_next = semu_list;
263 * We didn't find a free one, if this is the first attempt
264 * then try to free some structures.
268 /* All the structures are in use - try to free some */
269 int did_something = 0;
272 while ((suptr = *supptr) != NULL) {
273 if (suptr->un_cnt == 0) {
274 suptr->un_proc = NULL;
275 *supptr = suptr->un_next;
278 supptr = &(suptr->un_next);
281 /* If we didn't free anything then just give-up */
286 * The second pass failed even though we freed
287 * something after the first pass!
288 * This is IMPOSSIBLE!
290 panic("semu_alloc - second attempt failed");
297 * Adjust a particular entry for a particular proc
301 semundo_adjust(p, supptr, semid, semnum, adjval)
302 register struct proc *p;
303 struct sem_undo **supptr;
307 register struct sem_undo *suptr;
308 register struct undo *sunptr;
311 /* Look for and remember the sem_undo if the caller doesn't provide
316 for (suptr = semu_list; suptr != NULL;
317 suptr = suptr->un_next) {
318 if (suptr->un_proc == p) {
326 suptr = semu_alloc(p);
334 * Look for the requested entry and adjust it (delete if adjval becomes
337 sunptr = &suptr->un_ent[0];
338 for (i = 0; i < suptr->un_cnt; i++, sunptr++) {
339 if (sunptr->un_id != semid || sunptr->un_num != semnum)
342 sunptr->un_adjval = 0;
344 sunptr->un_adjval += adjval;
345 if (sunptr->un_adjval == 0) {
347 if (i < suptr->un_cnt)
349 suptr->un_ent[suptr->un_cnt];
354 /* Didn't find the right entry - create it */
357 if (suptr->un_cnt != seminfo.semume) {
358 sunptr = &suptr->un_ent[suptr->un_cnt];
360 sunptr->un_adjval = adjval;
361 sunptr->un_id = semid; sunptr->un_num = semnum;
368 semundo_clear(semid, semnum)
371 register struct sem_undo *suptr;
373 for (suptr = semu_list; suptr != NULL; suptr = suptr->un_next) {
374 register struct undo *sunptr = &suptr->un_ent[0];
377 while (i < suptr->un_cnt) {
378 if (sunptr->un_id == semid) {
379 if (semnum == -1 || sunptr->un_num == semnum) {
381 if (i < suptr->un_cnt) {
383 suptr->un_ent[suptr->un_cnt];
396 * Note that the user-mode half of this passes a union, not a pointer
398 #ifndef _SYS_SYSPROTO_H_
399 struct __semctl_args {
410 register struct __semctl_args *uap;
412 int semid = uap->semid;
413 int semnum = uap->semnum;
415 union semun *arg = uap->arg;
416 union semun real_arg;
417 struct ucred *cred = p->p_ucred;
419 struct semid_ds sbuf;
420 register struct semid_ds *semaptr;
423 printf("call to semctl(%d, %d, %d, 0x%x)\n", semid, semnum, cmd, arg);
426 if (!jail_sysvipc_allowed && p->p_prison != NULL)
429 semid = IPCID_TO_IX(semid);
430 if (semid < 0 || semid >= seminfo.semmni)
433 semaptr = &sema[semid];
434 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
435 semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
443 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_M)))
445 semaptr->sem_perm.cuid = cred->cr_uid;
446 semaptr->sem_perm.uid = cred->cr_uid;
447 semtot -= semaptr->sem_nsems;
448 for (i = semaptr->sem_base - sem; i < semtot; i++)
449 sem[i] = sem[i + semaptr->sem_nsems];
450 for (i = 0; i < seminfo.semmni; i++) {
451 if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
452 sema[i].sem_base > semaptr->sem_base)
453 sema[i].sem_base -= semaptr->sem_nsems;
455 semaptr->sem_perm.mode = 0;
456 semundo_clear(semid, -1);
457 wakeup((caddr_t)semaptr);
461 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_M)))
463 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
465 if ((eval = copyin(real_arg.buf, (caddr_t)&sbuf,
468 semaptr->sem_perm.uid = sbuf.sem_perm.uid;
469 semaptr->sem_perm.gid = sbuf.sem_perm.gid;
470 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
471 (sbuf.sem_perm.mode & 0777);
472 semaptr->sem_ctime = time_second;
476 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
478 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
480 eval = copyout((caddr_t)semaptr, real_arg.buf,
481 sizeof(struct semid_ds));
485 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
487 if (semnum < 0 || semnum >= semaptr->sem_nsems)
489 rval = semaptr->sem_base[semnum].semncnt;
493 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
495 if (semnum < 0 || semnum >= semaptr->sem_nsems)
497 rval = semaptr->sem_base[semnum].sempid;
501 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
503 if (semnum < 0 || semnum >= semaptr->sem_nsems)
505 rval = semaptr->sem_base[semnum].semval;
509 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
511 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
513 for (i = 0; i < semaptr->sem_nsems; i++) {
514 eval = copyout((caddr_t)&semaptr->sem_base[i].semval,
515 &real_arg.array[i], sizeof(real_arg.array[0]));
522 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
524 if (semnum < 0 || semnum >= semaptr->sem_nsems)
526 rval = semaptr->sem_base[semnum].semzcnt;
530 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W)))
532 if (semnum < 0 || semnum >= semaptr->sem_nsems)
534 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
536 semaptr->sem_base[semnum].semval = real_arg.val;
537 semundo_clear(semid, semnum);
538 wakeup((caddr_t)semaptr);
542 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W)))
544 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
546 for (i = 0; i < semaptr->sem_nsems; i++) {
547 eval = copyin(&real_arg.array[i],
548 (caddr_t)&semaptr->sem_base[i].semval,
549 sizeof(real_arg.array[0]));
553 semundo_clear(semid, -1);
554 wakeup((caddr_t)semaptr);
562 p->p_retval[0] = rval;
566 #ifndef _SYS_SYSPROTO_H_
577 register struct semget_args *uap;
581 int nsems = uap->nsems;
582 int semflg = uap->semflg;
583 struct ucred *cred = p->p_ucred;
586 printf("semget(0x%x, %d, 0%o)\n", key, nsems, semflg);
589 if (!jail_sysvipc_allowed && p->p_prison != NULL)
592 if (key != IPC_PRIVATE) {
593 for (semid = 0; semid < seminfo.semmni; semid++) {
594 if ((sema[semid].sem_perm.mode & SEM_ALLOC) &&
595 sema[semid].sem_perm.key == key)
598 if (semid < seminfo.semmni) {
600 printf("found public key\n");
602 if ((eval = ipcperm(p, &sema[semid].sem_perm,
605 if (nsems > 0 && sema[semid].sem_nsems < nsems) {
607 printf("too small\n");
611 if ((semflg & IPC_CREAT) && (semflg & IPC_EXCL)) {
613 printf("not exclusive\n");
622 printf("need to allocate the semid_ds\n");
624 if (key == IPC_PRIVATE || (semflg & IPC_CREAT)) {
625 if (nsems <= 0 || nsems > seminfo.semmsl) {
627 printf("nsems out of range (0<%d<=%d)\n", nsems,
632 if (nsems > seminfo.semmns - semtot) {
634 printf("not enough semaphores left (need %d, got %d)\n",
635 nsems, seminfo.semmns - semtot);
639 for (semid = 0; semid < seminfo.semmni; semid++) {
640 if ((sema[semid].sem_perm.mode & SEM_ALLOC) == 0)
643 if (semid == seminfo.semmni) {
645 printf("no more semid_ds's available\n");
650 printf("semid %d is available\n", semid);
652 sema[semid].sem_perm.key = key;
653 sema[semid].sem_perm.cuid = cred->cr_uid;
654 sema[semid].sem_perm.uid = cred->cr_uid;
655 sema[semid].sem_perm.cgid = cred->cr_gid;
656 sema[semid].sem_perm.gid = cred->cr_gid;
657 sema[semid].sem_perm.mode = (semflg & 0777) | SEM_ALLOC;
658 sema[semid].sem_perm.seq =
659 (sema[semid].sem_perm.seq + 1) & 0x7fff;
660 sema[semid].sem_nsems = nsems;
661 sema[semid].sem_otime = 0;
662 sema[semid].sem_ctime = time_second;
663 sema[semid].sem_base = &sem[semtot];
665 bzero(sema[semid].sem_base,
666 sizeof(sema[semid].sem_base[0])*nsems);
668 printf("sembase = 0x%x, next = 0x%x\n", sema[semid].sem_base,
673 printf("didn't find it and wasn't asked to create it\n");
679 p->p_retval[0] = IXSEQ_TO_IPCID(semid, sema[semid].sem_perm);
683 #ifndef _SYS_SYSPROTO_H_
694 register struct semop_args *uap;
696 int semid = uap->semid;
697 u_int nsops = uap->nsops;
698 struct sembuf sops[MAX_SOPS];
699 register struct semid_ds *semaptr;
700 register struct sembuf *sopptr;
701 register struct sem *semptr;
702 struct sem_undo *suptr = NULL;
704 int do_wakeup, do_undos;
707 printf("call to semop(%d, 0x%x, %u)\n", semid, sops, nsops);
710 if (!jail_sysvipc_allowed && p->p_prison != NULL)
713 semid = IPCID_TO_IX(semid); /* Convert back to zero origin */
715 if (semid < 0 || semid >= seminfo.semmni)
718 semaptr = &sema[semid];
719 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
721 if (semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
724 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W))) {
726 printf("eval = %d from ipaccess\n", eval);
731 if (nsops > MAX_SOPS) {
733 printf("too many sops (max=%d, nsops=%u)\n", MAX_SOPS, nsops);
738 if ((eval = copyin(uap->sops, &sops, nsops * sizeof(sops[0]))) != 0) {
740 printf("eval = %d from copyin(%08x, %08x, %u)\n", eval,
741 uap->sops, &sops, nsops * sizeof(sops[0]));
747 * Loop trying to satisfy the vector of requests.
748 * If we reach a point where we must wait, any requests already
749 * performed are rolled back and we go to sleep until some other
750 * process wakes us up. At this point, we start all over again.
752 * This ensures that from the perspective of other tasks, a set
753 * of requests is atomic (never partially satisfied).
760 for (i = 0; i < nsops; i++) {
763 if (sopptr->sem_num >= semaptr->sem_nsems)
766 semptr = &semaptr->sem_base[sopptr->sem_num];
769 printf("semop: semaptr=%x, sem_base=%x, semptr=%x, sem[%d]=%d : op=%d, flag=%s\n",
770 semaptr, semaptr->sem_base, semptr,
771 sopptr->sem_num, semptr->semval, sopptr->sem_op,
772 (sopptr->sem_flg & IPC_NOWAIT) ? "nowait" : "wait");
775 if (sopptr->sem_op < 0) {
776 if (semptr->semval + sopptr->sem_op < 0) {
778 printf("semop: can't do it now\n");
782 semptr->semval += sopptr->sem_op;
783 if (semptr->semval == 0 &&
787 if (sopptr->sem_flg & SEM_UNDO)
789 } else if (sopptr->sem_op == 0) {
790 if (semptr->semval > 0) {
792 printf("semop: not zero now\n");
797 if (semptr->semncnt > 0)
799 semptr->semval += sopptr->sem_op;
800 if (sopptr->sem_flg & SEM_UNDO)
806 * Did we get through the entire vector?
812 * No ... rollback anything that we've already done
815 printf("semop: rollback 0 through %d\n", i-1);
817 for (j = 0; j < i; j++)
818 semaptr->sem_base[sops[j].sem_num].semval -=
822 * If the request that we couldn't satisfy has the
823 * NOWAIT flag set then return with EAGAIN.
825 if (sopptr->sem_flg & IPC_NOWAIT)
828 if (sopptr->sem_op == 0)
834 printf("semop: good night!\n");
836 eval = tsleep((caddr_t)semaptr, (PZERO - 4) | PCATCH,
839 printf("semop: good morning (eval=%d)!\n", eval);
842 suptr = NULL; /* sem_undo may have been reallocated */
847 printf("semop: good morning!\n");
851 * Make sure that the semaphore still exists
853 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
854 semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
858 * The semaphore is still alive. Readjust the count of
861 if (sopptr->sem_op == 0)
869 * Process any SEM_UNDO requests.
872 for (i = 0; i < nsops; i++) {
874 * We only need to deal with SEM_UNDO's for non-zero
879 if ((sops[i].sem_flg & SEM_UNDO) == 0)
881 adjval = sops[i].sem_op;
884 eval = semundo_adjust(p, &suptr, semid,
885 sops[i].sem_num, -adjval);
890 * Oh-Oh! We ran out of either sem_undo's or undo's.
891 * Rollback the adjustments to this point and then
892 * rollback the semaphore ups and down so we can return
893 * with an error with all structures restored. We
894 * rollback the undo's in the exact reverse order that
895 * we applied them. This guarantees that we won't run
896 * out of space as we roll things back out.
898 for (j = i - 1; j >= 0; j--) {
899 if ((sops[j].sem_flg & SEM_UNDO) == 0)
901 adjval = sops[j].sem_op;
904 if (semundo_adjust(p, &suptr, semid,
905 sops[j].sem_num, adjval) != 0)
906 panic("semop - can't undo undos");
909 for (j = 0; j < nsops; j++)
910 semaptr->sem_base[sops[j].sem_num].semval -=
914 printf("eval = %d from semundo_adjust\n", eval);
917 } /* loop through the sops */
918 } /* if (do_undos) */
920 /* We're definitely done - set the sempid's */
921 for (i = 0; i < nsops; i++) {
923 semptr = &semaptr->sem_base[sopptr->sem_num];
924 semptr->sempid = p->p_pid;
927 /* Do a wakeup if any semaphore was up'd. */
930 printf("semop: doing wakeup\n");
932 wakeup((caddr_t)semaptr);
934 printf("semop: back from wakeup\n");
938 printf("semop: done\n");
945 * Go through the undo structures for this process and apply the adjustments to
952 register struct sem_undo *suptr;
953 register struct sem_undo **supptr;
959 * Go through the chain of undo vectors looking for one
960 * associated with this process.
963 for (supptr = &semu_list; (suptr = *supptr) != NULL;
964 supptr = &suptr->un_next) {
965 if (suptr->un_proc == p)
973 printf("proc @%08x has undo structure with %d entries\n", p,
978 * If there are any active undo elements then process them.
980 if (suptr->un_cnt > 0) {
983 for (ix = 0; ix < suptr->un_cnt; ix++) {
984 int semid = suptr->un_ent[ix].un_id;
985 int semnum = suptr->un_ent[ix].un_num;
986 int adjval = suptr->un_ent[ix].un_adjval;
987 struct semid_ds *semaptr;
989 semaptr = &sema[semid];
990 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
991 panic("semexit - semid not allocated");
992 if (semnum >= semaptr->sem_nsems)
993 panic("semexit - semnum out of range");
996 printf("semexit: %08x id=%d num=%d(adj=%d) ; sem=%d\n",
997 suptr->un_proc, suptr->un_ent[ix].un_id,
998 suptr->un_ent[ix].un_num,
999 suptr->un_ent[ix].un_adjval,
1000 semaptr->sem_base[semnum].semval);
1004 if (semaptr->sem_base[semnum].semval < -adjval)
1005 semaptr->sem_base[semnum].semval = 0;
1007 semaptr->sem_base[semnum].semval +=
1010 semaptr->sem_base[semnum].semval += adjval;
1012 wakeup((caddr_t)semaptr);
1014 printf("semexit: back from wakeup\n");
1020 * Deallocate the undo vector.
1023 printf("removing vector\n");
1025 suptr->un_proc = NULL;
1026 *supptr = suptr->un_next;