1*d91f98a8Spgoyette /* $NetBSD: kern_ipc_10.c,v 1.26 2019/01/27 02:08:39 pgoyette Exp $ */
2dcb2a50bSchristos
3dcb2a50bSchristos /*
46d3d8a13Smycroft * Copyright (c) 1994 Adam Glass and Charles M. Hannum. All rights reserved.
5dcb2a50bSchristos *
6dcb2a50bSchristos * Redistribution and use in source and binary forms, with or without
7dcb2a50bSchristos * modification, are permitted provided that the following conditions
8dcb2a50bSchristos * are met:
9dcb2a50bSchristos * 1. Redistributions of source code must retain the above copyright
10dcb2a50bSchristos * notice, this list of conditions and the following disclaimer.
11dcb2a50bSchristos * 2. Redistributions in binary form must reproduce the above copyright
12dcb2a50bSchristos * notice, this list of conditions and the following disclaimer in the
13dcb2a50bSchristos * documentation and/or other materials provided with the distribution.
14dcb2a50bSchristos * 3. All advertising materials mentioning features or use of this software
15dcb2a50bSchristos * must display the following acknowledgement:
166d3d8a13Smycroft * This product includes software developed by Adam Glass and Charles M.
17dcb2a50bSchristos * Hannum.
18dcb2a50bSchristos * 4. The names of the authors may not be used to endorse or promote products
19dcb2a50bSchristos * derived from this software without specific prior written permission.
20dcb2a50bSchristos *
21dcb2a50bSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
22dcb2a50bSchristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23dcb2a50bSchristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24dcb2a50bSchristos * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25dcb2a50bSchristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26dcb2a50bSchristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27dcb2a50bSchristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28dcb2a50bSchristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29dcb2a50bSchristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30dcb2a50bSchristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31dcb2a50bSchristos */
32dcb2a50bSchristos
33dab6ef8bSlukem #include <sys/cdefs.h>
34*d91f98a8Spgoyette __KERNEL_RCSID(0, "$NetBSD: kern_ipc_10.c,v 1.26 2019/01/27 02:08:39 pgoyette Exp $");
35dab6ef8bSlukem
36c5122072Sad #ifdef _KERNEL_OPT
37*d91f98a8Spgoyette #include "opt_compat_netbsd.h"
38ccb04baaStron #include "opt_sysv.h"
39c5122072Sad #endif
40ccb04baaStron
41dcb2a50bSchristos #include <sys/param.h>
42dcb2a50bSchristos #include <sys/systm.h>
43dcb2a50bSchristos #include <sys/kernel.h>
44dcb2a50bSchristos #include <sys/proc.h>
45dcb2a50bSchristos #include <sys/sem.h>
46461a86f9Schristos #include <sys/shm.h>
47dcb2a50bSchristos
48dcb2a50bSchristos #include <sys/mount.h>
49dcb2a50bSchristos #include <sys/syscallargs.h>
50dcb2a50bSchristos
51498bb953Sscottb #include <compat/common/compat_util.h>
522a4a5534Schristos #include <compat/sys/shm.h>
53353f1bdbSdsl #include <compat/sys/sem.h>
54498bb953Sscottb
55b34d6729Sscw #if defined(SYSVSEM) && !defined(_LP64)
56dcb2a50bSchristos int
compat_10_sys_semsys(struct lwp * l,const struct compat_10_sys_semsys_args * uap,register_t * retval)577e2790cfSdsl compat_10_sys_semsys(struct lwp *l, const struct compat_10_sys_semsys_args *uap, register_t *retval)
587160dfc8Sthorpej {
597e2790cfSdsl /* {
60dcb2a50bSchristos syscallarg(int) which;
61dcb2a50bSchristos syscallarg(int) a2;
62dcb2a50bSchristos syscallarg(int) a3;
63dcb2a50bSchristos syscallarg(int) a4;
64dcb2a50bSchristos syscallarg(int) a5;
657e2790cfSdsl } */
66245f292fSmycroft struct sys_semget_args /* {
67dcb2a50bSchristos syscallarg(key_t) key;
68dcb2a50bSchristos syscallarg(int) nsems;
69dcb2a50bSchristos syscallarg(int) semflg;
70dcb2a50bSchristos } */ semget_args;
71245f292fSmycroft struct sys_semop_args /* {
72dcb2a50bSchristos syscallarg(int) semid;
73dcb2a50bSchristos syscallarg(struct sembuf *) sops;
74dcb2a50bSchristos syscallarg(u_int) nsops;
75dcb2a50bSchristos } */ semop_args;
76245f292fSmycroft struct sys_semconfig_args /* {
77dcb2a50bSchristos syscallarg(int) flag;
78dcb2a50bSchristos } */ semconfig_args;
79353f1bdbSdsl struct semid_ds sembuf;
80353f1bdbSdsl struct semid_ds14 osembuf;
81353f1bdbSdsl void *pass_arg;
827e2790cfSdsl int a5 = SCARG(uap, a5);
83353f1bdbSdsl int error;
84dcb2a50bSchristos
85dcb2a50bSchristos switch (SCARG(uap, which)) {
86dcb2a50bSchristos case 0: /* __semctl() */
87353f1bdbSdsl #define semctl_semid SCARG(uap, a2)
88353f1bdbSdsl #define semctl_semnum SCARG(uap, a3)
89353f1bdbSdsl #define semctl_cmd SCARG(uap, a4)
907e2790cfSdsl #define semctl_arg ((union __semun *)&a5)
91353f1bdbSdsl pass_arg = get_semctl_arg(semctl_cmd, &sembuf, semctl_arg);
92353f1bdbSdsl if (semctl_cmd == IPC_SET) {
93353f1bdbSdsl error = copyin(semctl_arg->buf, &osembuf, sizeof osembuf);
94353f1bdbSdsl if (error != 0)
95353f1bdbSdsl return error;
96461a86f9Schristos __semid_ds14_to_native(&osembuf, &sembuf);
97353f1bdbSdsl }
98353f1bdbSdsl error = semctl1(l, semctl_semid, semctl_semnum, semctl_cmd,
99353f1bdbSdsl pass_arg, retval);
100353f1bdbSdsl if (error == 0 && semctl_cmd == IPC_STAT) {
101461a86f9Schristos __native_to_semid_ds14(&sembuf, &osembuf);
102353f1bdbSdsl error = copyout(&osembuf, semctl_arg->buf, sizeof(osembuf));
103353f1bdbSdsl }
104353f1bdbSdsl return error;
105353f1bdbSdsl #undef semctl_semid
106353f1bdbSdsl #undef semctl_semnum
107353f1bdbSdsl #undef semctl_cmd
108353f1bdbSdsl #undef semctl_arg
109dcb2a50bSchristos
110dcb2a50bSchristos case 1: /* semget() */
111dcb2a50bSchristos SCARG(&semget_args, key) = SCARG(uap, a2);
112dcb2a50bSchristos SCARG(&semget_args, nsems) = SCARG(uap, a3);
113dcb2a50bSchristos SCARG(&semget_args, semflg) = SCARG(uap, a4);
1146762b37eSthorpej return (sys_semget(l, &semget_args, retval));
115dcb2a50bSchristos
116dcb2a50bSchristos case 2: /* semop() */
117dcb2a50bSchristos SCARG(&semop_args, semid) = SCARG(uap, a2);
118705b50bfSmrg SCARG(&semop_args, sops) =
119705b50bfSmrg (struct sembuf *)(u_long)SCARG(uap, a3);
120dcb2a50bSchristos SCARG(&semop_args, nsops) = SCARG(uap, a4);
1216762b37eSthorpej return (sys_semop(l, &semop_args, retval));
122dcb2a50bSchristos
123dcb2a50bSchristos case 3: /* semconfig() */
124dcb2a50bSchristos SCARG(&semconfig_args, flag) = SCARG(uap, a2);
1256762b37eSthorpej return (sys_semconfig(l, &semconfig_args, retval));
126dcb2a50bSchristos
127dcb2a50bSchristos default:
128dcb2a50bSchristos return (EINVAL);
129dcb2a50bSchristos }
130dcb2a50bSchristos }
1316f7dc7fdSmycroft #endif
132dcb2a50bSchristos
133b34d6729Sscw #if defined(SYSVSHM) && !defined(_LP64)
134dcb2a50bSchristos int
compat_10_sys_shmsys(struct lwp * l,const struct compat_10_sys_shmsys_args * uap,register_t * retval)1357e2790cfSdsl compat_10_sys_shmsys(struct lwp *l, const struct compat_10_sys_shmsys_args *uap, register_t *retval)
1367160dfc8Sthorpej {
1377e2790cfSdsl /* {
138dcb2a50bSchristos syscallarg(int) which;
139dcb2a50bSchristos syscallarg(int) a2;
140dcb2a50bSchristos syscallarg(int) a3;
141dcb2a50bSchristos syscallarg(int) a4;
1427e2790cfSdsl } */
143245f292fSmycroft struct sys_shmat_args /* {
144dcb2a50bSchristos syscallarg(int) shmid;
145dcb2a50bSchristos syscallarg(void *) shmaddr;
146dcb2a50bSchristos syscallarg(int) shmflg;
147dcb2a50bSchristos } */ shmat_args;
1489244fc5bSthorpej struct compat_14_sys_shmctl_args /* {
149dcb2a50bSchristos syscallarg(int) shmid;
150dcb2a50bSchristos syscallarg(int) cmd;
1519244fc5bSthorpej syscallarg(struct shmid14_ds *) buf;
152dcb2a50bSchristos } */ shmctl_args;
153245f292fSmycroft struct sys_shmdt_args /* {
154dcb2a50bSchristos syscallarg(void *) shmaddr;
155dcb2a50bSchristos } */ shmdt_args;
156245f292fSmycroft struct sys_shmget_args /* {
157dcb2a50bSchristos syscallarg(key_t) key;
158dcb2a50bSchristos syscallarg(int) size;
159dcb2a50bSchristos syscallarg(int) shmflg;
160dcb2a50bSchristos } */ shmget_args;
161dcb2a50bSchristos
162dcb2a50bSchristos switch (SCARG(uap, which)) {
163dcb2a50bSchristos case 0: /* shmat() */
164dcb2a50bSchristos SCARG(&shmat_args, shmid) = SCARG(uap, a2);
165705b50bfSmrg SCARG(&shmat_args, shmaddr) =
166705b50bfSmrg (void *)(u_long)SCARG(uap, a3);
167dcb2a50bSchristos SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
1686762b37eSthorpej return (sys_shmat(l, &shmat_args, retval));
169dcb2a50bSchristos
170dcb2a50bSchristos case 1: /* shmctl() */
171dcb2a50bSchristos SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
172dcb2a50bSchristos SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
173705b50bfSmrg SCARG(&shmctl_args, buf) =
174705b50bfSmrg (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
1756762b37eSthorpej return (compat_14_sys_shmctl(l, &shmctl_args, retval));
176dcb2a50bSchristos
177dcb2a50bSchristos case 2: /* shmdt() */
178705b50bfSmrg SCARG(&shmdt_args, shmaddr) =
179705b50bfSmrg (void *)(u_long)SCARG(uap, a2);
1806762b37eSthorpej return (sys_shmdt(l, &shmdt_args, retval));
181dcb2a50bSchristos
182dcb2a50bSchristos case 3: /* shmget() */
183dcb2a50bSchristos SCARG(&shmget_args, key) = SCARG(uap, a2);
184dcb2a50bSchristos SCARG(&shmget_args, size) = SCARG(uap, a3);
185dcb2a50bSchristos SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
1866762b37eSthorpej return (sys_shmget(l, &shmget_args, retval));
187dcb2a50bSchristos
188dcb2a50bSchristos default:
189dcb2a50bSchristos return (EINVAL);
190dcb2a50bSchristos }
191dcb2a50bSchristos }
1926f7dc7fdSmycroft #endif
193dcb2a50bSchristos
194b34d6729Sscw #if defined(SYSVMSG) && !defined(_LP64)
195dcb2a50bSchristos int
compat_10_sys_msgsys(struct lwp * l,const struct compat_10_sys_msgsys_args * uap,register_t * retval)1967e2790cfSdsl compat_10_sys_msgsys(struct lwp *l, const struct compat_10_sys_msgsys_args *uap, register_t *retval)
1977160dfc8Sthorpej {
1987e2790cfSdsl /* {
199dcb2a50bSchristos syscallarg(int) which;
200dcb2a50bSchristos syscallarg(int) a2;
201dcb2a50bSchristos syscallarg(int) a3;
202dcb2a50bSchristos syscallarg(int) a4;
203dcb2a50bSchristos syscallarg(int) a5;
204dcb2a50bSchristos syscallarg(int) a6;
2057e2790cfSdsl } */
2069244fc5bSthorpej struct compat_14_sys_msgctl_args /* {
207dcb2a50bSchristos syscallarg(int) msqid;
208dcb2a50bSchristos syscallarg(int) cmd;
2099244fc5bSthorpej syscallarg(struct msqid14_ds *) buf;
210dcb2a50bSchristos } */ msgctl_args;
211245f292fSmycroft struct sys_msgget_args /* {
212dcb2a50bSchristos syscallarg(key_t) key;
213dcb2a50bSchristos syscallarg(int) msgflg;
214dcb2a50bSchristos } */ msgget_args;
215245f292fSmycroft struct sys_msgsnd_args /* {
216dcb2a50bSchristos syscallarg(int) msqid;
217dcb2a50bSchristos syscallarg(void *) msgp;
218dcb2a50bSchristos syscallarg(size_t) msgsz;
219dcb2a50bSchristos syscallarg(int) msgflg;
220dcb2a50bSchristos } */ msgsnd_args;
221245f292fSmycroft struct sys_msgrcv_args /* {
222dcb2a50bSchristos syscallarg(int) msqid;
223dcb2a50bSchristos syscallarg(void *) msgp;
224dcb2a50bSchristos syscallarg(size_t) msgsz;
225dcb2a50bSchristos syscallarg(long) msgtyp;
226dcb2a50bSchristos syscallarg(int) msgflg;
227dcb2a50bSchristos } */ msgrcv_args;
228dcb2a50bSchristos
229dcb2a50bSchristos switch (SCARG(uap, which)) {
230dcb2a50bSchristos case 0: /* msgctl()*/
231dcb2a50bSchristos SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
232dcb2a50bSchristos SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
233dcb2a50bSchristos SCARG(&msgctl_args, buf) =
234705b50bfSmrg (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
2356762b37eSthorpej return (compat_14_sys_msgctl(l, &msgctl_args, retval));
236dcb2a50bSchristos
237dcb2a50bSchristos case 1: /* msgget() */
238dcb2a50bSchristos SCARG(&msgget_args, key) = SCARG(uap, a2);
239dcb2a50bSchristos SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
2406762b37eSthorpej return (sys_msgget(l, &msgget_args, retval));
241dcb2a50bSchristos
242dcb2a50bSchristos case 2: /* msgsnd() */
243dcb2a50bSchristos SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
244705b50bfSmrg SCARG(&msgsnd_args, msgp) =
245705b50bfSmrg (void *)(u_long)SCARG(uap, a3);
246dcb2a50bSchristos SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
247dcb2a50bSchristos SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
2486762b37eSthorpej return (sys_msgsnd(l, &msgsnd_args, retval));
249dcb2a50bSchristos
250dcb2a50bSchristos case 3: /* msgrcv() */
251dcb2a50bSchristos SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
252705b50bfSmrg SCARG(&msgrcv_args, msgp) =
253705b50bfSmrg (void *)(u_long)SCARG(uap, a3);
254dcb2a50bSchristos SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
255dcb2a50bSchristos SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
256dcb2a50bSchristos SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
2576762b37eSthorpej return (sys_msgrcv(l, &msgrcv_args, retval));
258dcb2a50bSchristos
259dcb2a50bSchristos default:
260dcb2a50bSchristos return (EINVAL);
261dcb2a50bSchristos }
262dcb2a50bSchristos }
2636f7dc7fdSmycroft #endif
264