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