Deleted Added
full compact
sysv_sem.c (10653) sysv_sem.c (11626)
1/* $Id: sysv_sem.c,v 1.8 1995/08/30 00:33:01 bde Exp $ */
1/* $Id: sysv_sem.c,v 1.9 1995/09/09 18:10:07 davidg Exp $ */
2
3/*
4 * Implementation of SVID semaphores
5 *
6 * Author: Daniel Boulet
7 *
8 * This software is provided ``AS IS'' without any warranties of any kind.
9 */
10
11#include <sys/param.h>
12#include <sys/systm.h>
2
3/*
4 * Implementation of SVID semaphores
5 *
6 * Author: Daniel Boulet
7 *
8 * This software is provided ``AS IS'' without any warranties of any kind.
9 */
10
11#include <sys/param.h>
12#include <sys/systm.h>
13#include <sys/sysproto.h>
13#include <sys/kernel.h>
14#include <sys/proc.h>
15#include <sys/sem.h>
14#include <sys/kernel.h>
15#include <sys/proc.h>
16#include <sys/sem.h>
16#include <sys/malloc.h>
17#include <sys/sysent.h>
17
18static void seminit __P((void *));
19SYSINIT(sysv_sem, SI_SUB_SYSV_SEM, SI_ORDER_FIRST, seminit, NULL)
20
18
19static void seminit __P((void *));
20SYSINIT(sysv_sem, SI_SUB_SYSV_SEM, SI_ORDER_FIRST, seminit, NULL)
21
21static int semctl(), semget(), semop(), semconfig();
22int (*semcalls[])() = { semctl, semget, semop, semconfig };
22struct semctl_args;
23static int semctl __P((struct proc *p, struct semctl_args *uap, int *retval));
24struct semget_args;
25static int semget __P((struct proc *p, struct semget_args *uap, int *retval));
26struct semop_args;
27static int semop __P((struct proc *p, struct semop_args *uap, int *retval));
28struct semconfig_args;
29static int semconfig __P((struct proc *p, struct semconfig_args *uap, int *retval));
30
31struct sem_undo *semu_alloc __P((struct proc *p));
32int semundo_adjust __P((struct proc *p, struct sem_undo **supptr, int semid, int semnum, int adjval));
33void semundo_clear __P((int semid, int semnum));
34void semexit __P((struct proc *p));
35
36/* XXX casting to (sy_call_t *) is bogus, as usual. */
37sy_call_t *semcalls[] = {
38 (sy_call_t *)semctl, (sy_call_t *)semget,
39 (sy_call_t *)semop, (sy_call_t *)semconfig
40};
41
23int semtot = 0;
24struct semid_ds *sema; /* semaphore id pool */
25struct sem *sem; /* semaphore pool */
26struct map *semmap; /* semaphore allocation map */
27struct sem_undo *semu_list; /* list of active undo structures */
28int *semu; /* undo structure pool */
29
30static struct proc *semlock_holder = NULL;
31
32void
42int semtot = 0;
43struct semid_ds *sema; /* semaphore id pool */
44struct sem *sem; /* semaphore pool */
45struct map *semmap; /* semaphore allocation map */
46struct sem_undo *semu_list; /* list of active undo structures */
47int *semu; /* undo structure pool */
48
49static struct proc *semlock_holder = NULL;
50
51void
33seminit(udata)
34 void *udata;
52seminit(dummy)
53 void *dummy;
35{
36 register int i;
37
38 if (sema == NULL)
39 panic("sema is NULL");
40 if (semu == NULL)
41 panic("semu is NULL");
42

--- 6 unchanged lines hidden (view full) ---

49 suptr->un_proc = NULL;
50 }
51 semu_list = NULL;
52}
53
54/*
55 * Entry point for all SEM calls
56 */
54{
55 register int i;
56
57 if (sema == NULL)
58 panic("sema is NULL");
59 if (semu == NULL)
60 panic("semu is NULL");
61

--- 6 unchanged lines hidden (view full) ---

68 suptr->un_proc = NULL;
69 }
70 semu_list = NULL;
71}
72
73/*
74 * Entry point for all SEM calls
75 */
57
58struct semsys_args {
59 u_int which;
60};
61
62int
63semsys(p, uap, retval)
64 struct proc *p;
76int
77semsys(p, uap, retval)
78 struct proc *p;
65 struct semsys_args *uap;
79 /* XXX actually varargs. */
80 struct semsys_args /* {
81 u_int which;
82 int a2;
83 int a3;
84 int a4;
85 int a5;
86 } */ *uap;
66 int *retval;
67{
68
69 while (semlock_holder != NULL && semlock_holder != p)
70 (void) tsleep((caddr_t)&semlock_holder, (PZERO - 4), "semsys", 0);
71
72 if (uap->which >= sizeof(semcalls)/sizeof(semcalls[0]))
73 return (EINVAL);
87 int *retval;
88{
89
90 while (semlock_holder != NULL && semlock_holder != p)
91 (void) tsleep((caddr_t)&semlock_holder, (PZERO - 4), "semsys", 0);
92
93 if (uap->which >= sizeof(semcalls)/sizeof(semcalls[0]))
94 return (EINVAL);
74 return ((*semcalls[uap->which])(p, &uap[1], retval));
95 return ((*semcalls[uap->which])(p, &uap->a2, retval));
75}
76
77/*
78 * Lock or unlock the entire semaphore facility.
79 *
80 * This will probably eventually evolve into a general purpose semaphore
81 * facility status enquiry mechanism (I don't like the "read /dev/kmem"
82 * approach currently taken by ipcs and the amount of info that we want

--- 5 unchanged lines hidden (view full) ---

88 * semaphore facility data structures remain static while it fishes around
89 * in /dev/kmem.
90 */
91
92struct semconfig_args {
93 semconfig_ctl_t flag;
94};
95
96}
97
98/*
99 * Lock or unlock the entire semaphore facility.
100 *
101 * This will probably eventually evolve into a general purpose semaphore
102 * facility status enquiry mechanism (I don't like the "read /dev/kmem"
103 * approach currently taken by ipcs and the amount of info that we want

--- 5 unchanged lines hidden (view full) ---

109 * semaphore facility data structures remain static while it fishes around
110 * in /dev/kmem.
111 */
112
113struct semconfig_args {
114 semconfig_ctl_t flag;
115};
116
96int
117static int
97semconfig(p, uap, retval)
98 struct proc *p;
99 struct semconfig_args *uap;
100 int *retval;
101{
102 int eval = 0;
103
104 switch (uap->flag) {

--- 189 unchanged lines hidden (view full) ---

294
295struct semctl_args {
296 int semid;
297 int semnum;
298 int cmd;
299 union semun *arg;
300};
301
118semconfig(p, uap, retval)
119 struct proc *p;
120 struct semconfig_args *uap;
121 int *retval;
122{
123 int eval = 0;
124
125 switch (uap->flag) {

--- 189 unchanged lines hidden (view full) ---

315
316struct semctl_args {
317 int semid;
318 int semnum;
319 int cmd;
320 union semun *arg;
321};
322
302int
323static int
303semctl(p, uap, retval)
304 struct proc *p;
305 register struct semctl_args *uap;
306 int *retval;
307{
308 int semid = uap->semid;
309 int semnum = uap->semnum;
310 int cmd = uap->cmd;

--- 146 unchanged lines hidden (view full) ---

457}
458
459struct semget_args {
460 key_t key;
461 int nsems;
462 int semflg;
463};
464
324semctl(p, uap, retval)
325 struct proc *p;
326 register struct semctl_args *uap;
327 int *retval;
328{
329 int semid = uap->semid;
330 int semnum = uap->semnum;
331 int cmd = uap->cmd;

--- 146 unchanged lines hidden (view full) ---

478}
479
480struct semget_args {
481 key_t key;
482 int nsems;
483 int semflg;
484};
485
465int
486static int
466semget(p, uap, retval)
467 struct proc *p;
468 register struct semget_args *uap;
469 int *retval;
470{
471 int semid, eval;
472 int key = uap->key;
473 int nsems = uap->nsems;

--- 96 unchanged lines hidden (view full) ---

570}
571
572struct semop_args {
573 int semid;
574 struct sembuf *sops;
575 int nsops;
576};
577
487semget(p, uap, retval)
488 struct proc *p;
489 register struct semget_args *uap;
490 int *retval;
491{
492 int semid, eval;
493 int key = uap->key;
494 int nsems = uap->nsems;

--- 96 unchanged lines hidden (view full) ---

591}
592
593struct semop_args {
594 int semid;
595 struct sembuf *sops;
596 int nsops;
597};
598
578int
599static int
579semop(p, uap, retval)
580 struct proc *p;
581 register struct semop_args *uap;
582 int *retval;
583{
584 int semid = uap->semid;
585 int nsops = uap->nsops;
586 struct sembuf sops[MAX_SOPS];

--- 363 unchanged lines hidden ---
600semop(p, uap, retval)
601 struct proc *p;
602 register struct semop_args *uap;
603 int *retval;
604{
605 int semid = uap->semid;
606 int nsops = uap->nsops;
607 struct sembuf sops[MAX_SOPS];

--- 363 unchanged lines hidden ---