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.3 2003/06/23 17:55: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
204 * semsys_args(u_int which, a2, a3, ...) (VARARGS)
207 semsys(struct semsys_args *uap)
209 struct proc *p = curproc;
211 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
214 if (uap->which >= sizeof(semcalls)/sizeof(semcalls[0]))
216 return ((*semcalls[uap->which])(&uap->a2));
220 * Allocate a new sem_undo structure for a process
221 * (returns ptr to structure or NULL if no more room)
224 static struct sem_undo *
229 register struct sem_undo *suptr;
230 register struct sem_undo **supptr;
234 * Try twice to allocate something.
235 * (we'll purge any empty structures after the first pass so
236 * two passes are always enough)
239 for (attempt = 0; attempt < 2; attempt++) {
241 * Look for a free structure.
242 * Fill it in and return it if we find one.
245 for (i = 0; i < seminfo.semmnu; i++) {
247 if (suptr->un_proc == NULL) {
248 suptr->un_next = semu_list;
257 * We didn't find a free one, if this is the first attempt
258 * then try to free some structures.
262 /* All the structures are in use - try to free some */
263 int did_something = 0;
266 while ((suptr = *supptr) != NULL) {
267 if (suptr->un_cnt == 0) {
268 suptr->un_proc = NULL;
269 *supptr = suptr->un_next;
272 supptr = &(suptr->un_next);
275 /* If we didn't free anything then just give-up */
280 * The second pass failed even though we freed
281 * something after the first pass!
282 * This is IMPOSSIBLE!
284 panic("semu_alloc - second attempt failed");
291 * Adjust a particular entry for a particular proc
295 semundo_adjust(p, supptr, semid, semnum, adjval)
296 register struct proc *p;
297 struct sem_undo **supptr;
301 register struct sem_undo *suptr;
302 register struct undo *sunptr;
305 /* Look for and remember the sem_undo if the caller doesn't provide
310 for (suptr = semu_list; suptr != NULL;
311 suptr = suptr->un_next) {
312 if (suptr->un_proc == p) {
320 suptr = semu_alloc(p);
328 * Look for the requested entry and adjust it (delete if adjval becomes
331 sunptr = &suptr->un_ent[0];
332 for (i = 0; i < suptr->un_cnt; i++, sunptr++) {
333 if (sunptr->un_id != semid || sunptr->un_num != semnum)
336 sunptr->un_adjval = 0;
338 sunptr->un_adjval += adjval;
339 if (sunptr->un_adjval == 0) {
341 if (i < suptr->un_cnt)
343 suptr->un_ent[suptr->un_cnt];
348 /* Didn't find the right entry - create it */
351 if (suptr->un_cnt != seminfo.semume) {
352 sunptr = &suptr->un_ent[suptr->un_cnt];
354 sunptr->un_adjval = adjval;
355 sunptr->un_id = semid; sunptr->un_num = semnum;
362 semundo_clear(semid, semnum)
365 register struct sem_undo *suptr;
367 for (suptr = semu_list; suptr != NULL; suptr = suptr->un_next) {
368 register struct undo *sunptr = &suptr->un_ent[0];
371 while (i < suptr->un_cnt) {
372 if (sunptr->un_id == semid) {
373 if (semnum == -1 || sunptr->un_num == semnum) {
375 if (i < suptr->un_cnt) {
377 suptr->un_ent[suptr->un_cnt];
390 * Note that the user-mode half of this passes a union, not a pointer
392 #ifndef _SYS_SYSPROTO_H_
393 struct __semctl_args {
402 __semctl(struct __semctl_args *uap)
404 struct proc *p = curproc;
405 int semid = uap->semid;
406 int semnum = uap->semnum;
408 union semun *arg = uap->arg;
409 union semun real_arg;
410 struct ucred *cred = p->p_ucred;
412 struct semid_ds sbuf;
413 register struct semid_ds *semaptr;
416 printf("call to semctl(%d, %d, %d, 0x%x)\n", semid, semnum, cmd, arg);
419 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
422 semid = IPCID_TO_IX(semid);
423 if (semid < 0 || semid >= seminfo.semmni)
426 semaptr = &sema[semid];
427 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
428 semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
436 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_M)))
438 semaptr->sem_perm.cuid = cred->cr_uid;
439 semaptr->sem_perm.uid = cred->cr_uid;
440 semtot -= semaptr->sem_nsems;
441 for (i = semaptr->sem_base - sem; i < semtot; i++)
442 sem[i] = sem[i + semaptr->sem_nsems];
443 for (i = 0; i < seminfo.semmni; i++) {
444 if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
445 sema[i].sem_base > semaptr->sem_base)
446 sema[i].sem_base -= semaptr->sem_nsems;
448 semaptr->sem_perm.mode = 0;
449 semundo_clear(semid, -1);
450 wakeup((caddr_t)semaptr);
454 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_M)))
456 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
458 if ((eval = copyin(real_arg.buf, (caddr_t)&sbuf,
461 semaptr->sem_perm.uid = sbuf.sem_perm.uid;
462 semaptr->sem_perm.gid = sbuf.sem_perm.gid;
463 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
464 (sbuf.sem_perm.mode & 0777);
465 semaptr->sem_ctime = time_second;
469 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
471 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
473 eval = copyout((caddr_t)semaptr, real_arg.buf,
474 sizeof(struct semid_ds));
478 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
480 if (semnum < 0 || semnum >= semaptr->sem_nsems)
482 rval = semaptr->sem_base[semnum].semncnt;
486 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
488 if (semnum < 0 || semnum >= semaptr->sem_nsems)
490 rval = semaptr->sem_base[semnum].sempid;
494 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
496 if (semnum < 0 || semnum >= semaptr->sem_nsems)
498 rval = semaptr->sem_base[semnum].semval;
502 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
504 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
506 for (i = 0; i < semaptr->sem_nsems; i++) {
507 eval = copyout((caddr_t)&semaptr->sem_base[i].semval,
508 &real_arg.array[i], sizeof(real_arg.array[0]));
515 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
517 if (semnum < 0 || semnum >= semaptr->sem_nsems)
519 rval = semaptr->sem_base[semnum].semzcnt;
523 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W)))
525 if (semnum < 0 || semnum >= semaptr->sem_nsems)
527 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
529 semaptr->sem_base[semnum].semval = real_arg.val;
530 semundo_clear(semid, semnum);
531 wakeup((caddr_t)semaptr);
535 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W)))
537 if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
539 for (i = 0; i < semaptr->sem_nsems; i++) {
540 eval = copyin(&real_arg.array[i],
541 (caddr_t)&semaptr->sem_base[i].semval,
542 sizeof(real_arg.array[0]));
546 semundo_clear(semid, -1);
547 wakeup((caddr_t)semaptr);
555 p->p_retval[0] = rval;
559 #ifndef _SYS_SYSPROTO_H_
568 semget(struct semget_args *uap)
570 struct proc *p = curproc;
573 int nsems = uap->nsems;
574 int semflg = uap->semflg;
575 struct ucred *cred = p->p_ucred;
578 printf("semget(0x%x, %d, 0%o)\n", key, nsems, semflg);
581 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
584 if (key != IPC_PRIVATE) {
585 for (semid = 0; semid < seminfo.semmni; semid++) {
586 if ((sema[semid].sem_perm.mode & SEM_ALLOC) &&
587 sema[semid].sem_perm.key == key)
590 if (semid < seminfo.semmni) {
592 printf("found public key\n");
594 if ((eval = ipcperm(p, &sema[semid].sem_perm,
597 if (nsems > 0 && sema[semid].sem_nsems < nsems) {
599 printf("too small\n");
603 if ((semflg & IPC_CREAT) && (semflg & IPC_EXCL)) {
605 printf("not exclusive\n");
614 printf("need to allocate the semid_ds\n");
616 if (key == IPC_PRIVATE || (semflg & IPC_CREAT)) {
617 if (nsems <= 0 || nsems > seminfo.semmsl) {
619 printf("nsems out of range (0<%d<=%d)\n", nsems,
624 if (nsems > seminfo.semmns - semtot) {
626 printf("not enough semaphores left (need %d, got %d)\n",
627 nsems, seminfo.semmns - semtot);
631 for (semid = 0; semid < seminfo.semmni; semid++) {
632 if ((sema[semid].sem_perm.mode & SEM_ALLOC) == 0)
635 if (semid == seminfo.semmni) {
637 printf("no more semid_ds's available\n");
642 printf("semid %d is available\n", semid);
644 sema[semid].sem_perm.key = key;
645 sema[semid].sem_perm.cuid = cred->cr_uid;
646 sema[semid].sem_perm.uid = cred->cr_uid;
647 sema[semid].sem_perm.cgid = cred->cr_gid;
648 sema[semid].sem_perm.gid = cred->cr_gid;
649 sema[semid].sem_perm.mode = (semflg & 0777) | SEM_ALLOC;
650 sema[semid].sem_perm.seq =
651 (sema[semid].sem_perm.seq + 1) & 0x7fff;
652 sema[semid].sem_nsems = nsems;
653 sema[semid].sem_otime = 0;
654 sema[semid].sem_ctime = time_second;
655 sema[semid].sem_base = &sem[semtot];
657 bzero(sema[semid].sem_base,
658 sizeof(sema[semid].sem_base[0])*nsems);
660 printf("sembase = 0x%x, next = 0x%x\n", sema[semid].sem_base,
665 printf("didn't find it and wasn't asked to create it\n");
671 p->p_retval[0] = IXSEQ_TO_IPCID(semid, sema[semid].sem_perm);
675 #ifndef _SYS_SYSPROTO_H_
684 semop(struct semop_args *uap)
686 struct proc *p = curproc;
687 int semid = uap->semid;
688 u_int nsops = uap->nsops;
689 struct sembuf sops[MAX_SOPS];
690 register struct semid_ds *semaptr;
691 register struct sembuf *sopptr;
692 register struct sem *semptr;
693 struct sem_undo *suptr = NULL;
695 int do_wakeup, do_undos;
698 printf("call to semop(%d, 0x%x, %u)\n", semid, sops, nsops);
701 if (!jail_sysvipc_allowed && p->p_ucred->cr_prison != NULL)
704 semid = IPCID_TO_IX(semid); /* Convert back to zero origin */
706 if (semid < 0 || semid >= seminfo.semmni)
709 semaptr = &sema[semid];
710 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
712 if (semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
715 if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_W))) {
717 printf("eval = %d from ipaccess\n", eval);
722 if (nsops > MAX_SOPS) {
724 printf("too many sops (max=%d, nsops=%u)\n", MAX_SOPS, nsops);
729 if ((eval = copyin(uap->sops, &sops, nsops * sizeof(sops[0]))) != 0) {
731 printf("eval = %d from copyin(%08x, %08x, %u)\n", eval,
732 uap->sops, &sops, nsops * sizeof(sops[0]));
738 * Loop trying to satisfy the vector of requests.
739 * If we reach a point where we must wait, any requests already
740 * performed are rolled back and we go to sleep until some other
741 * process wakes us up. At this point, we start all over again.
743 * This ensures that from the perspective of other tasks, a set
744 * of requests is atomic (never partially satisfied).
751 for (i = 0; i < nsops; i++) {
754 if (sopptr->sem_num >= semaptr->sem_nsems)
757 semptr = &semaptr->sem_base[sopptr->sem_num];
760 printf("semop: semaptr=%x, sem_base=%x, semptr=%x, sem[%d]=%d : op=%d, flag=%s\n",
761 semaptr, semaptr->sem_base, semptr,
762 sopptr->sem_num, semptr->semval, sopptr->sem_op,
763 (sopptr->sem_flg & IPC_NOWAIT) ? "nowait" : "wait");
766 if (sopptr->sem_op < 0) {
767 if (semptr->semval + sopptr->sem_op < 0) {
769 printf("semop: can't do it now\n");
773 semptr->semval += sopptr->sem_op;
774 if (semptr->semval == 0 &&
778 if (sopptr->sem_flg & SEM_UNDO)
780 } else if (sopptr->sem_op == 0) {
781 if (semptr->semval > 0) {
783 printf("semop: not zero now\n");
788 if (semptr->semncnt > 0)
790 semptr->semval += sopptr->sem_op;
791 if (sopptr->sem_flg & SEM_UNDO)
797 * Did we get through the entire vector?
803 * No ... rollback anything that we've already done
806 printf("semop: rollback 0 through %d\n", i-1);
808 for (j = 0; j < i; j++)
809 semaptr->sem_base[sops[j].sem_num].semval -=
813 * If the request that we couldn't satisfy has the
814 * NOWAIT flag set then return with EAGAIN.
816 if (sopptr->sem_flg & IPC_NOWAIT)
819 if (sopptr->sem_op == 0)
825 printf("semop: good night!\n");
827 eval = tsleep((caddr_t)semaptr, (PZERO - 4) | PCATCH,
830 printf("semop: good morning (eval=%d)!\n", eval);
833 suptr = NULL; /* sem_undo may have been reallocated */
838 printf("semop: good morning!\n");
842 * Make sure that the semaphore still exists
844 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
845 semaptr->sem_perm.seq != IPCID_TO_SEQ(uap->semid))
849 * The semaphore is still alive. Readjust the count of
852 if (sopptr->sem_op == 0)
860 * Process any SEM_UNDO requests.
863 for (i = 0; i < nsops; i++) {
865 * We only need to deal with SEM_UNDO's for non-zero
870 if ((sops[i].sem_flg & SEM_UNDO) == 0)
872 adjval = sops[i].sem_op;
875 eval = semundo_adjust(p, &suptr, semid,
876 sops[i].sem_num, -adjval);
881 * Oh-Oh! We ran out of either sem_undo's or undo's.
882 * Rollback the adjustments to this point and then
883 * rollback the semaphore ups and down so we can return
884 * with an error with all structures restored. We
885 * rollback the undo's in the exact reverse order that
886 * we applied them. This guarantees that we won't run
887 * out of space as we roll things back out.
889 for (j = i - 1; j >= 0; j--) {
890 if ((sops[j].sem_flg & SEM_UNDO) == 0)
892 adjval = sops[j].sem_op;
895 if (semundo_adjust(p, &suptr, semid,
896 sops[j].sem_num, adjval) != 0)
897 panic("semop - can't undo undos");
900 for (j = 0; j < nsops; j++)
901 semaptr->sem_base[sops[j].sem_num].semval -=
905 printf("eval = %d from semundo_adjust\n", eval);
908 } /* loop through the sops */
909 } /* if (do_undos) */
911 /* We're definitely done - set the sempid's */
912 for (i = 0; i < nsops; i++) {
914 semptr = &semaptr->sem_base[sopptr->sem_num];
915 semptr->sempid = p->p_pid;
918 /* Do a wakeup if any semaphore was up'd. */
921 printf("semop: doing wakeup\n");
923 wakeup((caddr_t)semaptr);
925 printf("semop: back from wakeup\n");
929 printf("semop: done\n");
936 * Go through the undo structures for this process and apply the adjustments to
943 register struct sem_undo *suptr;
944 register struct sem_undo **supptr;
950 * Go through the chain of undo vectors looking for one
951 * associated with this process.
954 for (supptr = &semu_list; (suptr = *supptr) != NULL;
955 supptr = &suptr->un_next) {
956 if (suptr->un_proc == p)
964 printf("proc @%08x has undo structure with %d entries\n", p,
969 * If there are any active undo elements then process them.
971 if (suptr->un_cnt > 0) {
974 for (ix = 0; ix < suptr->un_cnt; ix++) {
975 int semid = suptr->un_ent[ix].un_id;
976 int semnum = suptr->un_ent[ix].un_num;
977 int adjval = suptr->un_ent[ix].un_adjval;
978 struct semid_ds *semaptr;
980 semaptr = &sema[semid];
981 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0)
982 panic("semexit - semid not allocated");
983 if (semnum >= semaptr->sem_nsems)
984 panic("semexit - semnum out of range");
987 printf("semexit: %08x id=%d num=%d(adj=%d) ; sem=%d\n",
988 suptr->un_proc, suptr->un_ent[ix].un_id,
989 suptr->un_ent[ix].un_num,
990 suptr->un_ent[ix].un_adjval,
991 semaptr->sem_base[semnum].semval);
995 if (semaptr->sem_base[semnum].semval < -adjval)
996 semaptr->sem_base[semnum].semval = 0;
998 semaptr->sem_base[semnum].semval +=
1001 semaptr->sem_base[semnum].semval += adjval;
1003 wakeup((caddr_t)semaptr);
1005 printf("semexit: back from wakeup\n");
1011 * Deallocate the undo vector.
1014 printf("removing vector\n");
1016 suptr->un_proc = NULL;
1017 *supptr = suptr->un_next;