1 /* $Id: ipc.c,v 1.5 1999/12/09 00:41:00 davem Exp $
2 * ipc.c: Solaris IPC emulation
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/smp_lock.h>
10 #include <linux/wait.h>
11 #include <linux/mm.h>
12 #include <linux/shm.h>
13 #include <linux/sem.h>
14 #include <linux/msg.h>
15
16 #include <asm/uaccess.h>
17 #include <asm/string.h>
18 #include <asm/ipc.h>
19
20 #include "conv.h"
21
22 struct solaris_ipc_perm {
23 s32 uid;
24 s32 gid;
25 s32 cuid;
26 s32 cgid;
27 u32 mode;
28 u32 seq;
29 int key;
30 s32 pad[4];
31 };
32
33 struct solaris_shmid_ds {
34 struct solaris_ipc_perm shm_perm;
35 int shm_segsz;
36 u32 shm_amp;
37 unsigned short shm_lkcnt;
38 char __padxx[2];
39 s32 shm_lpid;
40 s32 shm_cpid;
41 u32 shm_nattch;
42 u32 shm_cnattch;
43 s32 shm_atime;
44 s32 shm_pad1;
45 s32 shm_dtime;
46 s32 shm_pad2;
47 s32 shm_ctime;
48 s32 shm_pad3;
49 unsigned short shm_cv;
50 char shm_pad4[2];
51 u32 shm_sptas;
52 s32 shm_pad5[2];
53 };
54
solaris_shmsys(int cmd,u32 arg1,u32 arg2,u32 arg3)55 asmlinkage long solaris_shmsys(int cmd, u32 arg1, u32 arg2, u32 arg3)
56 {
57 int (*sys_ipc)(unsigned,int,int,unsigned long,void *,long) =
58 (int (*)(unsigned,int,int,unsigned long,void *,long))SYS(ipc);
59 mm_segment_t old_fs;
60 unsigned long raddr;
61 int ret;
62
63 switch (cmd) {
64 case 0: /* shmat */
65 old_fs = get_fs();
66 set_fs(KERNEL_DS);
67 ret = sys_ipc(SHMAT, arg1, arg3 & ~0x4000, (unsigned long)&raddr, (void *)A(arg2), 0);
68 set_fs(old_fs);
69 if (ret >= 0) return (u32)raddr;
70 else return ret;
71 case 1: /* shmctl */
72 switch (arg2) {
73 case 3: /* SHM_LOCK */
74 case 4: /* SHM_UNLOCK */
75 return sys_ipc(SHMCTL, arg1, (arg2 == 3) ? SHM_LOCK : SHM_UNLOCK, 0, NULL, 0);
76 case 10: /* IPC_RMID */
77 return sys_ipc(SHMCTL, arg1, IPC_RMID, 0, NULL, 0);
78 case 11: /* IPC_SET */
79 {
80 struct shmid_ds s;
81
82 if (get_user (s.shm_perm.uid, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.uid)) ||
83 __get_user (s.shm_perm.gid, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.gid)) ||
84 __get_user (s.shm_perm.mode, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.mode)))
85 return -EFAULT;
86 old_fs = get_fs();
87 set_fs(KERNEL_DS);
88 ret = sys_ipc(SHMCTL, arg1, IPC_SET, 0, &s, 0);
89 set_fs(old_fs);
90 return ret;
91 }
92 case 12: /* IPC_STAT */
93 {
94 struct shmid_ds s;
95
96 old_fs = get_fs();
97 set_fs(KERNEL_DS);
98 ret = sys_ipc(SHMCTL, arg1, IPC_SET, 0, &s, 0);
99 set_fs(old_fs);
100 if (get_user (s.shm_perm.uid, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.uid)) ||
101 __get_user (s.shm_perm.gid, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.gid)) ||
102 __get_user (s.shm_perm.cuid, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.cuid)) ||
103 __get_user (s.shm_perm.cgid, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.cgid)) ||
104 __get_user (s.shm_perm.mode, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.mode)) ||
105 __get_user (s.shm_perm.seq, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.seq)) ||
106 __get_user (s.shm_perm.key, &(((struct solaris_shmid_ds *)A(arg3))->shm_perm.key)) ||
107 __get_user (s.shm_segsz, &(((struct solaris_shmid_ds *)A(arg3))->shm_segsz)) ||
108 __get_user (s.shm_lpid, &(((struct solaris_shmid_ds *)A(arg3))->shm_lpid)) ||
109 __get_user (s.shm_cpid, &(((struct solaris_shmid_ds *)A(arg3))->shm_cpid)) ||
110 __get_user (s.shm_nattch, &(((struct solaris_shmid_ds *)A(arg3))->shm_nattch)) ||
111 __get_user (s.shm_atime, &(((struct solaris_shmid_ds *)A(arg3))->shm_atime)) ||
112 __get_user (s.shm_dtime, &(((struct solaris_shmid_ds *)A(arg3))->shm_dtime)) ||
113 __get_user (s.shm_ctime, &(((struct solaris_shmid_ds *)A(arg3))->shm_ctime)))
114 return -EFAULT;
115 return ret;
116 }
117 default: return -EINVAL;
118 }
119 case 2: /* shmdt */
120 return sys_ipc(SHMDT, 0, 0, 0, (void *)A(arg1), 0);
121 case 3: /* shmget */
122 return sys_ipc(SHMGET, arg1, arg2, arg3, NULL, 0);
123 }
124 return -EINVAL;
125 }
126