1 /* $NetBSD: kern_ipc_10.c,v 1.23.8.3 2008/11/20 20:45:38 christos Exp $ */
4 * Copyright (c) 1994 Adam Glass and Charles M. Hannum. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: kern_ipc_10.c,v 1.23.8.3 2008/11/20 20:45:38 christos Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
47 #include <sys/mount.h>
48 #include <sys/syscallargs.h>
50 #include <compat/common/compat_util.h>
51 #include <compat/sys/shm.h>
52 #include <compat/sys/sem.h>
54 #if defined(SYSVSEM) && !defined(_LP64)
56 compat_10_sys_semsys(struct lwp
*l
, const struct compat_10_sys_semsys_args
*uap
, register_t
*retval
)
59 syscallarg(int) which;
65 struct sys_semget_args
/* {
66 syscallarg(key_t) key;
67 syscallarg(int) nsems;
68 syscallarg(int) semflg;
70 struct sys_semop_args
/* {
71 syscallarg(int) semid;
72 syscallarg(struct sembuf *) sops;
73 syscallarg(u_int) nsops;
75 struct sys_semconfig_args
/* {
78 struct semid_ds sembuf
;
79 struct semid_ds14 osembuf
;
81 int a5
= SCARG(uap
, a5
);
84 switch (SCARG(uap
, which
)) {
85 case 0: /* __semctl() */
86 #define semctl_semid SCARG(uap, a2)
87 #define semctl_semnum SCARG(uap, a3)
88 #define semctl_cmd SCARG(uap, a4)
89 #define semctl_arg ((union __semun *)&a5)
90 pass_arg
= get_semctl_arg(semctl_cmd
, &sembuf
, semctl_arg
);
91 if (semctl_cmd
== IPC_SET
) {
92 error
= copyin(semctl_arg
->buf
, &osembuf
, sizeof osembuf
);
95 __semid_ds14_to_native(&osembuf
, &sembuf
);
97 error
= semctl1(l
, semctl_semid
, semctl_semnum
, semctl_cmd
,
99 if (error
== 0 && semctl_cmd
== IPC_STAT
) {
100 __native_to_semid_ds14(&sembuf
, &osembuf
);
101 error
= copyout(&osembuf
, semctl_arg
->buf
, sizeof(osembuf
));
109 case 1: /* semget() */
110 SCARG(&semget_args
, key
) = SCARG(uap
, a2
);
111 SCARG(&semget_args
, nsems
) = SCARG(uap
, a3
);
112 SCARG(&semget_args
, semflg
) = SCARG(uap
, a4
);
113 return (sys_semget(l
, &semget_args
, retval
));
115 case 2: /* semop() */
116 SCARG(&semop_args
, semid
) = SCARG(uap
, a2
);
117 SCARG(&semop_args
, sops
) =
118 (struct sembuf
*)(u_long
)SCARG(uap
, a3
);
119 SCARG(&semop_args
, nsops
) = SCARG(uap
, a4
);
120 return (sys_semop(l
, &semop_args
, retval
));
122 case 3: /* semconfig() */
123 SCARG(&semconfig_args
, flag
) = SCARG(uap
, a2
);
124 return (sys_semconfig(l
, &semconfig_args
, retval
));
132 #if defined(SYSVSHM) && !defined(_LP64)
134 compat_10_sys_shmsys(struct lwp
*l
, const struct compat_10_sys_shmsys_args
*uap
, register_t
*retval
)
137 syscallarg(int) which;
142 struct sys_shmat_args
/* {
143 syscallarg(int) shmid;
144 syscallarg(void *) shmaddr;
145 syscallarg(int) shmflg;
147 struct compat_14_sys_shmctl_args
/* {
148 syscallarg(int) shmid;
150 syscallarg(struct shmid14_ds *) buf;
152 struct sys_shmdt_args
/* {
153 syscallarg(void *) shmaddr;
155 struct sys_shmget_args
/* {
156 syscallarg(key_t) key;
157 syscallarg(int) size;
158 syscallarg(int) shmflg;
161 switch (SCARG(uap
, which
)) {
162 case 0: /* shmat() */
163 SCARG(&shmat_args
, shmid
) = SCARG(uap
, a2
);
164 SCARG(&shmat_args
, shmaddr
) =
165 (void *)(u_long
)SCARG(uap
, a3
);
166 SCARG(&shmat_args
, shmflg
) = SCARG(uap
, a4
);
167 return (sys_shmat(l
, &shmat_args
, retval
));
169 case 1: /* shmctl() */
170 SCARG(&shmctl_args
, shmid
) = SCARG(uap
, a2
);
171 SCARG(&shmctl_args
, cmd
) = SCARG(uap
, a3
);
172 SCARG(&shmctl_args
, buf
) =
173 (struct shmid_ds14
*)(u_long
)SCARG(uap
, a4
);
174 return (compat_14_sys_shmctl(l
, &shmctl_args
, retval
));
176 case 2: /* shmdt() */
177 SCARG(&shmdt_args
, shmaddr
) =
178 (void *)(u_long
)SCARG(uap
, a2
);
179 return (sys_shmdt(l
, &shmdt_args
, retval
));
181 case 3: /* shmget() */
182 SCARG(&shmget_args
, key
) = SCARG(uap
, a2
);
183 SCARG(&shmget_args
, size
) = SCARG(uap
, a3
);
184 SCARG(&shmget_args
, shmflg
) = SCARG(uap
, a4
);
185 return (sys_shmget(l
, &shmget_args
, retval
));
193 #if defined(SYSVMSG) && !defined(_LP64)
195 compat_10_sys_msgsys(struct lwp
*l
, const struct compat_10_sys_msgsys_args
*uap
, register_t
*retval
)
198 syscallarg(int) which;
205 struct compat_14_sys_msgctl_args
/* {
206 syscallarg(int) msqid;
208 syscallarg(struct msqid14_ds *) buf;
210 struct sys_msgget_args
/* {
211 syscallarg(key_t) key;
212 syscallarg(int) msgflg;
214 struct sys_msgsnd_args
/* {
215 syscallarg(int) msqid;
216 syscallarg(void *) msgp;
217 syscallarg(size_t) msgsz;
218 syscallarg(int) msgflg;
220 struct sys_msgrcv_args
/* {
221 syscallarg(int) msqid;
222 syscallarg(void *) msgp;
223 syscallarg(size_t) msgsz;
224 syscallarg(long) msgtyp;
225 syscallarg(int) msgflg;
228 switch (SCARG(uap
, which
)) {
229 case 0: /* msgctl()*/
230 SCARG(&msgctl_args
, msqid
) = SCARG(uap
, a2
);
231 SCARG(&msgctl_args
, cmd
) = SCARG(uap
, a3
);
232 SCARG(&msgctl_args
, buf
) =
233 (struct msqid_ds14
*)(u_long
)SCARG(uap
, a4
);
234 return (compat_14_sys_msgctl(l
, &msgctl_args
, retval
));
236 case 1: /* msgget() */
237 SCARG(&msgget_args
, key
) = SCARG(uap
, a2
);
238 SCARG(&msgget_args
, msgflg
) = SCARG(uap
, a3
);
239 return (sys_msgget(l
, &msgget_args
, retval
));
241 case 2: /* msgsnd() */
242 SCARG(&msgsnd_args
, msqid
) = SCARG(uap
, a2
);
243 SCARG(&msgsnd_args
, msgp
) =
244 (void *)(u_long
)SCARG(uap
, a3
);
245 SCARG(&msgsnd_args
, msgsz
) = SCARG(uap
, a4
);
246 SCARG(&msgsnd_args
, msgflg
) = SCARG(uap
, a5
);
247 return (sys_msgsnd(l
, &msgsnd_args
, retval
));
249 case 3: /* msgrcv() */
250 SCARG(&msgrcv_args
, msqid
) = SCARG(uap
, a2
);
251 SCARG(&msgrcv_args
, msgp
) =
252 (void *)(u_long
)SCARG(uap
, a3
);
253 SCARG(&msgrcv_args
, msgsz
) = SCARG(uap
, a4
);
254 SCARG(&msgrcv_args
, msgtyp
) = SCARG(uap
, a5
);
255 SCARG(&msgrcv_args
, msgflg
) = SCARG(uap
, a6
);
256 return (sys_msgrcv(l
, &msgrcv_args
, retval
));