This source file includes following definitions.
- ipc_init
- ipcperms
- sys_ipc
- sys_ipc
- sem_exit
- shm_swap
- shm_no_page
1
2
3
4
5
6 #include <linux/config.h>
7 #include <linux/errno.h>
8 #include <asm/segment.h>
9 #include <linux/sched.h>
10 #include <linux/mm.h>
11 #include <linux/sem.h>
12 #include <linux/msg.h>
13 #include <linux/shm.h>
14 #include <linux/stat.h>
15
16 void ipc_init (void);
17 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth);
18
19 #ifdef CONFIG_SYSVIPC
20
21 int ipcperms (struct ipc_perm *ipcp, short flag);
22 extern void sem_init (void), msg_init (void), shm_init (void);
23 extern int sys_semget (key_t key, int nsems, int semflg);
24 extern int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
25 extern int sys_semctl (int semid, int semnum, int cmd, union semun arg);
26 extern int sys_msgget (key_t key, int msgflg);
27 extern int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg);
28 extern int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
29 int msgflg);
30 extern int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf);
31 extern int sys_shmget (key_t key, int size, int flag);
32 extern int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr);
33 extern int sys_shmdt (char *shmaddr);
34 extern int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf);
35
36 void ipc_init (void)
37 {
38 sem_init();
39 msg_init();
40 shm_init();
41 return;
42 }
43
44
45
46
47
48 int ipcperms (struct ipc_perm *ipcp, short flag)
49 {
50 int requested_mode, granted_mode;
51
52 if (suser())
53 return 0;
54 requested_mode = (flag >> 6) | (flag >> 3) | flag;
55 granted_mode = ipcp->mode;
56 if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
57 granted_mode >>= 6;
58 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
59 granted_mode >>= 3;
60
61 if (requested_mode & ~granted_mode & 0007)
62 return -1;
63 return 0;
64 }
65
66 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
67 {
68 int version;
69
70 version = call >> 16;
71 call &= 0xffff;
72
73 if (call <= SEMCTL)
74 switch (call) {
75 case SEMOP:
76 return sys_semop (first, (struct sembuf *)ptr, second);
77 case SEMGET:
78 return sys_semget (first, second, third);
79 case SEMCTL: {
80 union semun fourth;
81 int err;
82 if (!ptr)
83 return -EINVAL;
84 if ((err = verify_area (VERIFY_READ, ptr, sizeof(long))))
85 return err;
86 fourth.__pad = (void *) get_fs_long(ptr);
87 return sys_semctl (first, second, third, fourth);
88 }
89 default:
90 return -EINVAL;
91 }
92 if (call <= MSGCTL)
93 switch (call) {
94 case MSGSND:
95 return sys_msgsnd (first, (struct msgbuf *) ptr,
96 second, third);
97 case MSGRCV:
98 switch (version) {
99 case 0: {
100 struct ipc_kludge tmp;
101 int err;
102 if (!ptr)
103 return -EINVAL;
104 if ((err = verify_area (VERIFY_READ, ptr, sizeof(tmp))))
105 return err;
106 memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr,
107 sizeof (tmp));
108 return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
109 }
110 case 1: default:
111 return sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
112 }
113 case MSGGET:
114 return sys_msgget ((key_t) first, second);
115 case MSGCTL:
116 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
117 default:
118 return -EINVAL;
119 }
120 if (call <= SHMCTL)
121 switch (call) {
122 case SHMAT:
123 switch (version) {
124 case 0: default: {
125 ulong raddr;
126 int err;
127 if ((err = verify_area(VERIFY_WRITE, (ulong*) third, sizeof(ulong))))
128 return err;
129 err = sys_shmat (first, (char *) ptr, second, &raddr);
130 if (err)
131 return err;
132 put_fs_long (raddr, (ulong *) third);
133 return 0;
134 }
135 case 1:
136 if (get_fs() != get_ds())
137 return -EINVAL;
138 return sys_shmat (first, (char *) ptr, second, (ulong *) third);
139 }
140 case SHMDT:
141 return sys_shmdt ((char *)ptr);
142 case SHMGET:
143 return sys_shmget (first, second, third);
144 case SHMCTL:
145 return sys_shmctl (first, second, (struct shmid_ds *) ptr);
146 default:
147 return -EINVAL;
148 }
149 return -EINVAL;
150 }
151
152 #else
153
154 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
155 {
156 return -ENOSYS;
157 }
158
159 void sem_exit (void)
160 {
161 return;
162 }
163
164 int shm_swap (int prio)
165 {
166 return 0;
167 }
168
169 void shm_no_page (unsigned long *ptent)
170 {
171 return;
172 }
173
174 #endif