kern_ipc_10.c revision 1.22 1 /* $NetBSD: kern_ipc_10.c,v 1.22 2007/12/08 18:35:54 dsl Exp $ */
2
3 /*
4 * Copyright (c) 1994 Adam Glass and Charles M. Hannum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Adam Glass and Charles M.
17 * Hannum.
18 * 4. The names of the authors may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: kern_ipc_10.c,v 1.22 2007/12/08 18:35:54 dsl Exp $");
35
36 #include "opt_sysv.h"
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/proc.h>
42 #include <sys/sem.h>
43
44 #include <sys/mount.h>
45 #include <sys/syscallargs.h>
46
47 #include <compat/common/compat_util.h>
48 #include <compat/sys/shm.h>
49 #include <compat/sys/sem.h>
50
51 #if defined(SYSVSEM) && !defined(_LP64)
52 int
53 compat_10_sys_semsys(struct lwp *l, void *v, register_t *retval)
54 {
55 struct compat_10_sys_semsys_args /* {
56 syscallarg(int) which;
57 syscallarg(int) a2;
58 syscallarg(int) a3;
59 syscallarg(int) a4;
60 syscallarg(int) a5;
61 } */ *uap = v;
62 struct sys_semget_args /* {
63 syscallarg(key_t) key;
64 syscallarg(int) nsems;
65 syscallarg(int) semflg;
66 } */ semget_args;
67 struct sys_semop_args /* {
68 syscallarg(int) semid;
69 syscallarg(struct sembuf *) sops;
70 syscallarg(u_int) nsops;
71 } */ semop_args;
72 struct sys_semconfig_args /* {
73 syscallarg(int) flag;
74 } */ semconfig_args;
75 struct semid_ds sembuf;
76 struct semid_ds14 osembuf;
77 void *pass_arg;
78 int error;
79
80 switch (SCARG(uap, which)) {
81 case 0: /* __semctl() */
82 #define semctl_semid SCARG(uap, a2)
83 #define semctl_semnum SCARG(uap, a3)
84 #define semctl_cmd SCARG(uap, a4)
85 #define semctl_arg ((union __semun *)&SCARG(uap, a5))
86 pass_arg = get_semctl_arg(semctl_cmd, &sembuf, semctl_arg);
87 if (semctl_cmd == IPC_SET) {
88 error = copyin(semctl_arg->buf, &osembuf, sizeof osembuf);
89 if (error != 0)
90 return error;
91 semid_ds14_to_native(&osembuf, &sembuf);
92 }
93 error = semctl1(l, semctl_semid, semctl_semnum, semctl_cmd,
94 pass_arg, retval);
95 if (error == 0 && semctl_cmd == IPC_STAT) {
96 native_to_semid_ds14(&sembuf, &osembuf);
97 error = copyout(&osembuf, semctl_arg->buf, sizeof(osembuf));
98 }
99 return error;
100 #undef semctl_semid
101 #undef semctl_semnum
102 #undef semctl_cmd
103 #undef semctl_arg
104
105 case 1: /* semget() */
106 SCARG(&semget_args, key) = SCARG(uap, a2);
107 SCARG(&semget_args, nsems) = SCARG(uap, a3);
108 SCARG(&semget_args, semflg) = SCARG(uap, a4);
109 return (sys_semget(l, &semget_args, retval));
110
111 case 2: /* semop() */
112 SCARG(&semop_args, semid) = SCARG(uap, a2);
113 SCARG(&semop_args, sops) =
114 (struct sembuf *)(u_long)SCARG(uap, a3);
115 SCARG(&semop_args, nsops) = SCARG(uap, a4);
116 return (sys_semop(l, &semop_args, retval));
117
118 case 3: /* semconfig() */
119 SCARG(&semconfig_args, flag) = SCARG(uap, a2);
120 return (sys_semconfig(l, &semconfig_args, retval));
121
122 default:
123 return (EINVAL);
124 }
125 }
126 #endif
127
128 #if defined(SYSVSHM) && !defined(_LP64)
129 int
130 compat_10_sys_shmsys(struct lwp *l, void *v, register_t *retval)
131 {
132 struct compat_10_sys_shmsys_args /* {
133 syscallarg(int) which;
134 syscallarg(int) a2;
135 syscallarg(int) a3;
136 syscallarg(int) a4;
137 } */ *uap = v;
138 struct sys_shmat_args /* {
139 syscallarg(int) shmid;
140 syscallarg(void *) shmaddr;
141 syscallarg(int) shmflg;
142 } */ shmat_args;
143 struct compat_14_sys_shmctl_args /* {
144 syscallarg(int) shmid;
145 syscallarg(int) cmd;
146 syscallarg(struct shmid14_ds *) buf;
147 } */ shmctl_args;
148 struct sys_shmdt_args /* {
149 syscallarg(void *) shmaddr;
150 } */ shmdt_args;
151 struct sys_shmget_args /* {
152 syscallarg(key_t) key;
153 syscallarg(int) size;
154 syscallarg(int) shmflg;
155 } */ shmget_args;
156
157 switch (SCARG(uap, which)) {
158 case 0: /* shmat() */
159 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
160 SCARG(&shmat_args, shmaddr) =
161 (void *)(u_long)SCARG(uap, a3);
162 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
163 return (sys_shmat(l, &shmat_args, retval));
164
165 case 1: /* shmctl() */
166 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
167 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
168 SCARG(&shmctl_args, buf) =
169 (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
170 return (compat_14_sys_shmctl(l, &shmctl_args, retval));
171
172 case 2: /* shmdt() */
173 SCARG(&shmdt_args, shmaddr) =
174 (void *)(u_long)SCARG(uap, a2);
175 return (sys_shmdt(l, &shmdt_args, retval));
176
177 case 3: /* shmget() */
178 SCARG(&shmget_args, key) = SCARG(uap, a2);
179 SCARG(&shmget_args, size) = SCARG(uap, a3);
180 SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
181 return (sys_shmget(l, &shmget_args, retval));
182
183 default:
184 return (EINVAL);
185 }
186 }
187 #endif
188
189 #if defined(SYSVMSG) && !defined(_LP64)
190 int
191 compat_10_sys_msgsys(struct lwp *l, void *v, register_t *retval)
192 {
193 struct compat_10_sys_msgsys_args /* {
194 syscallarg(int) which;
195 syscallarg(int) a2;
196 syscallarg(int) a3;
197 syscallarg(int) a4;
198 syscallarg(int) a5;
199 syscallarg(int) a6;
200 } */ *uap = v;
201 struct compat_14_sys_msgctl_args /* {
202 syscallarg(int) msqid;
203 syscallarg(int) cmd;
204 syscallarg(struct msqid14_ds *) buf;
205 } */ msgctl_args;
206 struct sys_msgget_args /* {
207 syscallarg(key_t) key;
208 syscallarg(int) msgflg;
209 } */ msgget_args;
210 struct sys_msgsnd_args /* {
211 syscallarg(int) msqid;
212 syscallarg(void *) msgp;
213 syscallarg(size_t) msgsz;
214 syscallarg(int) msgflg;
215 } */ msgsnd_args;
216 struct sys_msgrcv_args /* {
217 syscallarg(int) msqid;
218 syscallarg(void *) msgp;
219 syscallarg(size_t) msgsz;
220 syscallarg(long) msgtyp;
221 syscallarg(int) msgflg;
222 } */ msgrcv_args;
223
224 switch (SCARG(uap, which)) {
225 case 0: /* msgctl()*/
226 SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
227 SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
228 SCARG(&msgctl_args, buf) =
229 (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
230 return (compat_14_sys_msgctl(l, &msgctl_args, retval));
231
232 case 1: /* msgget() */
233 SCARG(&msgget_args, key) = SCARG(uap, a2);
234 SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
235 return (sys_msgget(l, &msgget_args, retval));
236
237 case 2: /* msgsnd() */
238 SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
239 SCARG(&msgsnd_args, msgp) =
240 (void *)(u_long)SCARG(uap, a3);
241 SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
242 SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
243 return (sys_msgsnd(l, &msgsnd_args, retval));
244
245 case 3: /* msgrcv() */
246 SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
247 SCARG(&msgrcv_args, msgp) =
248 (void *)(u_long)SCARG(uap, a3);
249 SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
250 SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
251 SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
252 return (sys_msgrcv(l, &msgrcv_args, retval));
253
254 default:
255 return (EINVAL);
256 }
257 }
258 #endif
259