freebsd_ipc.c revision 1.4 1 1.4 tron /* $NetBSD: freebsd_ipc.c,v 1.4 1998/10/19 22:27:38 tron Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*
4 1.3 mycroft * Copyright (c) 1994 Adam Glass and Charles M. Hannum. All rights reserved.
5 1.1 mycroft *
6 1.1 mycroft * Redistribution and use in source and binary forms, with or without
7 1.1 mycroft * modification, are permitted provided that the following conditions
8 1.1 mycroft * are met:
9 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.1 mycroft * notice, this list of conditions and the following disclaimer.
11 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.1 mycroft * documentation and/or other materials provided with the distribution.
14 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.1 mycroft * must display the following acknowledgement:
16 1.3 mycroft * This product includes software developed by Adam Glass and Charles M.
17 1.1 mycroft * Hannum.
18 1.1 mycroft * 4. The names of the authors may not be used to endorse or promote products
19 1.1 mycroft * derived from this software without specific prior written permission.
20 1.1 mycroft *
21 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
22 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 mycroft * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 mycroft */
32 1.4 tron
33 1.4 tron #include "opt_sysv.h"
34 1.1 mycroft
35 1.1 mycroft #include <sys/param.h>
36 1.1 mycroft #include <sys/systm.h>
37 1.1 mycroft #include <sys/kernel.h>
38 1.1 mycroft #include <sys/proc.h>
39 1.1 mycroft #include <sys/sem.h>
40 1.1 mycroft #include <sys/malloc.h>
41 1.1 mycroft
42 1.1 mycroft #include <sys/mount.h>
43 1.1 mycroft #include <sys/syscallargs.h>
44 1.1 mycroft
45 1.1 mycroft #include <vm/vm.h>
46 1.1 mycroft #include <vm/vm_map.h>
47 1.1 mycroft #include <vm/vm_map.h>
48 1.1 mycroft #include <vm/vm_kern.h>
49 1.1 mycroft
50 1.1 mycroft #include <compat/freebsd/freebsd_syscallargs.h>
51 1.1 mycroft
52 1.1 mycroft #ifdef SYSVSEM
53 1.1 mycroft int
54 1.1 mycroft freebsd_sys_semsys(p, v, retval)
55 1.1 mycroft struct proc *p;
56 1.1 mycroft void *v;
57 1.1 mycroft register_t *retval;
58 1.1 mycroft {
59 1.1 mycroft struct freebsd_sys_semsys_args /* {
60 1.1 mycroft syscallarg(int) which;
61 1.1 mycroft syscallarg(int) a2;
62 1.1 mycroft syscallarg(int) a3;
63 1.1 mycroft syscallarg(int) a4;
64 1.1 mycroft syscallarg(int) a5;
65 1.1 mycroft } */ *uap = v;
66 1.1 mycroft struct sys___semctl_args /* {
67 1.1 mycroft syscallarg(int) semid;
68 1.1 mycroft syscallarg(int) semnum;
69 1.1 mycroft syscallarg(int) cmd;
70 1.1 mycroft syscallarg(union semun *) arg;
71 1.1 mycroft } */ __semctl_args;
72 1.1 mycroft struct sys_semget_args /* {
73 1.1 mycroft syscallarg(key_t) key;
74 1.1 mycroft syscallarg(int) nsems;
75 1.1 mycroft syscallarg(int) semflg;
76 1.1 mycroft } */ semget_args;
77 1.1 mycroft struct sys_semop_args /* {
78 1.1 mycroft syscallarg(int) semid;
79 1.1 mycroft syscallarg(struct sembuf *) sops;
80 1.1 mycroft syscallarg(u_int) nsops;
81 1.1 mycroft } */ semop_args;
82 1.1 mycroft struct sys_semconfig_args /* {
83 1.1 mycroft syscallarg(int) flag;
84 1.1 mycroft } */ semconfig_args;
85 1.1 mycroft
86 1.1 mycroft switch (SCARG(uap, which)) {
87 1.1 mycroft case 0: /* __semctl() */
88 1.1 mycroft SCARG(&__semctl_args, semid) = SCARG(uap, a2);
89 1.1 mycroft SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
90 1.1 mycroft SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
91 1.1 mycroft SCARG(&__semctl_args, arg) = (union semun *)SCARG(uap, a5);
92 1.1 mycroft return (sys___semctl(p, &__semctl_args, retval));
93 1.1 mycroft
94 1.1 mycroft case 1: /* semget() */
95 1.1 mycroft SCARG(&semget_args, key) = SCARG(uap, a2);
96 1.1 mycroft SCARG(&semget_args, nsems) = SCARG(uap, a3);
97 1.1 mycroft SCARG(&semget_args, semflg) = SCARG(uap, a4);
98 1.1 mycroft return (sys_semget(p, &semget_args, retval));
99 1.1 mycroft
100 1.1 mycroft case 2: /* semop() */
101 1.1 mycroft SCARG(&semop_args, semid) = SCARG(uap, a2);
102 1.1 mycroft SCARG(&semop_args, sops) = (struct sembuf *)SCARG(uap, a3);
103 1.1 mycroft SCARG(&semop_args, nsops) = SCARG(uap, a4);
104 1.1 mycroft return (sys_semop(p, &semop_args, retval));
105 1.1 mycroft
106 1.1 mycroft case 3: /* semconfig() */
107 1.1 mycroft SCARG(&semconfig_args, flag) = SCARG(uap, a2);
108 1.1 mycroft return (sys_semconfig(p, &semconfig_args, retval));
109 1.1 mycroft
110 1.1 mycroft default:
111 1.1 mycroft return (EINVAL);
112 1.1 mycroft }
113 1.1 mycroft }
114 1.1 mycroft #endif
115 1.1 mycroft
116 1.1 mycroft #ifdef SYSVSHM
117 1.1 mycroft int
118 1.1 mycroft freebsd_sys_shmsys(p, v, retval)
119 1.1 mycroft struct proc *p;
120 1.1 mycroft void *v;
121 1.1 mycroft register_t *retval;
122 1.1 mycroft {
123 1.1 mycroft struct freebsd_sys_shmsys_args /* {
124 1.1 mycroft syscallarg(int) which;
125 1.1 mycroft syscallarg(int) a2;
126 1.1 mycroft syscallarg(int) a3;
127 1.1 mycroft syscallarg(int) a4;
128 1.1 mycroft } */ *uap = v;
129 1.1 mycroft struct sys_shmat_args /* {
130 1.1 mycroft syscallarg(int) shmid;
131 1.1 mycroft syscallarg(void *) shmaddr;
132 1.1 mycroft syscallarg(int) shmflg;
133 1.1 mycroft } */ shmat_args;
134 1.1 mycroft struct sys_shmctl_args /* {
135 1.1 mycroft syscallarg(int) shmid;
136 1.1 mycroft syscallarg(int) cmd;
137 1.1 mycroft syscallarg(struct shmid_ds *) buf;
138 1.1 mycroft } */ shmctl_args;
139 1.1 mycroft struct sys_shmdt_args /* {
140 1.1 mycroft syscallarg(void *) shmaddr;
141 1.1 mycroft } */ shmdt_args;
142 1.1 mycroft struct sys_shmget_args /* {
143 1.1 mycroft syscallarg(key_t) key;
144 1.1 mycroft syscallarg(int) size;
145 1.1 mycroft syscallarg(int) shmflg;
146 1.1 mycroft } */ shmget_args;
147 1.1 mycroft
148 1.1 mycroft switch (SCARG(uap, which)) {
149 1.1 mycroft case 0: /* shmat() */
150 1.1 mycroft SCARG(&shmat_args, shmid) = SCARG(uap, a2);
151 1.1 mycroft SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
152 1.1 mycroft SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
153 1.1 mycroft return (sys_shmat(p, &shmat_args, retval));
154 1.1 mycroft
155 1.1 mycroft case 1: /* oshmctl() */
156 1.1 mycroft /* XXX Need to translate shmid_ds format. */
157 1.1 mycroft return (EINVAL);
158 1.1 mycroft
159 1.1 mycroft case 2: /* shmdt() */
160 1.2 mycroft SCARG(&shmdt_args, shmaddr) = (void *)SCARG(uap, a2);
161 1.1 mycroft return (sys_shmdt(p, &shmdt_args, retval));
162 1.1 mycroft
163 1.1 mycroft case 3: /* shmget() */
164 1.1 mycroft SCARG(&shmget_args, key) = SCARG(uap, a2);
165 1.1 mycroft SCARG(&shmget_args, size) = SCARG(uap, a3);
166 1.1 mycroft SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
167 1.1 mycroft return (sys_shmget(p, &shmget_args, retval));
168 1.1 mycroft
169 1.1 mycroft case 4: /* shmctl() */
170 1.1 mycroft SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
171 1.1 mycroft SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
172 1.1 mycroft SCARG(&shmctl_args, buf) = (struct shmid_ds *)SCARG(uap, a4);
173 1.1 mycroft return (sys_shmctl(p, &shmctl_args, retval));
174 1.1 mycroft
175 1.1 mycroft default:
176 1.1 mycroft return (EINVAL);
177 1.1 mycroft }
178 1.1 mycroft }
179 1.1 mycroft #endif
180 1.1 mycroft
181 1.1 mycroft #ifdef SYSVMSG
182 1.1 mycroft int
183 1.1 mycroft freebsd_sys_msgsys(p, v, retval)
184 1.1 mycroft struct proc *p;
185 1.1 mycroft void *v;
186 1.1 mycroft register_t *retval;
187 1.1 mycroft {
188 1.1 mycroft struct freebsd_sys_msgsys_args /* {
189 1.1 mycroft syscallarg(int) which;
190 1.1 mycroft syscallarg(int) a2;
191 1.1 mycroft syscallarg(int) a3;
192 1.1 mycroft syscallarg(int) a4;
193 1.1 mycroft syscallarg(int) a5;
194 1.1 mycroft syscallarg(int) a6;
195 1.1 mycroft } */ *uap = v;
196 1.1 mycroft struct sys_msgctl_args /* {
197 1.1 mycroft syscallarg(int) msqid;
198 1.1 mycroft syscallarg(int) cmd;
199 1.1 mycroft syscallarg(struct msqid_ds *) buf;
200 1.1 mycroft } */ msgctl_args;
201 1.1 mycroft struct sys_msgget_args /* {
202 1.1 mycroft syscallarg(key_t) key;
203 1.1 mycroft syscallarg(int) msgflg;
204 1.1 mycroft } */ msgget_args;
205 1.1 mycroft struct sys_msgsnd_args /* {
206 1.1 mycroft syscallarg(int) msqid;
207 1.1 mycroft syscallarg(void *) msgp;
208 1.1 mycroft syscallarg(size_t) msgsz;
209 1.1 mycroft syscallarg(int) msgflg;
210 1.1 mycroft } */ msgsnd_args;
211 1.1 mycroft struct sys_msgrcv_args /* {
212 1.1 mycroft syscallarg(int) msqid;
213 1.1 mycroft syscallarg(void *) msgp;
214 1.1 mycroft syscallarg(size_t) msgsz;
215 1.1 mycroft syscallarg(long) msgtyp;
216 1.1 mycroft syscallarg(int) msgflg;
217 1.1 mycroft } */ msgrcv_args;
218 1.1 mycroft
219 1.1 mycroft switch (SCARG(uap, which)) {
220 1.1 mycroft case 0: /* msgctl()*/
221 1.1 mycroft SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
222 1.1 mycroft SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
223 1.1 mycroft SCARG(&msgctl_args, buf) =
224 1.1 mycroft (struct msqid_ds *)SCARG(uap, a4);
225 1.1 mycroft return (sys_msgctl(p, &msgctl_args, retval));
226 1.1 mycroft
227 1.1 mycroft case 1: /* msgget() */
228 1.1 mycroft SCARG(&msgget_args, key) = SCARG(uap, a2);
229 1.1 mycroft SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
230 1.1 mycroft return (sys_msgget(p, &msgget_args, retval));
231 1.1 mycroft
232 1.1 mycroft case 2: /* msgsnd() */
233 1.1 mycroft SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
234 1.1 mycroft SCARG(&msgsnd_args, msgp) = (void *)SCARG(uap, a3);
235 1.1 mycroft SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
236 1.1 mycroft SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
237 1.1 mycroft return (sys_msgsnd(p, &msgsnd_args, retval));
238 1.1 mycroft
239 1.1 mycroft case 3: /* msgrcv() */
240 1.1 mycroft SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
241 1.1 mycroft SCARG(&msgrcv_args, msgp) = (void *)SCARG(uap, a3);
242 1.1 mycroft SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
243 1.1 mycroft SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
244 1.1 mycroft SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
245 1.1 mycroft return (sys_msgrcv(p, &msgrcv_args, retval));
246 1.1 mycroft
247 1.1 mycroft default:
248 1.1 mycroft return (EINVAL);
249 1.1 mycroft }
250 1.1 mycroft }
251 1.1 mycroft #endif
252