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