xref: /netbsd-src/sys/compat/freebsd/freebsd_ipc.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: freebsd_ipc.c,v 1.16 2009/01/11 02:45:47 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: freebsd_ipc.c,v 1.16 2009/01/11 02:45:47 christos Exp $");
35 
36 #if defined(_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 #include <sys/malloc.h>
47 
48 #include <sys/mount.h>
49 #include <sys/syscallargs.h>
50 
51 #include <compat/sys/shm.h>
52 #include <compat/freebsd/freebsd_syscallargs.h>
53 
54 #ifdef SYSVSEM
55 int
56 freebsd_sys_semsys(struct lwp *l, const struct freebsd_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 compat_14_sys___semctl_args /* {
66 		syscallarg(int) semid;
67 		syscallarg(int) semnum;
68 		syscallarg(int) cmd;
69 		syscallarg(union __semun *) arg;
70 	} */ __semctl_args;
71 	struct sys_semget_args /* {
72 		syscallarg(key_t) key;
73 		syscallarg(int) nsems;
74 		syscallarg(int) semflg;
75 	} */ semget_args;
76 	struct sys_semop_args /* {
77 		syscallarg(int) semid;
78 		syscallarg(struct sembuf *) sops;
79 		syscallarg(u_int) nsops;
80 	} */ semop_args;
81 	struct sys_semconfig_args /* {
82 		syscallarg(int) flag;
83 	} */ semconfig_args;
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) = (union __semun *)SCARG(uap, a5);
91 		return (compat_14_sys___semctl(l, &__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(l, &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(l, &semop_args, retval));
104 
105 	case 3:						/* semconfig() */
106 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
107 		return (sys_semconfig(l, &semconfig_args, retval));
108 
109 	default:
110 		return (EINVAL);
111 	}
112 }
113 #endif
114 
115 #ifdef SYSVSHM
116 int
117 freebsd_sys_shmsys(struct lwp *l, const struct freebsd_sys_shmsys_args *uap, register_t *retval)
118 {
119 	/* {
120 		syscallarg(int) which;
121 		syscallarg(int) a2;
122 		syscallarg(int) a3;
123 		syscallarg(int) a4;
124 	} */
125 	struct sys_shmat_args /* {
126 		syscallarg(int) shmid;
127 		syscallarg(void *) shmaddr;
128 		syscallarg(int) shmflg;
129 	} */ shmat_args;
130 	struct compat_14_sys_shmctl_args /* {
131 		syscallarg(int) shmid;
132 		syscallarg(int) cmd;
133 		syscallarg(struct shmid_ds14 *) buf;
134 	} */ shmctl_args;
135 	struct sys_shmdt_args /* {
136 		syscallarg(void *) shmaddr;
137 	} */ shmdt_args;
138 	struct sys_shmget_args /* {
139 		syscallarg(key_t) key;
140 		syscallarg(int) size;
141 		syscallarg(int) shmflg;
142 	} */ shmget_args;
143 
144 	switch (SCARG(uap, which)) {
145 	case 0:						/* shmat() */
146 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
147 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
148 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
149 		return (sys_shmat(l, &shmat_args, retval));
150 
151 	case 1:						/* oshmctl() */
152 		/* XXX Need to translate shmid_ds format. */
153 		return (EINVAL);
154 
155 	case 2:						/* shmdt() */
156 		SCARG(&shmdt_args, shmaddr) = (void *)SCARG(uap, a2);
157 		return (sys_shmdt(l, &shmdt_args, retval));
158 
159 	case 3:						/* shmget() */
160 		SCARG(&shmget_args, key) = SCARG(uap, a2);
161 		SCARG(&shmget_args, size) = SCARG(uap, a3);
162 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
163 		return (sys_shmget(l, &shmget_args, retval));
164 
165 	case 4:						/* shmctl() */
166 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
167 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
168 		SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
169 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
170 
171 	default:
172 		return (EINVAL);
173 	}
174 }
175 #endif
176 
177 #ifdef SYSVMSG
178 int
179 freebsd_sys_msgsys(struct lwp *l, const struct freebsd_sys_msgsys_args *uap, register_t *retval)
180 {
181 	/* {
182 		syscallarg(int) which;
183 		syscallarg(int) a2;
184 		syscallarg(int) a3;
185 		syscallarg(int) a4;
186 		syscallarg(int) a5;
187 		syscallarg(int) a6;
188 	} */
189 	struct compat_14_sys_msgctl_args /* {
190 		syscallarg(int) msqid;
191 		syscallarg(int) cmd;
192 		syscallarg(struct msqid_ds14 *) buf;
193 	} */ msgctl_args;
194 	struct sys_msgget_args /* {
195 		syscallarg(key_t) key;
196 		syscallarg(int) msgflg;
197 	} */ msgget_args;
198 	struct sys_msgsnd_args /* {
199 		syscallarg(int) msqid;
200 		syscallarg(void *) msgp;
201 		syscallarg(size_t) msgsz;
202 		syscallarg(int) msgflg;
203 	} */ msgsnd_args;
204 	struct sys_msgrcv_args /* {
205 		syscallarg(int) msqid;
206 		syscallarg(void *) msgp;
207 		syscallarg(size_t) msgsz;
208 		syscallarg(long) msgtyp;
209 		syscallarg(int) msgflg;
210 	} */ msgrcv_args;
211 
212 	switch (SCARG(uap, which)) {
213 	case 0:					/* msgctl()*/
214 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
215 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
216 		SCARG(&msgctl_args, buf) =
217 		    (struct msqid_ds14 *)SCARG(uap, a4);
218 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
219 
220 	case 1:					/* msgget() */
221 		SCARG(&msgget_args, key) = SCARG(uap, a2);
222 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
223 		return (sys_msgget(l, &msgget_args, retval));
224 
225 	case 2:					/* msgsnd() */
226 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
227 		SCARG(&msgsnd_args, msgp) = (void *)SCARG(uap, a3);
228 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
229 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
230 		return (sys_msgsnd(l, &msgsnd_args, retval));
231 
232 	case 3:					/* msgrcv() */
233 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
234 		SCARG(&msgrcv_args, msgp) = (void *)SCARG(uap, a3);
235 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
236 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
237 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
238 		return (sys_msgrcv(l, &msgrcv_args, retval));
239 
240 	default:
241 		return (EINVAL);
242 	}
243 }
244 #endif
245