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