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