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