Annotation of sys/compat/svr4/svr4_ipc.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: svr4_ipc.c,v 1.9 2002/03/14 01:26:51 millert Exp $ */
2: /* $NetBSD: svr4_ipc.c,v 1.3 1997/03/30 17:21:02 christos Exp $ */
3:
4: /*
5: * Copyright (c) 1995 Christos Zoulas. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by Christos Zoulas.
18: * 4. The name of the author 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 AUTHOR ``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 AUTHOR 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: * Mostly stolen from: linux_ipc.c,v 1.4 1995/06/24 20:20:22 christos Exp
33: */
34:
35: #include <sys/types.h>
36: #include <sys/param.h>
37: #include <sys/kernel.h>
38: #include <sys/shm.h>
39: #include <sys/msg.h>
40: #include <sys/sem.h>
41: #include <sys/proc.h>
42: #include <sys/uio.h>
43: #include <sys/time.h>
44: #include <sys/malloc.h>
45: #include <sys/mman.h>
46: #include <sys/systm.h>
47: #include <sys/stat.h>
48:
49: #include <sys/mount.h>
50: #include <sys/syscallargs.h>
51:
52: #include <compat/svr4/svr4_types.h>
53: #include <compat/svr4/svr4_signal.h>
54: #include <compat/svr4/svr4_syscallargs.h>
55: #include <compat/svr4/svr4_util.h>
56: #include <compat/svr4/svr4_ipc.h>
57:
58: #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
59: static void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *,
60: struct ipc_perm *);
61: static void bsd_to_svr4_ipc_perm(const struct ipc_perm *,
62: struct svr4_ipc_perm *);
63: #endif
64:
65: #ifdef SYSVSEM
66: static void bsd_to_svr4_semid_ds(const struct semid_ds *,
67: struct svr4_semid_ds *);
68: static void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *,
69: struct semid_ds *);
70: static int svr4_semop(struct proc *, void *, register_t *);
71: static int svr4_semget(struct proc *, void *, register_t *);
72: static int svr4_semctl(struct proc *, void *, register_t *);
73: #endif
74:
75: #ifdef SYSVMSG
76: static void bsd_to_svr4_msqid_ds(const struct msqid_ds *,
77: struct svr4_msqid_ds *);
78: static void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *,
79: struct msqid_ds *);
80: static int svr4_msgsnd(struct proc *, void *, register_t *);
81: static int svr4_msgrcv(struct proc *, void *, register_t *);
82: static int svr4_msgget(struct proc *, void *, register_t *);
83: static int svr4_msgctl(struct proc *, void *, register_t *);
84: #endif
85:
86: #ifdef SYSVSHM
87: static void bsd_to_svr4_shmid_ds(const struct shmid_ds *,
88: struct svr4_shmid_ds *);
89: static void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *,
90: struct shmid_ds *);
91: static int svr4_shmat(struct proc *, void *, register_t *);
92: static int svr4_shmdt(struct proc *, void *, register_t *);
93: static int svr4_shmget(struct proc *, void *, register_t *);
94: static int svr4_shmctl(struct proc *, void *, register_t *);
95: #endif
96:
97: #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
98:
99: static void
100: svr4_to_bsd_ipc_perm(spp, bpp)
101: const struct svr4_ipc_perm *spp;
102: struct ipc_perm *bpp;
103: {
104: bpp->key = spp->key;
105: bpp->uid = spp->uid;
106: bpp->gid = spp->gid;
107: bpp->cuid = spp->cuid;
108: bpp->cgid = spp->cgid;
109: bpp->mode = spp->mode;
110: bpp->seq = spp->seq;
111: }
112:
113: static void
114: bsd_to_svr4_ipc_perm(bpp, spp)
115: const struct ipc_perm *bpp;
116: struct svr4_ipc_perm *spp;
117: {
118: spp->key = bpp->key;
119: spp->uid = bpp->uid;
120: spp->gid = bpp->gid;
121: spp->cuid = bpp->cuid;
122: spp->cgid = bpp->cgid;
123: spp->mode = bpp->mode;
124: spp->seq = bpp->seq;
125: }
126: #endif
127:
128: #ifdef SYSVSEM
129: static void
130: bsd_to_svr4_semid_ds(bds, sds)
131: const struct semid_ds *bds;
132: struct svr4_semid_ds *sds;
133: {
134: bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
135: sds->sem_base = (struct svr4_sem *) bds->sem_base;
136: sds->sem_nsems = bds->sem_nsems;
137: sds->sem_otime = bds->sem_otime;
138: sds->sem_pad1 = bds->sem_pad1;
139: sds->sem_ctime = bds->sem_ctime;
140: sds->sem_pad2 = bds->sem_pad2;
141: }
142:
143: static void
144: svr4_to_bsd_semid_ds(sds, bds)
145: const struct svr4_semid_ds *sds;
146: struct semid_ds *bds;
147: {
148: svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
149: bds->sem_base = (struct sem *) sds->sem_base;
150: bds->sem_nsems = sds->sem_nsems;
151: bds->sem_otime = sds->sem_otime;
152: bds->sem_pad1 = sds->sem_pad1;
153: bds->sem_ctime = sds->sem_ctime;
154: bds->sem_pad2 = sds->sem_pad2;
155: }
156:
157: struct svr4_sys_semctl_args {
158: syscallarg(int) what;
159: syscallarg(int) semid;
160: syscallarg(int) semnum;
161: syscallarg(int) cmd;
162: syscallarg(void *) arg;
163: };
164:
165: static int
166: svr4_semctl(p, v, retval)
167: struct proc *p;
168: void *v;
169: register_t *retval;
170: {
171: int error;
172: struct svr4_sys_semctl_args *uap = v;
173: struct sys___semctl_args ap;
174: struct svr4_semid_ds ss;
175: struct semid_ds bs;
176: caddr_t sg = stackgap_init(p->p_emul);
177:
178: SCARG(&ap, semid) = SCARG(uap, semid);
179: SCARG(&ap, semnum) = SCARG(uap, semnum);
180:
181: switch (SCARG(uap, cmd)) {
182: case SVR4_SEM_GETZCNT:
183: case SVR4_SEM_GETNCNT:
184: case SVR4_SEM_GETPID:
185: case SVR4_SEM_GETVAL:
186: switch (SCARG(uap, cmd)) {
187: case SVR4_SEM_GETZCNT:
188: SCARG(&ap, cmd) = GETZCNT;
189: break;
190: case SVR4_SEM_GETNCNT:
191: SCARG(&ap, cmd) = GETNCNT;
192: break;
193: case SVR4_SEM_GETPID:
194: SCARG(&ap, cmd) = GETPID;
195: break;
196: case SVR4_SEM_GETVAL:
197: SCARG(&ap, cmd) = GETVAL;
198: break;
199: }
200: return sys___semctl(p, &ap, retval);
201:
202: case SVR4_SEM_SETVAL:
203: SCARG(&ap, arg)->val = (int) SCARG(uap, arg);
204: SCARG(&ap, cmd) = SETVAL;
205: return sys___semctl(p, &ap, retval);
206:
207: case SVR4_SEM_GETALL:
208: SCARG(&ap, arg)->array = SCARG(uap, arg);
209: SCARG(&ap, cmd) = GETVAL;
210: return sys___semctl(p, &ap, retval);
211:
212: case SVR4_SEM_SETALL:
213: SCARG(&ap, arg)->array = SCARG(uap, arg);
214: SCARG(&ap, cmd) = SETVAL;
215: return sys___semctl(p, &ap, retval);
216:
217: case SVR4_IPC_STAT:
218: SCARG(&ap, cmd) = IPC_STAT;
219: SCARG(&ap, arg)->buf = stackgap_alloc(&sg, sizeof(bs));
220: if ((error = sys___semctl(p, &ap, retval)) != 0)
221: return error;
222: error = copyin(SCARG(&ap, arg)->buf, &bs, sizeof bs);
223: if (error)
224: return error;
225: bsd_to_svr4_semid_ds(&bs, &ss);
226: return copyout(&ss, SCARG(uap, arg), sizeof ss);
227:
228: case SVR4_IPC_SET:
229: SCARG(&ap, cmd) = IPC_SET;
230: SCARG(&ap, arg)->buf = stackgap_alloc(&sg, sizeof(bs));
231: error = copyin(SCARG(uap, arg), (caddr_t) &ss, sizeof ss);
232: if (error)
233: return error;
234: svr4_to_bsd_semid_ds(&ss, &bs);
235: error = copyout(&bs, SCARG(&ap, arg)->buf, sizeof bs);
236: if (error)
237: return error;
238: return sys___semctl(p, &ap, retval);
239:
240: case SVR4_IPC_RMID:
241: SCARG(&ap, cmd) = IPC_RMID;
242: SCARG(&ap, arg)->buf = stackgap_alloc(&sg, sizeof(bs));
243: error = copyin(SCARG(uap, arg), &ss, sizeof ss);
244: if (error)
245: return error;
246: svr4_to_bsd_semid_ds(&ss, &bs);
247: error = copyout(&bs, SCARG(&ap, arg)->buf, sizeof bs);
248: if (error)
249: return error;
250: return sys___semctl(p, &ap, retval);
251:
252: default:
253: return EINVAL;
254: }
255: }
256:
257: struct svr4_sys_semget_args {
258: syscallarg(int) what;
259: syscallarg(svr4_key_t) key;
260: syscallarg(int) nsems;
261: syscallarg(int) semflg;
262: };
263:
264: static int
265: svr4_semget(p, v, retval)
266: struct proc *p;
267: void *v;
268: register_t *retval;
269: {
270: struct svr4_sys_semget_args *uap = v;
271: struct sys_semget_args ap;
272:
273: SCARG(&ap, key) = SCARG(uap, key);
274: SCARG(&ap, nsems) = SCARG(uap, nsems);
275: SCARG(&ap, semflg) = SCARG(uap, semflg);
276:
277: return sys_semget(p, &ap, retval);
278: }
279:
280: struct svr4_sys_semop_args {
281: syscallarg(int) what;
282: syscallarg(int) semid;
283: syscallarg(struct svr4_sembuf *) sops;
284: syscallarg(u_int) nsops;
285: };
286:
287: static int
288: svr4_semop(p, v, retval)
289: struct proc *p;
290: void *v;
291: register_t *retval;
292: {
293: struct svr4_sys_semop_args *uap = v;
294: struct sys_semop_args ap;
295:
296: SCARG(&ap, semid) = SCARG(uap, semid);
297: /* These are the same */
298: SCARG(&ap, sops) = (struct sembuf *) SCARG(uap, sops);
299: SCARG(&ap, nsops) = SCARG(uap, nsops);
300:
301: return sys_semop(p, &ap, retval);
302: }
303:
304: int
305: svr4_sys_semsys(p, v, retval)
306: struct proc *p;
307: void *v;
308: register_t *retval;
309: {
310: struct svr4_sys_semsys_args *uap = v;
311:
312: DPRINTF(("svr4_semsys(%d)\n", SCARG(uap, what)));
313:
314: switch (SCARG(uap, what)) {
315: case SVR4_semctl:
316: return svr4_semctl(p, v, retval);
317: case SVR4_semget:
318: return svr4_semget(p, v, retval);
319: case SVR4_semop:
320: return svr4_semop(p, v, retval);
321: default:
322: return EINVAL;
323: }
324: }
325: #endif
326:
327: #ifdef SYSVMSG
328: static void
329: bsd_to_svr4_msqid_ds(bds, sds)
330: const struct msqid_ds *bds;
331: struct svr4_msqid_ds *sds;
332: {
333: bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
334: sds->msg_first = (struct svr4_msg *) bds->msg_first;
335: sds->msg_last = (struct svr4_msg *) bds->msg_last;
336: sds->msg_cbytes = bds->msg_cbytes;
337: sds->msg_qnum = bds->msg_qnum;
338: sds->msg_qbytes = bds->msg_qbytes;
339: sds->msg_lspid = bds->msg_lspid;
340: sds->msg_lrpid = bds->msg_lrpid;
341: sds->msg_stime = bds->msg_stime;
342: sds->msg_pad1 = bds->msg_pad1;
343: sds->msg_rtime = bds->msg_rtime;
344: sds->msg_pad2 = bds->msg_pad2;
345: sds->msg_ctime = bds->msg_ctime;
346: sds->msg_pad3 = bds->msg_pad3;
347:
348: /* use the padding for the rest of the fields */
349: {
350: const short *pad = (const short *) bds->msg_pad4;
351: sds->msg_cv = pad[0];
352: sds->msg_qnum_cv = pad[1];
353: }
354: }
355:
356: static void
357: svr4_to_bsd_msqid_ds(sds, bds)
358: const struct svr4_msqid_ds *sds;
359: struct msqid_ds *bds;
360: {
361: svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
362: bds->msg_first = (struct msg *) sds->msg_first;
363: bds->msg_last = (struct msg *) sds->msg_last;
364: bds->msg_cbytes = sds->msg_cbytes;
365: bds->msg_qnum = sds->msg_qnum;
366: bds->msg_qbytes = sds->msg_qbytes;
367: bds->msg_lspid = sds->msg_lspid;
368: bds->msg_lrpid = sds->msg_lrpid;
369: bds->msg_stime = sds->msg_stime;
370: bds->msg_pad1 = sds->msg_pad1;
371: bds->msg_rtime = sds->msg_rtime;
372: bds->msg_pad2 = sds->msg_pad2;
373: bds->msg_ctime = sds->msg_ctime;
374: bds->msg_pad3 = sds->msg_pad3;
375:
376: /* use the padding for the rest of the fields */
377: {
378: short *pad = (short *) bds->msg_pad4;
379: pad[0] = sds->msg_cv;
380: pad[1] = sds->msg_qnum_cv;
381: }
382: }
383:
384: struct svr4_sys_msgsnd_args {
385: syscallarg(int) what;
386: syscallarg(int) msqid;
387: syscallarg(void *) msgp;
388: syscallarg(size_t) msgsz;
389: syscallarg(int) msgflg;
390: };
391:
392: static int
393: svr4_msgsnd(p, v, retval)
394: struct proc *p;
395: void *v;
396: register_t *retval;
397: {
398: struct svr4_sys_msgsnd_args *uap = v;
399: struct sys_msgsnd_args ap;
400:
401: SCARG(&ap, msqid) = SCARG(uap, msqid);
402: SCARG(&ap, msgp) = SCARG(uap, msgp);
403: SCARG(&ap, msgsz) = SCARG(uap, msgsz);
404: SCARG(&ap, msgflg) = SCARG(uap, msgflg);
405:
406: return sys_msgsnd(p, &ap, retval);
407: }
408:
409: struct svr4_sys_msgrcv_args {
410: syscallarg(int) what;
411: syscallarg(int) msqid;
412: syscallarg(void *) msgp;
413: syscallarg(size_t) msgsz;
414: syscallarg(long) msgtyp;
415: syscallarg(int) msgflg;
416: };
417:
418: static int
419: svr4_msgrcv(p, v, retval)
420: struct proc *p;
421: void *v;
422: register_t *retval;
423: {
424: struct svr4_sys_msgrcv_args *uap = v;
425: struct sys_msgrcv_args ap;
426:
427: SCARG(&ap, msqid) = SCARG(uap, msqid);
428: SCARG(&ap, msgp) = SCARG(uap, msgp);
429: SCARG(&ap, msgsz) = SCARG(uap, msgsz);
430: SCARG(&ap, msgtyp) = SCARG(uap, msgtyp);
431: SCARG(&ap, msgflg) = SCARG(uap, msgflg);
432:
433: return sys_msgrcv(p, &ap, retval);
434: }
435:
436: struct svr4_sys_msgget_args {
437: syscallarg(int) what;
438: syscallarg(svr4_key_t) key;
439: syscallarg(int) msgflg;
440: };
441:
442: static int
443: svr4_msgget(p, v, retval)
444: struct proc *p;
445: void *v;
446: register_t *retval;
447: {
448: struct svr4_sys_msgget_args *uap = v;
449: struct sys_msgget_args ap;
450:
451: SCARG(&ap, key) = SCARG(uap, key);
452: SCARG(&ap, msgflg) = SCARG(uap, msgflg);
453:
454: return sys_msgget(p, &ap, retval);
455: }
456:
457: struct svr4_sys_msgctl_args {
458: syscallarg(int) what;
459: syscallarg(int) msqid;
460: syscallarg(int) cmd;
461: syscallarg(struct svr4_msqid_ds *) buf;
462: };
463:
464: static int
465: svr4_msgctl(p, v, retval)
466: struct proc *p;
467: void *v;
468: register_t *retval;
469: {
470: int error;
471: struct svr4_sys_msgctl_args *uap = v;
472: struct sys_msgctl_args ap;
473: struct svr4_msqid_ds ss;
474: struct msqid_ds bs;
475: caddr_t sg = stackgap_init(p->p_emul);
476:
477: SCARG(&ap, msqid) = SCARG(uap, msqid);
478: SCARG(&ap, cmd) = SCARG(uap, cmd);
479: SCARG(&ap, buf) = stackgap_alloc(&sg, sizeof(bs));
480:
481: switch (SCARG(uap, cmd)) {
482: case SVR4_IPC_STAT:
483: SCARG(&ap, cmd) = IPC_STAT;
484: if ((error = sys_msgctl(p, &ap, retval)) != 0)
485: return error;
486: error = copyin(SCARG(&ap, buf), &bs, sizeof bs);
487: if (error)
488: return error;
489: bsd_to_svr4_msqid_ds(&bs, &ss);
490: return copyout(&ss, SCARG(uap, buf), sizeof ss);
491:
492: case SVR4_IPC_SET:
493: SCARG(&ap, cmd) = IPC_SET;
494: error = copyin(SCARG(uap, buf), &ss, sizeof ss);
495: if (error)
496: return error;
497: svr4_to_bsd_msqid_ds(&ss, &bs);
498: error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
499: if (error)
500: return error;
501: return sys_msgctl(p, &ap, retval);
502:
503: case SVR4_IPC_RMID:
504: SCARG(&ap, cmd) = IPC_RMID;
505: error = copyin(SCARG(uap, buf), &ss, sizeof ss);
506: if (error)
507: return error;
508: svr4_to_bsd_msqid_ds(&ss, &bs);
509: error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
510: if (error)
511: return error;
512: return sys_msgctl(p, &ap, retval);
513:
514: default:
515: return EINVAL;
516: }
517: }
518:
519: int
520: svr4_sys_msgsys(p, v, retval)
521: struct proc *p;
522: void *v;
523: register_t *retval;
524: {
525: struct svr4_sys_msgsys_args *uap = v;
526:
527: DPRINTF(("svr4_msgsys(%d)\n", SCARG(uap, what)));
528:
529: switch (SCARG(uap, what)) {
530: case SVR4_msgsnd:
531: return svr4_msgsnd(p, v, retval);
532: case SVR4_msgrcv:
533: return svr4_msgrcv(p, v, retval);
534: case SVR4_msgget:
535: return svr4_msgget(p, v, retval);
536: case SVR4_msgctl:
537: return svr4_msgctl(p, v, retval);
538: default:
539: return EINVAL;
540: }
541: }
542: #endif
543:
544: #ifdef SYSVSHM
545:
546: static void
547: bsd_to_svr4_shmid_ds(bds, sds)
548: const struct shmid_ds *bds;
549: struct svr4_shmid_ds *sds;
550: {
551: bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
552: sds->shm_segsz = bds->shm_segsz;
553: sds->shm_lkcnt = 0;
554: sds->shm_lpid = bds->shm_lpid;
555: sds->shm_cpid = bds->shm_cpid;
556: sds->shm_amp = bds->shm_internal;
557: sds->shm_nattch = bds->shm_nattch;
558: sds->shm_cnattch = 0;
559: sds->shm_atime = bds->shm_atime;
560: sds->shm_pad1 = 0;
561: sds->shm_dtime = bds->shm_dtime;
562: sds->shm_pad2 = 0;
563: sds->shm_ctime = bds->shm_ctime;
564: sds->shm_pad3 = 0;
565: }
566:
567: static void
568: svr4_to_bsd_shmid_ds(sds, bds)
569: const struct svr4_shmid_ds *sds;
570: struct shmid_ds *bds;
571: {
572: svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
573: bds->shm_segsz = sds->shm_segsz;
574: bds->shm_lpid = sds->shm_lpid;
575: bds->shm_cpid = sds->shm_cpid;
576: bds->shm_internal = sds->shm_amp;
577: bds->shm_nattch = sds->shm_nattch;
578: bds->shm_atime = sds->shm_atime;
579: bds->shm_dtime = sds->shm_dtime;
580: bds->shm_ctime = sds->shm_ctime;
581: }
582:
583: struct svr4_sys_shmat_args {
584: syscallarg(int) what;
585: syscallarg(int) shmid;
586: syscallarg(void *) shmaddr;
587: syscallarg(int) shmflg;
588: };
589:
590: static int
591: svr4_shmat(p, v, retval)
592: struct proc *p;
593: void *v;
594: register_t *retval;
595: {
596: struct svr4_sys_shmat_args *uap = v;
597: struct sys_shmat_args ap;
598:
599: SCARG(&ap, shmid) = SCARG(uap, shmid);
600: SCARG(&ap, shmaddr) = SCARG(uap, shmaddr);
601: SCARG(&ap, shmflg) = SCARG(uap, shmflg);
602:
603: return sys_shmat(p, &ap, retval);
604: }
605:
606: struct svr4_sys_shmdt_args {
607: syscallarg(int) what;
608: syscallarg(void *) shmaddr;
609: };
610:
611: static int
612: svr4_shmdt(p, v, retval)
613: struct proc *p;
614: void *v;
615: register_t *retval;
616: {
617: struct svr4_sys_shmdt_args *uap = v;
618: struct sys_shmdt_args ap;
619:
620: SCARG(&ap, shmaddr) = SCARG(uap, shmaddr);
621:
622: return sys_shmdt(p, &ap, retval);
623: }
624:
625: struct svr4_sys_shmget_args {
626: syscallarg(int) what;
627: syscallarg(key_t) key;
628: syscallarg(int) size;
629: syscallarg(int) shmflg;
630: };
631:
632: static int
633: svr4_shmget(p, v, retval)
634: struct proc *p;
635: void *v;
636: register_t *retval;
637: {
638: struct svr4_sys_shmget_args *uap = v;
639: struct sys_shmget_args ap;
640:
641: SCARG(&ap, key) = SCARG(uap, key);
642: SCARG(&ap, size) = SCARG(uap, size);
643: SCARG(&ap, shmflg) = SCARG(uap, shmflg);
644:
645: return sys_shmget(p, &ap, retval);
646: }
647:
648: struct svr4_sys_shmctl_args {
649: syscallarg(int) what;
650: syscallarg(int) shmid;
651: syscallarg(int) cmd;
652: syscallarg(struct svr4_shmid_ds *) buf;
653: };
654:
655: int
656: svr4_shmctl(p, v, retval)
657: struct proc *p;
658: void *v;
659: register_t *retval;
660: {
661: struct svr4_sys_shmctl_args *uap = v;
662: int error;
663: caddr_t sg = stackgap_init(p->p_emul);
664: struct sys_shmctl_args ap;
665: struct shmid_ds bs;
666: struct svr4_shmid_ds ss;
667:
668: SCARG(&ap, shmid) = SCARG(uap, shmid);
669:
670: if (SCARG(uap, buf) != NULL) {
671: SCARG(&ap, buf) = stackgap_alloc(&sg, sizeof (struct shmid_ds));
672: switch (SCARG(uap, cmd)) {
673: case SVR4_IPC_SET:
674: case SVR4_IPC_RMID:
675: case SVR4_SHM_LOCK:
676: case SVR4_SHM_UNLOCK:
677: error = copyin(SCARG(uap, buf), (caddr_t) &ss,
678: sizeof ss);
679: if (error)
680: return error;
681: svr4_to_bsd_shmid_ds(&ss, &bs);
682: error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
683: if (error)
684: return error;
685: break;
686: default:
687: break;
688: }
689: }
690: else
691: SCARG(&ap, buf) = NULL;
692:
693:
694: switch (SCARG(uap, cmd)) {
695: case SVR4_IPC_STAT:
696: SCARG(&ap, cmd) = IPC_STAT;
697: if ((error = sys_shmctl(p, &ap, retval)) != 0)
698: return error;
699: if (SCARG(uap, buf) == NULL)
700: return 0;
701: error = copyin(SCARG(&ap, buf), &bs, sizeof bs);
702: if (error)
703: return error;
704: bsd_to_svr4_shmid_ds(&bs, &ss);
705: return copyout(&ss, SCARG(uap, buf), sizeof ss);
706:
707: case SVR4_IPC_SET:
708: SCARG(&ap, cmd) = IPC_SET;
709: return sys_shmctl(p, &ap, retval);
710:
711: case SVR4_IPC_RMID:
712: case SVR4_SHM_LOCK:
713: case SVR4_SHM_UNLOCK:
714: switch (SCARG(uap, cmd)) {
715: case SVR4_IPC_RMID:
716: SCARG(&ap, cmd) = IPC_RMID;
717: break;
718: case SVR4_SHM_LOCK:
719: SCARG(&ap, cmd) = SHM_LOCK;
720: break;
721: case SVR4_SHM_UNLOCK:
722: SCARG(&ap, cmd) = SHM_UNLOCK;
723: break;
724: default:
725: return EINVAL;
726: }
727: return sys_shmctl(p, &ap, retval);
728:
729: default:
730: return EINVAL;
731: }
732: }
733:
734: int
735: svr4_sys_shmsys(p, v, retval)
736: struct proc *p;
737: void *v;
738: register_t *retval;
739: {
740: struct svr4_sys_shmsys_args *uap = v;
741:
742: DPRINTF(("svr4_shmsys(%d)\n", SCARG(uap, what)));
743:
744: switch (SCARG(uap, what)) {
745: case SVR4_shmat:
746: return svr4_shmat(p, v, retval);
747: case SVR4_shmdt:
748: return svr4_shmdt(p, v, retval);
749: case SVR4_shmget:
750: return svr4_shmget(p, v, retval);
751: case SVR4_shmctl:
752: return svr4_shmctl(p, v, retval);
753: default:
754: return ENOSYS;
755: }
756: }
757: #endif /* SYSVSHM */
CVSweb