linux_ipccall.c revision 1.17 1 1.17 drochner /* $NetBSD: linux_ipccall.c,v 1.17 1998/11/22 15:00:47 drochner 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.17 drochner
39 1.17 drochner #include "opt_sysv.h"
40 1.1 fvdl
41 1.1 fvdl #include <sys/types.h>
42 1.1 fvdl #include <sys/param.h>
43 1.1 fvdl #include <sys/shm.h>
44 1.6 fvdl #include <sys/sem.h>
45 1.1 fvdl #include <sys/msg.h>
46 1.1 fvdl #include <sys/proc.h>
47 1.1 fvdl #include <sys/systm.h>
48 1.1 fvdl
49 1.14 erh /* real syscalls */
50 1.1 fvdl #include <sys/mount.h>
51 1.1 fvdl #include <sys/syscallargs.h>
52 1.1 fvdl
53 1.14 erh
54 1.14 erh /* sys_ipc + args prototype */
55 1.15 christos #include <compat/linux/common/linux_types.h>
56 1.15 christos #include <compat/linux/common/linux_signal.h>
57 1.15 christos
58 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
59 1.14 erh #include <compat/linux/linux_syscall.h>
60 1.14 erh
61 1.14 erh /* general ipc defines */
62 1.15 christos #include <compat/linux/common/linux_ipc.h>
63 1.14 erh
64 1.14 erh /* prototypes for real/normal linux-emul syscalls */
65 1.15 christos #include <compat/linux/common/linux_msg.h>
66 1.15 christos #include <compat/linux/common/linux_shm.h>
67 1.15 christos #include <compat/linux/common/linux_sem.h>
68 1.14 erh
69 1.14 erh /* prototypes for sys_ipc stuff */
70 1.15 christos #include <compat/linux/common/linux_ipccall.h>
71 1.15 christos
72 1.1 fvdl
73 1.14 erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
74 1.14 erh /* Not used on: alpha */
75 1.14 erh
76 1.1 fvdl /*
77 1.1 fvdl * Stuff to deal with the SysV ipc/shm/semaphore interface in Linux.
78 1.1 fvdl * The main difference is, that Linux handles it all via one
79 1.1 fvdl * system call, which has the usual maximum amount of 5 arguments.
80 1.1 fvdl * This results in a kludge for calls that take 6 of them.
81 1.1 fvdl *
82 1.14 erh * The SYSV??? options have to be enabled to get the appropriate
83 1.1 fvdl * functions to work.
84 1.1 fvdl */
85 1.1 fvdl
86 1.1 fvdl int
87 1.8 mycroft linux_sys_ipc(p, v, retval)
88 1.1 fvdl struct proc *p;
89 1.7 thorpej void *v;
90 1.7 thorpej register_t *retval;
91 1.7 thorpej {
92 1.8 mycroft struct linux_sys_ipc_args /* {
93 1.1 fvdl syscallarg(int) what;
94 1.1 fvdl syscallarg(int) a1;
95 1.1 fvdl syscallarg(int) a2;
96 1.1 fvdl syscallarg(int) a3;
97 1.1 fvdl syscallarg(caddr_t) ptr;
98 1.7 thorpej } */ *uap = v;
99 1.1 fvdl
100 1.1 fvdl switch (SCARG(uap, what)) {
101 1.1 fvdl #ifdef SYSVSEM
102 1.6 fvdl case LINUX_SYS_semop:
103 1.6 fvdl return linux_semop(p, uap, retval);
104 1.6 fvdl case LINUX_SYS_semget:
105 1.6 fvdl return linux_semget(p, uap, retval);
106 1.14 erh case LINUX_SYS_semctl: {
107 1.14 erh struct linux_sys_semctl_args bsa;
108 1.14 erh union linux_semun arg;
109 1.14 erh int error;
110 1.14 erh
111 1.14 erh SCARG(&bsa, semid) = SCARG(uap, a1);
112 1.14 erh SCARG(&bsa, semnum) = SCARG(uap, a2);
113 1.14 erh SCARG(&bsa, cmd) = SCARG(uap, a3);
114 1.14 erh /* Convert from (union linux_semun *) to (union linux_semun) */
115 1.14 erh if ((error = copyin(SCARG(uap, ptr), &arg, sizeof arg)))
116 1.14 erh return error;
117 1.14 erh SCARG(&bsa, arg) = arg;
118 1.14 erh
119 1.14 erh return linux_sys_semctl(p, &bsa, retval);
120 1.14 erh }
121 1.1 fvdl #endif
122 1.1 fvdl #ifdef SYSVMSG
123 1.6 fvdl case LINUX_SYS_msgsnd:
124 1.6 fvdl return linux_msgsnd(p, uap, retval);
125 1.6 fvdl case LINUX_SYS_msgrcv:
126 1.6 fvdl return linux_msgrcv(p, uap, retval);
127 1.6 fvdl case LINUX_SYS_msgget:
128 1.6 fvdl return linux_msgget(p, uap, retval);
129 1.14 erh case LINUX_SYS_msgctl: {
130 1.14 erh struct linux_sys_msgctl_args bsa;
131 1.14 erh
132 1.14 erh SCARG(&bsa, msqid) = SCARG(uap, a1);
133 1.14 erh SCARG(&bsa, cmd) = SCARG(uap, a2);
134 1.14 erh SCARG(&bsa, buf) = (struct linux_msqid_ds *)SCARG(uap, ptr);
135 1.14 erh
136 1.14 erh return linux_sys_msgctl(p, &bsa, retval);
137 1.14 erh }
138 1.1 fvdl #endif
139 1.1 fvdl #ifdef SYSVSHM
140 1.14 erh case LINUX_SYS_shmat: {
141 1.14 erh struct linux_sys_shmat_args bsa;
142 1.14 erh
143 1.14 erh SCARG(&bsa, shmid) = SCARG(uap, a1);
144 1.14 erh SCARG(&bsa, shmaddr) = (void *)SCARG(uap, ptr);
145 1.14 erh SCARG(&bsa, shmflg) = SCARG(uap, a2);
146 1.14 erh /* XXX passing pointer inside int here */
147 1.14 erh SCARG(&bsa, raddr) = (u_long *)SCARG(uap, a3);
148 1.14 erh
149 1.14 erh return linux_sys_shmat(p, &bsa, retval);
150 1.14 erh }
151 1.6 fvdl case LINUX_SYS_shmdt:
152 1.6 fvdl return linux_shmdt(p, uap, retval);
153 1.6 fvdl case LINUX_SYS_shmget:
154 1.6 fvdl return linux_shmget(p, uap, retval);
155 1.14 erh case LINUX_SYS_shmctl: {
156 1.14 erh struct linux_sys_shmctl_args bsa;
157 1.14 erh
158 1.14 erh SCARG(&bsa, shmid) = SCARG(uap, a1);
159 1.14 erh SCARG(&bsa, cmd) = SCARG(uap, a2);
160 1.14 erh SCARG(&bsa, buf) = (struct linux_shmid_ds *)SCARG(uap, ptr);
161 1.14 erh
162 1.14 erh return linux_sys_shmctl(p, &bsa, retval);
163 1.14 erh }
164 1.1 fvdl #endif
165 1.6 fvdl default:
166 1.6 fvdl return ENOSYS;
167 1.1 fvdl }
168 1.1 fvdl }
169 1.1 fvdl
170 1.1 fvdl #ifdef SYSVSEM
171 1.14 erh inline int
172 1.1 fvdl linux_semop(p, uap, retval)
173 1.1 fvdl struct proc *p;
174 1.8 mycroft struct linux_sys_ipc_args /* {
175 1.1 fvdl syscallarg(int) what;
176 1.1 fvdl syscallarg(int) a1;
177 1.1 fvdl syscallarg(int) a2;
178 1.1 fvdl syscallarg(int) a3;
179 1.1 fvdl syscallarg(caddr_t) ptr;
180 1.1 fvdl } */ *uap;
181 1.1 fvdl register_t *retval;
182 1.1 fvdl {
183 1.8 mycroft struct sys_semop_args bsa;
184 1.6 fvdl
185 1.6 fvdl SCARG(&bsa, semid) = SCARG(uap, a1);
186 1.6 fvdl SCARG(&bsa, sops) = (struct sembuf *)SCARG(uap, ptr);
187 1.6 fvdl SCARG(&bsa, nsops) = SCARG(uap, a2);
188 1.6 fvdl
189 1.8 mycroft return sys_semop(p, &bsa, retval);
190 1.1 fvdl }
191 1.1 fvdl
192 1.14 erh inline int
193 1.1 fvdl linux_semget(p, uap, retval)
194 1.1 fvdl struct proc *p;
195 1.8 mycroft struct linux_sys_ipc_args /* {
196 1.1 fvdl syscallarg(int) what;
197 1.1 fvdl syscallarg(int) a1;
198 1.1 fvdl syscallarg(int) a2;
199 1.1 fvdl syscallarg(int) a3;
200 1.1 fvdl syscallarg(caddr_t) ptr;
201 1.1 fvdl } */ *uap;
202 1.1 fvdl register_t *retval;
203 1.1 fvdl {
204 1.8 mycroft struct sys_semget_args bsa;
205 1.6 fvdl
206 1.6 fvdl SCARG(&bsa, key) = (key_t)SCARG(uap, a1);
207 1.6 fvdl SCARG(&bsa, nsems) = SCARG(uap, a2);
208 1.6 fvdl SCARG(&bsa, semflg) = SCARG(uap, a3);
209 1.6 fvdl
210 1.8 mycroft return sys_semget(p, &bsa, retval);
211 1.1 fvdl }
212 1.1 fvdl
213 1.1 fvdl #endif /* SYSVSEM */
214 1.1 fvdl
215 1.1 fvdl #ifdef SYSVMSG
216 1.6 fvdl
217 1.14 erh inline int
218 1.1 fvdl linux_msgsnd(p, uap, retval)
219 1.1 fvdl struct proc *p;
220 1.8 mycroft struct linux_sys_ipc_args /* {
221 1.1 fvdl syscallarg(int) what;
222 1.1 fvdl syscallarg(int) a1;
223 1.1 fvdl syscallarg(int) a2;
224 1.1 fvdl syscallarg(int) a3;
225 1.1 fvdl syscallarg(caddr_t) ptr;
226 1.1 fvdl } */ *uap;
227 1.1 fvdl register_t *retval;
228 1.1 fvdl {
229 1.8 mycroft struct sys_msgsnd_args bma;
230 1.6 fvdl
231 1.6 fvdl SCARG(&bma, msqid) = SCARG(uap, a1);
232 1.6 fvdl SCARG(&bma, msgp) = SCARG(uap, ptr);
233 1.6 fvdl SCARG(&bma, msgsz) = SCARG(uap, a2);
234 1.6 fvdl SCARG(&bma, msgflg) = SCARG(uap, a3);
235 1.6 fvdl
236 1.8 mycroft return sys_msgsnd(p, &bma, retval);
237 1.1 fvdl }
238 1.1 fvdl
239 1.14 erh inline int
240 1.1 fvdl linux_msgrcv(p, uap, retval)
241 1.1 fvdl struct proc *p;
242 1.8 mycroft struct linux_sys_ipc_args /* {
243 1.1 fvdl syscallarg(int) what;
244 1.1 fvdl syscallarg(int) a1;
245 1.1 fvdl syscallarg(int) a2;
246 1.1 fvdl syscallarg(int) a3;
247 1.1 fvdl syscallarg(caddr_t) ptr;
248 1.1 fvdl } */ *uap;
249 1.1 fvdl register_t *retval;
250 1.1 fvdl {
251 1.8 mycroft struct sys_msgrcv_args bma;
252 1.6 fvdl struct linux_msgrcv_msgarg kluge;
253 1.6 fvdl int error;
254 1.6 fvdl
255 1.6 fvdl if ((error = copyin(SCARG(uap, ptr), &kluge, sizeof kluge)))
256 1.6 fvdl return error;
257 1.6 fvdl
258 1.6 fvdl SCARG(&bma, msqid) = SCARG(uap, a1);
259 1.6 fvdl SCARG(&bma, msgp) = kluge.msg;
260 1.6 fvdl SCARG(&bma, msgsz) = SCARG(uap, a2);
261 1.6 fvdl SCARG(&bma, msgtyp) = kluge.type;
262 1.6 fvdl SCARG(&bma, msgflg) = SCARG(uap, a3);
263 1.8 mycroft
264 1.8 mycroft return sys_msgrcv(p, &bma, retval);
265 1.1 fvdl }
266 1.1 fvdl
267 1.14 erh inline int
268 1.1 fvdl linux_msgget(p, uap, retval)
269 1.1 fvdl struct proc *p;
270 1.8 mycroft struct linux_sys_ipc_args /* {
271 1.1 fvdl syscallarg(int) what;
272 1.1 fvdl syscallarg(int) a1;
273 1.1 fvdl syscallarg(int) a2;
274 1.1 fvdl syscallarg(int) a3;
275 1.1 fvdl syscallarg(caddr_t) ptr;
276 1.1 fvdl } */ *uap;
277 1.1 fvdl register_t *retval;
278 1.1 fvdl {
279 1.8 mycroft struct sys_msgget_args bma;
280 1.6 fvdl
281 1.6 fvdl SCARG(&bma, key) = (key_t)SCARG(uap, a1);
282 1.6 fvdl SCARG(&bma, msgflg) = SCARG(uap, a2);
283 1.8 mycroft
284 1.8 mycroft return sys_msgget(p, &bma, retval);
285 1.1 fvdl }
286 1.1 fvdl
287 1.1 fvdl #endif /* SYSVMSG */
288 1.1 fvdl
289 1.1 fvdl #ifdef SYSVSHM
290 1.1 fvdl /*
291 1.1 fvdl * shmdt(): this could have been mapped directly, if it wasn't for
292 1.1 fvdl * the extra indirection by the linux_ipc system call.
293 1.1 fvdl */
294 1.14 erh inline int
295 1.1 fvdl linux_shmdt(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_shmdt_args bsa;
307 1.1 fvdl
308 1.1 fvdl SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
309 1.8 mycroft
310 1.8 mycroft return sys_shmdt(p, &bsa, retval);
311 1.1 fvdl }
312 1.1 fvdl
313 1.1 fvdl /*
314 1.1 fvdl * Same story as shmdt.
315 1.1 fvdl */
316 1.14 erh inline int
317 1.1 fvdl linux_shmget(p, uap, retval)
318 1.1 fvdl struct proc *p;
319 1.8 mycroft struct linux_sys_ipc_args /* {
320 1.1 fvdl syscallarg(int) what;
321 1.1 fvdl syscallarg(int) a1;
322 1.1 fvdl syscallarg(int) a2;
323 1.1 fvdl syscallarg(int) a3;
324 1.1 fvdl syscallarg(caddr_t) ptr;
325 1.1 fvdl } */ *uap;
326 1.1 fvdl register_t *retval;
327 1.1 fvdl {
328 1.8 mycroft struct sys_shmget_args bsa;
329 1.1 fvdl
330 1.1 fvdl SCARG(&bsa, key) = SCARG(uap, a1);
331 1.1 fvdl SCARG(&bsa, size) = SCARG(uap, a2);
332 1.1 fvdl SCARG(&bsa, shmflg) = SCARG(uap, a3);
333 1.8 mycroft
334 1.8 mycroft return sys_shmget(p, &bsa, retval);
335 1.1 fvdl }
336 1.1 fvdl
337 1.1 fvdl #endif /* SYSVSHM */
338