freebsd_ipc.c revision 1.12 1 /* $NetBSD: freebsd_ipc.c,v 1.12 2005/11/10 18:47:53 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.12 2005/11/10 18:47:53 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/malloc.h>
46
47 #include <sys/mount.h>
48 #include <sys/sa.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(l, v, retval)
57 struct lwp *l;
58 void *v;
59 register_t *retval;
60 {
61 struct freebsd_sys_semsys_args /* {
62 syscallarg(int) which;
63 syscallarg(int) a2;
64 syscallarg(int) a3;
65 syscallarg(int) a4;
66 syscallarg(int) a5;
67 } */ *uap = v;
68 struct compat_14_sys___semctl_args /* {
69 syscallarg(int) semid;
70 syscallarg(int) semnum;
71 syscallarg(int) cmd;
72 syscallarg(union __semun *) arg;
73 } */ __semctl_args;
74 struct sys_semget_args /* {
75 syscallarg(key_t) key;
76 syscallarg(int) nsems;
77 syscallarg(int) semflg;
78 } */ semget_args;
79 struct sys_semop_args /* {
80 syscallarg(int) semid;
81 syscallarg(struct sembuf *) sops;
82 syscallarg(u_int) nsops;
83 } */ semop_args;
84 struct sys_semconfig_args /* {
85 syscallarg(int) flag;
86 } */ semconfig_args;
87
88 switch (SCARG(uap, which)) {
89 case 0: /* __semctl() */
90 SCARG(&__semctl_args, semid) = SCARG(uap, a2);
91 SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
92 SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
93 SCARG(&__semctl_args, arg) = (union __semun *)SCARG(uap, a5);
94 return (compat_14_sys___semctl(l, &__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(l, &semget_args, retval));
101
102 case 2: /* semop() */
103 SCARG(&semop_args, semid) = SCARG(uap, a2);
104 SCARG(&semop_args, sops) = (struct sembuf *)SCARG(uap, a3);
105 SCARG(&semop_args, nsops) = SCARG(uap, a4);
106 return (sys_semop(l, &semop_args, retval));
107
108 case 3: /* semconfig() */
109 SCARG(&semconfig_args, flag) = SCARG(uap, a2);
110 return (sys_semconfig(l, &semconfig_args, retval));
111
112 default:
113 return (EINVAL);
114 }
115 }
116 #endif
117
118 #ifdef SYSVSHM
119 int
120 freebsd_sys_shmsys(l, v, retval)
121 struct lwp *l;
122 void *v;
123 register_t *retval;
124 {
125 struct freebsd_sys_shmsys_args /* {
126 syscallarg(int) which;
127 syscallarg(int) a2;
128 syscallarg(int) a3;
129 syscallarg(int) a4;
130 } */ *uap = v;
131 struct sys_shmat_args /* {
132 syscallarg(int) shmid;
133 syscallarg(void *) shmaddr;
134 syscallarg(int) shmflg;
135 } */ shmat_args;
136 struct compat_14_sys_shmctl_args /* {
137 syscallarg(int) shmid;
138 syscallarg(int) cmd;
139 syscallarg(struct shmid_ds14 *) buf;
140 } */ shmctl_args;
141 struct sys_shmdt_args /* {
142 syscallarg(void *) shmaddr;
143 } */ shmdt_args;
144 struct sys_shmget_args /* {
145 syscallarg(key_t) key;
146 syscallarg(int) size;
147 syscallarg(int) shmflg;
148 } */ shmget_args;
149
150 switch (SCARG(uap, which)) {
151 case 0: /* shmat() */
152 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
153 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
154 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
155 return (sys_shmat(l, &shmat_args, retval));
156
157 case 1: /* oshmctl() */
158 /* XXX Need to translate shmid_ds format. */
159 return (EINVAL);
160
161 case 2: /* shmdt() */
162 SCARG(&shmdt_args, shmaddr) = (void *)SCARG(uap, a2);
163 return (sys_shmdt(l, &shmdt_args, retval));
164
165 case 3: /* shmget() */
166 SCARG(&shmget_args, key) = SCARG(uap, a2);
167 SCARG(&shmget_args, size) = SCARG(uap, a3);
168 SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
169 return (sys_shmget(l, &shmget_args, retval));
170
171 case 4: /* shmctl() */
172 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
173 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
174 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
175 return (compat_14_sys_shmctl(l, &shmctl_args, retval));
176
177 default:
178 return (EINVAL);
179 }
180 }
181 #endif
182
183 #ifdef SYSVMSG
184 int
185 freebsd_sys_msgsys(l, v, retval)
186 struct lwp *l;
187 void *v;
188 register_t *retval;
189 {
190 struct freebsd_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 msqid_ds14 *) 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 *)SCARG(uap, a4);
227 return (compat_14_sys_msgctl(l, &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(l, &msgget_args, retval));
233
234 case 2: /* msgsnd() */
235 SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
236 SCARG(&msgsnd_args, msgp) = (void *)SCARG(uap, a3);
237 SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
238 SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
239 return (sys_msgsnd(l, &msgsnd_args, retval));
240
241 case 3: /* msgrcv() */
242 SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
243 SCARG(&msgrcv_args, msgp) = (void *)SCARG(uap, a3);
244 SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
245 SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
246 SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
247 return (sys_msgrcv(l, &msgrcv_args, retval));
248
249 default:
250 return (EINVAL);
251 }
252 }
253 #endif
254