freebsd_ipc.c revision 1.5.2.1 1 /* $NetBSD: freebsd_ipc.c,v 1.5.2.1 2000/11/20 18:08:10 bouyer 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/freebsd/freebsd_syscallargs.h>
46
47 #ifdef SYSVSEM
48 int
49 freebsd_sys_semsys(p, v, retval)
50 struct proc *p;
51 void *v;
52 register_t *retval;
53 {
54 struct freebsd_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
81 switch (SCARG(uap, which)) {
82 case 0: /* __semctl() */
83 SCARG(&__semctl_args, semid) = SCARG(uap, a2);
84 SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
85 SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
86 SCARG(&__semctl_args, arg) = (union __semun *)SCARG(uap, a5);
87 return (compat_14_sys___semctl(p, &__semctl_args, retval));
88
89 case 1: /* semget() */
90 SCARG(&semget_args, key) = SCARG(uap, a2);
91 SCARG(&semget_args, nsems) = SCARG(uap, a3);
92 SCARG(&semget_args, semflg) = SCARG(uap, a4);
93 return (sys_semget(p, &semget_args, retval));
94
95 case 2: /* semop() */
96 SCARG(&semop_args, semid) = SCARG(uap, a2);
97 SCARG(&semop_args, sops) = (struct sembuf *)SCARG(uap, a3);
98 SCARG(&semop_args, nsops) = SCARG(uap, a4);
99 return (sys_semop(p, &semop_args, retval));
100
101 case 3: /* semconfig() */
102 SCARG(&semconfig_args, flag) = SCARG(uap, a2);
103 return (sys_semconfig(p, &semconfig_args, retval));
104
105 default:
106 return (EINVAL);
107 }
108 }
109 #endif
110
111 #ifdef SYSVSHM
112 int
113 freebsd_sys_shmsys(p, v, retval)
114 struct proc *p;
115 void *v;
116 register_t *retval;
117 {
118 struct freebsd_sys_shmsys_args /* {
119 syscallarg(int) which;
120 syscallarg(int) a2;
121 syscallarg(int) a3;
122 syscallarg(int) a4;
123 } */ *uap = v;
124 struct sys_shmat_args /* {
125 syscallarg(int) shmid;
126 syscallarg(void *) shmaddr;
127 syscallarg(int) shmflg;
128 } */ shmat_args;
129 struct compat_14_sys_shmctl_args /* {
130 syscallarg(int) shmid;
131 syscallarg(int) cmd;
132 syscallarg(struct shmid_ds14 *) buf;
133 } */ shmctl_args;
134 struct sys_shmdt_args /* {
135 syscallarg(void *) shmaddr;
136 } */ shmdt_args;
137 struct sys_shmget_args /* {
138 syscallarg(key_t) key;
139 syscallarg(int) size;
140 syscallarg(int) shmflg;
141 } */ shmget_args;
142
143 switch (SCARG(uap, which)) {
144 case 0: /* shmat() */
145 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
146 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
147 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
148 return (sys_shmat(p, &shmat_args, retval));
149
150 case 1: /* oshmctl() */
151 /* XXX Need to translate shmid_ds format. */
152 return (EINVAL);
153
154 case 2: /* shmdt() */
155 SCARG(&shmdt_args, shmaddr) = (void *)SCARG(uap, a2);
156 return (sys_shmdt(p, &shmdt_args, retval));
157
158 case 3: /* shmget() */
159 SCARG(&shmget_args, key) = SCARG(uap, a2);
160 SCARG(&shmget_args, size) = SCARG(uap, a3);
161 SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
162 return (sys_shmget(p, &shmget_args, retval));
163
164 case 4: /* shmctl() */
165 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
166 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
167 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
168 return (compat_14_sys_shmctl(p, &shmctl_args, retval));
169
170 default:
171 return (EINVAL);
172 }
173 }
174 #endif
175
176 #ifdef SYSVMSG
177 int
178 freebsd_sys_msgsys(p, v, retval)
179 struct proc *p;
180 void *v;
181 register_t *retval;
182 {
183 struct freebsd_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 msqid_ds14 *) 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