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