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