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