kern_ipc_10.c revision 1.9.2.1 1 /* $NetBSD: kern_ipc_10.c,v 1.9.2.1 2000/11/20 18:08:07 bouyer 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 "opt_sysv.h"
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/proc.h>
39 #include <sys/sem.h>
40 #include <sys/malloc.h>
41
42 #include <sys/mount.h>
43 #include <sys/syscallargs.h>
44
45 #include <compat/common/compat_util.h>
46
47 #ifdef SYSVSEM
48 int
49 compat_10_sys_semsys(p, v, retval)
50 struct proc *p;
51 void *v;
52 register_t *retval;
53 {
54 struct compat_10_sys_semsys_args /* {
55 syscallarg(int) which;
56 syscallarg(int) a2;
57 syscallarg(int) a3;
58 syscallarg(int) a4;
59 syscallarg(int) a5;
60 } */ *uap = v;
61 struct compat_14_sys___semctl_args /* {
62 syscallarg(int) semid;
63 syscallarg(int) semnum;
64 syscallarg(int) cmd;
65 syscallarg(union __semun *) arg;
66 } */ __semctl_args;
67 struct sys_semget_args /* {
68 syscallarg(key_t) key;
69 syscallarg(int) nsems;
70 syscallarg(int) semflg;
71 } */ semget_args;
72 struct sys_semop_args /* {
73 syscallarg(int) semid;
74 syscallarg(struct sembuf *) sops;
75 syscallarg(u_int) nsops;
76 } */ semop_args;
77 struct sys_semconfig_args /* {
78 syscallarg(int) flag;
79 } */ semconfig_args;
80 caddr_t sg = stackgap_init(p->p_emul);
81
82 switch (SCARG(uap, which)) {
83 case 0: /* __semctl() */
84 SCARG(&__semctl_args, semid) = SCARG(uap, a2);
85 SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
86 SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
87 SCARG(&__semctl_args, arg) = stackgap_alloc(&sg,
88 sizeof(union semun *));
89 copyout(&SCARG(uap, a5), SCARG(&__semctl_args, arg),
90 sizeof(union __semun));
91 return (compat_14_sys___semctl(p, &__semctl_args, retval));
92
93 case 1: /* semget() */
94 SCARG(&semget_args, key) = SCARG(uap, a2);
95 SCARG(&semget_args, nsems) = SCARG(uap, a3);
96 SCARG(&semget_args, semflg) = SCARG(uap, a4);
97 return (sys_semget(p, &semget_args, retval));
98
99 case 2: /* semop() */
100 SCARG(&semop_args, semid) = SCARG(uap, a2);
101 SCARG(&semop_args, sops) =
102 (struct sembuf *)(u_long)SCARG(uap, a3);
103 SCARG(&semop_args, nsops) = SCARG(uap, a4);
104 return (sys_semop(p, &semop_args, retval));
105
106 case 3: /* semconfig() */
107 SCARG(&semconfig_args, flag) = SCARG(uap, a2);
108 return (sys_semconfig(p, &semconfig_args, retval));
109
110 default:
111 return (EINVAL);
112 }
113 }
114 #endif
115
116 #ifdef SYSVSHM
117 int
118 compat_10_sys_shmsys(p, v, retval)
119 struct proc *p;
120 void *v;
121 register_t *retval;
122 {
123 struct compat_10_sys_shmsys_args /* {
124 syscallarg(int) which;
125 syscallarg(int) a2;
126 syscallarg(int) a3;
127 syscallarg(int) a4;
128 } */ *uap = v;
129 struct sys_shmat_args /* {
130 syscallarg(int) shmid;
131 syscallarg(void *) shmaddr;
132 syscallarg(int) shmflg;
133 } */ shmat_args;
134 struct compat_14_sys_shmctl_args /* {
135 syscallarg(int) shmid;
136 syscallarg(int) cmd;
137 syscallarg(struct shmid14_ds *) buf;
138 } */ shmctl_args;
139 struct sys_shmdt_args /* {
140 syscallarg(void *) shmaddr;
141 } */ shmdt_args;
142 struct sys_shmget_args /* {
143 syscallarg(key_t) key;
144 syscallarg(int) size;
145 syscallarg(int) shmflg;
146 } */ shmget_args;
147
148 switch (SCARG(uap, which)) {
149 case 0: /* shmat() */
150 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
151 SCARG(&shmat_args, shmaddr) =
152 (void *)(u_long)SCARG(uap, a3);
153 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
154 return (sys_shmat(p, &shmat_args, retval));
155
156 case 1: /* shmctl() */
157 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
158 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
159 SCARG(&shmctl_args, buf) =
160 (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
161 return (compat_14_sys_shmctl(p, &shmctl_args, retval));
162
163 case 2: /* shmdt() */
164 SCARG(&shmdt_args, shmaddr) =
165 (void *)(u_long)SCARG(uap, a2);
166 return (sys_shmdt(p, &shmdt_args, retval));
167
168 case 3: /* shmget() */
169 SCARG(&shmget_args, key) = SCARG(uap, a2);
170 SCARG(&shmget_args, size) = SCARG(uap, a3);
171 SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
172 return (sys_shmget(p, &shmget_args, retval));
173
174 default:
175 return (EINVAL);
176 }
177 }
178 #endif
179
180 #ifdef SYSVMSG
181 int
182 compat_10_sys_msgsys(p, v, retval)
183 struct proc *p;
184 void *v;
185 register_t *retval;
186 {
187 struct compat_10_sys_msgsys_args /* {
188 syscallarg(int) which;
189 syscallarg(int) a2;
190 syscallarg(int) a3;
191 syscallarg(int) a4;
192 syscallarg(int) a5;
193 syscallarg(int) a6;
194 } */ *uap = v;
195 struct compat_14_sys_msgctl_args /* {
196 syscallarg(int) msqid;
197 syscallarg(int) cmd;
198 syscallarg(struct msqid14_ds *) buf;
199 } */ msgctl_args;
200 struct sys_msgget_args /* {
201 syscallarg(key_t) key;
202 syscallarg(int) msgflg;
203 } */ msgget_args;
204 struct sys_msgsnd_args /* {
205 syscallarg(int) msqid;
206 syscallarg(void *) msgp;
207 syscallarg(size_t) msgsz;
208 syscallarg(int) msgflg;
209 } */ msgsnd_args;
210 struct sys_msgrcv_args /* {
211 syscallarg(int) msqid;
212 syscallarg(void *) msgp;
213 syscallarg(size_t) msgsz;
214 syscallarg(long) msgtyp;
215 syscallarg(int) msgflg;
216 } */ msgrcv_args;
217
218 switch (SCARG(uap, which)) {
219 case 0: /* msgctl()*/
220 SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
221 SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
222 SCARG(&msgctl_args, buf) =
223 (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
224 return (compat_14_sys_msgctl(p, &msgctl_args, retval));
225
226 case 1: /* msgget() */
227 SCARG(&msgget_args, key) = SCARG(uap, a2);
228 SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
229 return (sys_msgget(p, &msgget_args, retval));
230
231 case 2: /* msgsnd() */
232 SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
233 SCARG(&msgsnd_args, msgp) =
234 (void *)(u_long)SCARG(uap, a3);
235 SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
236 SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
237 return (sys_msgsnd(p, &msgsnd_args, retval));
238
239 case 3: /* msgrcv() */
240 SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
241 SCARG(&msgrcv_args, msgp) =
242 (void *)(u_long)SCARG(uap, a3);
243 SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
244 SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
245 SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
246 return (sys_msgrcv(p, &msgrcv_args, retval));
247
248 default:
249 return (EINVAL);
250 }
251 }
252 #endif
253