xref: /netbsd/sys/compat/common/kern_ipc_10.c (revision 6550d01e)
1 /*	$NetBSD: kern_ipc_10.c,v 1.25 2009/01/11 02:45:46 christos 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.25 2009/01/11 02:45:46 christos Exp $");
35 
36 #ifdef _KERNEL_OPT
37 #include "opt_sysv.h"
38 #endif
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/proc.h>
44 #include <sys/sem.h>
45 #include <sys/shm.h>
46 
47 #include <sys/mount.h>
48 #include <sys/syscallargs.h>
49 
50 #include <compat/common/compat_util.h>
51 #include <compat/sys/shm.h>
52 #include <compat/sys/sem.h>
53 
54 #if defined(SYSVSEM) && !defined(_LP64)
55 int
56 compat_10_sys_semsys(struct lwp *l, const struct compat_10_sys_semsys_args *uap, register_t *retval)
57 {
58 	/* {
59 		syscallarg(int) which;
60 		syscallarg(int) a2;
61 		syscallarg(int) a3;
62 		syscallarg(int) a4;
63 		syscallarg(int) a5;
64 	} */
65 	struct sys_semget_args /* {
66 		syscallarg(key_t) key;
67 		syscallarg(int) nsems;
68 		syscallarg(int) semflg;
69 	} */ semget_args;
70 	struct sys_semop_args /* {
71 		syscallarg(int) semid;
72 		syscallarg(struct sembuf *) sops;
73 		syscallarg(u_int) nsops;
74 	} */ semop_args;
75 	struct sys_semconfig_args /* {
76 		syscallarg(int) flag;
77 	} */ semconfig_args;
78 	struct semid_ds sembuf;
79 	struct semid_ds14 osembuf;
80 	void *pass_arg;
81 	int a5 = SCARG(uap, a5);
82 	int error;
83 
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);
93 			if (error != 0)
94 				return error;
95 			__semid_ds14_to_native(&osembuf, &sembuf);
96 		}
97 		error = semctl1(l, semctl_semid, semctl_semnum, semctl_cmd,
98 		    pass_arg, retval);
99 		if (error == 0 && semctl_cmd == IPC_STAT) {
100 			__native_to_semid_ds14(&sembuf, &osembuf);
101 			error = copyout(&osembuf, semctl_arg->buf, sizeof(osembuf));
102 		}
103 		return error;
104 #undef	semctl_semid
105 #undef	semctl_semnum
106 #undef	semctl_cmd
107 #undef	semctl_arg
108 
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));
114 
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));
121 
122 	case 3:						/* semconfig() */
123 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
124 		return (sys_semconfig(l, &semconfig_args, retval));
125 
126 	default:
127 		return (EINVAL);
128 	}
129 }
130 #endif
131 
132 #if defined(SYSVSHM) && !defined(_LP64)
133 int
134 compat_10_sys_shmsys(struct lwp *l, const struct compat_10_sys_shmsys_args *uap, register_t *retval)
135 {
136 	/* {
137 		syscallarg(int) which;
138 		syscallarg(int) a2;
139 		syscallarg(int) a3;
140 		syscallarg(int) a4;
141 	} */
142 	struct sys_shmat_args /* {
143 		syscallarg(int) shmid;
144 		syscallarg(void *) shmaddr;
145 		syscallarg(int) shmflg;
146 	} */ shmat_args;
147 	struct compat_14_sys_shmctl_args /* {
148 		syscallarg(int) shmid;
149 		syscallarg(int) cmd;
150 		syscallarg(struct shmid14_ds *) buf;
151 	} */ shmctl_args;
152 	struct sys_shmdt_args /* {
153 		syscallarg(void *) shmaddr;
154 	} */ shmdt_args;
155 	struct sys_shmget_args /* {
156 		syscallarg(key_t) key;
157 		syscallarg(int) size;
158 		syscallarg(int) shmflg;
159 	} */ shmget_args;
160 
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));
168 
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));
175 
176 	case 2:						/* shmdt() */
177 		SCARG(&shmdt_args, shmaddr) =
178 		    (void *)(u_long)SCARG(uap, a2);
179 		return (sys_shmdt(l, &shmdt_args, retval));
180 
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));
186 
187 	default:
188 		return (EINVAL);
189 	}
190 }
191 #endif
192 
193 #if defined(SYSVMSG) && !defined(_LP64)
194 int
195 compat_10_sys_msgsys(struct lwp *l, const struct compat_10_sys_msgsys_args *uap, register_t *retval)
196 {
197 	/* {
198 		syscallarg(int) which;
199 		syscallarg(int) a2;
200 		syscallarg(int) a3;
201 		syscallarg(int) a4;
202 		syscallarg(int) a5;
203 		syscallarg(int) a6;
204 	} */
205 	struct compat_14_sys_msgctl_args /* {
206 		syscallarg(int) msqid;
207 		syscallarg(int) cmd;
208 		syscallarg(struct msqid14_ds *) buf;
209 	} */ msgctl_args;
210 	struct sys_msgget_args /* {
211 		syscallarg(key_t) key;
212 		syscallarg(int) msgflg;
213 	} */ msgget_args;
214 	struct sys_msgsnd_args /* {
215 		syscallarg(int) msqid;
216 		syscallarg(void *) msgp;
217 		syscallarg(size_t) msgsz;
218 		syscallarg(int) msgflg;
219 	} */ msgsnd_args;
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;
226 	} */ msgrcv_args;
227 
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));
235 
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));
240 
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));
248 
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));
257 
258 	default:
259 		return (EINVAL);
260 	}
261 }
262 #endif
263