Annotation of sys/compat/ibcs2/ibcs2_ipc.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: ibcs2_ipc.c,v 1.7 2002/03/14 01:26:50 millert Exp $ */
2: /* $NetBSD: ibcs2_ipc.c,v 1.7 1997/01/18 01:51:41 mycroft Exp $ */
3:
4: /*
5: * Copyright (c) 1995 Scott Bartram
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. The name of the author may not be used to endorse or promote products
14: * derived from this software without specific prior written permission
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: */
27: #include <sys/param.h>
28: #include <sys/systm.h>
29: #include <sys/namei.h>
30: #include <sys/proc.h>
31: #include <sys/file.h>
32: #include <sys/stat.h>
33: #include <sys/filedesc.h>
34: #include <sys/ioctl.h>
35: #include <sys/ipc.h>
36: #include <sys/kernel.h>
37: #include <sys/malloc.h>
38: #include <sys/mbuf.h>
39: #include <sys/mman.h>
40: #include <sys/mount.h>
41: #include <sys/reboot.h>
42: #include <sys/resource.h>
43: #include <sys/resourcevar.h>
44: #include <sys/signal.h>
45: #include <sys/signalvar.h>
46: #include <sys/socket.h>
47: #include <sys/time.h>
48: #include <sys/times.h>
49: #include <sys/vnode.h>
50: #include <sys/uio.h>
51: #include <sys/wait.h>
52: #include <sys/utsname.h>
53: #include <sys/unistd.h>
54: #include <sys/msg.h>
55: #include <sys/sem.h>
56: #include <sys/shm.h>
57: #include <sys/syscallargs.h>
58:
59: #include <uvm/uvm_extern.h>
60:
61: #include <compat/ibcs2/ibcs2_types.h>
62: #include <compat/ibcs2/ibcs2_signal.h>
63: #include <compat/ibcs2/ibcs2_syscallargs.h>
64: #include <compat/ibcs2/ibcs2_util.h>
65:
66: #define IBCS2_IPC_RMID 0
67: #define IBCS2_IPC_SET 1
68: #define IBCS2_IPC_STAT 2
69:
70: #ifdef SYSVMSG
71: /*
72: * iBCS2 msgsys call
73: */
74:
75: struct ibcs2_msqid_ds {
76: struct ipc_perm msg_perm;
77: struct msg *msg_first;
78: struct msg *msg_last;
79: u_short msg_cbytes;
80: u_short msg_qnum;
81: u_short msg_qbytes;
82: u_short msg_lspid;
83: u_short msg_lrpid;
84: ibcs2_time_t msg_stime;
85: ibcs2_time_t msg_rtime;
86: ibcs2_time_t msg_ctime;
87: };
88:
89: void cvt_msqid2imsqid(struct msqid_ds *, struct ibcs2_msqid_ds *);
90: void cvt_imsqid2msqid(struct ibcs2_msqid_ds *, struct msqid_ds *);
91:
92: void
93: cvt_msqid2imsqid(bp, ibp)
94: struct msqid_ds *bp;
95: struct ibcs2_msqid_ds *ibp;
96: {
97: ibp->msg_perm = bp->msg_perm;
98: ibp->msg_first = bp->msg_first;
99: ibp->msg_last = bp->msg_last;
100: ibp->msg_cbytes = (u_short)bp->msg_cbytes;
101: ibp->msg_qnum = (u_short)bp->msg_qnum;
102: ibp->msg_qbytes = (u_short)bp->msg_qbytes;
103: ibp->msg_lspid = (u_short)bp->msg_lspid;
104: ibp->msg_lrpid = (u_short)bp->msg_lrpid;
105: ibp->msg_stime = bp->msg_stime;
106: ibp->msg_rtime = bp->msg_rtime;
107: ibp->msg_ctime = bp->msg_ctime;
108: return;
109: }
110:
111: void
112: cvt_imsqid2msqid(ibp, bp)
113: struct ibcs2_msqid_ds *ibp;
114: struct msqid_ds *bp;
115: {
116: bp->msg_perm = ibp->msg_perm;
117: bp->msg_first = ibp->msg_first;
118: bp->msg_last = ibp->msg_last;
119: bp->msg_cbytes = ibp->msg_cbytes;
120: bp->msg_qnum = ibp->msg_qnum;
121: bp->msg_qbytes = ibp->msg_qbytes;
122: bp->msg_lspid = ibp->msg_lspid;
123: bp->msg_lrpid = ibp->msg_lrpid;
124: bp->msg_stime = ibp->msg_stime;
125: bp->msg_rtime = ibp->msg_rtime;
126: bp->msg_ctime = ibp->msg_ctime;
127: return;
128: }
129:
130: int
131: ibcs2_sys_msgsys(p, v, retval)
132: struct proc *p;
133: void *v;
134: register_t *retval;
135: {
136: struct ibcs2_sys_msgsys_args /* {
137: syscallarg(int) which;
138: syscallarg(int) a2;
139: syscallarg(int) a3;
140: syscallarg(int) a4;
141: syscallarg(int) a5;
142: syscallarg(int) a6;
143: } */ *uap = v;
144:
145: switch (SCARG(uap, which)) {
146: case 0: /* msgget */
147: SCARG(uap, which) = 1;
148: return compat_10_sys_msgsys(p, uap, retval);
149: case 1: { /* msgctl */
150: int error;
151: struct compat_10_sys_msgsys_args margs;
152: caddr_t sg = stackgap_init(p->p_emul);
153:
154: SCARG(&margs, which) = 0;
155: SCARG(&margs, a2) = SCARG(uap, a2);
156: SCARG(&margs, a4) =
157: (int)stackgap_alloc(&sg, sizeof(struct msqid_ds));
158: SCARG(&margs, a3) = SCARG(uap, a3);
159: switch (SCARG(&margs, a3)) {
160: case IBCS2_IPC_STAT:
161: error = compat_10_sys_msgsys(p, &margs, retval);
162: if (!error)
163: cvt_msqid2imsqid((struct msqid_ds *)
164: SCARG(&margs, a4),
165: (struct ibcs2_msqid_ds *)SCARG(uap, a4));
166: return error;
167: case IBCS2_IPC_SET:
168: cvt_imsqid2msqid((struct ibcs2_msqid_ds *)SCARG(uap,
169: a4),
170: (struct msqid_ds *) SCARG(&margs, a4));
171: return compat_10_sys_msgsys(p, &margs, retval);
172: case IBCS2_IPC_RMID:
173: return compat_10_sys_msgsys(p, &margs, retval);
174: }
175: return EINVAL;
176: }
177: case 2: /* msgrcv */
178: SCARG(uap, which) = 3;
179: return compat_10_sys_msgsys(p, uap, retval);
180: case 3: /* msgsnd */
181: SCARG(uap, which) = 2;
182: return compat_10_sys_msgsys(p, uap, retval);
183: default:
184: return EINVAL;
185: }
186: }
187: #endif
188:
189:
190: #ifdef SYSVSEM
191: /*
192: * iBCS2 semsys call
193: */
194:
195: struct ibcs2_semid_ds {
196: struct ipc_perm sem_perm;
197: struct ibcs2_sem *sem_base;
198: u_short sem_nsems;
199: int pad1;
200: ibcs2_time_t sem_otime;
201: ibcs2_time_t sem_ctime;
202: };
203:
204: struct ibcs2_sem {
205: u_short semval;
206: ibcs2_pid_t sempid;
207: u_short semncnt;
208: u_short semzcnt;
209: };
210:
211: void cvt_semid2isemid(struct semid_ds *, struct ibcs2_semid_ds *);
212: void cvt_isemid2semid(struct ibcs2_semid_ds *, struct semid_ds *);
213: #ifdef notdef
214: void cvt_sem2isem(struct sem *, struct ibcs2_sem *);
215: void cvt_isem2sem(struct ibcs2_sem *, struct sem *);
216:
217: void
218: cvt_sem2isem(bp, ibp)
219: struct sem *bp;
220: struct ibcs2_sem *ibp;
221: {
222: ibp->semval = bp->semval;
223: ibp->sempid = bp->sempid;
224: ibp->semncnt = bp->semncnt;
225: ibp->semzcnt = bp->semzcnt;
226: return;
227: }
228:
229: void
230: cvt_isem2sem(ibp, bp)
231: struct ibcs2_sem *ibp;
232: struct sem *bp;
233: {
234: bp->semval = ibp->semval;
235: bp->sempid = ibp->sempid;
236: bp->semncnt = ibp->semncnt;
237: bp->semzcnt = ibp->semzcnt;
238: return;
239: }
240: #endif
241:
242: void
243: cvt_semid2isemid(bp, ibp)
244: struct semid_ds *bp;
245: struct ibcs2_semid_ds *ibp;
246: {
247: ibp->sem_perm = bp->sem_perm;
248: ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
249: ibp->sem_nsems = bp->sem_nsems;
250: ibp->sem_otime = bp->sem_otime;
251: ibp->sem_ctime = bp->sem_ctime;
252: return;
253: }
254:
255: void
256: cvt_isemid2semid(ibp, bp)
257: struct ibcs2_semid_ds *ibp;
258: struct semid_ds *bp;
259: {
260: bp->sem_perm = ibp->sem_perm;
261: bp->sem_base = (struct sem *)ibp->sem_base;
262: bp->sem_nsems = ibp->sem_nsems;
263: bp->sem_otime = ibp->sem_otime;
264: bp->sem_ctime = ibp->sem_ctime;
265: return;
266: }
267:
268: int
269: ibcs2_sys_semsys(p, v, retval)
270: struct proc *p;
271: void *v;
272: register_t *retval;
273: {
274: struct ibcs2_sys_semsys_args /* {
275: syscallarg(int) which;
276: syscallarg(int) a2;
277: syscallarg(int) a3;
278: syscallarg(int) a4;
279: syscallarg(int) a5;
280: } */ *uap = v;
281: int error;
282:
283: switch (SCARG(uap, which)) {
284: case 0: /* semctl */
285: switch(SCARG(uap, a4)) {
286: case IBCS2_IPC_STAT:
287: {
288: struct ibcs2_semid_ds *isp;
289: struct semid_ds *sp;
290: caddr_t sg = stackgap_init(p->p_emul);
291:
292: isp = (struct ibcs2_semid_ds *)SCARG(uap, a5);
293: sp = stackgap_alloc(&sg, sizeof(struct semid_ds));
294: SCARG(uap, a5) = (int)sp;
295: error = compat_10_sys_semsys(p, uap, retval);
296: if (!error) {
297: SCARG(uap, a5) = (int)isp;
298: isp = stackgap_alloc(&sg, sizeof(*isp));
299: cvt_semid2isemid(sp, isp);
300: error = copyout((caddr_t)isp,
301: (caddr_t)SCARG(uap, a5),
302: sizeof(*isp));
303: }
304: return error;
305: }
306: case IBCS2_IPC_SET:
307: {
308: struct ibcs2_semid_ds *isp;
309: struct semid_ds *sp;
310: caddr_t sg = stackgap_init(p->p_emul);
311:
312: isp = stackgap_alloc(&sg, sizeof(*isp));
313: sp = stackgap_alloc(&sg, sizeof(*sp));
314: error = copyin((caddr_t)SCARG(uap, a5), (caddr_t)isp,
315: sizeof(*isp));
316: if (error)
317: return error;
318: cvt_isemid2semid(isp, sp);
319: SCARG(uap, a5) = (int)sp;
320: return compat_10_sys_semsys(p, uap, retval);
321: }
322: }
323: return compat_10_sys_semsys(p, uap, retval);
324:
325: case 1: /* semget */
326: return compat_10_sys_semsys(p, uap, retval);
327:
328: case 2: /* semop */
329: return compat_10_sys_semsys(p, uap, retval);
330: }
331: return EINVAL;
332: }
333: #endif
334:
335:
336: #ifdef SYSVSHM
337: /*
338: * iBCS2 shmsys call
339: */
340:
341: struct ibcs2_shmid_ds {
342: struct ipc_perm shm_perm;
343: int shm_segsz;
344: int pad1;
345: char pad2[4];
346: u_short shm_lpid;
347: u_short shm_cpid;
348: u_short shm_nattch;
349: u_short shm_cnattch;
350: ibcs2_time_t shm_atime;
351: ibcs2_time_t shm_dtime;
352: ibcs2_time_t shm_ctime;
353: };
354:
355: void cvt_shmid2ishmid(struct shmid_ds *, struct ibcs2_shmid_ds *);
356: void cvt_ishmid2shmid(struct ibcs2_shmid_ds *, struct shmid_ds *);
357:
358: void
359: cvt_shmid2ishmid(bp, ibp)
360: struct shmid_ds *bp;
361: struct ibcs2_shmid_ds *ibp;
362: {
363: ibp->shm_perm = bp->shm_perm;
364: ibp->shm_segsz = bp->shm_segsz;
365: ibp->shm_lpid = bp->shm_lpid;
366: ibp->shm_cpid = bp->shm_cpid;
367: ibp->shm_nattch = bp->shm_nattch;
368: ibp->shm_cnattch = 0; /* ignored anyway */
369: ibp->shm_atime = bp->shm_atime;
370: ibp->shm_dtime = bp->shm_dtime;
371: ibp->shm_ctime = bp->shm_ctime;
372: return;
373: }
374:
375: void
376: cvt_ishmid2shmid(ibp, bp)
377: struct ibcs2_shmid_ds *ibp;
378: struct shmid_ds *bp;
379: {
380: bp->shm_perm = ibp->shm_perm;
381: bp->shm_segsz = ibp->shm_segsz;
382: bp->shm_lpid = ibp->shm_lpid;
383: bp->shm_cpid = ibp->shm_cpid;
384: bp->shm_nattch = ibp->shm_nattch;
385: bp->shm_atime = ibp->shm_atime;
386: bp->shm_dtime = ibp->shm_dtime;
387: bp->shm_ctime = ibp->shm_ctime;
388: bp->shm_internal = (void *)0; /* ignored anyway */
389: return;
390: }
391:
392: int
393: ibcs2_sys_shmsys(p, v, retval)
394: struct proc *p;
395: void *v;
396: register_t *retval;
397: {
398: struct ibcs2_sys_shmsys_args /* {
399: syscallarg(int) which;
400: syscallarg(int) a2;
401: syscallarg(int) a3;
402: syscallarg(int) a4;
403: } */ *uap = v;
404: int error;
405:
406: switch (SCARG(uap, which)) {
407: case 0: /* shmat */
408: return compat_10_sys_shmsys(p, uap, retval);
409:
410: case 1: /* shmctl */
411: switch(SCARG(uap, a3)) {
412: case IBCS2_IPC_STAT:
413: {
414: struct ibcs2_shmid_ds *isp;
415: struct shmid_ds *sp;
416: caddr_t sg = stackgap_init(p->p_emul);
417:
418: isp = (struct ibcs2_shmid_ds *)SCARG(uap, a4);
419: sp = stackgap_alloc(&sg, sizeof(*sp));
420: SCARG(uap, a4) = (int)sp;
421: error = compat_10_sys_shmsys(p, uap, retval);
422: if (!error) {
423: SCARG(uap, a4) = (int)isp;
424: isp = stackgap_alloc(&sg, sizeof(*isp));
425: cvt_shmid2ishmid(sp, isp);
426: error = copyout((caddr_t)isp,
427: (caddr_t)SCARG(uap, a4),
428: sizeof(*isp));
429: }
430: return error;
431: }
432: case IBCS2_IPC_SET:
433: {
434: struct ibcs2_shmid_ds *isp;
435: struct shmid_ds *sp;
436: caddr_t sg = stackgap_init(p->p_emul);
437:
438: isp = stackgap_alloc(&sg, sizeof(*isp));
439: sp = stackgap_alloc(&sg, sizeof(*sp));
440: error = copyin((caddr_t)SCARG(uap, a4), (caddr_t)isp,
441: sizeof(*isp));
442: if (error)
443: return error;
444: cvt_ishmid2shmid(isp, sp);
445: SCARG(uap, a4) = (int)sp;
446: return compat_10_sys_shmsys(p, uap, retval);
447: }
448: }
449: return compat_10_sys_shmsys(p, uap, retval);
450:
451: case 2: /* shmdt */
452: return compat_10_sys_shmsys(p, uap, retval);
453:
454: case 3: /* shmget */
455: return compat_10_sys_shmsys(p, uap, retval);
456: }
457: return EINVAL;
458: }
459: #endif
CVSweb