linux_ipccall.c revision 1.18 1 1.18 erh /* $NetBSD: linux_ipccall.c,v 1.18 1999/01/03 04:30:56 erh Exp $ */
2 1.14 erh
3 1.14 erh /*-
4 1.14 erh * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.14 erh * All rights reserved.
6 1.14 erh *
7 1.14 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.16 fvdl * by Frank van der Linden and Eric Haszlakiewicz.
9 1.14 erh *
10 1.14 erh * Redistribution and use in source and binary forms, with or without
11 1.14 erh * modification, are permitted provided that the following conditions
12 1.14 erh * are met:
13 1.14 erh * 1. Redistributions of source code must retain the above copyright
14 1.14 erh * notice, this list of conditions and the following disclaimer.
15 1.14 erh * 2. Redistributions in binary form must reproduce the above copyright
16 1.14 erh * notice, this list of conditions and the following disclaimer in the
17 1.14 erh * documentation and/or other materials provided with the distribution.
18 1.14 erh * 3. All advertising materials mentioning features or use of this software
19 1.14 erh * must display the following acknowledgement:
20 1.14 erh * This product includes software developed by the NetBSD
21 1.14 erh * Foundation, Inc. and its contributors.
22 1.14 erh * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.14 erh * contributors may be used to endorse or promote products derived
24 1.14 erh * from this software without specific prior written permission.
25 1.14 erh *
26 1.14 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.14 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.14 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.14 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.14 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.14 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.14 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.14 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.14 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.14 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.14 erh * POSSIBILITY OF SUCH DAMAGE.
37 1.1 fvdl */
38 1.1 fvdl
39 1.1 fvdl #include <sys/types.h>
40 1.1 fvdl #include <sys/param.h>
41 1.1 fvdl #include <sys/shm.h>
42 1.6 fvdl #include <sys/sem.h>
43 1.1 fvdl #include <sys/msg.h>
44 1.1 fvdl #include <sys/proc.h>
45 1.1 fvdl #include <sys/systm.h>
46 1.1 fvdl
47 1.14 erh /* real syscalls */
48 1.1 fvdl #include <sys/mount.h>
49 1.1 fvdl #include <sys/syscallargs.h>
50 1.1 fvdl
51 1.14 erh
52 1.14 erh /* sys_ipc + args prototype */
53 1.15 christos #include <compat/linux/common/linux_types.h>
54 1.15 christos #include <compat/linux/common/linux_signal.h>
55 1.15 christos
56 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
57 1.14 erh #include <compat/linux/linux_syscall.h>
58 1.14 erh
59 1.14 erh /* general ipc defines */
60 1.15 christos #include <compat/linux/common/linux_ipc.h>
61 1.14 erh
62 1.14 erh /* prototypes for real/normal linux-emul syscalls */
63 1.15 christos #include <compat/linux/common/linux_msg.h>
64 1.15 christos #include <compat/linux/common/linux_shm.h>
65 1.15 christos #include <compat/linux/common/linux_sem.h>
66 1.14 erh
67 1.14 erh /* prototypes for sys_ipc stuff */
68 1.15 christos #include <compat/linux/common/linux_ipccall.h>
69 1.15 christos
70 1.1 fvdl
71 1.14 erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
72 1.14 erh /* Not used on: alpha */
73 1.14 erh
74 1.1 fvdl /*
75 1.1 fvdl * Stuff to deal with the SysV ipc/shm/semaphore interface in Linux.
76 1.1 fvdl * The main difference is, that Linux handles it all via one
77 1.1 fvdl * system call, which has the usual maximum amount of 5 arguments.
78 1.1 fvdl * This results in a kludge for calls that take 6 of them.
79 1.1 fvdl *
80 1.14 erh * The SYSV??? options have to be enabled to get the appropriate
81 1.1 fvdl * functions to work.
82 1.1 fvdl */
83 1.1 fvdl
84 1.1 fvdl int
85 1.8 mycroft linux_sys_ipc(p, v, retval)
86 1.1 fvdl struct proc *p;
87 1.7 thorpej void *v;
88 1.7 thorpej register_t *retval;
89 1.7 thorpej {
90 1.8 mycroft struct linux_sys_ipc_args /* {
91 1.1 fvdl syscallarg(int) what;
92 1.1 fvdl syscallarg(int) a1;
93 1.1 fvdl syscallarg(int) a2;
94 1.1 fvdl syscallarg(int) a3;
95 1.1 fvdl syscallarg(caddr_t) ptr;
96 1.7 thorpej } */ *uap = v;
97 1.1 fvdl
98 1.1 fvdl switch (SCARG(uap, what)) {
99 1.1 fvdl #ifdef SYSVSEM
100 1.6 fvdl case LINUX_SYS_semop:
101 1.6 fvdl return linux_semop(p, uap, retval);
102 1.6 fvdl case LINUX_SYS_semget:
103 1.6 fvdl return linux_semget(p, uap, retval);
104 1.14 erh case LINUX_SYS_semctl: {
105 1.14 erh struct linux_sys_semctl_args bsa;
106 1.14 erh union linux_semun arg;
107 1.14 erh int error;
108 1.14 erh
109 1.14 erh SCARG(&bsa, semid) = SCARG(uap, a1);
110 1.14 erh SCARG(&bsa, semnum) = SCARG(uap, a2);
111 1.14 erh SCARG(&bsa, cmd) = SCARG(uap, a3);
112 1.14 erh /* Convert from (union linux_semun *) to (union linux_semun) */
113 1.14 erh if ((error = copyin(SCARG(uap, ptr), &arg, sizeof arg)))
114 1.14 erh return error;
115 1.14 erh SCARG(&bsa, arg) = arg;
116 1.14 erh
117 1.14 erh return linux_sys_semctl(p, &bsa, retval);
118 1.14 erh }
119 1.1 fvdl #endif
120 1.1 fvdl #ifdef SYSVMSG
121 1.6 fvdl case LINUX_SYS_msgsnd:
122 1.6 fvdl return linux_msgsnd(p, uap, retval);
123 1.6 fvdl case LINUX_SYS_msgrcv:
124 1.6 fvdl return linux_msgrcv(p, uap, retval);
125 1.6 fvdl case LINUX_SYS_msgget:
126 1.6 fvdl return linux_msgget(p, uap, retval);
127 1.14 erh case LINUX_SYS_msgctl: {
128 1.14 erh struct linux_sys_msgctl_args bsa;
129 1.14 erh
130 1.14 erh SCARG(&bsa, msqid) = SCARG(uap, a1);
131 1.14 erh SCARG(&bsa, cmd) = SCARG(uap, a2);
132 1.14 erh SCARG(&bsa, buf) = (struct linux_msqid_ds *)SCARG(uap, ptr);
133 1.14 erh
134 1.14 erh return linux_sys_msgctl(p, &bsa, retval);
135 1.14 erh }
136 1.1 fvdl #endif
137 1.1 fvdl #ifdef SYSVSHM
138 1.14 erh case LINUX_SYS_shmat: {
139 1.14 erh struct linux_sys_shmat_args bsa;
140 1.14 erh
141 1.14 erh SCARG(&bsa, shmid) = SCARG(uap, a1);
142 1.14 erh SCARG(&bsa, shmaddr) = (void *)SCARG(uap, ptr);
143 1.14 erh SCARG(&bsa, shmflg) = SCARG(uap, a2);
144 1.14 erh /* XXX passing pointer inside int here */
145 1.14 erh SCARG(&bsa, raddr) = (u_long *)SCARG(uap, a3);
146 1.14 erh
147 1.14 erh return linux_sys_shmat(p, &bsa, retval);
148 1.14 erh }
149 1.6 fvdl case LINUX_SYS_shmdt:
150 1.6 fvdl return linux_shmdt(p, uap, retval);
151 1.6 fvdl case LINUX_SYS_shmget:
152 1.6 fvdl return linux_shmget(p, uap, retval);
153 1.14 erh case LINUX_SYS_shmctl: {
154 1.14 erh struct linux_sys_shmctl_args bsa;
155 1.14 erh
156 1.14 erh SCARG(&bsa, shmid) = SCARG(uap, a1);
157 1.14 erh SCARG(&bsa, cmd) = SCARG(uap, a2);
158 1.14 erh SCARG(&bsa, buf) = (struct linux_shmid_ds *)SCARG(uap, ptr);
159 1.14 erh
160 1.14 erh return linux_sys_shmctl(p, &bsa, retval);
161 1.14 erh }
162 1.1 fvdl #endif
163 1.6 fvdl default:
164 1.6 fvdl return ENOSYS;
165 1.1 fvdl }
166 1.1 fvdl }
167 1.1 fvdl
168 1.1 fvdl #ifdef SYSVSEM
169 1.14 erh inline int
170 1.1 fvdl linux_semop(p, uap, retval)
171 1.1 fvdl struct proc *p;
172 1.8 mycroft struct linux_sys_ipc_args /* {
173 1.1 fvdl syscallarg(int) what;
174 1.1 fvdl syscallarg(int) a1;
175 1.1 fvdl syscallarg(int) a2;
176 1.1 fvdl syscallarg(int) a3;
177 1.1 fvdl syscallarg(caddr_t) ptr;
178 1.1 fvdl } */ *uap;
179 1.1 fvdl register_t *retval;
180 1.1 fvdl {
181 1.8 mycroft struct sys_semop_args bsa;
182 1.6 fvdl
183 1.6 fvdl SCARG(&bsa, semid) = SCARG(uap, a1);
184 1.6 fvdl SCARG(&bsa, sops) = (struct sembuf *)SCARG(uap, ptr);
185 1.6 fvdl SCARG(&bsa, nsops) = SCARG(uap, a2);
186 1.6 fvdl
187 1.8 mycroft return sys_semop(p, &bsa, retval);
188 1.1 fvdl }
189 1.1 fvdl
190 1.14 erh inline int
191 1.1 fvdl linux_semget(p, uap, retval)
192 1.1 fvdl struct proc *p;
193 1.8 mycroft struct linux_sys_ipc_args /* {
194 1.1 fvdl syscallarg(int) what;
195 1.1 fvdl syscallarg(int) a1;
196 1.1 fvdl syscallarg(int) a2;
197 1.1 fvdl syscallarg(int) a3;
198 1.1 fvdl syscallarg(caddr_t) ptr;
199 1.1 fvdl } */ *uap;
200 1.1 fvdl register_t *retval;
201 1.1 fvdl {
202 1.8 mycroft struct sys_semget_args bsa;
203 1.6 fvdl
204 1.6 fvdl SCARG(&bsa, key) = (key_t)SCARG(uap, a1);
205 1.6 fvdl SCARG(&bsa, nsems) = SCARG(uap, a2);
206 1.6 fvdl SCARG(&bsa, semflg) = SCARG(uap, a3);
207 1.6 fvdl
208 1.8 mycroft return sys_semget(p, &bsa, retval);
209 1.1 fvdl }
210 1.1 fvdl
211 1.1 fvdl #endif /* SYSVSEM */
212 1.1 fvdl
213 1.1 fvdl #ifdef SYSVMSG
214 1.6 fvdl
215 1.14 erh inline int
216 1.1 fvdl linux_msgsnd(p, uap, retval)
217 1.1 fvdl struct proc *p;
218 1.8 mycroft struct linux_sys_ipc_args /* {
219 1.1 fvdl syscallarg(int) what;
220 1.1 fvdl syscallarg(int) a1;
221 1.1 fvdl syscallarg(int) a2;
222 1.1 fvdl syscallarg(int) a3;
223 1.1 fvdl syscallarg(caddr_t) ptr;
224 1.1 fvdl } */ *uap;
225 1.1 fvdl register_t *retval;
226 1.1 fvdl {
227 1.8 mycroft struct sys_msgsnd_args bma;
228 1.6 fvdl
229 1.6 fvdl SCARG(&bma, msqid) = SCARG(uap, a1);
230 1.6 fvdl SCARG(&bma, msgp) = SCARG(uap, ptr);
231 1.6 fvdl SCARG(&bma, msgsz) = SCARG(uap, a2);
232 1.6 fvdl SCARG(&bma, msgflg) = SCARG(uap, a3);
233 1.6 fvdl
234 1.8 mycroft return sys_msgsnd(p, &bma, retval);
235 1.1 fvdl }
236 1.1 fvdl
237 1.14 erh inline int
238 1.1 fvdl linux_msgrcv(p, uap, retval)
239 1.1 fvdl struct proc *p;
240 1.8 mycroft struct linux_sys_ipc_args /* {
241 1.1 fvdl syscallarg(int) what;
242 1.1 fvdl syscallarg(int) a1;
243 1.1 fvdl syscallarg(int) a2;
244 1.1 fvdl syscallarg(int) a3;
245 1.1 fvdl syscallarg(caddr_t) ptr;
246 1.1 fvdl } */ *uap;
247 1.1 fvdl register_t *retval;
248 1.1 fvdl {
249 1.8 mycroft struct sys_msgrcv_args bma;
250 1.6 fvdl struct linux_msgrcv_msgarg kluge;
251 1.6 fvdl int error;
252 1.6 fvdl
253 1.6 fvdl if ((error = copyin(SCARG(uap, ptr), &kluge, sizeof kluge)))
254 1.6 fvdl return error;
255 1.6 fvdl
256 1.6 fvdl SCARG(&bma, msqid) = SCARG(uap, a1);
257 1.6 fvdl SCARG(&bma, msgp) = kluge.msg;
258 1.6 fvdl SCARG(&bma, msgsz) = SCARG(uap, a2);
259 1.6 fvdl SCARG(&bma, msgtyp) = kluge.type;
260 1.6 fvdl SCARG(&bma, msgflg) = SCARG(uap, a3);
261 1.8 mycroft
262 1.8 mycroft return sys_msgrcv(p, &bma, retval);
263 1.1 fvdl }
264 1.1 fvdl
265 1.14 erh inline int
266 1.1 fvdl linux_msgget(p, uap, retval)
267 1.1 fvdl struct proc *p;
268 1.8 mycroft struct linux_sys_ipc_args /* {
269 1.1 fvdl syscallarg(int) what;
270 1.1 fvdl syscallarg(int) a1;
271 1.1 fvdl syscallarg(int) a2;
272 1.1 fvdl syscallarg(int) a3;
273 1.1 fvdl syscallarg(caddr_t) ptr;
274 1.1 fvdl } */ *uap;
275 1.1 fvdl register_t *retval;
276 1.1 fvdl {
277 1.8 mycroft struct sys_msgget_args bma;
278 1.6 fvdl
279 1.6 fvdl SCARG(&bma, key) = (key_t)SCARG(uap, a1);
280 1.6 fvdl SCARG(&bma, msgflg) = SCARG(uap, a2);
281 1.8 mycroft
282 1.8 mycroft return sys_msgget(p, &bma, retval);
283 1.1 fvdl }
284 1.1 fvdl
285 1.1 fvdl #endif /* SYSVMSG */
286 1.1 fvdl
287 1.1 fvdl #ifdef SYSVSHM
288 1.1 fvdl /*
289 1.1 fvdl * shmdt(): this could have been mapped directly, if it wasn't for
290 1.1 fvdl * the extra indirection by the linux_ipc system call.
291 1.1 fvdl */
292 1.14 erh inline int
293 1.1 fvdl linux_shmdt(p, uap, retval)
294 1.1 fvdl struct proc *p;
295 1.8 mycroft struct linux_sys_ipc_args /* {
296 1.1 fvdl syscallarg(int) what;
297 1.1 fvdl syscallarg(int) a1;
298 1.1 fvdl syscallarg(int) a2;
299 1.1 fvdl syscallarg(int) a3;
300 1.1 fvdl syscallarg(caddr_t) ptr;
301 1.1 fvdl } */ *uap;
302 1.1 fvdl register_t *retval;
303 1.1 fvdl {
304 1.8 mycroft struct sys_shmdt_args bsa;
305 1.1 fvdl
306 1.1 fvdl SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
307 1.8 mycroft
308 1.8 mycroft return sys_shmdt(p, &bsa, retval);
309 1.1 fvdl }
310 1.1 fvdl
311 1.1 fvdl /*
312 1.1 fvdl * Same story as shmdt.
313 1.1 fvdl */
314 1.14 erh inline int
315 1.1 fvdl linux_shmget(p, uap, retval)
316 1.1 fvdl struct proc *p;
317 1.8 mycroft struct linux_sys_ipc_args /* {
318 1.1 fvdl syscallarg(int) what;
319 1.1 fvdl syscallarg(int) a1;
320 1.1 fvdl syscallarg(int) a2;
321 1.1 fvdl syscallarg(int) a3;
322 1.1 fvdl syscallarg(caddr_t) ptr;
323 1.1 fvdl } */ *uap;
324 1.1 fvdl register_t *retval;
325 1.1 fvdl {
326 1.8 mycroft struct sys_shmget_args bsa;
327 1.1 fvdl
328 1.1 fvdl SCARG(&bsa, key) = SCARG(uap, a1);
329 1.1 fvdl SCARG(&bsa, size) = SCARG(uap, a2);
330 1.1 fvdl SCARG(&bsa, shmflg) = SCARG(uap, a3);
331 1.8 mycroft
332 1.8 mycroft return sys_shmget(p, &bsa, retval);
333 1.1 fvdl }
334 1.1 fvdl
335 1.1 fvdl #endif /* SYSVSHM */
336