aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/solaris
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc64/solaris
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sparc64/solaris')
-rw-r--r--arch/sparc64/solaris/Makefile10
-rw-r--r--arch/sparc64/solaris/conv.h38
-rw-r--r--arch/sparc64/solaris/entry64.S218
-rw-r--r--arch/sparc64/solaris/fs.c739
-rw-r--r--arch/sparc64/solaris/ioctl.c820
-rw-r--r--arch/sparc64/solaris/ipc.c127
-rw-r--r--arch/sparc64/solaris/misc.c784
-rw-r--r--arch/sparc64/solaris/signal.c430
-rw-r--r--arch/sparc64/solaris/signal.h108
-rw-r--r--arch/sparc64/solaris/socket.c415
-rw-r--r--arch/sparc64/solaris/socksys.c211
-rw-r--r--arch/sparc64/solaris/socksys.h208
-rw-r--r--arch/sparc64/solaris/systbl.S314
-rw-r--r--arch/sparc64/solaris/timod.c959
14 files changed, 5381 insertions, 0 deletions
diff --git a/arch/sparc64/solaris/Makefile b/arch/sparc64/solaris/Makefile
new file mode 100644
index 000000000000..8c8663033bfb
--- /dev/null
+++ b/arch/sparc64/solaris/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the Solaris binary emulation.
3#
4
5EXTRA_AFLAGS := -ansi
6
7solaris-objs := entry64.o fs.o misc.o signal.o systbl.o socket.o \
8 ioctl.o ipc.o socksys.o timod.o
9
10obj-$(CONFIG_SOLARIS_EMUL) += solaris.o
diff --git a/arch/sparc64/solaris/conv.h b/arch/sparc64/solaris/conv.h
new file mode 100644
index 000000000000..5faf59a9de39
--- /dev/null
+++ b/arch/sparc64/solaris/conv.h
@@ -0,0 +1,38 @@
1/* $Id: conv.h,v 1.4 1998/08/15 20:42:51 davem Exp $
2 * conv.h: Utility macros for Solaris emulation
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7/* #define DEBUG_SOLARIS */
8#define DEBUG_SOLARIS_KMALLOC
9
10#ifndef __ASSEMBLY__
11
12#include <asm/unistd.h>
13
14/* Use this to get at 32-bit user passed pointers. */
15#define A(__x) \
16({ unsigned long __ret; \
17 __asm__ ("srl %0, 0, %0" \
18 : "=r" (__ret) \
19 : "0" (__x)); \
20 (void __user *)__ret; \
21})
22
23extern unsigned sys_call_table[];
24extern unsigned sys_call_table32[];
25extern unsigned sunos_sys_table[];
26
27#define SYS(name) ((long)sys_call_table[__NR_##name])
28#define SUNOS(x) ((long)sunos_sys_table[x])
29
30#ifdef DEBUG_SOLARIS
31#define SOLD(s) printk("%s,%d,%s(): %s\n",__FILE__,__LINE__,__FUNCTION__,(s))
32#define SOLDD(s) printk("solaris: "); printk s
33#else
34#define SOLD(s)
35#define SOLDD(s)
36#endif
37
38#endif /* __ASSEMBLY__ */
diff --git a/arch/sparc64/solaris/entry64.S b/arch/sparc64/solaris/entry64.S
new file mode 100644
index 000000000000..0cc9dad75c5e
--- /dev/null
+++ b/arch/sparc64/solaris/entry64.S
@@ -0,0 +1,218 @@
1/* $Id: entry64.S,v 1.7 2002/02/09 19:49:31 davem Exp $
2 * entry64.S: Solaris syscall emulation entry point.
3 *
4 * Copyright (C) 1996,1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 */
8
9#include <linux/errno.h>
10
11#include <asm/head.h>
12#include <asm/asi.h>
13#include <asm/smp.h>
14#include <asm/ptrace.h>
15#include <asm/page.h>
16#include <asm/signal.h>
17#include <asm/pgtable.h>
18#include <asm/processor.h>
19#include <asm/thread_info.h>
20
21#include "conv.h"
22
23#define NR_SYSCALLS 256
24
25 .text
26solaris_syscall_trace:
27 call syscall_trace
28 nop
29 srl %i0, 0, %o0
30 mov %i4, %o4
31 srl %i1, 0, %o1
32 mov %i5, %o5
33 andcc %l3, 1, %g0
34 be,pt %icc, 2f
35 srl %i2, 0, %o2
36 b,pt %xcc, 2f
37 add %sp, PTREGS_OFF, %o0
38
39solaris_sucks:
40/* Solaris is a big system which needs to be able to do all the things
41 * in Inf+1 different ways */
42 add %i6, 0x5c, %o0
43 mov %i0, %g1
44 mov %i1, %i0
45 mov %i2, %i1
46 srl %o0, 0, %o0
47 mov %i3, %i2
48 movrz %g1, 256, %g1 /* Ensure we don't loop forever */
49 mov %i4, %i3
50 mov %i5, %i4
51 ba,pt %xcc, solaris_sparc_syscall
52exen: lduwa [%o0] ASI_S, %i5
53
54exenf: ba,pt %xcc, solaris_sparc_syscall
55 clr %i5
56
57/* For shared binaries, binfmt_elf32 already sets up personality
58 and exec_domain. This is to handle static binaries as well */
59solaris_reg:
60 call solaris_register
61 nop
62 ba,pt %xcc, 1f
63 mov %i4, %o4
64
65linux_syscall_for_solaris:
66 sethi %hi(sys_call_table32), %l6
67 or %l6, %lo(sys_call_table32), %l6
68 sll %l3, 2, %l4
69 ba,pt %xcc, 10f
70 lduw [%l6 + %l4], %l3
71
72 /* Solaris system calls enter here... */
73 .align 32
74 .globl solaris_sparc_syscall, entry64_personality_patch
75solaris_sparc_syscall:
76entry64_personality_patch:
77 ldub [%g4 + 0x0], %l0
78 cmp %g1, 255
79 bg,pn %icc, solaris_unimplemented
80 srl %g1, 0, %g1
81 sethi %hi(solaris_sys_table), %l7
82 or %l7, %lo(solaris_sys_table), %l7
83 brz,pn %g1, solaris_sucks
84 mov %i4, %o4
85 sll %g1, 2, %l4
86 cmp %l0, 1
87 bne,pn %icc, solaris_reg
881: srl %i0, 0, %o0
89 lduw [%l7 + %l4], %l3
90 srl %i1, 0, %o1
91 ldx [%g6 + TI_FLAGS], %l5
92 cmp %l3, NR_SYSCALLS
93 bleu,a,pn %xcc, linux_syscall_for_solaris
94 nop
95 andcc %l3, 1, %g0
96 bne,a,pn %icc, 10f
97 add %sp, PTREGS_OFF, %o0
9810: srl %i2, 0, %o2
99 mov %i5, %o5
100 andn %l3, 3, %l7
101 andcc %l5, _TIF_SYSCALL_TRACE, %g0
102 bne,pn %icc, solaris_syscall_trace
103 mov %i0, %l5
1042: call %l7
105 srl %i3, 0, %o3
106ret_from_solaris:
107 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
108 ldx [%g6 + TI_FLAGS], %l6
109 sra %o0, 0, %o0
110 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
111 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
112 cmp %o0, -ERESTART_RESTARTBLOCK
113 sllx %g2, 32, %g2
114 bgeu,pn %xcc, 1f
115 andcc %l6, _TIF_SYSCALL_TRACE, %l6
116
117 /* System call success, clear Carry condition code. */
118 andn %g3, %g2, %g3
119 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
120 bne,pn %icc, solaris_syscall_trace2
121 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1
122 andcc %l1, 1, %g0
123 bne,pn %icc, 2f
124 clr %l6
125 add %l1, 0x4, %l2
126 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC] ! pc = npc
127 call rtrap
128 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC] !npc = npc+4
129
130 /* When tnpc & 1, this comes from setcontext and we don't want to advance pc */
1312: andn %l1, 3, %l1
132 call rtrap
133 stx %l1, [%sp + PTREGS_OFF + PT_V9_TNPC] !npc = npc&~3
134
1351:
136 /* System call failure, set Carry condition code.
137 * Also, get abs(errno) to return to the process.
138 */
139 sub %g0, %o0, %o0
140 or %g3, %g2, %g3
141 cmp %o0, ERANGE /* 0-ERANGE are identity mapped */
142 bleu,pt %icc, 1f
143 cmp %o0, EMEDIUMTYPE
144 bgu,pn %icc, 1f
145 sethi %hi(solaris_err_table), %l6
146 sll %o0, 2, %o0
147 or %l6, %lo(solaris_err_table), %l6
148 ldsw [%l6 + %o0], %o0
1491: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
150 mov 1, %l6
151 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
152 bne,pn %icc, solaris_syscall_trace2
153 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1
154 andcc %l1, 1, %g0
155 bne,pn %icc, 2b
156 add %l1, 0x4, %l2
157 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC] ! pc = npc
158 call rtrap
159 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC] !npc = npc+4
160
161solaris_syscall_trace2:
162 call syscall_trace
163 add %l1, 0x4, %l2 /* npc = npc+4 */
164 andcc %l1, 1, %g0
165 bne,pn %icc, 2b
166 nop
167 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
168 call rtrap
169 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
170
171 /* This one is tricky, so that's why we do it in assembly */
172 .globl solaris_sigsuspend
173solaris_sigsuspend:
174 call do_sol_sigsuspend
175 nop
176 brlz,pn %o0, ret_from_solaris
177 nop
178 call sys_sigsuspend
179 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
180
181 .globl solaris_getpid
182solaris_getpid:
183 call sys_getppid
184 nop
185 call sys_getpid
186 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
187 b,pt %xcc, ret_from_solaris
188 nop
189
190 .globl solaris_getuid
191solaris_getuid:
192 call sys_geteuid
193 nop
194 call sys_getuid
195 stx %o1, [%sp + PTREGS_OFF + PT_V9_I1]
196 b,pt %xcc, ret_from_solaris
197 nop
198
199 .globl solaris_getgid
200solaris_getgid:
201 call sys_getegid
202 nop
203 call sys_getgid
204 stx %o1, [%sp + PTREGS_OFF + PT_V9_I1]
205 b,pt %xcc, ret_from_solaris
206 nop
207
208 .globl solaris_unimplemented
209solaris_unimplemented:
210 call do_sol_unimplemented
211 add %sp, PTREGS_OFF, %o0
212 ba,pt %xcc, ret_from_solaris
213 nop
214
215 .section __ex_table,#alloc
216 .align 4
217 .word exen, exenf
218
diff --git a/arch/sparc64/solaris/fs.c b/arch/sparc64/solaris/fs.c
new file mode 100644
index 000000000000..d7c99fa89661
--- /dev/null
+++ b/arch/sparc64/solaris/fs.c
@@ -0,0 +1,739 @@
1/* $Id: fs.c,v 1.27 2002/02/08 03:57:14 davem Exp $
2 * fs.c: fs related syscall emulation for Solaris
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 *
6 * 1999-08-19 Implemented solaris F_FREESP (truncate)
7 * fcntl, by Jason Rappleye (rappleye@ccr.buffalo.edu)
8 */
9
10#include <linux/types.h>
11#include <linux/sched.h>
12#include <linux/slab.h>
13#include <linux/fs.h>
14#include <linux/namei.h>
15#include <linux/mm.h>
16#include <linux/file.h>
17#include <linux/stat.h>
18#include <linux/smp_lock.h>
19#include <linux/limits.h>
20#include <linux/resource.h>
21#include <linux/quotaops.h>
22#include <linux/mount.h>
23#include <linux/vfs.h>
24
25#include <asm/uaccess.h>
26#include <asm/string.h>
27#include <asm/ptrace.h>
28
29#include "conv.h"
30
31#define R3_VERSION 1
32#define R4_VERSION 2
33
34typedef struct {
35 s32 tv_sec;
36 s32 tv_nsec;
37} timestruct_t;
38
39struct sol_stat {
40 u32 st_dev;
41 s32 st_pad1[3]; /* network id */
42 u32 st_ino;
43 u32 st_mode;
44 u32 st_nlink;
45 u32 st_uid;
46 u32 st_gid;
47 u32 st_rdev;
48 s32 st_pad2[2];
49 s32 st_size;
50 s32 st_pad3; /* st_size, off_t expansion */
51 timestruct_t st_atime;
52 timestruct_t st_mtime;
53 timestruct_t st_ctime;
54 s32 st_blksize;
55 s32 st_blocks;
56 char st_fstype[16];
57 s32 st_pad4[8]; /* expansion area */
58};
59
60struct sol_stat64 {
61 u32 st_dev;
62 s32 st_pad1[3]; /* network id */
63 u64 st_ino;
64 u32 st_mode;
65 u32 st_nlink;
66 u32 st_uid;
67 u32 st_gid;
68 u32 st_rdev;
69 s32 st_pad2[2];
70 s64 st_size;
71 timestruct_t st_atime;
72 timestruct_t st_mtime;
73 timestruct_t st_ctime;
74 s64 st_blksize;
75 s32 st_blocks;
76 char st_fstype[16];
77 s32 st_pad4[4]; /* expansion area */
78};
79
80#define UFSMAGIC (((unsigned)'u'<<24)||((unsigned)'f'<<16)||((unsigned)'s'<<8))
81
82static inline int putstat(struct sol_stat __user *ubuf, struct kstat *kbuf)
83{
84 if (kbuf->size > MAX_NON_LFS ||
85 !sysv_valid_dev(kbuf->dev) ||
86 !sysv_valid_dev(kbuf->rdev))
87 return -EOVERFLOW;
88 if (put_user (sysv_encode_dev(kbuf->dev), &ubuf->st_dev) ||
89 __put_user (kbuf->ino, &ubuf->st_ino) ||
90 __put_user (kbuf->mode, &ubuf->st_mode) ||
91 __put_user (kbuf->nlink, &ubuf->st_nlink) ||
92 __put_user (kbuf->uid, &ubuf->st_uid) ||
93 __put_user (kbuf->gid, &ubuf->st_gid) ||
94 __put_user (sysv_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
95 __put_user (kbuf->size, &ubuf->st_size) ||
96 __put_user (kbuf->atime.tv_sec, &ubuf->st_atime.tv_sec) ||
97 __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime.tv_nsec) ||
98 __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime.tv_sec) ||
99 __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime.tv_nsec) ||
100 __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime.tv_sec) ||
101 __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime.tv_nsec) ||
102 __put_user (kbuf->blksize, &ubuf->st_blksize) ||
103 __put_user (kbuf->blocks, &ubuf->st_blocks) ||
104 __put_user (UFSMAGIC, (unsigned __user *)ubuf->st_fstype))
105 return -EFAULT;
106 return 0;
107}
108
109static inline int putstat64(struct sol_stat64 __user *ubuf, struct kstat *kbuf)
110{
111 if (!sysv_valid_dev(kbuf->dev) || !sysv_valid_dev(kbuf->rdev))
112 return -EOVERFLOW;
113 if (put_user (sysv_encode_dev(kbuf->dev), &ubuf->st_dev) ||
114 __put_user (kbuf->ino, &ubuf->st_ino) ||
115 __put_user (kbuf->mode, &ubuf->st_mode) ||
116 __put_user (kbuf->nlink, &ubuf->st_nlink) ||
117 __put_user (kbuf->uid, &ubuf->st_uid) ||
118 __put_user (kbuf->gid, &ubuf->st_gid) ||
119 __put_user (sysv_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
120 __put_user (kbuf->size, &ubuf->st_size) ||
121 __put_user (kbuf->atime.tv_sec, &ubuf->st_atime.tv_sec) ||
122 __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime.tv_nsec) ||
123 __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime.tv_sec) ||
124 __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime.tv_nsec) ||
125 __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime.tv_sec) ||
126 __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime.tv_nsec) ||
127 __put_user (kbuf->blksize, &ubuf->st_blksize) ||
128 __put_user (kbuf->blocks, &ubuf->st_blocks) ||
129 __put_user (UFSMAGIC, (unsigned __user *)ubuf->st_fstype))
130 return -EFAULT;
131 return 0;
132}
133
134asmlinkage int solaris_stat(u32 filename, u32 statbuf)
135{
136 struct kstat s;
137 int ret = vfs_stat(A(filename), &s);
138 if (!ret)
139 return putstat(A(statbuf), &s);
140 return ret;
141}
142
143asmlinkage int solaris_xstat(int vers, u32 filename, u32 statbuf)
144{
145 /* Solaris doesn't bother with looking at vers, so we do neither */
146 return solaris_stat(filename, statbuf);
147}
148
149asmlinkage int solaris_stat64(u32 filename, u32 statbuf)
150{
151 struct kstat s;
152 int ret = vfs_stat(A(filename), &s);
153 if (!ret)
154 return putstat64(A(statbuf), &s);
155 return ret;
156}
157
158asmlinkage int solaris_lstat(u32 filename, u32 statbuf)
159{
160 struct kstat s;
161 int ret = vfs_lstat(A(filename), &s);
162 if (!ret)
163 return putstat(A(statbuf), &s);
164 return ret;
165}
166
167asmlinkage int solaris_lxstat(int vers, u32 filename, u32 statbuf)
168{
169 return solaris_lstat(filename, statbuf);
170}
171
172asmlinkage int solaris_lstat64(u32 filename, u32 statbuf)
173{
174 struct kstat s;
175 int ret = vfs_lstat(A(filename), &s);
176 if (!ret)
177 return putstat64(A(statbuf), &s);
178 return ret;
179}
180
181asmlinkage int solaris_fstat(unsigned int fd, u32 statbuf)
182{
183 struct kstat s;
184 int ret = vfs_fstat(fd, &s);
185 if (!ret)
186 return putstat(A(statbuf), &s);
187 return ret;
188}
189
190asmlinkage int solaris_fxstat(int vers, u32 fd, u32 statbuf)
191{
192 return solaris_fstat(fd, statbuf);
193}
194
195asmlinkage int solaris_fstat64(unsigned int fd, u32 statbuf)
196{
197 struct kstat s;
198 int ret = vfs_fstat(fd, &s);
199 if (!ret)
200 return putstat64(A(statbuf), &s);
201 return ret;
202}
203
204asmlinkage int solaris_mknod(u32 path, u32 mode, s32 dev)
205{
206 int (*sys_mknod)(const char __user *,int,unsigned) =
207 (int (*)(const char __user *,int,unsigned))SYS(mknod);
208 int major = sysv_major(dev);
209 int minor = sysv_minor(dev);
210
211 /* minor is guaranteed to be OK for MKDEV, major might be not */
212 if (major > 0xfff)
213 return -EINVAL;
214 return sys_mknod(A(path), mode, new_encode_dev(MKDEV(major,minor)));
215}
216
217asmlinkage int solaris_xmknod(int vers, u32 path, u32 mode, s32 dev)
218{
219 return solaris_mknod(path, mode, dev);
220}
221
222asmlinkage int solaris_getdents64(unsigned int fd, void __user *dirent, unsigned int count)
223{
224 int (*sys_getdents)(unsigned int, void __user *, unsigned int) =
225 (int (*)(unsigned int, void __user *, unsigned int))SYS(getdents);
226
227 return sys_getdents(fd, dirent, count);
228}
229
230/* This statfs thingie probably will go in the near future, but... */
231
232struct sol_statfs {
233 short f_type;
234 s32 f_bsize;
235 s32 f_frsize;
236 s32 f_blocks;
237 s32 f_bfree;
238 u32 f_files;
239 u32 f_ffree;
240 char f_fname[6];
241 char f_fpack[6];
242};
243
244asmlinkage int solaris_statfs(u32 path, u32 buf, int len, int fstype)
245{
246 int ret;
247 struct statfs s;
248 mm_segment_t old_fs = get_fs();
249 int (*sys_statfs)(const char __user *,struct statfs __user *) =
250 (int (*)(const char __user *,struct statfs __user *))SYS(statfs);
251 struct sol_statfs __user *ss = A(buf);
252
253 if (len != sizeof(struct sol_statfs)) return -EINVAL;
254 if (!fstype) {
255 /* FIXME: mixing userland and kernel pointers */
256 set_fs (KERNEL_DS);
257 ret = sys_statfs(A(path), &s);
258 set_fs (old_fs);
259 if (!ret) {
260 if (put_user (s.f_type, &ss->f_type) ||
261 __put_user (s.f_bsize, &ss->f_bsize) ||
262 __put_user (0, &ss->f_frsize) ||
263 __put_user (s.f_blocks, &ss->f_blocks) ||
264 __put_user (s.f_bfree, &ss->f_bfree) ||
265 __put_user (s.f_files, &ss->f_files) ||
266 __put_user (s.f_ffree, &ss->f_ffree) ||
267 __clear_user (&ss->f_fname, 12))
268 return -EFAULT;
269 }
270 return ret;
271 }
272/* Linux can't stat unmounted filesystems so we
273 * simply lie and claim 100MB of 1GB is free. Sorry.
274 */
275 if (put_user (fstype, &ss->f_type) ||
276 __put_user (1024, &ss->f_bsize) ||
277 __put_user (0, &ss->f_frsize) ||
278 __put_user (1024*1024, &ss->f_blocks) ||
279 __put_user (100*1024, &ss->f_bfree) ||
280 __put_user (60000, &ss->f_files) ||
281 __put_user (50000, &ss->f_ffree) ||
282 __clear_user (&ss->f_fname, 12))
283 return -EFAULT;
284 return 0;
285}
286
287asmlinkage int solaris_fstatfs(u32 fd, u32 buf, int len, int fstype)
288{
289 int ret;
290 struct statfs s;
291 mm_segment_t old_fs = get_fs();
292 int (*sys_fstatfs)(unsigned,struct statfs __user *) =
293 (int (*)(unsigned,struct statfs __user *))SYS(fstatfs);
294 struct sol_statfs __user *ss = A(buf);
295
296 if (len != sizeof(struct sol_statfs)) return -EINVAL;
297 if (!fstype) {
298 set_fs (KERNEL_DS);
299 ret = sys_fstatfs(fd, &s);
300 set_fs (old_fs);
301 if (!ret) {
302 if (put_user (s.f_type, &ss->f_type) ||
303 __put_user (s.f_bsize, &ss->f_bsize) ||
304 __put_user (0, &ss->f_frsize) ||
305 __put_user (s.f_blocks, &ss->f_blocks) ||
306 __put_user (s.f_bfree, &ss->f_bfree) ||
307 __put_user (s.f_files, &ss->f_files) ||
308 __put_user (s.f_ffree, &ss->f_ffree) ||
309 __clear_user (&ss->f_fname, 12))
310 return -EFAULT;
311 }
312 return ret;
313 }
314 /* Otherwise fstatfs is the same as statfs */
315 return solaris_statfs(0, buf, len, fstype);
316}
317
318struct sol_statvfs {
319 u32 f_bsize;
320 u32 f_frsize;
321 u32 f_blocks;
322 u32 f_bfree;
323 u32 f_bavail;
324 u32 f_files;
325 u32 f_ffree;
326 u32 f_favail;
327 u32 f_fsid;
328 char f_basetype[16];
329 u32 f_flag;
330 u32 f_namemax;
331 char f_fstr[32];
332 u32 f_filler[16];
333};
334
335struct sol_statvfs64 {
336 u32 f_bsize;
337 u32 f_frsize;
338 u64 f_blocks;
339 u64 f_bfree;
340 u64 f_bavail;
341 u64 f_files;
342 u64 f_ffree;
343 u64 f_favail;
344 u32 f_fsid;
345 char f_basetype[16];
346 u32 f_flag;
347 u32 f_namemax;
348 char f_fstr[32];
349 u32 f_filler[16];
350};
351
352static int report_statvfs(struct vfsmount *mnt, struct inode *inode, u32 buf)
353{
354 struct kstatfs s;
355 int error;
356 struct sol_statvfs __user *ss = A(buf);
357
358 error = vfs_statfs(mnt->mnt_sb, &s);
359 if (!error) {
360 const char *p = mnt->mnt_sb->s_type->name;
361 int i = 0;
362 int j = strlen (p);
363
364 if (j > 15) j = 15;
365 if (IS_RDONLY(inode)) i = 1;
366 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
367 if (!sysv_valid_dev(inode->i_sb->s_dev))
368 return -EOVERFLOW;
369 if (put_user (s.f_bsize, &ss->f_bsize) ||
370 __put_user (0, &ss->f_frsize) ||
371 __put_user (s.f_blocks, &ss->f_blocks) ||
372 __put_user (s.f_bfree, &ss->f_bfree) ||
373 __put_user (s.f_bavail, &ss->f_bavail) ||
374 __put_user (s.f_files, &ss->f_files) ||
375 __put_user (s.f_ffree, &ss->f_ffree) ||
376 __put_user (s.f_ffree, &ss->f_favail) ||
377 __put_user (sysv_encode_dev(inode->i_sb->s_dev), &ss->f_fsid) ||
378 __copy_to_user (ss->f_basetype,p,j) ||
379 __put_user (0, (char __user *)&ss->f_basetype[j]) ||
380 __put_user (s.f_namelen, &ss->f_namemax) ||
381 __put_user (i, &ss->f_flag) ||
382 __clear_user (&ss->f_fstr, 32))
383 return -EFAULT;
384 }
385 return error;
386}
387
388static int report_statvfs64(struct vfsmount *mnt, struct inode *inode, u32 buf)
389{
390 struct kstatfs s;
391 int error;
392 struct sol_statvfs64 __user *ss = A(buf);
393
394 error = vfs_statfs(mnt->mnt_sb, &s);
395 if (!error) {
396 const char *p = mnt->mnt_sb->s_type->name;
397 int i = 0;
398 int j = strlen (p);
399
400 if (j > 15) j = 15;
401 if (IS_RDONLY(inode)) i = 1;
402 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
403 if (!sysv_valid_dev(inode->i_sb->s_dev))
404 return -EOVERFLOW;
405 if (put_user (s.f_bsize, &ss->f_bsize) ||
406 __put_user (0, &ss->f_frsize) ||
407 __put_user (s.f_blocks, &ss->f_blocks) ||
408 __put_user (s.f_bfree, &ss->f_bfree) ||
409 __put_user (s.f_bavail, &ss->f_bavail) ||
410 __put_user (s.f_files, &ss->f_files) ||
411 __put_user (s.f_ffree, &ss->f_ffree) ||
412 __put_user (s.f_ffree, &ss->f_favail) ||
413 __put_user (sysv_encode_dev(inode->i_sb->s_dev), &ss->f_fsid) ||
414 __copy_to_user (ss->f_basetype,p,j) ||
415 __put_user (0, (char __user *)&ss->f_basetype[j]) ||
416 __put_user (s.f_namelen, &ss->f_namemax) ||
417 __put_user (i, &ss->f_flag) ||
418 __clear_user (&ss->f_fstr, 32))
419 return -EFAULT;
420 }
421 return error;
422}
423
424asmlinkage int solaris_statvfs(u32 path, u32 buf)
425{
426 struct nameidata nd;
427 int error;
428
429 error = user_path_walk(A(path),&nd);
430 if (!error) {
431 struct inode * inode = nd.dentry->d_inode;
432 error = report_statvfs(nd.mnt, inode, buf);
433 path_release(&nd);
434 }
435 return error;
436}
437
438asmlinkage int solaris_fstatvfs(unsigned int fd, u32 buf)
439{
440 struct file * file;
441 int error;
442
443 error = -EBADF;
444 file = fget(fd);
445 if (file) {
446 error = report_statvfs(file->f_vfsmnt, file->f_dentry->d_inode, buf);
447 fput(file);
448 }
449
450 return error;
451}
452
453asmlinkage int solaris_statvfs64(u32 path, u32 buf)
454{
455 struct nameidata nd;
456 int error;
457
458 lock_kernel();
459 error = user_path_walk(A(path), &nd);
460 if (!error) {
461 struct inode * inode = nd.dentry->d_inode;
462 error = report_statvfs64(nd.mnt, inode, buf);
463 path_release(&nd);
464 }
465 unlock_kernel();
466 return error;
467}
468
469asmlinkage int solaris_fstatvfs64(unsigned int fd, u32 buf)
470{
471 struct file * file;
472 int error;
473
474 error = -EBADF;
475 file = fget(fd);
476 if (file) {
477 lock_kernel();
478 error = report_statvfs64(file->f_vfsmnt, file->f_dentry->d_inode, buf);
479 unlock_kernel();
480 fput(file);
481 }
482 return error;
483}
484
485extern asmlinkage long sparc32_open(const char * filename, int flags, int mode);
486
487asmlinkage int solaris_open(u32 fname, int flags, u32 mode)
488{
489 const char *filename = (const char *)(long)fname;
490 int fl = flags & 0xf;
491
492 /* Translate flags first. */
493 if (flags & 0x2000) fl |= O_LARGEFILE;
494 if (flags & 0x8050) fl |= O_SYNC;
495 if (flags & 0x80) fl |= O_NONBLOCK;
496 if (flags & 0x100) fl |= O_CREAT;
497 if (flags & 0x200) fl |= O_TRUNC;
498 if (flags & 0x400) fl |= O_EXCL;
499 if (flags & 0x800) fl |= O_NOCTTY;
500 flags = fl;
501
502 return sparc32_open(filename, flags, mode);
503}
504
505#define SOL_F_SETLK 6
506#define SOL_F_SETLKW 7
507#define SOL_F_FREESP 11
508#define SOL_F_ISSTREAM 13
509#define SOL_F_GETLK 14
510#define SOL_F_PRIV 15
511#define SOL_F_NPRIV 16
512#define SOL_F_QUOTACTL 17
513#define SOL_F_BLOCKS 18
514#define SOL_F_BLKSIZE 19
515#define SOL_F_GETOWN 23
516#define SOL_F_SETOWN 24
517
518struct sol_flock {
519 short l_type;
520 short l_whence;
521 u32 l_start;
522 u32 l_len;
523 s32 l_sysid;
524 s32 l_pid;
525 s32 l_pad[4];
526};
527
528asmlinkage int solaris_fcntl(unsigned fd, unsigned cmd, u32 arg)
529{
530 int (*sys_fcntl)(unsigned,unsigned,unsigned long) =
531 (int (*)(unsigned,unsigned,unsigned long))SYS(fcntl);
532 int ret, flags;
533
534 switch (cmd) {
535 case F_DUPFD:
536 case F_GETFD:
537 case F_SETFD: return sys_fcntl(fd, cmd, (unsigned long)arg);
538 case F_GETFL:
539 flags = sys_fcntl(fd, cmd, 0);
540 ret = flags & 0xf;
541 if (flags & O_SYNC) ret |= 0x8050;
542 if (flags & O_NONBLOCK) ret |= 0x80;
543 return ret;
544 case F_SETFL:
545 flags = arg & 0xf;
546 if (arg & 0x8050) flags |= O_SYNC;
547 if (arg & 0x80) flags |= O_NONBLOCK;
548 return sys_fcntl(fd, cmd, (long)flags);
549 case SOL_F_GETLK:
550 case SOL_F_SETLK:
551 case SOL_F_SETLKW:
552 {
553 struct flock f;
554 struct sol_flock __user *p = A(arg);
555 mm_segment_t old_fs = get_fs();
556
557 switch (cmd) {
558 case SOL_F_GETLK: cmd = F_GETLK; break;
559 case SOL_F_SETLK: cmd = F_SETLK; break;
560 case SOL_F_SETLKW: cmd = F_SETLKW; break;
561 }
562
563 if (get_user (f.l_type, &p->l_type) ||
564 __get_user (f.l_whence, &p->l_whence) ||
565 __get_user (f.l_start, &p->l_start) ||
566 __get_user (f.l_len, &p->l_len) ||
567 __get_user (f.l_pid, &p->l_sysid))
568 return -EFAULT;
569
570 set_fs(KERNEL_DS);
571 ret = sys_fcntl(fd, cmd, (unsigned long)&f);
572 set_fs(old_fs);
573
574 if (__put_user (f.l_type, &p->l_type) ||
575 __put_user (f.l_whence, &p->l_whence) ||
576 __put_user (f.l_start, &p->l_start) ||
577 __put_user (f.l_len, &p->l_len) ||
578 __put_user (f.l_pid, &p->l_pid) ||
579 __put_user (0, &p->l_sysid))
580 return -EFAULT;
581
582 return ret;
583 }
584 case SOL_F_FREESP:
585 {
586 int length;
587 int (*sys_newftruncate)(unsigned int, unsigned long)=
588 (int (*)(unsigned int, unsigned long))SYS(ftruncate);
589
590 if (get_user(length, &((struct sol_flock __user *)A(arg))->l_start))
591 return -EFAULT;
592
593 return sys_newftruncate(fd, length);
594 }
595 };
596 return -EINVAL;
597}
598
599asmlinkage int solaris_ulimit(int cmd, int val)
600{
601 switch (cmd) {
602 case 1: /* UL_GETFSIZE - in 512B chunks */
603 return current->signal->rlim[RLIMIT_FSIZE].rlim_cur >> 9;
604 case 2: /* UL_SETFSIZE */
605 if ((unsigned long)val > (LONG_MAX>>9)) return -ERANGE;
606 val <<= 9;
607 task_lock(current->group_leader);
608 if (val > current->signal->rlim[RLIMIT_FSIZE].rlim_max) {
609 if (!capable(CAP_SYS_RESOURCE)) {
610 task_unlock(current->group_leader);
611 return -EPERM;
612 }
613 current->signal->rlim[RLIMIT_FSIZE].rlim_max = val;
614 }
615 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = val;
616 task_unlock(current->group_leader);
617 return 0;
618 case 3: /* UL_GMEMLIM */
619 return current->signal->rlim[RLIMIT_DATA].rlim_cur;
620 case 4: /* UL_GDESLIM */
621 return NR_OPEN;
622 }
623 return -EINVAL;
624}
625
626/* At least at the time I'm writing this, Linux doesn't have ACLs, so we
627 just fake this */
628asmlinkage int solaris_acl(u32 filename, int cmd, int nentries, u32 aclbufp)
629{
630 return -ENOSYS;
631}
632
633asmlinkage int solaris_facl(unsigned int fd, int cmd, int nentries, u32 aclbufp)
634{
635 return -ENOSYS;
636}
637
638asmlinkage int solaris_pread(unsigned int fd, char __user *buf, u32 count, u32 pos)
639{
640 ssize_t (*sys_pread64)(unsigned int, char __user *, size_t, loff_t) =
641 (ssize_t (*)(unsigned int, char __user *, size_t, loff_t))SYS(pread64);
642
643 return sys_pread64(fd, buf, count, (loff_t)pos);
644}
645
646asmlinkage int solaris_pwrite(unsigned int fd, char __user *buf, u32 count, u32 pos)
647{
648 ssize_t (*sys_pwrite64)(unsigned int, char __user *, size_t, loff_t) =
649 (ssize_t (*)(unsigned int, char __user *, size_t, loff_t))SYS(pwrite64);
650
651 return sys_pwrite64(fd, buf, count, (loff_t)pos);
652}
653
654/* POSIX.1 names */
655#define _PC_LINK_MAX 1
656#define _PC_MAX_CANON 2
657#define _PC_MAX_INPUT 3
658#define _PC_NAME_MAX 4
659#define _PC_PATH_MAX 5
660#define _PC_PIPE_BUF 6
661#define _PC_NO_TRUNC 7
662#define _PC_VDISABLE 8
663#define _PC_CHOWN_RESTRICTED 9
664/* POSIX.4 names */
665#define _PC_ASYNC_IO 10
666#define _PC_PRIO_IO 11
667#define _PC_SYNC_IO 12
668#define _PC_LAST 12
669
670/* This is not a real and complete implementation yet, just to keep
671 * the easy Solaris binaries happy.
672 */
673asmlinkage int solaris_fpathconf(int fd, int name)
674{
675 int ret;
676
677 switch(name) {
678 case _PC_LINK_MAX:
679 ret = LINK_MAX;
680 break;
681 case _PC_MAX_CANON:
682 ret = MAX_CANON;
683 break;
684 case _PC_MAX_INPUT:
685 ret = MAX_INPUT;
686 break;
687 case _PC_NAME_MAX:
688 ret = NAME_MAX;
689 break;
690 case _PC_PATH_MAX:
691 ret = PATH_MAX;
692 break;
693 case _PC_PIPE_BUF:
694 ret = PIPE_BUF;
695 break;
696 case _PC_CHOWN_RESTRICTED:
697 ret = 1;
698 break;
699 case _PC_NO_TRUNC:
700 case _PC_VDISABLE:
701 ret = 0;
702 break;
703 default:
704 ret = -EINVAL;
705 break;
706 }
707 return ret;
708}
709
710asmlinkage int solaris_pathconf(u32 path, int name)
711{
712 return solaris_fpathconf(0, name);
713}
714
715/* solaris_llseek returns long long - quite difficult */
716asmlinkage long solaris_llseek(struct pt_regs *regs, u32 off_hi, u32 off_lo, int whence)
717{
718 int (*sys_llseek)(unsigned int, unsigned long, unsigned long, loff_t __user *, unsigned int) =
719 (int (*)(unsigned int, unsigned long, unsigned long, loff_t __user *, unsigned int))SYS(_llseek);
720 int ret;
721 mm_segment_t old_fs = get_fs();
722 loff_t retval;
723
724 set_fs(KERNEL_DS);
725 ret = sys_llseek((unsigned int)regs->u_regs[UREG_I0], off_hi, off_lo, &retval, whence);
726 set_fs(old_fs);
727 if (ret < 0) return ret;
728 regs->u_regs[UREG_I1] = (u32)retval;
729 return (retval >> 32);
730}
731
732/* Have to mask out all but lower 3 bits */
733asmlinkage int solaris_access(u32 filename, long mode)
734{
735 int (*sys_access)(const char __user *, int) =
736 (int (*)(const char __user *, int))SYS(access);
737
738 return sys_access(A(filename), mode & 7);
739}
diff --git a/arch/sparc64/solaris/ioctl.c b/arch/sparc64/solaris/ioctl.c
new file mode 100644
index 000000000000..cac0a1cf0050
--- /dev/null
+++ b/arch/sparc64/solaris/ioctl.c
@@ -0,0 +1,820 @@
1/* $Id: ioctl.c,v 1.17 2002/02/08 03:57:14 davem Exp $
2 * ioctl.c: Solaris ioctl emulation.
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997,1998 Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
6 *
7 * Streams & timod emulation based on code
8 * Copyright (C) 1995, 1996 Mike Jagdis (jaggy@purplet.demon.co.uk)
9 *
10 * 1999-08-19 Implemented solaris 'm' (mag tape) and
11 * 'O' (openprom) ioctls, by Jason Rappleye
12 * (rappleye@ccr.buffalo.edu)
13 */
14
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/sched.h>
18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/syscalls.h>
21#include <linux/ioctl.h>
22#include <linux/fs.h>
23#include <linux/file.h>
24#include <linux/netdevice.h>
25#include <linux/mtio.h>
26#include <linux/time.h>
27#include <linux/compat.h>
28
29#include <net/sock.h>
30
31#include <asm/uaccess.h>
32#include <asm/termios.h>
33#include <asm/openpromio.h>
34
35#include "conv.h"
36#include "socksys.h"
37
38extern asmlinkage int compat_sys_ioctl(unsigned int fd, unsigned int cmd,
39 u32 arg);
40asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg);
41
42extern int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
43 char __user *data_buf, int data_len, int flags);
44extern int timod_getmsg(unsigned int fd, char __user *ctl_buf, int ctl_maxlen, int __user *ctl_len,
45 char __user *data_buf, int data_maxlen, int __user *data_len, int *flags);
46
47/* termio* stuff {{{ */
48
49struct solaris_termios {
50 u32 c_iflag;
51 u32 c_oflag;
52 u32 c_cflag;
53 u32 c_lflag;
54 u8 c_cc[19];
55};
56
57struct solaris_termio {
58 u16 c_iflag;
59 u16 c_oflag;
60 u16 c_cflag;
61 u16 c_lflag;
62 s8 c_line;
63 u8 c_cc[8];
64};
65
66struct solaris_termiox {
67 u16 x_hflag;
68 u16 x_cflag;
69 u16 x_rflag[5];
70 u16 x_sflag;
71};
72
73static u32 solaris_to_linux_cflag(u32 cflag)
74{
75 cflag &= 0x7fdff000;
76 if (cflag & 0x200000) {
77 int baud = cflag & 0xf;
78 cflag &= ~0x20000f;
79 switch (baud) {
80 case 0: baud = B57600; break;
81 case 1: baud = B76800; break;
82 case 2: baud = B115200; break;
83 case 3: baud = B153600; break;
84 case 4: baud = B230400; break;
85 case 5: baud = B307200; break;
86 case 6: baud = B460800; break;
87 }
88 cflag |= CBAUDEX | baud;
89 }
90 return cflag;
91}
92
93static u32 linux_to_solaris_cflag(u32 cflag)
94{
95 cflag &= ~(CMSPAR | CIBAUD);
96 if (cflag & CBAUDEX) {
97 int baud = cflag & CBAUD;
98 cflag &= ~CBAUD;
99 switch (baud) {
100 case B57600: baud = 0; break;
101 case B76800: baud = 1; break;
102 case B115200: baud = 2; break;
103 case B153600: baud = 3; break;
104 case B230400: baud = 4; break;
105 case B307200: baud = 5; break;
106 case B460800: baud = 6; break;
107 case B614400: baud = 7; break;
108 case B921600: baud = 8; break;
109#if 0
110 case B1843200: baud = 9; break;
111#endif
112 }
113 cflag |= 0x200000 | baud;
114 }
115 return cflag;
116}
117
118static inline int linux_to_solaris_termio(unsigned int fd, unsigned int cmd, u32 arg)
119{
120 struct solaris_termio __user *p = A(arg);
121 int ret;
122
123 ret = sys_ioctl(fd, cmd, (unsigned long)p);
124 if (!ret) {
125 u32 cflag;
126
127 if (__get_user (cflag, &p->c_cflag))
128 return -EFAULT;
129 cflag = linux_to_solaris_cflag(cflag);
130 if (__put_user (cflag, &p->c_cflag))
131 return -EFAULT;
132 }
133 return ret;
134}
135
136static int solaris_to_linux_termio(unsigned int fd, unsigned int cmd, u32 arg)
137{
138 int ret;
139 struct solaris_termio s;
140 mm_segment_t old_fs = get_fs();
141
142 if (copy_from_user (&s, (struct solaris_termio __user *)A(arg), sizeof(struct solaris_termio)))
143 return -EFAULT;
144 s.c_cflag = solaris_to_linux_cflag(s.c_cflag);
145 set_fs(KERNEL_DS);
146 ret = sys_ioctl(fd, cmd, (unsigned long)&s);
147 set_fs(old_fs);
148 return ret;
149}
150
151static inline int linux_to_solaris_termios(unsigned int fd, unsigned int cmd, u32 arg)
152{
153 int ret;
154 struct solaris_termios s;
155 mm_segment_t old_fs = get_fs();
156
157 set_fs(KERNEL_DS);
158 ret = sys_ioctl(fd, cmd, (unsigned long)&s);
159 set_fs(old_fs);
160 if (!ret) {
161 struct solaris_termios __user *p = A(arg);
162 if (put_user (s.c_iflag, &p->c_iflag) ||
163 __put_user (s.c_oflag, &p->c_oflag) ||
164 __put_user (linux_to_solaris_cflag(s.c_cflag), &p->c_cflag) ||
165 __put_user (s.c_lflag, &p->c_lflag) ||
166 __copy_to_user (p->c_cc, s.c_cc, 16) ||
167 __clear_user (p->c_cc + 16, 2))
168 return -EFAULT;
169 }
170 return ret;
171}
172
173static int solaris_to_linux_termios(unsigned int fd, unsigned int cmd, u32 arg)
174{
175 int ret;
176 struct solaris_termios s;
177 struct solaris_termios __user *p = A(arg);
178 mm_segment_t old_fs = get_fs();
179
180 set_fs(KERNEL_DS);
181 ret = sys_ioctl(fd, TCGETS, (unsigned long)&s);
182 set_fs(old_fs);
183 if (ret) return ret;
184 if (put_user (s.c_iflag, &p->c_iflag) ||
185 __put_user (s.c_oflag, &p->c_oflag) ||
186 __put_user (s.c_cflag, &p->c_cflag) ||
187 __put_user (s.c_lflag, &p->c_lflag) ||
188 __copy_from_user (s.c_cc, p->c_cc, 16))
189 return -EFAULT;
190 s.c_cflag = solaris_to_linux_cflag(s.c_cflag);
191 set_fs(KERNEL_DS);
192 ret = sys_ioctl(fd, cmd, (unsigned long)&s);
193 set_fs(old_fs);
194 return ret;
195}
196
197static inline int solaris_T(unsigned int fd, unsigned int cmd, u32 arg)
198{
199 switch (cmd & 0xff) {
200 case 1: /* TCGETA */
201 return linux_to_solaris_termio(fd, TCGETA, arg);
202 case 2: /* TCSETA */
203 return solaris_to_linux_termio(fd, TCSETA, arg);
204 case 3: /* TCSETAW */
205 return solaris_to_linux_termio(fd, TCSETAW, arg);
206 case 4: /* TCSETAF */
207 return solaris_to_linux_termio(fd, TCSETAF, arg);
208 case 5: /* TCSBRK */
209 return sys_ioctl(fd, TCSBRK, arg);
210 case 6: /* TCXONC */
211 return sys_ioctl(fd, TCXONC, arg);
212 case 7: /* TCFLSH */
213 return sys_ioctl(fd, TCFLSH, arg);
214 case 13: /* TCGETS */
215 return linux_to_solaris_termios(fd, TCGETS, arg);
216 case 14: /* TCSETS */
217 return solaris_to_linux_termios(fd, TCSETS, arg);
218 case 15: /* TCSETSW */
219 return solaris_to_linux_termios(fd, TCSETSW, arg);
220 case 16: /* TCSETSF */
221 return solaris_to_linux_termios(fd, TCSETSF, arg);
222 case 103: /* TIOCSWINSZ */
223 return sys_ioctl(fd, TIOCSWINSZ, arg);
224 case 104: /* TIOCGWINSZ */
225 return sys_ioctl(fd, TIOCGWINSZ, arg);
226 }
227 return -ENOSYS;
228}
229
230static inline int solaris_t(unsigned int fd, unsigned int cmd, u32 arg)
231{
232 switch (cmd & 0xff) {
233 case 20: /* TIOCGPGRP */
234 return sys_ioctl(fd, TIOCGPGRP, arg);
235 case 21: /* TIOCSPGRP */
236 return sys_ioctl(fd, TIOCSPGRP, arg);
237 }
238 return -ENOSYS;
239}
240
241/* }}} */
242
243/* A pseudo STREAMS support {{{ */
244
245struct strioctl {
246 int cmd, timeout, len;
247 u32 data;
248};
249
250struct solaris_si_sockparams {
251 int sp_family;
252 int sp_type;
253 int sp_protocol;
254};
255
256struct solaris_o_si_udata {
257 int tidusize;
258 int addrsize;
259 int optsize;
260 int etsdusize;
261 int servtype;
262 int so_state;
263 int so_options;
264 int tsdusize;
265};
266
267struct solaris_si_udata {
268 int tidusize;
269 int addrsize;
270 int optsize;
271 int etsdusize;
272 int servtype;
273 int so_state;
274 int so_options;
275 int tsdusize;
276 struct solaris_si_sockparams sockparams;
277};
278
279#define SOLARIS_MODULE_TIMOD 0
280#define SOLARIS_MODULE_SOCKMOD 1
281#define SOLARIS_MODULE_MAX 2
282
283static struct module_info {
284 const char *name;
285 /* can be expanded further if needed */
286} module_table[ SOLARIS_MODULE_MAX + 1 ] = {
287 /* the ordering here must match the module numbers above! */
288 { "timod" },
289 { "sockmod" },
290 { NULL }
291};
292
293static inline int solaris_sockmod(unsigned int fd, unsigned int cmd, u32 arg)
294{
295 struct inode *ino;
296 /* I wonder which of these tests are superfluous... --patrik */
297 spin_lock(&current->files->file_lock);
298 if (! current->files->fd[fd] ||
299 ! current->files->fd[fd]->f_dentry ||
300 ! (ino = current->files->fd[fd]->f_dentry->d_inode) ||
301 ! S_ISSOCK(ino->i_mode)) {
302 spin_unlock(&current->files->file_lock);
303 return TBADF;
304 }
305 spin_unlock(&current->files->file_lock);
306
307 switch (cmd & 0xff) {
308 case 109: /* SI_SOCKPARAMS */
309 {
310 struct solaris_si_sockparams si;
311 if (copy_from_user (&si, A(arg), sizeof(si)))
312 return (EFAULT << 8) | TSYSERR;
313
314 /* Should we modify socket ino->socket_i.ops and type? */
315 return 0;
316 }
317 case 110: /* SI_GETUDATA */
318 {
319 int etsdusize, servtype;
320 struct solaris_si_udata __user *p = A(arg);
321 switch (SOCKET_I(ino)->type) {
322 case SOCK_STREAM:
323 etsdusize = 1;
324 servtype = 2;
325 break;
326 default:
327 etsdusize = -2;
328 servtype = 3;
329 break;
330 }
331 if (put_user(16384, &p->tidusize) ||
332 __put_user(sizeof(struct sockaddr), &p->addrsize) ||
333 __put_user(-1, &p->optsize) ||
334 __put_user(etsdusize, &p->etsdusize) ||
335 __put_user(servtype, &p->servtype) ||
336 __put_user(0, &p->so_state) ||
337 __put_user(0, &p->so_options) ||
338 __put_user(16384, &p->tsdusize) ||
339 __put_user(SOCKET_I(ino)->ops->family, &p->sockparams.sp_family) ||
340 __put_user(SOCKET_I(ino)->type, &p->sockparams.sp_type) ||
341 __put_user(SOCKET_I(ino)->ops->family, &p->sockparams.sp_protocol))
342 return (EFAULT << 8) | TSYSERR;
343 return 0;
344 }
345 case 101: /* O_SI_GETUDATA */
346 {
347 int etsdusize, servtype;
348 struct solaris_o_si_udata __user *p = A(arg);
349 switch (SOCKET_I(ino)->type) {
350 case SOCK_STREAM:
351 etsdusize = 1;
352 servtype = 2;
353 break;
354 default:
355 etsdusize = -2;
356 servtype = 3;
357 break;
358 }
359 if (put_user(16384, &p->tidusize) ||
360 __put_user(sizeof(struct sockaddr), &p->addrsize) ||
361 __put_user(-1, &p->optsize) ||
362 __put_user(etsdusize, &p->etsdusize) ||
363 __put_user(servtype, &p->servtype) ||
364 __put_user(0, &p->so_state) ||
365 __put_user(0, &p->so_options) ||
366 __put_user(16384, &p->tsdusize))
367 return (EFAULT << 8) | TSYSERR;
368 return 0;
369 }
370 case 102: /* SI_SHUTDOWN */
371 case 103: /* SI_LISTEN */
372 case 104: /* SI_SETMYNAME */
373 case 105: /* SI_SETPEERNAME */
374 case 106: /* SI_GETINTRANSIT */
375 case 107: /* SI_TCL_LINK */
376 case 108: /* SI_TCL_UNLINK */
377 ;
378 }
379 return TNOTSUPPORT;
380}
381
382static inline int solaris_timod(unsigned int fd, unsigned int cmd, u32 arg,
383 int len, int __user *len_p)
384{
385 int ret;
386
387 switch (cmd & 0xff) {
388 case 141: /* TI_OPTMGMT */
389 {
390 int i;
391 u32 prim;
392 SOLD("TI_OPMGMT entry");
393 ret = timod_putmsg(fd, A(arg), len, NULL, -1, 0);
394 SOLD("timod_putmsg() returned");
395 if (ret)
396 return (-ret << 8) | TSYSERR;
397 i = MSG_HIPRI;
398 SOLD("calling timod_getmsg()");
399 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
400 SOLD("timod_getmsg() returned");
401 if (ret)
402 return (-ret << 8) | TSYSERR;
403 SOLD("ret ok");
404 if (get_user(prim, (u32 __user *)A(arg)))
405 return (EFAULT << 8) | TSYSERR;
406 SOLD("got prim");
407 if (prim == T_ERROR_ACK) {
408 u32 tmp, tmp2;
409 SOLD("prim is T_ERROR_ACK");
410 if (get_user(tmp, (u32 __user *)A(arg)+3) ||
411 get_user(tmp2, (u32 __user *)A(arg)+2))
412 return (EFAULT << 8) | TSYSERR;
413 return (tmp2 << 8) | tmp;
414 }
415 SOLD("TI_OPMGMT return 0");
416 return 0;
417 }
418 case 142: /* TI_BIND */
419 {
420 int i;
421 u32 prim;
422 SOLD("TI_BIND entry");
423 ret = timod_putmsg(fd, A(arg), len, NULL, -1, 0);
424 SOLD("timod_putmsg() returned");
425 if (ret)
426 return (-ret << 8) | TSYSERR;
427 len = 1024; /* Solaris allows arbitrary return size */
428 i = MSG_HIPRI;
429 SOLD("calling timod_getmsg()");
430 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
431 SOLD("timod_getmsg() returned");
432 if (ret)
433 return (-ret << 8) | TSYSERR;
434 SOLD("ret ok");
435 if (get_user(prim, (u32 __user *)A(arg)))
436 return (EFAULT << 8) | TSYSERR;
437 SOLD("got prim");
438 if (prim == T_ERROR_ACK) {
439 u32 tmp, tmp2;
440 SOLD("prim is T_ERROR_ACK");
441 if (get_user(tmp, (u32 __user *)A(arg)+3) ||
442 get_user(tmp2, (u32 __user *)A(arg)+2))
443 return (EFAULT << 8) | TSYSERR;
444 return (tmp2 << 8) | tmp;
445 }
446 SOLD("no ERROR_ACK requested");
447 if (prim != T_OK_ACK)
448 return TBADSEQ;
449 SOLD("OK_ACK requested");
450 i = MSG_HIPRI;
451 SOLD("calling timod_getmsg()");
452 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
453 SOLD("timod_getmsg() returned");
454 if (ret)
455 return (-ret << 8) | TSYSERR;
456 SOLD("TI_BIND return ok");
457 return 0;
458 }
459 case 140: /* TI_GETINFO */
460 case 143: /* TI_UNBIND */
461 case 144: /* TI_GETMYNAME */
462 case 145: /* TI_GETPEERNAME */
463 case 146: /* TI_SETMYNAME */
464 case 147: /* TI_SETPEERNAME */
465 ;
466 }
467 return TNOTSUPPORT;
468}
469
470static inline int solaris_S(struct file *filp, unsigned int fd, unsigned int cmd, u32 arg)
471{
472 char *p;
473 int ret;
474 mm_segment_t old_fs;
475 struct strioctl si;
476 struct inode *ino;
477 struct sol_socket_struct *sock;
478 struct module_info *mi;
479
480 ino = filp->f_dentry->d_inode;
481 if (!S_ISSOCK(ino->i_mode))
482 return -EBADF;
483 sock = filp->private_data;
484 if (! sock) {
485 printk("solaris_S: NULL private_data\n");
486 return -EBADF;
487 }
488 if (sock->magic != SOLARIS_SOCKET_MAGIC) {
489 printk("solaris_S: invalid magic\n");
490 return -EBADF;
491 }
492
493
494 switch (cmd & 0xff) {
495 case 1: /* I_NREAD */
496 return -ENOSYS;
497 case 2: /* I_PUSH */
498 {
499 p = getname (A(arg));
500 if (IS_ERR (p))
501 return PTR_ERR(p);
502 ret = -EINVAL;
503 for (mi = module_table; mi->name; mi++) {
504 if (strcmp(mi->name, p) == 0) {
505 sol_module m;
506 if (sock->modcount >= MAX_NR_STREAM_MODULES) {
507 ret = -ENXIO;
508 break;
509 }
510 m = (sol_module) (mi - module_table);
511 sock->module[sock->modcount++] = m;
512 ret = 0;
513 break;
514 }
515 }
516 putname (p);
517 return ret;
518 }
519 case 3: /* I_POP */
520 if (sock->modcount <= 0) return -EINVAL;
521 sock->modcount--;
522 return 0;
523 case 4: /* I_LOOK */
524 {
525 const char *p;
526 if (sock->modcount <= 0) return -EINVAL;
527 p = module_table[(unsigned)sock->module[sock->modcount]].name;
528 if (copy_to_user (A(arg), p, strlen(p)))
529 return -EFAULT;
530 return 0;
531 }
532 case 5: /* I_FLUSH */
533 return 0;
534 case 8: /* I_STR */
535 if (copy_from_user(&si, A(arg), sizeof(struct strioctl)))
536 return -EFAULT;
537 /* We ignore what module is actually at the top of stack. */
538 switch ((si.cmd >> 8) & 0xff) {
539 case 'I':
540 return solaris_sockmod(fd, si.cmd, si.data);
541 case 'T':
542 return solaris_timod(fd, si.cmd, si.data, si.len,
543 &((struct strioctl __user *)A(arg))->len);
544 default:
545 return solaris_ioctl(fd, si.cmd, si.data);
546 }
547 case 9: /* I_SETSIG */
548 return sys_ioctl(fd, FIOSETOWN, current->pid);
549 case 10: /* I_GETSIG */
550 old_fs = get_fs();
551 set_fs(KERNEL_DS);
552 sys_ioctl(fd, FIOGETOWN, (unsigned long)&ret);
553 set_fs(old_fs);
554 if (ret == current->pid) return 0x3ff;
555 else return -EINVAL;
556 case 11: /* I_FIND */
557 {
558 int i;
559 p = getname (A(arg));
560 if (IS_ERR (p))
561 return PTR_ERR(p);
562 ret = 0;
563 for (i = 0; i < sock->modcount; i++) {
564 unsigned m = sock->module[i];
565 if (strcmp(module_table[m].name, p) == 0) {
566 ret = 1;
567 break;
568 }
569 }
570 putname (p);
571 return ret;
572 }
573 case 19: /* I_SWROPT */
574 case 32: /* I_SETCLTIME */
575 return 0; /* Lie */
576 }
577 return -ENOSYS;
578}
579
580static inline int solaris_s(unsigned int fd, unsigned int cmd, u32 arg)
581{
582 switch (cmd & 0xff) {
583 case 0: /* SIOCSHIWAT */
584 case 2: /* SIOCSLOWAT */
585 return 0; /* We don't support them */
586 case 1: /* SIOCGHIWAT */
587 case 3: /* SIOCGLOWAT */
588 if (put_user (0, (u32 __user *)A(arg)))
589 return -EFAULT;
590 return 0; /* Lie */
591 case 7: /* SIOCATMARK */
592 return sys_ioctl(fd, SIOCATMARK, arg);
593 case 8: /* SIOCSPGRP */
594 return sys_ioctl(fd, SIOCSPGRP, arg);
595 case 9: /* SIOCGPGRP */
596 return sys_ioctl(fd, SIOCGPGRP, arg);
597 }
598 return -ENOSYS;
599}
600
601static inline int solaris_r(unsigned int fd, unsigned int cmd, u32 arg)
602{
603 switch (cmd & 0xff) {
604 case 10: /* SIOCADDRT */
605 return compat_sys_ioctl(fd, SIOCADDRT, arg);
606 case 11: /* SIOCDELRT */
607 return compat_sys_ioctl(fd, SIOCDELRT, arg);
608 }
609 return -ENOSYS;
610}
611
612static inline int solaris_i(unsigned int fd, unsigned int cmd, u32 arg)
613{
614 switch (cmd & 0xff) {
615 case 12: /* SIOCSIFADDR */
616 return compat_sys_ioctl(fd, SIOCSIFADDR, arg);
617 case 13: /* SIOCGIFADDR */
618 return compat_sys_ioctl(fd, SIOCGIFADDR, arg);
619 case 14: /* SIOCSIFDSTADDR */
620 return compat_sys_ioctl(fd, SIOCSIFDSTADDR, arg);
621 case 15: /* SIOCGIFDSTADDR */
622 return compat_sys_ioctl(fd, SIOCGIFDSTADDR, arg);
623 case 16: /* SIOCSIFFLAGS */
624 return compat_sys_ioctl(fd, SIOCSIFFLAGS, arg);
625 case 17: /* SIOCGIFFLAGS */
626 return compat_sys_ioctl(fd, SIOCGIFFLAGS, arg);
627 case 18: /* SIOCSIFMEM */
628 return compat_sys_ioctl(fd, SIOCSIFMEM, arg);
629 case 19: /* SIOCGIFMEM */
630 return compat_sys_ioctl(fd, SIOCGIFMEM, arg);
631 case 20: /* SIOCGIFCONF */
632 return compat_sys_ioctl(fd, SIOCGIFCONF, arg);
633 case 21: /* SIOCSIFMTU */
634 return compat_sys_ioctl(fd, SIOCSIFMTU, arg);
635 case 22: /* SIOCGIFMTU */
636 return compat_sys_ioctl(fd, SIOCGIFMTU, arg);
637 case 23: /* SIOCGIFBRDADDR */
638 return compat_sys_ioctl(fd, SIOCGIFBRDADDR, arg);
639 case 24: /* SIOCSIFBRDADDR */
640 return compat_sys_ioctl(fd, SIOCSIFBRDADDR, arg);
641 case 25: /* SIOCGIFNETMASK */
642 return compat_sys_ioctl(fd, SIOCGIFNETMASK, arg);
643 case 26: /* SIOCSIFNETMASK */
644 return compat_sys_ioctl(fd, SIOCSIFNETMASK, arg);
645 case 27: /* SIOCGIFMETRIC */
646 return compat_sys_ioctl(fd, SIOCGIFMETRIC, arg);
647 case 28: /* SIOCSIFMETRIC */
648 return compat_sys_ioctl(fd, SIOCSIFMETRIC, arg);
649 case 30: /* SIOCSARP */
650 return compat_sys_ioctl(fd, SIOCSARP, arg);
651 case 31: /* SIOCGARP */
652 return compat_sys_ioctl(fd, SIOCGARP, arg);
653 case 32: /* SIOCDARP */
654 return compat_sys_ioctl(fd, SIOCDARP, arg);
655 case 52: /* SIOCGETNAME */
656 case 53: /* SIOCGETPEER */
657 {
658 struct sockaddr uaddr;
659 int uaddr_len = sizeof(struct sockaddr), ret;
660 long args[3];
661 mm_segment_t old_fs = get_fs();
662 int (*sys_socketcall)(int, unsigned long *) =
663 (int (*)(int, unsigned long *))SYS(socketcall);
664
665 args[0] = fd; args[1] = (long)&uaddr; args[2] = (long)&uaddr_len;
666 set_fs(KERNEL_DS);
667 ret = sys_socketcall(((cmd & 0xff) == 52) ? SYS_GETSOCKNAME : SYS_GETPEERNAME,
668 args);
669 set_fs(old_fs);
670 if (ret >= 0) {
671 if (copy_to_user(A(arg), &uaddr, uaddr_len))
672 return -EFAULT;
673 }
674 return ret;
675 }
676#if 0
677 case 86: /* SIOCSOCKSYS */
678 return socksys_syscall(fd, arg);
679#endif
680 case 87: /* SIOCGIFNUM */
681 {
682 struct net_device *d;
683 int i = 0;
684
685 read_lock_bh(&dev_base_lock);
686 for (d = dev_base; d; d = d->next) i++;
687 read_unlock_bh(&dev_base_lock);
688
689 if (put_user (i, (int __user *)A(arg)))
690 return -EFAULT;
691 return 0;
692 }
693 }
694 return -ENOSYS;
695}
696
697static int solaris_m(unsigned int fd, unsigned int cmd, u32 arg)
698{
699 int ret;
700
701 switch (cmd & 0xff) {
702 case 1: /* MTIOCTOP */
703 ret = sys_ioctl(fd, MTIOCTOP, (unsigned long)&arg);
704 break;
705 case 2: /* MTIOCGET */
706 ret = sys_ioctl(fd, MTIOCGET, (unsigned long)&arg);
707 break;
708 case 3: /* MTIOCGETDRIVETYPE */
709 case 4: /* MTIOCPERSISTENT */
710 case 5: /* MTIOCPERSISTENTSTATUS */
711 case 6: /* MTIOCLRERR */
712 case 7: /* MTIOCGUARANTEEDORDER */
713 case 8: /* MTIOCRESERVE */
714 case 9: /* MTIOCRELEASE */
715 case 10: /* MTIOCFORCERESERVE */
716 case 13: /* MTIOCSTATE */
717 case 14: /* MTIOCREADIGNOREILI */
718 case 15: /* MTIOCREADIGNOREEOFS */
719 case 16: /* MTIOCSHORTFMK */
720 default:
721 ret = -ENOSYS; /* linux doesn't support these */
722 break;
723 };
724
725 return ret;
726}
727
728static int solaris_O(unsigned int fd, unsigned int cmd, u32 arg)
729{
730 int ret = -EINVAL;
731
732 switch (cmd & 0xff) {
733 case 1: /* OPROMGETOPT */
734 ret = sys_ioctl(fd, OPROMGETOPT, arg);
735 break;
736 case 2: /* OPROMSETOPT */
737 ret = sys_ioctl(fd, OPROMSETOPT, arg);
738 break;
739 case 3: /* OPROMNXTOPT */
740 ret = sys_ioctl(fd, OPROMNXTOPT, arg);
741 break;
742 case 4: /* OPROMSETOPT2 */
743 ret = sys_ioctl(fd, OPROMSETOPT2, arg);
744 break;
745 case 5: /* OPROMNEXT */
746 ret = sys_ioctl(fd, OPROMNEXT, arg);
747 break;
748 case 6: /* OPROMCHILD */
749 ret = sys_ioctl(fd, OPROMCHILD, arg);
750 break;
751 case 7: /* OPROMGETPROP */
752 ret = sys_ioctl(fd, OPROMGETPROP, arg);
753 break;
754 case 8: /* OPROMNXTPROP */
755 ret = sys_ioctl(fd, OPROMNXTPROP, arg);
756 break;
757 case 9: /* OPROMU2P */
758 ret = sys_ioctl(fd, OPROMU2P, arg);
759 break;
760 case 10: /* OPROMGETCONS */
761 ret = sys_ioctl(fd, OPROMGETCONS, arg);
762 break;
763 case 11: /* OPROMGETFBNAME */
764 ret = sys_ioctl(fd, OPROMGETFBNAME, arg);
765 break;
766 case 12: /* OPROMGETBOOTARGS */
767 ret = sys_ioctl(fd, OPROMGETBOOTARGS, arg);
768 break;
769 case 13: /* OPROMGETVERSION */
770 case 14: /* OPROMPATH2DRV */
771 case 15: /* OPROMDEV2PROMNAME */
772 case 16: /* OPROMPROM2DEVNAME */
773 case 17: /* OPROMGETPROPLEN */
774 default:
775 ret = -EINVAL;
776 break;
777 };
778 return ret;
779}
780
781/* }}} */
782
783asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg)
784{
785 struct file *filp;
786 int error = -EBADF;
787
788 filp = fget(fd);
789 if (!filp)
790 goto out;
791
792 lock_kernel();
793 error = -EFAULT;
794 switch ((cmd >> 8) & 0xff) {
795 case 'S': error = solaris_S(filp, fd, cmd, arg); break;
796 case 'T': error = solaris_T(fd, cmd, arg); break;
797 case 'i': error = solaris_i(fd, cmd, arg); break;
798 case 'r': error = solaris_r(fd, cmd, arg); break;
799 case 's': error = solaris_s(fd, cmd, arg); break;
800 case 't': error = solaris_t(fd, cmd, arg); break;
801 case 'f': error = sys_ioctl(fd, cmd, arg); break;
802 case 'm': error = solaris_m(fd, cmd, arg); break;
803 case 'O': error = solaris_O(fd, cmd, arg); break;
804 default:
805 error = -ENOSYS;
806 break;
807 }
808 unlock_kernel();
809 fput(filp);
810out:
811 if (error == -ENOSYS) {
812 unsigned char c = cmd>>8;
813
814 if (c < ' ' || c > 126) c = '.';
815 printk("solaris_ioctl: Unknown cmd fd(%d) cmd(%08x '%c') arg(%08x)\n",
816 (int)fd, (unsigned int)cmd, c, (unsigned int)arg);
817 error = -EINVAL;
818 }
819 return error;
820}
diff --git a/arch/sparc64/solaris/ipc.c b/arch/sparc64/solaris/ipc.c
new file mode 100644
index 000000000000..8cef5fd57b2e
--- /dev/null
+++ b/arch/sparc64/solaris/ipc.c
@@ -0,0 +1,127 @@
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
22struct 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
33struct 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
55asmlinkage long solaris_shmsys(int cmd, u32 arg1, u32 arg2, u32 arg3)
56{
57 int (*sys_ipc)(unsigned,int,int,unsigned long,void __user *,long) =
58 (int (*)(unsigned,int,int,unsigned long,void __user *,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, 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 struct solaris_shmid_ds __user *p = A(arg3);
82
83 if (get_user (s.shm_perm.uid, &p->shm_perm.uid) ||
84 __get_user (s.shm_perm.gid, &p->shm_perm.gid) ||
85 __get_user (s.shm_perm.mode, &p->shm_perm.mode))
86 return -EFAULT;
87 old_fs = get_fs();
88 set_fs(KERNEL_DS);
89 ret = sys_ipc(SHMCTL, arg1, IPC_SET, 0, &s, 0);
90 set_fs(old_fs);
91 return ret;
92 }
93 case 12: /* IPC_STAT */
94 {
95 struct shmid_ds s;
96 struct solaris_shmid_ds __user *p = A(arg3);
97
98 old_fs = get_fs();
99 set_fs(KERNEL_DS);
100 ret = sys_ipc(SHMCTL, arg1, IPC_SET, 0, &s, 0);
101 set_fs(old_fs);
102 if (put_user (s.shm_perm.uid, &(p->shm_perm.uid)) ||
103 __put_user (s.shm_perm.gid, &(p->shm_perm.gid)) ||
104 __put_user (s.shm_perm.cuid, &(p->shm_perm.cuid)) ||
105 __put_user (s.shm_perm.cgid, &(p->shm_perm.cgid)) ||
106 __put_user (s.shm_perm.mode, &(p->shm_perm.mode)) ||
107 __put_user (s.shm_perm.seq, &(p->shm_perm.seq)) ||
108 __put_user (s.shm_perm.key, &(p->shm_perm.key)) ||
109 __put_user (s.shm_segsz, &(p->shm_segsz)) ||
110 __put_user (s.shm_lpid, &(p->shm_lpid)) ||
111 __put_user (s.shm_cpid, &(p->shm_cpid)) ||
112 __put_user (s.shm_nattch, &(p->shm_nattch)) ||
113 __put_user (s.shm_atime, &(p->shm_atime)) ||
114 __put_user (s.shm_dtime, &(p->shm_dtime)) ||
115 __put_user (s.shm_ctime, &(p->shm_ctime)))
116 return -EFAULT;
117 return ret;
118 }
119 default: return -EINVAL;
120 }
121 case 2: /* shmdt */
122 return sys_ipc(SHMDT, 0, 0, 0, A(arg1), 0);
123 case 3: /* shmget */
124 return sys_ipc(SHMGET, arg1, arg2, arg3, NULL, 0);
125 }
126 return -EINVAL;
127}
diff --git a/arch/sparc64/solaris/misc.c b/arch/sparc64/solaris/misc.c
new file mode 100644
index 000000000000..15b4cfe07557
--- /dev/null
+++ b/arch/sparc64/solaris/misc.c
@@ -0,0 +1,784 @@
1/* $Id: misc.c,v 1.36 2002/02/09 19:49:31 davem Exp $
2 * misc.c: Miscellaneous syscall emulation for Solaris
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7#include <linux/config.h>
8#include <linux/module.h>
9#include <linux/types.h>
10#include <linux/smp_lock.h>
11#include <linux/utsname.h>
12#include <linux/limits.h>
13#include <linux/mm.h>
14#include <linux/smp.h>
15#include <linux/mman.h>
16#include <linux/file.h>
17#include <linux/timex.h>
18#include <linux/major.h>
19#include <linux/compat.h>
20
21#include <asm/uaccess.h>
22#include <asm/string.h>
23#include <asm/oplib.h>
24#include <asm/idprom.h>
25#include <asm/smp.h>
26
27#include "conv.h"
28
29/* Conversion from Linux to Solaris errnos. 0-34 are identity mapped.
30 Some Linux errnos (EPROCLIM, EDOTDOT, ERREMOTE, EUCLEAN, ENOTNAM,
31 ENAVAIL, EISNAM, EREMOTEIO, ENOMEDIUM, EMEDIUMTYPE) have no Solaris
32 equivalents. I return EINVAL in that case, which is very wrong. If
33 someone suggest a better value for them, you're welcomed.
34 On the other side, Solaris ECANCELED and ENOTSUP have no Linux equivalents,
35 but that doesn't matter here. --jj */
36int solaris_err_table[] = {
37/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
38/* 10 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
39/* 20 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
40/* 30 */ 30, 31, 32, 33, 34, 22, 150, 149, 95, 96,
41/* 40 */ 97, 98, 99, 120, 121, 122, 123, 124, 125, 126,
42/* 50 */ 127, 128, 129, 130, 131, 132, 133, 134, 143, 144,
43/* 60 */ 145, 146, 90, 78, 147, 148, 93, 22, 94, 49,
44/* 70 */ 151, 66, 60, 62, 63, 35, 77, 36, 45, 46,
45/* 80 */ 64, 22, 67, 68, 69, 70, 71, 74, 22, 82,
46/* 90 */ 89, 92, 79, 81, 37, 38, 39, 40, 41, 42,
47/* 100 */ 43, 44, 50, 51, 52, 53, 54, 55, 56, 57,
48/* 110 */ 87, 61, 84, 65, 83, 80, 91, 22, 22, 22,
49/* 120 */ 22, 22, 88, 86, 85, 22, 22,
50};
51
52#define SOLARIS_NR_OPEN 256
53
54static u32 do_solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u64 off)
55{
56 struct file *file = NULL;
57 unsigned long retval, ret_type;
58
59 /* Do we need it here? */
60 set_personality(PER_SVR4);
61 if (flags & MAP_NORESERVE) {
62 static int cnt;
63
64 if (cnt < 5) {
65 printk("%s: unimplemented Solaris MAP_NORESERVE mmap() flag\n",
66 current->comm);
67 cnt++;
68 }
69 flags &= ~MAP_NORESERVE;
70 }
71 retval = -EBADF;
72 if(!(flags & MAP_ANONYMOUS)) {
73 if(fd >= SOLARIS_NR_OPEN)
74 goto out;
75 file = fget(fd);
76 if (!file)
77 goto out;
78 else {
79 struct inode * inode = file->f_dentry->d_inode;
80 if(imajor(inode) == MEM_MAJOR &&
81 iminor(inode) == 5) {
82 flags |= MAP_ANONYMOUS;
83 fput(file);
84 file = NULL;
85 }
86 }
87 }
88
89 retval = -EINVAL;
90 len = PAGE_ALIGN(len);
91 if(!(flags & MAP_FIXED))
92 addr = 0;
93 else if (len > 0xf0000000UL || addr > 0xf0000000UL - len)
94 goto out_putf;
95 ret_type = flags & _MAP_NEW;
96 flags &= ~_MAP_NEW;
97
98 down_write(&current->mm->mmap_sem);
99 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
100 retval = do_mmap(file,
101 (unsigned long) addr, (unsigned long) len,
102 (unsigned long) prot, (unsigned long) flags, off);
103 up_write(&current->mm->mmap_sem);
104 if(!ret_type)
105 retval = ((retval < 0xf0000000) ? 0 : retval);
106
107out_putf:
108 if (file)
109 fput(file);
110out:
111 return (u32) retval;
112}
113
114asmlinkage u32 solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off)
115{
116 return do_solaris_mmap(addr, len, prot, flags, fd, (u64) off);
117}
118
119asmlinkage u32 solaris_mmap64(struct pt_regs *regs, u32 len, u32 prot, u32 flags, u32 fd, u32 offhi)
120{
121 u32 offlo;
122
123 if (regs->u_regs[UREG_G1]) {
124 if (get_user (offlo, (u32 __user *)(long)((u32)regs->u_regs[UREG_I6] + 0x5c)))
125 return -EFAULT;
126 } else {
127 if (get_user (offlo, (u32 __user *)(long)((u32)regs->u_regs[UREG_I6] + 0x60)))
128 return -EFAULT;
129 }
130 return do_solaris_mmap((u32)regs->u_regs[UREG_I0], len, prot, flags, fd, (((u64)offhi)<<32)|offlo);
131}
132
133asmlinkage int solaris_brk(u32 brk)
134{
135 int (*sunos_brk)(u32) = (int (*)(u32))SUNOS(17);
136
137 return sunos_brk(brk);
138}
139
140static int __set_utsfield(char __user *to, int to_size,
141 const char *from, int from_size,
142 int dotchop, int countfrom)
143{
144 int len = countfrom ? (to_size > from_size ?
145 from_size : to_size) : to_size;
146 int off;
147
148 if (copy_to_user(to, from, len))
149 return -EFAULT;
150
151 off = len < to_size? len: len - 1;
152 if (dotchop) {
153 const char *p = strnchr(from, len, '.');
154 if (p) off = p - from;
155 }
156
157 if (__put_user('\0', to + off))
158 return -EFAULT;
159
160 return 0;
161}
162
163#define set_utsfield(to, from, dotchop, countfrom) \
164 __set_utsfield((to), sizeof(to), \
165 (from), sizeof(from), \
166 (dotchop), (countfrom))
167
168struct sol_uname {
169 char sysname[9];
170 char nodename[9];
171 char release[9];
172 char version[9];
173 char machine[9];
174};
175
176struct sol_utsname {
177 char sysname[257];
178 char nodename[257];
179 char release[257];
180 char version[257];
181 char machine[257];
182};
183
184static char *machine(void)
185{
186 switch (sparc_cpu_model) {
187 case sun4: return "sun4";
188 case sun4c: return "sun4c";
189 case sun4e: return "sun4e";
190 case sun4m: return "sun4m";
191 case sun4d: return "sun4d";
192 case sun4u: return "sun4u";
193 default: return "sparc";
194 }
195}
196
197static char *platform(char *buffer)
198{
199 int len;
200
201 *buffer = 0;
202 len = prom_getproperty(prom_root_node, "name", buffer, 256);
203 if(len > 0)
204 buffer[len] = 0;
205 if (*buffer) {
206 char *p;
207
208 for (p = buffer; *p; p++)
209 if (*p == '/' || *p == ' ') *p = '_';
210 return buffer;
211 }
212
213 return "sun4u";
214}
215
216static char *serial(char *buffer)
217{
218 int node = prom_getchild(prom_root_node);
219 int len;
220
221 node = prom_searchsiblings(node, "options");
222 *buffer = 0;
223 len = prom_getproperty(node, "system-board-serial#", buffer, 256);
224 if(len > 0)
225 buffer[len] = 0;
226 if (!*buffer)
227 return "4512348717234";
228 else
229 return buffer;
230}
231
232asmlinkage int solaris_utssys(u32 buf, u32 flags, int which, u32 buf2)
233{
234 struct sol_uname __user *v = A(buf);
235 int err;
236
237 switch (which) {
238 case 0: /* old uname */
239 /* Let's cheat */
240 err = set_utsfield(v->sysname, "SunOS", 1, 0);
241 down_read(&uts_sem);
242 err |= set_utsfield(v->nodename, system_utsname.nodename,
243 1, 1);
244 up_read(&uts_sem);
245 err |= set_utsfield(v->release, "2.6", 0, 0);
246 err |= set_utsfield(v->version, "Generic", 0, 0);
247 err |= set_utsfield(v->machine, machine(), 0, 0);
248 return (err ? -EFAULT : 0);
249 case 2: /* ustat */
250 return -ENOSYS;
251 case 3: /* fusers */
252 return -ENOSYS;
253 default:
254 return -ENOSYS;
255 }
256}
257
258asmlinkage int solaris_utsname(u32 buf)
259{
260 struct sol_utsname __user *v = A(buf);
261 int err;
262
263 /* Why should we not lie a bit? */
264 down_read(&uts_sem);
265 err = set_utsfield(v->sysname, "SunOS", 0, 0);
266 err |= set_utsfield(v->nodename, system_utsname.nodename, 1, 1);
267 err |= set_utsfield(v->release, "5.6", 0, 0);
268 err |= set_utsfield(v->version, "Generic", 0, 0);
269 err |= set_utsfield(v->machine, machine(), 0, 0);
270 up_read(&uts_sem);
271
272 return (err ? -EFAULT : 0);
273}
274
275#define SI_SYSNAME 1 /* return name of operating system */
276#define SI_HOSTNAME 2 /* return name of node */
277#define SI_RELEASE 3 /* return release of operating system */
278#define SI_VERSION 4 /* return version field of utsname */
279#define SI_MACHINE 5 /* return kind of machine */
280#define SI_ARCHITECTURE 6 /* return instruction set arch */
281#define SI_HW_SERIAL 7 /* return hardware serial number */
282#define SI_HW_PROVIDER 8 /* return hardware manufacturer */
283#define SI_SRPC_DOMAIN 9 /* return secure RPC domain */
284#define SI_PLATFORM 513 /* return platform identifier */
285
286asmlinkage int solaris_sysinfo(int cmd, u32 buf, s32 count)
287{
288 char *p, *q, *r;
289 char buffer[256];
290 int len;
291
292 /* Again, we cheat :)) */
293 switch (cmd) {
294 case SI_SYSNAME: r = "SunOS"; break;
295 case SI_HOSTNAME:
296 r = buffer + 256;
297 down_read(&uts_sem);
298 for (p = system_utsname.nodename, q = buffer;
299 q < r && *p && *p != '.'; *q++ = *p++);
300 up_read(&uts_sem);
301 *q = 0;
302 r = buffer;
303 break;
304 case SI_RELEASE: r = "5.6"; break;
305 case SI_MACHINE: r = machine(); break;
306 case SI_ARCHITECTURE: r = "sparc"; break;
307 case SI_HW_PROVIDER: r = "Sun_Microsystems"; break;
308 case SI_HW_SERIAL: r = serial(buffer); break;
309 case SI_PLATFORM: r = platform(buffer); break;
310 case SI_SRPC_DOMAIN: r = ""; break;
311 case SI_VERSION: r = "Generic"; break;
312 default: return -EINVAL;
313 }
314 len = strlen(r) + 1;
315 if (count < len) {
316 if (copy_to_user(A(buf), r, count - 1) ||
317 __put_user(0, (char __user *)A(buf) + count - 1))
318 return -EFAULT;
319 } else {
320 if (copy_to_user(A(buf), r, len))
321 return -EFAULT;
322 }
323 return len;
324}
325
326#define SOLARIS_CONFIG_NGROUPS 2
327#define SOLARIS_CONFIG_CHILD_MAX 3
328#define SOLARIS_CONFIG_OPEN_FILES 4
329#define SOLARIS_CONFIG_POSIX_VER 5
330#define SOLARIS_CONFIG_PAGESIZE 6
331#define SOLARIS_CONFIG_CLK_TCK 7
332#define SOLARIS_CONFIG_XOPEN_VER 8
333#define SOLARIS_CONFIG_PROF_TCK 10
334#define SOLARIS_CONFIG_NPROC_CONF 11
335#define SOLARIS_CONFIG_NPROC_ONLN 12
336#define SOLARIS_CONFIG_AIO_LISTIO_MAX 13
337#define SOLARIS_CONFIG_AIO_MAX 14
338#define SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX 15
339#define SOLARIS_CONFIG_DELAYTIMER_MAX 16
340#define SOLARIS_CONFIG_MQ_OPEN_MAX 17
341#define SOLARIS_CONFIG_MQ_PRIO_MAX 18
342#define SOLARIS_CONFIG_RTSIG_MAX 19
343#define SOLARIS_CONFIG_SEM_NSEMS_MAX 20
344#define SOLARIS_CONFIG_SEM_VALUE_MAX 21
345#define SOLARIS_CONFIG_SIGQUEUE_MAX 22
346#define SOLARIS_CONFIG_SIGRT_MIN 23
347#define SOLARIS_CONFIG_SIGRT_MAX 24
348#define SOLARIS_CONFIG_TIMER_MAX 25
349#define SOLARIS_CONFIG_PHYS_PAGES 26
350#define SOLARIS_CONFIG_AVPHYS_PAGES 27
351
352asmlinkage int solaris_sysconf(int id)
353{
354 switch (id) {
355 case SOLARIS_CONFIG_NGROUPS: return NGROUPS_MAX;
356 case SOLARIS_CONFIG_CHILD_MAX: return CHILD_MAX;
357 case SOLARIS_CONFIG_OPEN_FILES: return OPEN_MAX;
358 case SOLARIS_CONFIG_POSIX_VER: return 199309;
359 case SOLARIS_CONFIG_PAGESIZE: return PAGE_SIZE;
360 case SOLARIS_CONFIG_XOPEN_VER: return 3;
361 case SOLARIS_CONFIG_CLK_TCK:
362 case SOLARIS_CONFIG_PROF_TCK:
363 return sparc64_get_clock_tick(smp_processor_id());
364#ifdef CONFIG_SMP
365 case SOLARIS_CONFIG_NPROC_CONF: return NR_CPUS;
366 case SOLARIS_CONFIG_NPROC_ONLN: return num_online_cpus();
367#else
368 case SOLARIS_CONFIG_NPROC_CONF: return 1;
369 case SOLARIS_CONFIG_NPROC_ONLN: return 1;
370#endif
371 case SOLARIS_CONFIG_SIGRT_MIN: return 37;
372 case SOLARIS_CONFIG_SIGRT_MAX: return 44;
373 case SOLARIS_CONFIG_PHYS_PAGES:
374 case SOLARIS_CONFIG_AVPHYS_PAGES:
375 {
376 struct sysinfo s;
377
378 si_meminfo(&s);
379 if (id == SOLARIS_CONFIG_PHYS_PAGES)
380 return s.totalram >>= PAGE_SHIFT;
381 else
382 return s.freeram >>= PAGE_SHIFT;
383 }
384 /* XXX support these as well -jj */
385 case SOLARIS_CONFIG_AIO_LISTIO_MAX: return -EINVAL;
386 case SOLARIS_CONFIG_AIO_MAX: return -EINVAL;
387 case SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX: return -EINVAL;
388 case SOLARIS_CONFIG_DELAYTIMER_MAX: return -EINVAL;
389 case SOLARIS_CONFIG_MQ_OPEN_MAX: return -EINVAL;
390 case SOLARIS_CONFIG_MQ_PRIO_MAX: return -EINVAL;
391 case SOLARIS_CONFIG_RTSIG_MAX: return -EINVAL;
392 case SOLARIS_CONFIG_SEM_NSEMS_MAX: return -EINVAL;
393 case SOLARIS_CONFIG_SEM_VALUE_MAX: return -EINVAL;
394 case SOLARIS_CONFIG_SIGQUEUE_MAX: return -EINVAL;
395 case SOLARIS_CONFIG_TIMER_MAX: return -EINVAL;
396 default: return -EINVAL;
397 }
398}
399
400asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
401{
402 int ret;
403
404 switch (cmd) {
405 case 0: /* getpgrp */
406 return process_group(current);
407 case 1: /* setpgrp */
408 {
409 int (*sys_setpgid)(pid_t,pid_t) =
410 (int (*)(pid_t,pid_t))SYS(setpgid);
411
412 /* can anyone explain me the difference between
413 Solaris setpgrp and setsid? */
414 ret = sys_setpgid(0, 0);
415 if (ret) return ret;
416 current->signal->tty = NULL;
417 return process_group(current);
418 }
419 case 2: /* getsid */
420 {
421 int (*sys_getsid)(pid_t) = (int (*)(pid_t))SYS(getsid);
422 return sys_getsid(pid);
423 }
424 case 3: /* setsid */
425 {
426 int (*sys_setsid)(void) = (int (*)(void))SYS(setsid);
427 return sys_setsid();
428 }
429 case 4: /* getpgid */
430 {
431 int (*sys_getpgid)(pid_t) = (int (*)(pid_t))SYS(getpgid);
432 return sys_getpgid(pid);
433 }
434 case 5: /* setpgid */
435 {
436 int (*sys_setpgid)(pid_t,pid_t) =
437 (int (*)(pid_t,pid_t))SYS(setpgid);
438 return sys_setpgid(pid,pgid);
439 }
440 }
441 return -EINVAL;
442}
443
444asmlinkage int solaris_gettimeofday(u32 tim)
445{
446 int (*sys_gettimeofday)(struct timeval *, struct timezone *) =
447 (int (*)(struct timeval *, struct timezone *))SYS(gettimeofday);
448
449 return sys_gettimeofday((struct timeval *)(u64)tim, NULL);
450}
451
452#define RLIM_SOL_INFINITY32 0x7fffffff
453#define RLIM_SOL_SAVED_MAX32 0x7ffffffe
454#define RLIM_SOL_SAVED_CUR32 0x7ffffffd
455#define RLIM_SOL_INFINITY ((u64)-3)
456#define RLIM_SOL_SAVED_MAX ((u64)-2)
457#define RLIM_SOL_SAVED_CUR ((u64)-1)
458#define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
459#define RLIMIT_SOL_NOFILE 5
460#define RLIMIT_SOL_VMEM 6
461
462struct rlimit32 {
463 u32 rlim_cur;
464 u32 rlim_max;
465};
466
467asmlinkage int solaris_getrlimit(unsigned int resource, struct rlimit32 __user *rlim)
468{
469 struct rlimit r;
470 int ret;
471 mm_segment_t old_fs = get_fs ();
472 int (*sys_getrlimit)(unsigned int, struct rlimit *) =
473 (int (*)(unsigned int, struct rlimit *))SYS(getrlimit);
474
475 if (resource > RLIMIT_SOL_VMEM)
476 return -EINVAL;
477 switch (resource) {
478 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
479 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
480 default: break;
481 }
482 set_fs (KERNEL_DS);
483 ret = sys_getrlimit(resource, &r);
484 set_fs (old_fs);
485 if (!ret) {
486 if (r.rlim_cur == RLIM_INFINITY)
487 r.rlim_cur = RLIM_SOL_INFINITY32;
488 else if ((u64)r.rlim_cur > RLIM_SOL_INFINITY32)
489 r.rlim_cur = RLIM_SOL_SAVED_CUR32;
490 if (r.rlim_max == RLIM_INFINITY)
491 r.rlim_max = RLIM_SOL_INFINITY32;
492 else if ((u64)r.rlim_max > RLIM_SOL_INFINITY32)
493 r.rlim_max = RLIM_SOL_SAVED_MAX32;
494 ret = put_user (r.rlim_cur, &rlim->rlim_cur);
495 ret |= __put_user (r.rlim_max, &rlim->rlim_max);
496 }
497 return ret;
498}
499
500asmlinkage int solaris_setrlimit(unsigned int resource, struct rlimit32 __user *rlim)
501{
502 struct rlimit r, rold;
503 int ret;
504 mm_segment_t old_fs = get_fs ();
505 int (*sys_getrlimit)(unsigned int, struct rlimit __user *) =
506 (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit);
507 int (*sys_setrlimit)(unsigned int, struct rlimit __user *) =
508 (int (*)(unsigned int, struct rlimit __user *))SYS(setrlimit);
509
510 if (resource > RLIMIT_SOL_VMEM)
511 return -EINVAL;
512 switch (resource) {
513 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
514 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
515 default: break;
516 }
517 if (get_user (r.rlim_cur, &rlim->rlim_cur) ||
518 __get_user (r.rlim_max, &rlim->rlim_max))
519 return -EFAULT;
520 set_fs (KERNEL_DS);
521 ret = sys_getrlimit(resource, &rold);
522 if (!ret) {
523 if (r.rlim_cur == RLIM_SOL_INFINITY32)
524 r.rlim_cur = RLIM_INFINITY;
525 else if (r.rlim_cur == RLIM_SOL_SAVED_CUR32)
526 r.rlim_cur = rold.rlim_cur;
527 else if (r.rlim_cur == RLIM_SOL_SAVED_MAX32)
528 r.rlim_cur = rold.rlim_max;
529 if (r.rlim_max == RLIM_SOL_INFINITY32)
530 r.rlim_max = RLIM_INFINITY;
531 else if (r.rlim_max == RLIM_SOL_SAVED_CUR32)
532 r.rlim_max = rold.rlim_cur;
533 else if (r.rlim_max == RLIM_SOL_SAVED_MAX32)
534 r.rlim_max = rold.rlim_max;
535 ret = sys_setrlimit(resource, &r);
536 }
537 set_fs (old_fs);
538 return ret;
539}
540
541asmlinkage int solaris_getrlimit64(unsigned int resource, struct rlimit __user *rlim)
542{
543 struct rlimit r;
544 int ret;
545 mm_segment_t old_fs = get_fs ();
546 int (*sys_getrlimit)(unsigned int, struct rlimit __user *) =
547 (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit);
548
549 if (resource > RLIMIT_SOL_VMEM)
550 return -EINVAL;
551 switch (resource) {
552 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
553 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
554 default: break;
555 }
556 set_fs (KERNEL_DS);
557 ret = sys_getrlimit(resource, &r);
558 set_fs (old_fs);
559 if (!ret) {
560 if (r.rlim_cur == RLIM_INFINITY)
561 r.rlim_cur = RLIM_SOL_INFINITY;
562 if (r.rlim_max == RLIM_INFINITY)
563 r.rlim_max = RLIM_SOL_INFINITY;
564 ret = put_user (r.rlim_cur, &rlim->rlim_cur);
565 ret |= __put_user (r.rlim_max, &rlim->rlim_max);
566 }
567 return ret;
568}
569
570asmlinkage int solaris_setrlimit64(unsigned int resource, struct rlimit __user *rlim)
571{
572 struct rlimit r, rold;
573 int ret;
574 mm_segment_t old_fs = get_fs ();
575 int (*sys_getrlimit)(unsigned int, struct rlimit __user *) =
576 (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit);
577 int (*sys_setrlimit)(unsigned int, struct rlimit __user *) =
578 (int (*)(unsigned int, struct rlimit __user *))SYS(setrlimit);
579
580 if (resource > RLIMIT_SOL_VMEM)
581 return -EINVAL;
582 switch (resource) {
583 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
584 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
585 default: break;
586 }
587 if (get_user (r.rlim_cur, &rlim->rlim_cur) ||
588 __get_user (r.rlim_max, &rlim->rlim_max))
589 return -EFAULT;
590 set_fs (KERNEL_DS);
591 ret = sys_getrlimit(resource, &rold);
592 if (!ret) {
593 if (r.rlim_cur == RLIM_SOL_INFINITY)
594 r.rlim_cur = RLIM_INFINITY;
595 else if (r.rlim_cur == RLIM_SOL_SAVED_CUR)
596 r.rlim_cur = rold.rlim_cur;
597 else if (r.rlim_cur == RLIM_SOL_SAVED_MAX)
598 r.rlim_cur = rold.rlim_max;
599 if (r.rlim_max == RLIM_SOL_INFINITY)
600 r.rlim_max = RLIM_INFINITY;
601 else if (r.rlim_max == RLIM_SOL_SAVED_CUR)
602 r.rlim_max = rold.rlim_cur;
603 else if (r.rlim_max == RLIM_SOL_SAVED_MAX)
604 r.rlim_max = rold.rlim_max;
605 ret = sys_setrlimit(resource, &r);
606 }
607 set_fs (old_fs);
608 return ret;
609}
610
611struct sol_ntptimeval {
612 struct compat_timeval time;
613 s32 maxerror;
614 s32 esterror;
615};
616
617struct sol_timex {
618 u32 modes;
619 s32 offset;
620 s32 freq;
621 s32 maxerror;
622 s32 esterror;
623 s32 status;
624 s32 constant;
625 s32 precision;
626 s32 tolerance;
627 s32 ppsfreq;
628 s32 jitter;
629 s32 shift;
630 s32 stabil;
631 s32 jitcnt;
632 s32 calcnt;
633 s32 errcnt;
634 s32 stbcnt;
635};
636
637asmlinkage int solaris_ntp_gettime(struct sol_ntptimeval __user *ntp)
638{
639 int (*sys_adjtimex)(struct timex __user *) =
640 (int (*)(struct timex __user *))SYS(adjtimex);
641 struct timex t;
642 int ret;
643 mm_segment_t old_fs = get_fs();
644
645 set_fs(KERNEL_DS);
646 t.modes = 0;
647 ret = sys_adjtimex(&t);
648 set_fs(old_fs);
649 if (ret < 0)
650 return ret;
651 ret = put_user (t.time.tv_sec, &ntp->time.tv_sec);
652 ret |= __put_user (t.time.tv_usec, &ntp->time.tv_usec);
653 ret |= __put_user (t.maxerror, &ntp->maxerror);
654 ret |= __put_user (t.esterror, &ntp->esterror);
655 return ret;
656}
657
658asmlinkage int solaris_ntp_adjtime(struct sol_timex __user *txp)
659{
660 int (*sys_adjtimex)(struct timex __user *) =
661 (int (*)(struct timex __user *))SYS(adjtimex);
662 struct timex t;
663 int ret, err;
664 mm_segment_t old_fs = get_fs();
665
666 ret = get_user (t.modes, &txp->modes);
667 ret |= __get_user (t.offset, &txp->offset);
668 ret |= __get_user (t.freq, &txp->freq);
669 ret |= __get_user (t.maxerror, &txp->maxerror);
670 ret |= __get_user (t.esterror, &txp->esterror);
671 ret |= __get_user (t.status, &txp->status);
672 ret |= __get_user (t.constant, &txp->constant);
673 set_fs(KERNEL_DS);
674 ret = sys_adjtimex(&t);
675 set_fs(old_fs);
676 if (ret < 0)
677 return ret;
678 err = put_user (t.offset, &txp->offset);
679 err |= __put_user (t.freq, &txp->freq);
680 err |= __put_user (t.maxerror, &txp->maxerror);
681 err |= __put_user (t.esterror, &txp->esterror);
682 err |= __put_user (t.status, &txp->status);
683 err |= __put_user (t.constant, &txp->constant);
684 err |= __put_user (t.precision, &txp->precision);
685 err |= __put_user (t.tolerance, &txp->tolerance);
686 err |= __put_user (t.ppsfreq, &txp->ppsfreq);
687 err |= __put_user (t.jitter, &txp->jitter);
688 err |= __put_user (t.shift, &txp->shift);
689 err |= __put_user (t.stabil, &txp->stabil);
690 err |= __put_user (t.jitcnt, &txp->jitcnt);
691 err |= __put_user (t.calcnt, &txp->calcnt);
692 err |= __put_user (t.errcnt, &txp->errcnt);
693 err |= __put_user (t.stbcnt, &txp->stbcnt);
694 if (err)
695 return -EFAULT;
696 return ret;
697}
698
699asmlinkage int do_sol_unimplemented(struct pt_regs *regs)
700{
701 printk ("Unimplemented Solaris syscall %d %08x %08x %08x %08x\n",
702 (int)regs->u_regs[UREG_G1],
703 (int)regs->u_regs[UREG_I0],
704 (int)regs->u_regs[UREG_I1],
705 (int)regs->u_regs[UREG_I2],
706 (int)regs->u_regs[UREG_I3]);
707 return -ENOSYS;
708}
709
710asmlinkage void solaris_register(void)
711{
712 set_personality(PER_SVR4);
713}
714
715extern long solaris_to_linux_signals[], linux_to_solaris_signals[];
716
717struct exec_domain solaris_exec_domain = {
718 .name = "Solaris",
719 .handler = NULL,
720 .pers_low = 1, /* PER_SVR4 personality */
721 .pers_high = 1,
722 .signal_map = solaris_to_linux_signals,
723 .signal_invmap =linux_to_solaris_signals,
724 .module = THIS_MODULE,
725 .next = NULL
726};
727
728extern int init_socksys(void);
729
730#ifdef MODULE
731
732MODULE_AUTHOR("Jakub Jelinek (jj@ultra.linux.cz), Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)");
733MODULE_DESCRIPTION("Solaris binary emulation module");
734MODULE_LICENSE("GPL");
735
736#ifdef __sparc_v9__
737extern u32 tl0_solaris[8];
738#define update_ttable(x) \
739 tl0_solaris[3] = (((long)(x) - (long)tl0_solaris - 3) >> 2) | 0x40000000; \
740 __asm__ __volatile__ ("membar #StoreStore; flush %0" : : "r" (&tl0_solaris[3]))
741#else
742#endif
743
744extern u32 solaris_sparc_syscall[];
745extern u32 solaris_syscall[];
746extern void cleanup_socksys(void);
747
748extern u32 entry64_personality_patch;
749
750int init_module(void)
751{
752 int ret;
753
754 SOLDD(("Solaris module at %p\n", solaris_sparc_syscall));
755 register_exec_domain(&solaris_exec_domain);
756 if ((ret = init_socksys())) {
757 unregister_exec_domain(&solaris_exec_domain);
758 return ret;
759 }
760 update_ttable(solaris_sparc_syscall);
761 entry64_personality_patch |=
762 (offsetof(struct task_struct, personality) +
763 (sizeof(unsigned long) - 1));
764 __asm__ __volatile__("membar #StoreStore; flush %0"
765 : : "r" (&entry64_personality_patch));
766 return 0;
767}
768
769void cleanup_module(void)
770{
771 update_ttable(solaris_syscall);
772 cleanup_socksys();
773 unregister_exec_domain(&solaris_exec_domain);
774}
775
776#else
777int init_solaris_emul(void)
778{
779 register_exec_domain(&solaris_exec_domain);
780 init_socksys();
781 return 0;
782}
783#endif
784
diff --git a/arch/sparc64/solaris/signal.c b/arch/sparc64/solaris/signal.c
new file mode 100644
index 000000000000..7fa2634e2085
--- /dev/null
+++ b/arch/sparc64/solaris/signal.c
@@ -0,0 +1,430 @@
1/* $Id: signal.c,v 1.7 2000/09/05 21:44:54 davem Exp $
2 * signal.c: Signal emulation for Solaris
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7#include <linux/types.h>
8#include <linux/smp_lock.h>
9#include <linux/errno.h>
10
11#include <asm/uaccess.h>
12#include <asm/svr4.h>
13#include <asm/string.h>
14
15#include "conv.h"
16#include "signal.h"
17
18#define _S(nr) (1L<<((nr)-1))
19
20#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
21
22long linux_to_solaris_signals[] = {
23 0,
24 SOLARIS_SIGHUP, SOLARIS_SIGINT,
25 SOLARIS_SIGQUIT, SOLARIS_SIGILL,
26 SOLARIS_SIGTRAP, SOLARIS_SIGIOT,
27 SOLARIS_SIGEMT, SOLARIS_SIGFPE,
28 SOLARIS_SIGKILL, SOLARIS_SIGBUS,
29 SOLARIS_SIGSEGV, SOLARIS_SIGSYS,
30 SOLARIS_SIGPIPE, SOLARIS_SIGALRM,
31 SOLARIS_SIGTERM, SOLARIS_SIGURG,
32 SOLARIS_SIGSTOP, SOLARIS_SIGTSTP,
33 SOLARIS_SIGCONT, SOLARIS_SIGCLD,
34 SOLARIS_SIGTTIN, SOLARIS_SIGTTOU,
35 SOLARIS_SIGPOLL, SOLARIS_SIGXCPU,
36 SOLARIS_SIGXFSZ, SOLARIS_SIGVTALRM,
37 SOLARIS_SIGPROF, SOLARIS_SIGWINCH,
38 SOLARIS_SIGUSR1, SOLARIS_SIGUSR1,
39 SOLARIS_SIGUSR2, -1,
40};
41
42long solaris_to_linux_signals[] = {
43 0,
44 SIGHUP, SIGINT, SIGQUIT, SIGILL,
45 SIGTRAP, SIGIOT, SIGEMT, SIGFPE,
46 SIGKILL, SIGBUS, SIGSEGV, SIGSYS,
47 SIGPIPE, SIGALRM, SIGTERM, SIGUSR1,
48 SIGUSR2, SIGCHLD, -1, SIGWINCH,
49 SIGURG, SIGPOLL, SIGSTOP, SIGTSTP,
50 SIGCONT, SIGTTIN, SIGTTOU, SIGVTALRM,
51 SIGPROF, SIGXCPU, SIGXFSZ, -1,
52 -1, -1, -1, -1,
53 -1, -1, -1, -1,
54 -1, -1, -1, -1,
55};
56
57static inline long mapsig(long sig)
58{
59 if ((unsigned long)sig > SOLARIS_NSIGNALS)
60 return -EINVAL;
61 return solaris_to_linux_signals[sig];
62}
63
64asmlinkage int solaris_kill(int pid, int sig)
65{
66 int (*sys_kill)(int,int) =
67 (int (*)(int,int))SYS(kill);
68 int s = mapsig(sig);
69
70 if (s < 0) return s;
71 return sys_kill(pid, s);
72}
73
74static long sig_handler(int sig, u32 arg, int one_shot)
75{
76 struct sigaction sa, old;
77 int ret;
78 mm_segment_t old_fs = get_fs();
79 int (*sys_sigaction)(int,struct sigaction __user *,struct sigaction __user *) =
80 (int (*)(int,struct sigaction __user *,struct sigaction __user *))SYS(sigaction);
81
82 sigemptyset(&sa.sa_mask);
83 sa.sa_restorer = NULL;
84 sa.sa_handler = (__sighandler_t)A(arg);
85 sa.sa_flags = 0;
86 if (one_shot) sa.sa_flags = SA_ONESHOT | SA_NOMASK;
87 set_fs (KERNEL_DS);
88 ret = sys_sigaction(sig, (void __user *)&sa, (void __user *)&old);
89 set_fs (old_fs);
90 if (ret < 0) return ret;
91 return (u32)(unsigned long)old.sa_handler;
92}
93
94static inline long solaris_signal(int sig, u32 arg)
95{
96 return sig_handler (sig, arg, 1);
97}
98
99static long solaris_sigset(int sig, u32 arg)
100{
101 if (arg != 2) /* HOLD */ {
102 spin_lock_irq(&current->sighand->siglock);
103 sigdelsetmask(&current->blocked, _S(sig));
104 recalc_sigpending();
105 spin_unlock_irq(&current->sighand->siglock);
106 return sig_handler (sig, arg, 0);
107 } else {
108 spin_lock_irq(&current->sighand->siglock);
109 sigaddsetmask(&current->blocked, (_S(sig) & ~_BLOCKABLE));
110 recalc_sigpending();
111 spin_unlock_irq(&current->sighand->siglock);
112 return 0;
113 }
114}
115
116static inline long solaris_sighold(int sig)
117{
118 return solaris_sigset(sig, 2);
119}
120
121static inline long solaris_sigrelse(int sig)
122{
123 spin_lock_irq(&current->sighand->siglock);
124 sigdelsetmask(&current->blocked, _S(sig));
125 recalc_sigpending();
126 spin_unlock_irq(&current->sighand->siglock);
127 return 0;
128}
129
130static inline long solaris_sigignore(int sig)
131{
132 return sig_handler(sig, (u32)(unsigned long)SIG_IGN, 0);
133}
134
135static inline long solaris_sigpause(int sig)
136{
137 printk ("Need to support solaris sigpause\n");
138 return -ENOSYS;
139}
140
141asmlinkage long solaris_sigfunc(int sig, u32 arg)
142{
143 int func = sig & ~0xff;
144
145 sig = mapsig(sig & 0xff);
146 if (sig < 0) return sig;
147 switch (func) {
148 case 0: return solaris_signal(sig, arg);
149 case 0x100: return solaris_sigset(sig, arg);
150 case 0x200: return solaris_sighold(sig);
151 case 0x400: return solaris_sigrelse(sig);
152 case 0x800: return solaris_sigignore(sig);
153 case 0x1000: return solaris_sigpause(sig);
154 }
155 return -EINVAL;
156}
157
158typedef struct {
159 u32 __sigbits[4];
160} sol_sigset_t;
161
162static inline int mapin(u32 *p, sigset_t *q)
163{
164 int i;
165 u32 x;
166 int sig;
167
168 sigemptyset(q);
169 x = p[0];
170 for (i = 1; i <= SOLARIS_NSIGNALS; i++) {
171 if (x & 1) {
172 sig = solaris_to_linux_signals[i];
173 if (sig == -1)
174 return -EINVAL;
175 sigaddsetmask(q, (1L << (sig - 1)));
176 }
177 x >>= 1;
178 if (i == 32)
179 x = p[1];
180 }
181 return 0;
182}
183
184static inline int mapout(sigset_t *q, u32 *p)
185{
186 int i;
187 int sig;
188
189 p[0] = 0;
190 p[1] = 0;
191 for (i = 1; i <= 32; i++) {
192 if (sigismember(q, sigmask(i))) {
193 sig = linux_to_solaris_signals[i];
194 if (sig == -1)
195 return -EINVAL;
196 if (sig > 32)
197 p[1] |= 1L << (sig - 33);
198 else
199 p[0] |= 1L << (sig - 1);
200 }
201 }
202 return 0;
203}
204
205asmlinkage int solaris_sigprocmask(int how, u32 in, u32 out)
206{
207 sigset_t in_s, *ins, out_s, *outs;
208 mm_segment_t old_fs = get_fs();
209 int ret;
210 int (*sys_sigprocmask)(int,sigset_t __user *,sigset_t __user *) =
211 (int (*)(int,sigset_t __user *,sigset_t __user *))SYS(sigprocmask);
212
213 ins = NULL; outs = NULL;
214 if (in) {
215 u32 tmp[2];
216
217 if (copy_from_user (tmp, (void __user *)A(in), 2*sizeof(u32)))
218 return -EFAULT;
219 ins = &in_s;
220 if (mapin (tmp, ins)) return -EINVAL;
221 }
222 if (out) outs = &out_s;
223 set_fs (KERNEL_DS);
224 ret = sys_sigprocmask((how == 3) ? SIG_SETMASK : how,
225 (void __user *)ins, (void __user *)outs);
226 set_fs (old_fs);
227 if (ret) return ret;
228 if (out) {
229 u32 tmp[4];
230
231 tmp[2] = 0; tmp[3] = 0;
232 if (mapout (outs, tmp)) return -EINVAL;
233 if (copy_to_user((void __user *)A(out), tmp, 4*sizeof(u32)))
234 return -EFAULT;
235 }
236 return 0;
237}
238
239asmlinkage long do_sol_sigsuspend(u32 mask)
240{
241 sigset_t s;
242 u32 tmp[2];
243
244 if (copy_from_user (tmp, (sol_sigset_t __user *)A(mask), 2*sizeof(u32)))
245 return -EFAULT;
246 if (mapin (tmp, &s)) return -EINVAL;
247 return (long)s.sig[0];
248}
249
250struct sol_sigaction {
251 int sa_flags;
252 u32 sa_handler;
253 u32 sa_mask[4];
254 int sa_resv[2];
255};
256
257asmlinkage int solaris_sigaction(int sig, u32 act, u32 old)
258{
259 u32 tmp, tmp2[4];
260 struct sigaction s, s2;
261 int ret;
262 mm_segment_t old_fs = get_fs();
263 struct sol_sigaction __user *p = (void __user *)A(old);
264 int (*sys_sigaction)(int,struct sigaction __user *,struct sigaction __user *) =
265 (int (*)(int,struct sigaction __user *,struct sigaction __user *))SYS(sigaction);
266
267 sig = mapsig(sig);
268 if (sig < 0) {
269 /* We cheat a little bit for Solaris only signals */
270 if (old && clear_user(p, sizeof(struct sol_sigaction)))
271 return -EFAULT;
272 return 0;
273 }
274 if (act) {
275 if (get_user (tmp, &p->sa_flags))
276 return -EFAULT;
277 s.sa_flags = 0;
278 if (tmp & SOLARIS_SA_ONSTACK) s.sa_flags |= SA_STACK;
279 if (tmp & SOLARIS_SA_RESTART) s.sa_flags |= SA_RESTART;
280 if (tmp & SOLARIS_SA_NODEFER) s.sa_flags |= SA_NOMASK;
281 if (tmp & SOLARIS_SA_RESETHAND) s.sa_flags |= SA_ONESHOT;
282 if (tmp & SOLARIS_SA_NOCLDSTOP) s.sa_flags |= SA_NOCLDSTOP;
283 if (get_user (tmp, &p->sa_handler) ||
284 copy_from_user (tmp2, &p->sa_mask, 2*sizeof(u32)))
285 return -EFAULT;
286 s.sa_handler = (__sighandler_t)A(tmp);
287 if (mapin (tmp2, &s.sa_mask)) return -EINVAL;
288 s.sa_restorer = NULL;
289 }
290 set_fs(KERNEL_DS);
291 ret = sys_sigaction(sig, act ? (void __user *)&s : NULL,
292 old ? (void __user *)&s2 : NULL);
293 set_fs(old_fs);
294 if (ret) return ret;
295 if (old) {
296 if (mapout (&s2.sa_mask, tmp2)) return -EINVAL;
297 tmp = 0; tmp2[2] = 0; tmp2[3] = 0;
298 if (s2.sa_flags & SA_STACK) tmp |= SOLARIS_SA_ONSTACK;
299 if (s2.sa_flags & SA_RESTART) tmp |= SOLARIS_SA_RESTART;
300 if (s2.sa_flags & SA_NOMASK) tmp |= SOLARIS_SA_NODEFER;
301 if (s2.sa_flags & SA_ONESHOT) tmp |= SOLARIS_SA_RESETHAND;
302 if (s2.sa_flags & SA_NOCLDSTOP) tmp |= SOLARIS_SA_NOCLDSTOP;
303 if (put_user (tmp, &p->sa_flags) ||
304 __put_user ((u32)(unsigned long)s2.sa_handler, &p->sa_handler) ||
305 copy_to_user (&p->sa_mask, tmp2, 4*sizeof(u32)))
306 return -EFAULT;
307 }
308 return 0;
309}
310
311asmlinkage int solaris_sigpending(int which, u32 set)
312{
313 sigset_t s;
314 u32 tmp[4];
315 switch (which) {
316 case 1: /* sigpending */
317 spin_lock_irq(&current->sighand->siglock);
318 sigandsets(&s, &current->blocked, &current->pending.signal);
319 recalc_sigpending();
320 spin_unlock_irq(&current->sighand->siglock);
321 break;
322 case 2: /* sigfillset - I just set signals which have linux equivalents */
323 sigfillset(&s);
324 break;
325 default: return -EINVAL;
326 }
327 if (mapout (&s, tmp)) return -EINVAL;
328 tmp[2] = 0; tmp[3] = 0;
329 if (copy_to_user ((u32 __user *)A(set), tmp, sizeof(tmp)))
330 return -EFAULT;
331 return 0;
332}
333
334asmlinkage int solaris_wait(u32 stat_loc)
335{
336 unsigned __user *p = (unsigned __user *)A(stat_loc);
337 int (*sys_wait4)(pid_t,unsigned __user *, int, struct rusage __user *) =
338 (int (*)(pid_t,unsigned __user *, int, struct rusage __user *))SYS(wait4);
339 int ret, status;
340
341 ret = sys_wait4(-1, p, WUNTRACED, NULL);
342 if (ret >= 0 && stat_loc) {
343 if (get_user (status, p))
344 return -EFAULT;
345 if (((status - 1) & 0xffff) < 0xff)
346 status = linux_to_solaris_signals[status & 0x7f] & 0x7f;
347 else if ((status & 0xff) == 0x7f)
348 status = (linux_to_solaris_signals[(status >> 8) & 0xff] << 8) | 0x7f;
349 if (__put_user (status, p))
350 return -EFAULT;
351 }
352 return ret;
353}
354
355asmlinkage int solaris_waitid(int idtype, s32 pid, u32 info, int options)
356{
357 int (*sys_wait4)(pid_t,unsigned __user *, int, struct rusage __user *) =
358 (int (*)(pid_t,unsigned __user *, int, struct rusage __user *))SYS(wait4);
359 int opts, status, ret;
360
361 switch (idtype) {
362 case 0: /* P_PID */ break;
363 case 1: /* P_PGID */ pid = -pid; break;
364 case 7: /* P_ALL */ pid = -1; break;
365 default: return -EINVAL;
366 }
367 opts = 0;
368 if (options & SOLARIS_WUNTRACED) opts |= WUNTRACED;
369 if (options & SOLARIS_WNOHANG) opts |= WNOHANG;
370 current->state = TASK_RUNNING;
371 ret = sys_wait4(pid, (unsigned int __user *)A(info), opts, NULL);
372 if (ret < 0) return ret;
373 if (info) {
374 struct sol_siginfo __user *s = (void __user *)A(info);
375
376 if (get_user (status, (unsigned int __user *)A(info)))
377 return -EFAULT;
378
379 if (__put_user (SOLARIS_SIGCLD, &s->si_signo) ||
380 __put_user (ret, &s->_data._proc._pid))
381 return -EFAULT;
382
383 switch (status & 0xff) {
384 case 0: ret = SOLARIS_CLD_EXITED;
385 status = (status >> 8) & 0xff;
386 break;
387 case 0x7f:
388 status = (status >> 8) & 0xff;
389 switch (status) {
390 case SIGSTOP:
391 case SIGTSTP: ret = SOLARIS_CLD_STOPPED;
392 default: ret = SOLARIS_CLD_EXITED;
393 }
394 status = linux_to_solaris_signals[status];
395 break;
396 default:
397 if (status & 0x80) ret = SOLARIS_CLD_DUMPED;
398 else ret = SOLARIS_CLD_KILLED;
399 status = linux_to_solaris_signals[status & 0x7f];
400 break;
401 }
402
403 if (__put_user (ret, &s->si_code) ||
404 __put_user (status, &s->_data._proc._pdata._cld._status))
405 return -EFAULT;
406 }
407 return 0;
408}
409
410extern int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs);
411extern int svr4_getcontext(svr4_ucontext_t *c, struct pt_regs *regs);
412
413asmlinkage int solaris_context(struct pt_regs *regs)
414{
415 switch ((unsigned)regs->u_regs[UREG_I0]) {
416 case 0: /* getcontext */
417 return svr4_getcontext((svr4_ucontext_t *)(long)(u32)regs->u_regs[UREG_I1], regs);
418 case 1: /* setcontext */
419 return svr4_setcontext((svr4_ucontext_t *)(long)(u32)regs->u_regs[UREG_I1], regs);
420 default:
421 return -EINVAL;
422
423 }
424}
425
426asmlinkage int solaris_sigaltstack(u32 ss, u32 oss)
427{
428/* XXX Implement this soon */
429 return 0;
430}
diff --git a/arch/sparc64/solaris/signal.h b/arch/sparc64/solaris/signal.h
new file mode 100644
index 000000000000..e91570803050
--- /dev/null
+++ b/arch/sparc64/solaris/signal.h
@@ -0,0 +1,108 @@
1/* $Id: signal.h,v 1.3 1998/04/12 06:20:33 davem Exp $
2 * signal.h: Signal emulation for Solaris
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
6
7#define SOLARIS_SIGHUP 1
8#define SOLARIS_SIGINT 2
9#define SOLARIS_SIGQUIT 3
10#define SOLARIS_SIGILL 4
11#define SOLARIS_SIGTRAP 5
12#define SOLARIS_SIGIOT 6
13#define SOLARIS_SIGEMT 7
14#define SOLARIS_SIGFPE 8
15#define SOLARIS_SIGKILL 9
16#define SOLARIS_SIGBUS 10
17#define SOLARIS_SIGSEGV 11
18#define SOLARIS_SIGSYS 12
19#define SOLARIS_SIGPIPE 13
20#define SOLARIS_SIGALRM 14
21#define SOLARIS_SIGTERM 15
22#define SOLARIS_SIGUSR1 16
23#define SOLARIS_SIGUSR2 17
24#define SOLARIS_SIGCLD 18
25#define SOLARIS_SIGPWR 19
26#define SOLARIS_SIGWINCH 20
27#define SOLARIS_SIGURG 21
28#define SOLARIS_SIGPOLL 22
29#define SOLARIS_SIGSTOP 23
30#define SOLARIS_SIGTSTP 24
31#define SOLARIS_SIGCONT 25
32#define SOLARIS_SIGTTIN 26
33#define SOLARIS_SIGTTOU 27
34#define SOLARIS_SIGVTALRM 28
35#define SOLARIS_SIGPROF 29
36#define SOLARIS_SIGXCPU 30
37#define SOLARIS_SIGXFSZ 31
38#define SOLARIS_SIGWAITING 32
39#define SOLARIS_SIGLWP 33
40#define SOLARIS_SIGFREEZE 34
41#define SOLARIS_SIGTHAW 35
42#define SOLARIS_SIGCANCEL 36
43#define SOLARIS_SIGRTMIN 37
44#define SOLARIS_SIGRTMAX 44
45#define SOLARIS_NSIGNALS 44
46
47
48#define SOLARIS_SA_ONSTACK 1
49#define SOLARIS_SA_RESETHAND 2
50#define SOLARIS_SA_RESTART 4
51#define SOLARIS_SA_SIGINFO 8
52#define SOLARIS_SA_NODEFER 16
53#define SOLARIS_SA_NOCLDWAIT 0x10000
54#define SOLARIS_SA_NOCLDSTOP 0x20000
55
56struct sol_siginfo {
57 int si_signo;
58 int si_code;
59 int si_errno;
60 union {
61 char pad[128-3*sizeof(int)];
62 struct {
63 s32 _pid;
64 union {
65 struct {
66 s32 _uid;
67 s32 _value;
68 } _kill;
69 struct {
70 s32 _utime;
71 int _status;
72 s32 _stime;
73 } _cld;
74 } _pdata;
75 } _proc;
76 struct { /* SIGSEGV, SIGBUS, SIGILL and SIGFPE */
77 u32 _addr;
78 int _trapno;
79 } _fault;
80 struct { /* SIGPOLL, SIGXFSZ */
81 int _fd;
82 s32 _band;
83 } _file;
84 } _data;
85};
86
87#define SOLARIS_WUNTRACED 0x04
88#define SOLARIS_WNOHANG 0x40
89#define SOLARIS_WEXITED 0x01
90#define SOLARIS_WTRAPPED 0x02
91#define SOLARIS_WSTOPPED WUNTRACED
92#define SOLARIS_WCONTINUED 0x08
93#define SOLARIS_WNOWAIT 0x80
94
95#define SOLARIS_TRAP_BRKPT 1
96#define SOLARIS_TRAP_TRACE 2
97#define SOLARIS_CLD_EXITED 1
98#define SOLARIS_CLD_KILLED 2
99#define SOLARIS_CLD_DUMPED 3
100#define SOLARIS_CLD_TRAPPED 4
101#define SOLARIS_CLD_STOPPED 5
102#define SOLARIS_CLD_CONTINUED 6
103#define SOLARIS_POLL_IN 1
104#define SOLARIS_POLL_OUT 2
105#define SOLARIS_POLL_MSG 3
106#define SOLARIS_POLL_ERR 4
107#define SOLARIS_POLL_PRI 5
108#define SOLARIS_POLL_HUP 6
diff --git a/arch/sparc64/solaris/socket.c b/arch/sparc64/solaris/socket.c
new file mode 100644
index 000000000000..ec8e074c4eac
--- /dev/null
+++ b/arch/sparc64/solaris/socket.c
@@ -0,0 +1,415 @@
1/* $Id: socket.c,v 1.6 2002/02/08 03:57:14 davem Exp $
2 * socket.c: Socket syscall emulation for Solaris 2.6+
3 *
4 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
5 *
6 * 1999-08-19 Fixed socketpair code
7 * Jason Rappleye (rappleye@ccr.buffalo.edu)
8 */
9
10#include <linux/types.h>
11#include <linux/smp_lock.h>
12#include <linux/mm.h>
13#include <linux/slab.h>
14#include <linux/socket.h>
15#include <linux/file.h>
16#include <linux/net.h>
17#include <linux/compat.h>
18#include <net/compat.h>
19
20#include <asm/uaccess.h>
21#include <asm/string.h>
22#include <asm/oplib.h>
23#include <asm/idprom.h>
24
25#include "conv.h"
26
27#define SOCK_SOL_STREAM 2
28#define SOCK_SOL_DGRAM 1
29#define SOCK_SOL_RAW 4
30#define SOCK_SOL_RDM 5
31#define SOCK_SOL_SEQPACKET 6
32
33#define SOL_SO_SNDLOWAT 0x1003
34#define SOL_SO_RCVLOWAT 0x1004
35#define SOL_SO_SNDTIMEO 0x1005
36#define SOL_SO_RCVTIMEO 0x1006
37#define SOL_SO_STATE 0x2000
38
39#define SOL_SS_NDELAY 0x040
40#define SOL_SS_NONBLOCK 0x080
41#define SOL_SS_ASYNC 0x100
42
43#define SO_STATE 0x000e
44
45static int socket_check(int family, int type)
46{
47 if (family != PF_UNIX && family != PF_INET)
48 return -ESOCKTNOSUPPORT;
49 switch (type) {
50 case SOCK_SOL_STREAM: type = SOCK_STREAM; break;
51 case SOCK_SOL_DGRAM: type = SOCK_DGRAM; break;
52 case SOCK_SOL_RAW: type = SOCK_RAW; break;
53 case SOCK_SOL_RDM: type = SOCK_RDM; break;
54 case SOCK_SOL_SEQPACKET: type = SOCK_SEQPACKET; break;
55 default: return -EINVAL;
56 }
57 return type;
58}
59
60static int solaris_to_linux_sockopt(int optname)
61{
62 switch (optname) {
63 case SOL_SO_SNDLOWAT: optname = SO_SNDLOWAT; break;
64 case SOL_SO_RCVLOWAT: optname = SO_RCVLOWAT; break;
65 case SOL_SO_SNDTIMEO: optname = SO_SNDTIMEO; break;
66 case SOL_SO_RCVTIMEO: optname = SO_RCVTIMEO; break;
67 case SOL_SO_STATE: optname = SO_STATE; break;
68 };
69
70 return optname;
71}
72
73asmlinkage int solaris_socket(int family, int type, int protocol)
74{
75 int (*sys_socket)(int, int, int) =
76 (int (*)(int, int, int))SYS(socket);
77
78 type = socket_check (family, type);
79 if (type < 0) return type;
80 return sys_socket(family, type, protocol);
81}
82
83asmlinkage int solaris_socketpair(int *usockvec)
84{
85 int (*sys_socketpair)(int, int, int, int *) =
86 (int (*)(int, int, int, int *))SYS(socketpair);
87
88 /* solaris socketpair really only takes one arg at the syscall
89 * level, int * usockvec. The libs apparently take care of
90 * making sure that family==AF_UNIX and type==SOCK_STREAM. The
91 * pointer we really want ends up residing in the first (and
92 * supposedly only) argument.
93 */
94
95 return sys_socketpair(AF_UNIX, SOCK_STREAM, 0, (int *)usockvec);
96}
97
98asmlinkage int solaris_bind(int fd, struct sockaddr *addr, int addrlen)
99{
100 int (*sys_bind)(int, struct sockaddr *, int) =
101 (int (*)(int, struct sockaddr *, int))SUNOS(104);
102
103 return sys_bind(fd, addr, addrlen);
104}
105
106asmlinkage int solaris_setsockopt(int fd, int level, int optname, u32 optval, int optlen)
107{
108 int (*sunos_setsockopt)(int, int, int, u32, int) =
109 (int (*)(int, int, int, u32, int))SUNOS(105);
110
111 optname = solaris_to_linux_sockopt(optname);
112 if (optname < 0)
113 return optname;
114 if (optname == SO_STATE)
115 return 0;
116
117 return sunos_setsockopt(fd, level, optname, optval, optlen);
118}
119
120asmlinkage int solaris_getsockopt(int fd, int level, int optname, u32 optval, u32 optlen)
121{
122 int (*sunos_getsockopt)(int, int, int, u32, u32) =
123 (int (*)(int, int, int, u32, u32))SUNOS(118);
124
125 optname = solaris_to_linux_sockopt(optname);
126 if (optname < 0)
127 return optname;
128
129 if (optname == SO_STATE)
130 optname = SOL_SO_STATE;
131
132 return sunos_getsockopt(fd, level, optname, optval, optlen);
133}
134
135asmlinkage int solaris_connect(int fd, struct sockaddr __user *addr, int addrlen)
136{
137 int (*sys_connect)(int, struct sockaddr __user *, int) =
138 (int (*)(int, struct sockaddr __user *, int))SYS(connect);
139
140 return sys_connect(fd, addr, addrlen);
141}
142
143asmlinkage int solaris_accept(int fd, struct sockaddr __user *addr, int __user *addrlen)
144{
145 int (*sys_accept)(int, struct sockaddr __user *, int __user *) =
146 (int (*)(int, struct sockaddr __user *, int __user *))SYS(accept);
147
148 return sys_accept(fd, addr, addrlen);
149}
150
151asmlinkage int solaris_listen(int fd, int backlog)
152{
153 int (*sys_listen)(int, int) =
154 (int (*)(int, int))SUNOS(106);
155
156 return sys_listen(fd, backlog);
157}
158
159asmlinkage int solaris_shutdown(int fd, int how)
160{
161 int (*sys_shutdown)(int, int) =
162 (int (*)(int, int))SYS(shutdown);
163
164 return sys_shutdown(fd, how);
165}
166
167#define MSG_SOL_OOB 0x1
168#define MSG_SOL_PEEK 0x2
169#define MSG_SOL_DONTROUTE 0x4
170#define MSG_SOL_EOR 0x8
171#define MSG_SOL_CTRUNC 0x10
172#define MSG_SOL_TRUNC 0x20
173#define MSG_SOL_WAITALL 0x40
174#define MSG_SOL_DONTWAIT 0x80
175
176static int solaris_to_linux_msgflags(int flags)
177{
178 int fl = flags & (MSG_OOB|MSG_PEEK|MSG_DONTROUTE);
179
180 if (flags & MSG_SOL_EOR) fl |= MSG_EOR;
181 if (flags & MSG_SOL_CTRUNC) fl |= MSG_CTRUNC;
182 if (flags & MSG_SOL_TRUNC) fl |= MSG_TRUNC;
183 if (flags & MSG_SOL_WAITALL) fl |= MSG_WAITALL;
184 if (flags & MSG_SOL_DONTWAIT) fl |= MSG_DONTWAIT;
185 return fl;
186}
187
188static int linux_to_solaris_msgflags(int flags)
189{
190 int fl = flags & (MSG_OOB|MSG_PEEK|MSG_DONTROUTE);
191
192 if (flags & MSG_EOR) fl |= MSG_SOL_EOR;
193 if (flags & MSG_CTRUNC) fl |= MSG_SOL_CTRUNC;
194 if (flags & MSG_TRUNC) fl |= MSG_SOL_TRUNC;
195 if (flags & MSG_WAITALL) fl |= MSG_SOL_WAITALL;
196 if (flags & MSG_DONTWAIT) fl |= MSG_SOL_DONTWAIT;
197 return fl;
198}
199
200asmlinkage int solaris_recvfrom(int s, char __user *buf, int len, int flags, u32 from, u32 fromlen)
201{
202 int (*sys_recvfrom)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *) =
203 (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *))SYS(recvfrom);
204
205 return sys_recvfrom(s, buf, len, solaris_to_linux_msgflags(flags), A(from), A(fromlen));
206}
207
208asmlinkage int solaris_recv(int s, char __user *buf, int len, int flags)
209{
210 int (*sys_recvfrom)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *) =
211 (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *))SYS(recvfrom);
212
213 return sys_recvfrom(s, buf, len, solaris_to_linux_msgflags(flags), NULL, NULL);
214}
215
216asmlinkage int solaris_sendto(int s, char __user *buf, int len, int flags, u32 to, u32 tolen)
217{
218 int (*sys_sendto)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *) =
219 (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *))SYS(sendto);
220
221 return sys_sendto(s, buf, len, solaris_to_linux_msgflags(flags), A(to), A(tolen));
222}
223
224asmlinkage int solaris_send(int s, char *buf, int len, int flags)
225{
226 int (*sys_sendto)(int, void *, size_t, unsigned, struct sockaddr *, int *) =
227 (int (*)(int, void *, size_t, unsigned, struct sockaddr *, int *))SYS(sendto);
228
229 return sys_sendto(s, buf, len, solaris_to_linux_msgflags(flags), NULL, NULL);
230}
231
232asmlinkage int solaris_getpeername(int fd, struct sockaddr *addr, int *addrlen)
233{
234 int (*sys_getpeername)(int, struct sockaddr *, int *) =
235 (int (*)(int, struct sockaddr *, int *))SYS(getpeername);
236
237 return sys_getpeername(fd, addr, addrlen);
238}
239
240asmlinkage int solaris_getsockname(int fd, struct sockaddr *addr, int *addrlen)
241{
242 int (*sys_getsockname)(int, struct sockaddr *, int *) =
243 (int (*)(int, struct sockaddr *, int *))SYS(getsockname);
244
245 return sys_getsockname(fd, addr, addrlen);
246}
247
248/* XXX This really belongs in some header file... -DaveM */
249#define MAX_SOCK_ADDR 128 /* 108 for Unix domain -
250 16 for IP, 16 for IPX,
251 24 for IPv6,
252 about 80 for AX.25 */
253
254struct sol_nmsghdr {
255 u32 msg_name;
256 int msg_namelen;
257 u32 msg_iov;
258 u32 msg_iovlen;
259 u32 msg_control;
260 u32 msg_controllen;
261 u32 msg_flags;
262};
263
264struct sol_cmsghdr {
265 u32 cmsg_len;
266 int cmsg_level;
267 int cmsg_type;
268 unsigned char cmsg_data[0];
269};
270
271static inline int msghdr_from_user32_to_kern(struct msghdr *kmsg,
272 struct sol_nmsghdr __user *umsg)
273{
274 u32 tmp1, tmp2, tmp3;
275 int err;
276
277 err = get_user(tmp1, &umsg->msg_name);
278 err |= __get_user(tmp2, &umsg->msg_iov);
279 err |= __get_user(tmp3, &umsg->msg_control);
280 if (err)
281 return -EFAULT;
282
283 kmsg->msg_name = A(tmp1);
284 kmsg->msg_iov = A(tmp2);
285 kmsg->msg_control = A(tmp3);
286
287 err = get_user(kmsg->msg_namelen, &umsg->msg_namelen);
288 err |= get_user(kmsg->msg_controllen, &umsg->msg_controllen);
289 err |= get_user(kmsg->msg_flags, &umsg->msg_flags);
290
291 kmsg->msg_flags = solaris_to_linux_msgflags(kmsg->msg_flags);
292
293 return err;
294}
295
296asmlinkage int solaris_sendmsg(int fd, struct sol_nmsghdr __user *user_msg, unsigned user_flags)
297{
298 struct socket *sock;
299 char address[MAX_SOCK_ADDR];
300 struct iovec iov[UIO_FASTIOV];
301 unsigned char ctl[sizeof(struct cmsghdr) + 20];
302 unsigned char *ctl_buf = ctl;
303 struct msghdr kern_msg;
304 int err, total_len;
305
306 if(msghdr_from_user32_to_kern(&kern_msg, user_msg))
307 return -EFAULT;
308 if(kern_msg.msg_iovlen > UIO_MAXIOV)
309 return -EINVAL;
310 err = verify_compat_iovec(&kern_msg, iov, address, VERIFY_READ);
311 if (err < 0)
312 goto out;
313 total_len = err;
314
315 if(kern_msg.msg_controllen) {
316 struct sol_cmsghdr __user *ucmsg = kern_msg.msg_control;
317 unsigned long *kcmsg;
318 compat_size_t cmlen;
319
320 if(kern_msg.msg_controllen > sizeof(ctl) &&
321 kern_msg.msg_controllen <= 256) {
322 err = -ENOBUFS;
323 ctl_buf = kmalloc(kern_msg.msg_controllen, GFP_KERNEL);
324 if(!ctl_buf)
325 goto out_freeiov;
326 }
327 __get_user(cmlen, &ucmsg->cmsg_len);
328 kcmsg = (unsigned long *) ctl_buf;
329 *kcmsg++ = (unsigned long)cmlen;
330 err = -EFAULT;
331 if(copy_from_user(kcmsg, &ucmsg->cmsg_level,
332 kern_msg.msg_controllen - sizeof(compat_size_t)))
333 goto out_freectl;
334 kern_msg.msg_control = ctl_buf;
335 }
336 kern_msg.msg_flags = solaris_to_linux_msgflags(user_flags);
337
338 lock_kernel();
339 sock = sockfd_lookup(fd, &err);
340 if (sock != NULL) {
341 if (sock->file->f_flags & O_NONBLOCK)
342 kern_msg.msg_flags |= MSG_DONTWAIT;
343 err = sock_sendmsg(sock, &kern_msg, total_len);
344 sockfd_put(sock);
345 }
346 unlock_kernel();
347
348out_freectl:
349 /* N.B. Use kfree here, as kern_msg.msg_controllen might change? */
350 if(ctl_buf != ctl)
351 kfree(ctl_buf);
352out_freeiov:
353 if(kern_msg.msg_iov != iov)
354 kfree(kern_msg.msg_iov);
355out:
356 return err;
357}
358
359asmlinkage int solaris_recvmsg(int fd, struct sol_nmsghdr __user *user_msg, unsigned int user_flags)
360{
361 struct iovec iovstack[UIO_FASTIOV];
362 struct msghdr kern_msg;
363 char addr[MAX_SOCK_ADDR];
364 struct socket *sock;
365 struct iovec *iov = iovstack;
366 struct sockaddr __user *uaddr;
367 int __user *uaddr_len;
368 unsigned long cmsg_ptr;
369 int err, total_len, len = 0;
370
371 if(msghdr_from_user32_to_kern(&kern_msg, user_msg))
372 return -EFAULT;
373 if(kern_msg.msg_iovlen > UIO_MAXIOV)
374 return -EINVAL;
375
376 uaddr = kern_msg.msg_name;
377 uaddr_len = &user_msg->msg_namelen;
378 err = verify_compat_iovec(&kern_msg, iov, addr, VERIFY_WRITE);
379 if (err < 0)
380 goto out;
381 total_len = err;
382
383 cmsg_ptr = (unsigned long) kern_msg.msg_control;
384 kern_msg.msg_flags = 0;
385
386 lock_kernel();
387 sock = sockfd_lookup(fd, &err);
388 if (sock != NULL) {
389 if (sock->file->f_flags & O_NONBLOCK)
390 user_flags |= MSG_DONTWAIT;
391 err = sock_recvmsg(sock, &kern_msg, total_len, user_flags);
392 if(err >= 0)
393 len = err;
394 sockfd_put(sock);
395 }
396 unlock_kernel();
397
398 if(uaddr != NULL && err >= 0)
399 err = move_addr_to_user(addr, kern_msg.msg_namelen, uaddr, uaddr_len);
400 if(err >= 0) {
401 err = __put_user(linux_to_solaris_msgflags(kern_msg.msg_flags), &user_msg->msg_flags);
402 if(!err) {
403 /* XXX Convert cmsg back into userspace 32-bit format... */
404 err = __put_user((unsigned long)kern_msg.msg_control - cmsg_ptr,
405 &user_msg->msg_controllen);
406 }
407 }
408
409 if(kern_msg.msg_iov != iov)
410 kfree(kern_msg.msg_iov);
411out:
412 if(err < 0)
413 return err;
414 return len;
415}
diff --git a/arch/sparc64/solaris/socksys.c b/arch/sparc64/solaris/socksys.c
new file mode 100644
index 000000000000..d7c1c76582cc
--- /dev/null
+++ b/arch/sparc64/solaris/socksys.c
@@ -0,0 +1,211 @@
1/* $Id: socksys.c,v 1.21 2002/02/08 03:57:14 davem Exp $
2 * socksys.c: /dev/inet/ stuff for Solaris emulation.
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997, 1998 Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
6 * Copyright (C) 1995, 1996 Mike Jagdis (jaggy@purplet.demon.co.uk)
7 */
8
9/*
10 * Dave, _please_ give me specifications on this fscking mess so that I
11 * could at least get it into the state when it wouldn't screw the rest of
12 * the kernel over. socksys.c and timod.c _stink_ and we are not talking
13 * H2S here, it's isopropilmercaptan in concentrations way over LD50. -- AV
14 */
15
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/smp.h>
20#include <linux/smp_lock.h>
21#include <linux/ioctl.h>
22#include <linux/fs.h>
23#include <linux/file.h>
24#include <linux/init.h>
25#include <linux/poll.h>
26#include <linux/slab.h>
27#include <linux/syscalls.h>
28#include <linux/in.h>
29#include <linux/devfs_fs_kernel.h>
30
31#include <net/sock.h>
32
33#include <asm/uaccess.h>
34#include <asm/termios.h>
35
36#include "conv.h"
37#include "socksys.h"
38
39static int af_inet_protocols[] = {
40IPPROTO_ICMP, IPPROTO_ICMP, IPPROTO_IGMP, IPPROTO_IPIP, IPPROTO_TCP,
41IPPROTO_EGP, IPPROTO_PUP, IPPROTO_UDP, IPPROTO_IDP, IPPROTO_RAW,
420, 0, 0, 0, 0, 0,
43};
44
45#ifndef DEBUG_SOLARIS_KMALLOC
46
47#define mykmalloc kmalloc
48#define mykfree kfree
49
50#else
51
52extern void * mykmalloc(size_t s, int gfp);
53extern void mykfree(void *);
54
55#endif
56
57static unsigned int (*sock_poll)(struct file *, poll_table *);
58
59static struct file_operations socksys_file_ops = {
60 /* Currently empty */
61};
62
63static int socksys_open(struct inode * inode, struct file * filp)
64{
65 int family, type, protocol, fd;
66 struct dentry *dentry;
67 int (*sys_socket)(int,int,int) =
68 (int (*)(int,int,int))SUNOS(97);
69 struct sol_socket_struct * sock;
70
71 family = ((iminor(inode) >> 4) & 0xf);
72 switch (family) {
73 case AF_UNIX:
74 type = SOCK_STREAM;
75 protocol = 0;
76 break;
77 case AF_INET:
78 protocol = af_inet_protocols[iminor(inode) & 0xf];
79 switch (protocol) {
80 case IPPROTO_TCP: type = SOCK_STREAM; break;
81 case IPPROTO_UDP: type = SOCK_DGRAM; break;
82 default: type = SOCK_RAW; break;
83 }
84 break;
85 default:
86 type = SOCK_RAW;
87 protocol = 0;
88 break;
89 }
90
91 fd = sys_socket(family, type, protocol);
92 if (fd < 0)
93 return fd;
94 /*
95 * N.B. The following operations are not legal!
96 *
97 * No shit. WTF is it supposed to do, anyway?
98 *
99 * Try instead:
100 * d_delete(filp->f_dentry), then d_instantiate with sock inode
101 */
102 dentry = filp->f_dentry;
103 filp->f_dentry = dget(fcheck(fd)->f_dentry);
104 filp->f_dentry->d_inode->i_rdev = inode->i_rdev;
105 filp->f_dentry->d_inode->i_flock = inode->i_flock;
106 SOCKET_I(filp->f_dentry->d_inode)->file = filp;
107 filp->f_op = &socksys_file_ops;
108 sock = (struct sol_socket_struct*)
109 mykmalloc(sizeof(struct sol_socket_struct), GFP_KERNEL);
110 if (!sock) return -ENOMEM;
111 SOLDD(("sock=%016lx(%016lx)\n", sock, filp));
112 sock->magic = SOLARIS_SOCKET_MAGIC;
113 sock->modcount = 0;
114 sock->state = TS_UNBND;
115 sock->offset = 0;
116 sock->pfirst = sock->plast = NULL;
117 filp->private_data = sock;
118 SOLDD(("filp->private_data %016lx\n", filp->private_data));
119
120 sys_close(fd);
121 dput(dentry);
122 return 0;
123}
124
125static int socksys_release(struct inode * inode, struct file * filp)
126{
127 struct sol_socket_struct * sock;
128 struct T_primsg *it;
129
130 /* XXX: check this */
131 sock = (struct sol_socket_struct *)filp->private_data;
132 SOLDD(("sock release %016lx(%016lx)\n", sock, filp));
133 it = sock->pfirst;
134 while (it) {
135 struct T_primsg *next = it->next;
136
137 SOLDD(("socksys_release %016lx->%016lx\n", it, next));
138 mykfree((char*)it);
139 it = next;
140 }
141 filp->private_data = NULL;
142 SOLDD(("socksys_release %016lx\n", sock));
143 mykfree((char*)sock);
144 return 0;
145}
146
147static unsigned int socksys_poll(struct file * filp, poll_table * wait)
148{
149 struct inode *ino;
150 unsigned int mask = 0;
151
152 ino=filp->f_dentry->d_inode;
153 if (ino && S_ISSOCK(ino->i_mode)) {
154 struct sol_socket_struct *sock;
155 sock = (struct sol_socket_struct*)filp->private_data;
156 if (sock && sock->pfirst) {
157 mask |= POLLIN | POLLRDNORM;
158 if (sock->pfirst->pri == MSG_HIPRI)
159 mask |= POLLPRI;
160 }
161 }
162 if (sock_poll)
163 mask |= (*sock_poll)(filp, wait);
164 return mask;
165}
166
167static struct file_operations socksys_fops = {
168 .open = socksys_open,
169 .release = socksys_release,
170};
171
172int __init
173init_socksys(void)
174{
175 int ret;
176 struct file * file;
177 int (*sys_socket)(int,int,int) =
178 (int (*)(int,int,int))SUNOS(97);
179 int (*sys_close)(unsigned int) =
180 (int (*)(unsigned int))SYS(close);
181
182 ret = register_chrdev (30, "socksys", &socksys_fops);
183 if (ret < 0) {
184 printk ("Couldn't register socksys character device\n");
185 return ret;
186 }
187 ret = sys_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
188 if (ret < 0) {
189 printk ("Couldn't create socket\n");
190 return ret;
191 }
192
193 devfs_mk_cdev(MKDEV(30, 0), S_IFCHR|S_IRUSR|S_IWUSR, "socksys");
194
195 file = fcheck(ret);
196 /* N.B. Is this valid? Suppose the f_ops are in a module ... */
197 socksys_file_ops = *file->f_op;
198 sys_close(ret);
199 sock_poll = socksys_file_ops.poll;
200 socksys_file_ops.poll = socksys_poll;
201 socksys_file_ops.release = socksys_release;
202 return 0;
203}
204
205void
206cleanup_socksys(void)
207{
208 if (unregister_chrdev(30, "socksys"))
209 printk ("Couldn't unregister socksys character device\n");
210 devfs_remove ("socksys");
211}
diff --git a/arch/sparc64/solaris/socksys.h b/arch/sparc64/solaris/socksys.h
new file mode 100644
index 000000000000..5d1b78ec1600
--- /dev/null
+++ b/arch/sparc64/solaris/socksys.h
@@ -0,0 +1,208 @@
1/* $Id: socksys.h,v 1.2 1998/03/26 08:46:07 jj Exp $
2 * socksys.h: Definitions for STREAMS modules emulation code.
3 *
4 * Copyright (C) 1998 Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
5 */
6
7#define MSG_HIPRI 0x01
8#define MSG_ANY 0x02
9#define MSG_BAND 0x04
10
11#define MORECTL 1
12#define MOREDATA 2
13
14#define TBADADDR 1
15#define TBADOPT 2
16#define TACCES 3
17#define TBADF 4
18#define TNOADDR 5
19#define TOUTSTATE 6
20#define TBADSEQ 7
21#define TSYSERR 8
22#define TLOOK 9
23#define TBADDATA 10
24#define TBUFOVFLW 11
25#define TFLOW 12
26#define TNODATA 13
27#define TNODIS 14
28#define TNOUDERR 15
29#define TBADFLAG 16
30#define TNOREL 17
31#define TNOTSUPPORT 18
32#define TSTATECHNG 19
33
34#define T_CONN_REQ 0
35#define T_CONN_RES 1
36#define T_DISCON_REQ 2
37#define T_DATA_REQ 3
38#define T_EXDATA_REQ 4
39#define T_INFO_REQ 5
40#define T_BIND_REQ 6
41#define T_UNBIND_REQ 7
42#define T_UNITDATA_REQ 8
43#define T_OPTMGMT_REQ 9
44#define T_ORDREL_REQ 10
45
46#define T_CONN_IND 11
47#define T_CONN_CON 12
48#define T_DISCON_IND 13
49#define T_DATA_IND 14
50#define T_EXDATA_IND 15
51#define T_INFO_ACK 16
52#define T_BIND_ACK 17
53#define T_ERROR_ACK 18
54#define T_OK_ACK 19
55#define T_UNITDATA_IND 20
56#define T_UDERROR_IND 21
57#define T_OPTMGMT_ACK 22
58#define T_ORDREL_IND 23
59
60#define T_NEGOTIATE 0x0004
61#define T_FAILURE 0x0040
62
63#define TS_UNBND 0 /* unbound */
64#define TS_WACK_BREQ 1 /* waiting for T_BIND_REQ ack */
65#define TS_WACK_UREQ 2 /* waiting for T_UNBIND_REQ ack */
66#define TS_IDLE 3 /* idle */
67#define TS_WACK_OPTREQ 4 /* waiting for T_OPTMGMT_REQ ack */
68#define TS_WACK_CREQ 5 /* waiting for T_CONN_REQ ack */
69#define TS_WCON_CREQ 6 /* waiting for T_CONN_REQ confirmation */
70#define TS_WRES_CIND 7 /* waiting for T_CONN_IND */
71#define TS_WACK_CRES 8 /* waiting for T_CONN_RES ack */
72#define TS_DATA_XFER 9 /* data transfer */
73#define TS_WIND_ORDREL 10 /* releasing read but not write */
74#define TS_WREQ_ORDREL 11 /* wait to release write but not read */
75#define TS_WACK_DREQ6 12 /* waiting for T_DISCON_REQ ack */
76#define TS_WACK_DREQ7 13 /* waiting for T_DISCON_REQ ack */
77#define TS_WACK_DREQ9 14 /* waiting for T_DISCON_REQ ack */
78#define TS_WACK_DREQ10 15 /* waiting for T_DISCON_REQ ack */
79#define TS_WACK_DREQ11 16 /* waiting for T_DISCON_REQ ack */
80#define TS_NOSTATES 17
81
82struct T_conn_req {
83 s32 PRIM_type;
84 s32 DEST_length;
85 s32 DEST_offset;
86 s32 OPT_length;
87 s32 OPT_offset;
88};
89
90struct T_bind_req {
91 s32 PRIM_type;
92 s32 ADDR_length;
93 s32 ADDR_offset;
94 u32 CONIND_number;
95};
96
97struct T_unitdata_req {
98 s32 PRIM_type;
99 s32 DEST_length;
100 s32 DEST_offset;
101 s32 OPT_length;
102 s32 OPT_offset;
103};
104
105struct T_optmgmt_req {
106 s32 PRIM_type;
107 s32 OPT_length;
108 s32 OPT_offset;
109 s32 MGMT_flags;
110};
111
112struct T_bind_ack {
113 s32 PRIM_type;
114 s32 ADDR_length;
115 s32 ADDR_offset;
116 u32 CONIND_number;
117};
118
119struct T_error_ack {
120 s32 PRIM_type;
121 s32 ERROR_prim;
122 s32 TLI_error;
123 s32 UNIX_error;
124};
125
126struct T_ok_ack {
127 s32 PRIM_type;
128 s32 CORRECT_prim;
129};
130
131struct T_conn_ind {
132 s32 PRIM_type;
133 s32 SRC_length;
134 s32 SRC_offset;
135 s32 OPT_length;
136 s32 OPT_offset;
137 s32 SEQ_number;
138};
139
140struct T_conn_con {
141 s32 PRIM_type;
142 s32 RES_length;
143 s32 RES_offset;
144 s32 OPT_length;
145 s32 OPT_offset;
146};
147
148struct T_discon_ind {
149 s32 PRIM_type;
150 s32 DISCON_reason;
151 s32 SEQ_number;
152};
153
154struct T_unitdata_ind {
155 s32 PRIM_type;
156 s32 SRC_length;
157 s32 SRC_offset;
158 s32 OPT_length;
159 s32 OPT_offset;
160};
161
162struct T_optmgmt_ack {
163 s32 PRIM_type;
164 s32 OPT_length;
165 s32 OPT_offset;
166 s32 MGMT_flags;
167};
168
169struct opthdr {
170 s32 level;
171 s32 name;
172 s32 len;
173 char value[0];
174};
175
176struct T_primsg {
177 struct T_primsg *next;
178 unsigned char pri;
179 unsigned char band;
180 int length;
181 s32 type;
182};
183
184struct strbuf {
185 s32 maxlen;
186 s32 len;
187 u32 buf;
188} ;
189
190/* Constants used by STREAMS modules emulation code */
191
192typedef char sol_module;
193
194#define MAX_NR_STREAM_MODULES 16
195
196/* Private data structure assigned to sockets. */
197
198struct sol_socket_struct {
199 int magic;
200 int modcount;
201 sol_module module[MAX_NR_STREAM_MODULES];
202 long state;
203 int offset;
204 struct T_primsg *pfirst, *plast;
205};
206
207#define SOLARIS_SOCKET_MAGIC 0xADDED
208
diff --git a/arch/sparc64/solaris/systbl.S b/arch/sparc64/solaris/systbl.S
new file mode 100644
index 000000000000..d25667eeae10
--- /dev/null
+++ b/arch/sparc64/solaris/systbl.S
@@ -0,0 +1,314 @@
1/* $Id: systbl.S,v 1.11 2000/03/13 21:57:35 davem Exp $
2 * systbl.S: System call entry point table for Solaris compatibility.
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 */
7
8#include <asm/unistd.h>
9
10/* Fall back to sys_call_table32 entry */
11#define CHAIN(name) __NR_##name
12
13/* Pass pt_regs pointer as first argument */
14#define REGS(name) name+1
15
16/* Hack till all be implemented */
17#define solaris_getpmsg solaris_unimplemented
18#define solaris_hrtsys solaris_unimplemented
19#define solaris_msgsys solaris_unimplemented
20#define solaris_putpmsg solaris_unimplemented
21#define solaris_semsys solaris_unimplemented
22
23 .data
24 .globl solaris_sys_table
25solaris_sys_table:
26 .word solaris_unimplemented /* nosys 0 */
27 .word CHAIN(exit) /* exit d 1 */
28 .word CHAIN(fork) /* fork 2 */
29 .word CHAIN(read) /* read dpd 3 */
30 .word CHAIN(write) /* write dpd 4 */
31 .word solaris_open /* open soo 5 */
32 .word CHAIN(close) /* close d 6 */
33 .word solaris_wait /* wait xxx 7 */
34 .word CHAIN(creat) /* creat so 8 */
35 .word CHAIN(link) /* link ss 9 */
36 .word CHAIN(unlink) /* unlink s 10 */
37 .word solaris_unimplemented /* exec sxx 11 */
38 .word CHAIN(chdir) /* chdir s 12 */
39 .word CHAIN(time) /* time 13 */
40 .word solaris_mknod /* mknod sox 14 */
41 .word CHAIN(chmod) /* chmod so 15 */
42 .word CHAIN(chown) /* chown sdd 16 */
43 .word solaris_brk /* brk/break x 17 */
44 .word solaris_stat /* stat sp 18 */
45 .word CHAIN(lseek) /* seek/lseek ddd 19 */
46 .word solaris_getpid /* getpid 20 */
47 .word solaris_unimplemented /* mount 21 */
48 .word CHAIN(umount) /* umount s 22 */
49 .word CHAIN(setuid) /* setuid d 23 */
50 .word solaris_getuid /* getuid 24 */
51 .word CHAIN(stime) /* stime d 25 */
52#if 0
53 .word solaris_ptrace /* ptrace xdxx 26 */
54#else
55 .word CHAIN(ptrace) /* ptrace xdxx 26 */
56#endif
57 .word CHAIN(alarm) /* alarm d 27 */
58 .word solaris_fstat /* fstat dp 28 */
59 .word CHAIN(pause) /* pause 29 */
60 .word CHAIN(utime) /* utime xx 30 */
61 .word solaris_unimplemented /* stty 31 */
62 .word solaris_unimplemented /* gtty 32 */
63 .word solaris_access /* access so 33 */
64 .word CHAIN(nice) /* nice d 34 */
65 .word solaris_statfs /* statfs spdd 35 */
66 .word CHAIN(sync) /* sync 36 */
67 .word solaris_kill /* kill dd 37 */
68 .word solaris_fstatfs /* fstatfs dpdd 38 */
69 .word solaris_procids /* pgrpsys ddd 39 */
70 .word solaris_unimplemented /* xenix 40 */
71 .word CHAIN(dup) /* dup d 41 */
72 .word CHAIN(pipe) /* pipe 42 */
73 .word CHAIN(times) /* times p 43 */
74 .word 44 /*CHAIN(profil)*/ /* prof xxxx 44 */
75 .word solaris_unimplemented /* lock/plock 45 */
76 .word CHAIN(setgid) /* setgid d 46 */
77 .word solaris_getgid /* getgid 47 */
78 .word solaris_sigfunc /* sigfunc xx 48 */
79 .word REGS(solaris_msgsys) /* msgsys dxddd 49 */
80 .word solaris_unimplemented /* syssun/3b 50 */
81 .word CHAIN(acct) /* acct/sysacct x 51 */
82 .word solaris_shmsys /* shmsys ddxo 52 */
83 .word REGS(solaris_semsys) /* semsys dddx 53 */
84 .word solaris_ioctl /* ioctl dxx 54 */
85 .word solaris_unimplemented /* uadmin xxx 55 */
86 .word solaris_unimplemented /* reserved:exch 56 */
87 .word solaris_utssys /* utssys x 57 */
88 .word CHAIN(fsync) /* fsync d 58 */
89 .word CHAIN(execve) /* execv spp 59 */
90 .word CHAIN(umask) /* umask o 60 */
91 .word CHAIN(chroot) /* chroot s 61 */
92 .word solaris_fcntl /* fcntl dxx 62 */
93 .word solaris_ulimit /* ulimit xx 63 */
94 .word solaris_unimplemented /* ? 64 */
95 .word solaris_unimplemented /* ? 65 */
96 .word solaris_unimplemented /* ? 66 */
97 .word solaris_unimplemented /* ? 67 */
98 .word solaris_unimplemented /* ? 68 */
99 .word solaris_unimplemented /* ? 69 */
100 .word solaris_unimplemented /* advfs 70 */
101 .word solaris_unimplemented /* unadvfs 71 */
102 .word solaris_unimplemented /* rmount 72 */
103 .word solaris_unimplemented /* rumount 73 */
104 .word solaris_unimplemented /* rfstart 74 */
105 .word solaris_unimplemented /* ? 75 */
106 .word solaris_unimplemented /* rdebug 76 */
107 .word solaris_unimplemented /* rfstop 77 */
108 .word solaris_unimplemented /* rfsys 78 */
109 .word CHAIN(rmdir) /* rmdir s 79 */
110 .word CHAIN(mkdir) /* mkdir so 80 */
111 .word CHAIN(getdents) /* getdents dxd 81 */
112 .word solaris_unimplemented /* libattach 82 */
113 .word solaris_unimplemented /* libdetach 83 */
114 .word CHAIN(sysfs) /* sysfs dxx 84 */
115 .word solaris_getmsg /* getmsg dxxx 85 */
116 .word solaris_putmsg /* putmsg dxxd 86 */
117 .word CHAIN(poll) /* poll xdd 87 */
118 .word solaris_lstat /* lstat sp 88 */
119 .word CHAIN(symlink) /* symlink ss 89 */
120 .word CHAIN(readlink) /* readlink spd 90 */
121 .word CHAIN(setgroups) /* setgroups dp 91 */
122 .word CHAIN(getgroups) /* getgroups dp 92 */
123 .word CHAIN(fchmod) /* fchmod do 93 */
124 .word CHAIN(fchown) /* fchown ddd 94 */
125 .word solaris_sigprocmask /* sigprocmask dxx 95 */
126 .word solaris_sigsuspend /* sigsuspend x 96 */
127 .word solaris_sigaltstack /* sigaltstack xx 97 */
128 .word solaris_sigaction /* sigaction dxx 98 */
129 .word solaris_sigpending /* sigpending dd 99 */
130 .word REGS(solaris_context) /* context 100 */
131 .word solaris_unimplemented /* evsys 101 */
132 .word solaris_unimplemented /* evtrapret 102 */
133 .word solaris_statvfs /* statvfs sp 103 */
134 .word solaris_fstatvfs /* fstatvfs dp 104 */
135 .word solaris_unimplemented /* unknown 105 */
136 .word solaris_unimplemented /* nfssys 106 */
137 .word solaris_waitid /* waitid ddxd 107 */
138 .word solaris_unimplemented /* sigsendsys ddd 108 */
139 .word REGS(solaris_hrtsys) /* hrtsys xxx 109 */
140 .word solaris_unimplemented /* acancel dxd 110 */
141 .word solaris_unimplemented /* async 111 */
142 .word solaris_unimplemented /* priocntlsys 112 */
143 .word solaris_pathconf /* pathconf sd 113 */
144 .word CHAIN(mincore) /* mincore d 114 */
145 .word solaris_mmap /* mmap xxxxdx 115 */
146 .word CHAIN(mprotect) /* mprotect xdx 116 */
147 .word CHAIN(munmap) /* munmap xd 117 */
148 .word solaris_fpathconf /* fpathconf dd 118 */
149 .word CHAIN(fork) /* fork 119 */
150 .word solaris_unimplemented /* fchdir d 120 */
151 .word CHAIN(readv) /* readv dxd 121 */
152 .word CHAIN(writev) /* writev dxd 122 */
153 .word solaris_xstat /* xstat dsx 123 */
154 .word solaris_lxstat /* lxstat dsx 124 */
155 .word solaris_fxstat /* fxstat ddx 125 */
156 .word solaris_xmknod /* xmknod dsox 126 */
157 .word solaris_unimplemented /* syslocal d 127 */
158 .word solaris_setrlimit /* setrlimit dp 128 */
159 .word solaris_getrlimit /* getrlimit dp 129 */
160 .word CHAIN(chown) /* lchown sdd 130 */
161 .word solaris_unimplemented /* memcntl 131 */
162 .word solaris_getpmsg /* getpmsg dxxxx 132 */
163 .word solaris_putpmsg /* putpmsg dxxdd 133 */
164 .word CHAIN(rename) /* rename ss 134 */
165 .word solaris_utsname /* uname x 135 */
166 .word solaris_unimplemented /* setegid 136 */
167 .word solaris_sysconf /* sysconfig d 137 */
168 .word solaris_unimplemented /* adjtime 138 */
169 .word solaris_sysinfo /* systeminfo dsd 139 */
170 .word solaris_unimplemented /* ? 140 */
171 .word solaris_unimplemented /* seteuid 141 */
172 .word solaris_unimplemented /* ? 142 */
173 .word solaris_unimplemented /* ? 143 */
174 .word solaris_unimplemented /* secsys dx 144 */
175 .word solaris_unimplemented /* filepriv sdxd 145 */
176 .word solaris_unimplemented /* procpriv dxd 146 */
177 .word solaris_unimplemented /* devstat sdx 147 */
178 .word solaris_unimplemented /* aclipc ddddx 148 */
179 .word solaris_unimplemented /* fdevstat ddx 149 */
180 .word solaris_unimplemented /* flvlfile ddx 150 */
181 .word solaris_unimplemented /* lvlfile sdx 151 */
182 .word solaris_unimplemented /* ? 152 */
183 .word solaris_unimplemented /* fchroot d 153 */
184 .word solaris_unimplemented /* lvlproc dx 154 */
185 .word solaris_unimplemented /* ? 155 */
186 .word solaris_gettimeofday /* gettimeofday x 156 */
187 .word CHAIN(getitimer) /* getitimer dx 157 */
188 .word CHAIN(setitimer) /* setitimer dxx 158 */
189 .word solaris_unimplemented /* lwp-xxx 159 */
190 .word solaris_unimplemented /* lwp-xxx 160 */
191 .word solaris_unimplemented /* lwp-xxx 161 */
192 .word solaris_unimplemented /* lwp-xxx 162 */
193 .word solaris_unimplemented /* lwp-xxx 163 */
194 .word solaris_unimplemented /* lwp-xxx 164 */
195 .word solaris_unimplemented /* lwp-xxx 165 */
196 .word solaris_unimplemented /* lwp-xxx 166 */
197 .word solaris_unimplemented /* lwp-xxx 167 */
198 .word solaris_unimplemented /* lwp-xxx 168 */
199 .word solaris_unimplemented /* lwp-xxx 169 */
200 .word solaris_unimplemented /* lwp-xxx 170 */
201 .word solaris_unimplemented /* lwp-xxx 171 */
202 .word solaris_unimplemented /* lwp-xxx 172 */
203 .word solaris_pread /* pread dpdd 173 */
204 .word solaris_pwrite /* pwrite dpdd 174 */
205 .word REGS(solaris_llseek) /* llseek dLd 175 */
206 .word solaris_unimplemented /* lwpself 176 */
207 .word solaris_unimplemented /* lwpinfo 177 */
208 .word solaris_unimplemented /* lwpprivate 178 */
209 .word solaris_unimplemented /* processorbind 179 */
210 .word solaris_unimplemented /* processorexbind 180 */
211 .word solaris_unimplemented /* 181 */
212 .word solaris_unimplemented /* sync_mailbox 182 */
213 .word solaris_unimplemented /* prepblock 183 */
214 .word solaris_unimplemented /* block 184 */
215 .word solaris_acl /* acl sddp 185 */
216 .word solaris_unimplemented /* unblock 186 */
217 .word solaris_unimplemented /* cancelblock 187 */
218 .word solaris_unimplemented /* ? 188 */
219 .word solaris_unimplemented /* xxxxx 189 */
220 .word solaris_unimplemented /* xxxxxe 190 */
221 .word solaris_unimplemented /* 191 */
222 .word solaris_unimplemented /* 192 */
223 .word solaris_unimplemented /* 193 */
224 .word solaris_unimplemented /* 194 */
225 .word solaris_unimplemented /* 195 */
226 .word solaris_unimplemented /* 196 */
227 .word solaris_unimplemented /* 197 */
228 .word solaris_unimplemented /* 198 */
229 .word CHAIN(nanosleep) /* nanosleep dd 199 */
230 .word solaris_facl /* facl dddp 200 */
231 .word solaris_unimplemented /* 201 */
232 .word CHAIN(setreuid) /* setreuid dd 202 */
233 .word CHAIN(setregid) /* setregid dd 203 */
234 .word solaris_unimplemented /* 204 */
235 .word solaris_unimplemented /* 205 */
236 .word solaris_unimplemented /* 206 */
237 .word solaris_unimplemented /* 207 */
238 .word solaris_unimplemented /* 208 */
239 .word solaris_unimplemented /* 209 */
240 .word solaris_unimplemented /* 210 */
241 .word solaris_unimplemented /* 211 */
242 .word solaris_unimplemented /* 212 */
243 .word solaris_getdents64 /* getdents64 dpd 213 */
244 .word REGS(solaris_mmap64) /* mmap64 xxxxdX 214 */
245 .word solaris_stat64 /* stat64 sP 215 */
246 .word solaris_lstat64 /* lstat64 sP 216 */
247 .word solaris_fstat64 /* fstat64 dP 217 */
248 .word solaris_statvfs64 /* statvfs64 sP 218 */
249 .word solaris_fstatvfs64 /* fstatvfs64 dP 219 */
250 .word solaris_setrlimit64 /* setrlimit64 dP 220 */
251 .word solaris_getrlimit64 /* getrlimit64 dP 221 */
252 .word CHAIN(pread64) /* pread64 dpdD 222 */
253 .word CHAIN(pwrite64) /* pwrite64 dpdD 223 */
254 .word CHAIN(creat) /* creat64 so 224 */
255 .word solaris_open /* open64 soo 225 */
256 .word solaris_unimplemented /* 226 */
257 .word solaris_unimplemented /* 227 */
258 .word solaris_unimplemented /* 228 */
259 .word solaris_unimplemented /* 229 */
260 .word solaris_socket /* socket ddd 230 */
261 .word solaris_socketpair /* socketpair dddp 231 */
262 .word solaris_bind /* bind dpd 232 */
263 .word solaris_listen /* listen dd 233 */
264 .word solaris_accept /* accept dpp 234 */
265 .word solaris_connect /* connect dpd 235 */
266 .word solaris_shutdown /* shutdown dd 236 */
267 .word solaris_recv /* recv dpdd 237 */
268 .word solaris_recvfrom /* recvfrom dpddpp 238 */
269 .word solaris_recvmsg /* recvmsg dpd 239 */
270 .word solaris_send /* send dpdd 240 */
271 .word solaris_sendmsg /* sendmsg dpd 241 */
272 .word solaris_sendto /* sendto dpddpd 242 */
273 .word solaris_getpeername /* getpeername dpp 243 */
274 .word solaris_getsockname /* getsockname dpp 244 */
275 .word solaris_getsockopt /* getsockopt dddpp 245 */
276 .word solaris_setsockopt /* setsockopt dddpp 246 */
277 .word solaris_unimplemented /* 247 */
278 .word solaris_ntp_gettime /* ntp_gettime p 248 */
279 .word solaris_ntp_adjtime /* ntp_adjtime p 249 */
280 .word solaris_unimplemented /* 250 */
281 .word solaris_unimplemented /* 251 */
282 .word solaris_unimplemented /* 252 */
283 .word solaris_unimplemented /* 253 */
284 .word solaris_unimplemented /* 254 */
285 .word solaris_unimplemented /* 255 */
286 .word solaris_unimplemented /* 256 */
287 .word solaris_unimplemented /* 257 */
288 .word solaris_unimplemented /* 258 */
289 .word solaris_unimplemented /* 259 */
290 .word solaris_unimplemented /* 260 */
291 .word solaris_unimplemented /* 261 */
292 .word solaris_unimplemented /* 262 */
293 .word solaris_unimplemented /* 263 */
294 .word solaris_unimplemented /* 264 */
295 .word solaris_unimplemented /* 265 */
296 .word solaris_unimplemented /* 266 */
297 .word solaris_unimplemented /* 267 */
298 .word solaris_unimplemented /* 268 */
299 .word solaris_unimplemented /* 269 */
300 .word solaris_unimplemented /* 270 */
301 .word solaris_unimplemented /* 271 */
302 .word solaris_unimplemented /* 272 */
303 .word solaris_unimplemented /* 273 */
304 .word solaris_unimplemented /* 274 */
305 .word solaris_unimplemented /* 275 */
306 .word solaris_unimplemented /* 276 */
307 .word solaris_unimplemented /* 277 */
308 .word solaris_unimplemented /* 278 */
309 .word solaris_unimplemented /* 279 */
310 .word solaris_unimplemented /* 280 */
311 .word solaris_unimplemented /* 281 */
312 .word solaris_unimplemented /* 282 */
313 .word solaris_unimplemented /* 283 */
314
diff --git a/arch/sparc64/solaris/timod.c b/arch/sparc64/solaris/timod.c
new file mode 100644
index 000000000000..022c80f43392
--- /dev/null
+++ b/arch/sparc64/solaris/timod.c
@@ -0,0 +1,959 @@
1/* $Id: timod.c,v 1.19 2002/02/08 03:57:14 davem Exp $
2 * timod.c: timod emulation.
3 *
4 * Copyright (C) 1998 Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
5 *
6 * Streams & timod emulation based on code
7 * Copyright (C) 1995, 1996 Mike Jagdis (jaggy@purplet.demon.co.uk)
8 *
9 */
10
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/sched.h>
14#include <linux/smp.h>
15#include <linux/smp_lock.h>
16#include <linux/ioctl.h>
17#include <linux/fs.h>
18#include <linux/file.h>
19#include <linux/netdevice.h>
20#include <linux/poll.h>
21
22#include <net/sock.h>
23
24#include <asm/uaccess.h>
25#include <asm/termios.h>
26
27#include "conv.h"
28#include "socksys.h"
29
30asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg);
31
32static DEFINE_SPINLOCK(timod_pagelock);
33static char * page = NULL ;
34
35#ifndef DEBUG_SOLARIS_KMALLOC
36
37#define mykmalloc kmalloc
38#define mykfree kfree
39
40#else
41
42void * mykmalloc(size_t s, int gfp)
43{
44 static char * page;
45 static size_t free;
46 void * r;
47 s = ((s + 63) & ~63);
48 if( s > PAGE_SIZE ) {
49 SOLD("too big size, calling real kmalloc");
50 return kmalloc(s, gfp);
51 }
52 if( s > free ) {
53 /* we are wasting memory, but we don't care */
54 page = (char *)__get_free_page(gfp);
55 free = PAGE_SIZE;
56 }
57 r = page;
58 page += s;
59 free -= s;
60 return r;
61}
62
63void mykfree(void *p)
64{
65}
66
67#endif
68
69#ifndef DEBUG_SOLARIS
70
71#define BUF_SIZE PAGE_SIZE
72#define PUT_MAGIC(a,m)
73#define SCHECK_MAGIC(a,m)
74#define BUF_OFFSET 0
75#define MKCTL_TRAILER 0
76
77#else
78
79#define BUF_SIZE (PAGE_SIZE-2*sizeof(u64))
80#define BUFPAGE_MAGIC 0xBADC0DEDDEADBABEL
81#define MKCTL_MAGIC 0xDEADBABEBADC0DEDL
82#define PUT_MAGIC(a,m) do{(*(u64*)(a))=(m);}while(0)
83#define SCHECK_MAGIC(a,m) do{if((*(u64*)(a))!=(m))printk("%s,%u,%s(): magic %08x at %p corrupted!\n",\
84 __FILE__,__LINE__,__FUNCTION__,(m),(a));}while(0)
85#define BUF_OFFSET sizeof(u64)
86#define MKCTL_TRAILER sizeof(u64)
87
88#endif
89
90static char *getpage( void )
91{
92 char *r;
93 SOLD("getting page");
94 spin_lock(&timod_pagelock);
95 if (page) {
96 r = page;
97 page = NULL;
98 spin_unlock(&timod_pagelock);
99 SOLD("got cached");
100 return r + BUF_OFFSET;
101 }
102 spin_unlock(&timod_pagelock);
103 SOLD("getting new");
104 r = (char *)__get_free_page(GFP_KERNEL);
105 PUT_MAGIC(r,BUFPAGE_MAGIC);
106 PUT_MAGIC(r+PAGE_SIZE-sizeof(u64),BUFPAGE_MAGIC);
107 return r + BUF_OFFSET;
108}
109
110static void putpage(char *p)
111{
112 SOLD("putting page");
113 p = p - BUF_OFFSET;
114 SCHECK_MAGIC(p,BUFPAGE_MAGIC);
115 SCHECK_MAGIC(p+PAGE_SIZE-sizeof(u64),BUFPAGE_MAGIC);
116 spin_lock(&timod_pagelock);
117 if (page) {
118 spin_unlock(&timod_pagelock);
119 free_page((unsigned long)p);
120 SOLD("freed it");
121 } else {
122 page = p;
123 spin_unlock(&timod_pagelock);
124 SOLD("cached it");
125 }
126}
127
128static struct T_primsg *timod_mkctl(int size)
129{
130 struct T_primsg *it;
131
132 SOLD("creating primsg");
133 it = (struct T_primsg *)mykmalloc(size+sizeof(*it)-sizeof(s32)+2*MKCTL_TRAILER, GFP_KERNEL);
134 if (it) {
135 SOLD("got it");
136 it->pri = MSG_HIPRI;
137 it->length = size;
138 PUT_MAGIC((char*)((u64)(((char *)&it->type)+size+7)&~7),MKCTL_MAGIC);
139 }
140 return it;
141}
142
143static void timod_wake_socket(unsigned int fd)
144{
145 struct socket *sock;
146
147 SOLD("wakeing socket");
148 sock = SOCKET_I(current->files->fd[fd]->f_dentry->d_inode);
149 wake_up_interruptible(&sock->wait);
150 read_lock(&sock->sk->sk_callback_lock);
151 if (sock->fasync_list && !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
152 __kill_fasync(sock->fasync_list, SIGIO, POLL_IN);
153 read_unlock(&sock->sk->sk_callback_lock);
154 SOLD("done");
155}
156
157static void timod_queue(unsigned int fd, struct T_primsg *it)
158{
159 struct sol_socket_struct *sock;
160
161 SOLD("queuing primsg");
162 sock = (struct sol_socket_struct *)current->files->fd[fd]->private_data;
163 it->next = sock->pfirst;
164 sock->pfirst = it;
165 if (!sock->plast)
166 sock->plast = it;
167 timod_wake_socket(fd);
168 SOLD("done");
169}
170
171static void timod_queue_end(unsigned int fd, struct T_primsg *it)
172{
173 struct sol_socket_struct *sock;
174
175 SOLD("queuing primsg at end");
176 sock = (struct sol_socket_struct *)current->files->fd[fd]->private_data;
177 it->next = NULL;
178 if (sock->plast)
179 sock->plast->next = it;
180 else
181 sock->pfirst = it;
182 sock->plast = it;
183 SOLD("done");
184}
185
186static void timod_error(unsigned int fd, int prim, int terr, int uerr)
187{
188 struct T_primsg *it;
189
190 SOLD("making error");
191 it = timod_mkctl(sizeof(struct T_error_ack));
192 if (it) {
193 struct T_error_ack *err = (struct T_error_ack *)&it->type;
194
195 SOLD("got it");
196 err->PRIM_type = T_ERROR_ACK;
197 err->ERROR_prim = prim;
198 err->TLI_error = terr;
199 err->UNIX_error = uerr; /* FIXME: convert this */
200 timod_queue(fd, it);
201 }
202 SOLD("done");
203}
204
205static void timod_ok(unsigned int fd, int prim)
206{
207 struct T_primsg *it;
208 struct T_ok_ack *ok;
209
210 SOLD("creating ok ack");
211 it = timod_mkctl(sizeof(*ok));
212 if (it) {
213 SOLD("got it");
214 ok = (struct T_ok_ack *)&it->type;
215 ok->PRIM_type = T_OK_ACK;
216 ok->CORRECT_prim = prim;
217 timod_queue(fd, it);
218 }
219 SOLD("done");
220}
221
222static int timod_optmgmt(unsigned int fd, int flag, char __user *opt_buf, int opt_len, int do_ret)
223{
224 int error, failed;
225 int ret_space, ret_len;
226 long args[5];
227 char *ret_pos,*ret_buf;
228 int (*sys_socketcall)(int, unsigned long *) =
229 (int (*)(int, unsigned long *))SYS(socketcall);
230 mm_segment_t old_fs = get_fs();
231
232 SOLD("entry");
233 SOLDD(("fd %u flg %u buf %p len %u doret %u",fd,flag,opt_buf,opt_len,do_ret));
234 if (!do_ret && (!opt_buf || opt_len <= 0))
235 return 0;
236 SOLD("getting page");
237 ret_pos = ret_buf = getpage();
238 ret_space = BUF_SIZE;
239 ret_len = 0;
240
241 error = failed = 0;
242 SOLD("looping");
243 while(opt_len >= sizeof(struct opthdr)) {
244 struct opthdr *opt;
245 int orig_opt_len;
246 SOLD("loop start");
247 opt = (struct opthdr *)ret_pos;
248 if (ret_space < sizeof(struct opthdr)) {
249 failed = TSYSERR;
250 break;
251 }
252 SOLD("getting opthdr");
253 if (copy_from_user(opt, opt_buf, sizeof(struct opthdr)) ||
254 opt->len > opt_len) {
255 failed = TBADOPT;
256 break;
257 }
258 SOLD("got opthdr");
259 if (flag == T_NEGOTIATE) {
260 char *buf;
261
262 SOLD("handling T_NEGOTIATE");
263 buf = ret_pos + sizeof(struct opthdr);
264 if (ret_space < opt->len + sizeof(struct opthdr) ||
265 copy_from_user(buf, opt_buf+sizeof(struct opthdr), opt->len)) {
266 failed = TSYSERR;
267 break;
268 }
269 SOLD("got optdata");
270 args[0] = fd;
271 args[1] = opt->level;
272 args[2] = opt->name;
273 args[3] = (long)buf;
274 args[4] = opt->len;
275 SOLD("calling SETSOCKOPT");
276 set_fs(KERNEL_DS);
277 error = sys_socketcall(SYS_SETSOCKOPT, args);
278 set_fs(old_fs);
279 if (error) {
280 failed = TBADOPT;
281 break;
282 }
283 SOLD("SETSOCKOPT ok");
284 }
285 orig_opt_len = opt->len;
286 opt->len = ret_space - sizeof(struct opthdr);
287 if (opt->len < 0) {
288 failed = TSYSERR;
289 break;
290 }
291 args[0] = fd;
292 args[1] = opt->level;
293 args[2] = opt->name;
294 args[3] = (long)(ret_pos+sizeof(struct opthdr));
295 args[4] = (long)&opt->len;
296 SOLD("calling GETSOCKOPT");
297 set_fs(KERNEL_DS);
298 error = sys_socketcall(SYS_GETSOCKOPT, args);
299 set_fs(old_fs);
300 if (error) {
301 failed = TBADOPT;
302 break;
303 }
304 SOLD("GETSOCKOPT ok");
305 ret_space -= sizeof(struct opthdr) + opt->len;
306 ret_len += sizeof(struct opthdr) + opt->len;
307 ret_pos += sizeof(struct opthdr) + opt->len;
308 opt_len -= sizeof(struct opthdr) + orig_opt_len;
309 opt_buf += sizeof(struct opthdr) + orig_opt_len;
310 SOLD("loop end");
311 }
312 SOLD("loop done");
313 if (do_ret) {
314 SOLD("generating ret msg");
315 if (failed)
316 timod_error(fd, T_OPTMGMT_REQ, failed, -error);
317 else {
318 struct T_primsg *it;
319 it = timod_mkctl(sizeof(struct T_optmgmt_ack) + ret_len);
320 if (it) {
321 struct T_optmgmt_ack *ack =
322 (struct T_optmgmt_ack *)&it->type;
323 SOLD("got primsg");
324 ack->PRIM_type = T_OPTMGMT_ACK;
325 ack->OPT_length = ret_len;
326 ack->OPT_offset = sizeof(struct T_optmgmt_ack);
327 ack->MGMT_flags = (failed ? T_FAILURE : flag);
328 memcpy(((char*)ack)+sizeof(struct T_optmgmt_ack),
329 ret_buf, ret_len);
330 timod_queue(fd, it);
331 }
332 }
333 }
334 SOLDD(("put_page %p\n", ret_buf));
335 putpage(ret_buf);
336 SOLD("done");
337 return 0;
338}
339
340int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
341 char __user *data_buf, int data_len, int flags)
342{
343 int ret, error, terror;
344 char *buf;
345 struct file *filp;
346 struct inode *ino;
347 struct sol_socket_struct *sock;
348 mm_segment_t old_fs = get_fs();
349 long args[6];
350 int (*sys_socketcall)(int, unsigned long __user *) =
351 (int (*)(int, unsigned long __user *))SYS(socketcall);
352 int (*sys_sendto)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int) =
353 (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int))SYS(sendto);
354 filp = current->files->fd[fd];
355 ino = filp->f_dentry->d_inode;
356 sock = (struct sol_socket_struct *)filp->private_data;
357 SOLD("entry");
358 if (get_user(ret, (int __user *)A(ctl_buf)))
359 return -EFAULT;
360 switch (ret) {
361 case T_BIND_REQ:
362 {
363 struct T_bind_req req;
364
365 SOLDD(("bind %016lx(%016lx)\n", sock, filp));
366 SOLD("T_BIND_REQ");
367 if (sock->state != TS_UNBND) {
368 timod_error(fd, T_BIND_REQ, TOUTSTATE, 0);
369 return 0;
370 }
371 SOLD("state ok");
372 if (copy_from_user(&req, ctl_buf, sizeof(req))) {
373 timod_error(fd, T_BIND_REQ, TSYSERR, EFAULT);
374 return 0;
375 }
376 SOLD("got ctl req");
377 if (req.ADDR_offset && req.ADDR_length) {
378 if (req.ADDR_length > BUF_SIZE) {
379 timod_error(fd, T_BIND_REQ, TSYSERR, EFAULT);
380 return 0;
381 }
382 SOLD("req size ok");
383 buf = getpage();
384 if (copy_from_user(buf, ctl_buf + req.ADDR_offset, req.ADDR_length)) {
385 timod_error(fd, T_BIND_REQ, TSYSERR, EFAULT);
386 putpage(buf);
387 return 0;
388 }
389 SOLD("got ctl data");
390 args[0] = fd;
391 args[1] = (long)buf;
392 args[2] = req.ADDR_length;
393 SOLD("calling BIND");
394 set_fs(KERNEL_DS);
395 error = sys_socketcall(SYS_BIND, args);
396 set_fs(old_fs);
397 putpage(buf);
398 SOLD("BIND returned");
399 } else
400 error = 0;
401 if (!error) {
402 struct T_primsg *it;
403 if (req.CONIND_number) {
404 args[0] = fd;
405 args[1] = req.CONIND_number;
406 SOLD("calling LISTEN");
407 set_fs(KERNEL_DS);
408 error = sys_socketcall(SYS_LISTEN, args);
409 set_fs(old_fs);
410 SOLD("LISTEN done");
411 }
412 it = timod_mkctl(sizeof(struct T_bind_ack)+sizeof(struct sockaddr));
413 if (it) {
414 struct T_bind_ack *ack;
415
416 ack = (struct T_bind_ack *)&it->type;
417 ack->PRIM_type = T_BIND_ACK;
418 ack->ADDR_offset = sizeof(*ack);
419 ack->ADDR_length = sizeof(struct sockaddr);
420 ack->CONIND_number = req.CONIND_number;
421 args[0] = fd;
422 args[1] = (long)(ack+sizeof(*ack));
423 args[2] = (long)&ack->ADDR_length;
424 set_fs(KERNEL_DS);
425 sys_socketcall(SYS_GETSOCKNAME,args);
426 set_fs(old_fs);
427 sock->state = TS_IDLE;
428 timod_ok(fd, T_BIND_REQ);
429 timod_queue_end(fd, it);
430 SOLD("BIND done");
431 return 0;
432 }
433 }
434 SOLD("some error");
435 switch (error) {
436 case -EINVAL:
437 terror = TOUTSTATE;
438 error = 0;
439 break;
440 case -EACCES:
441 terror = TACCES;
442 error = 0;
443 break;
444 case -EADDRNOTAVAIL:
445 case -EADDRINUSE:
446 terror = TNOADDR;
447 error = 0;
448 break;
449 default:
450 terror = TSYSERR;
451 break;
452 }
453 timod_error(fd, T_BIND_REQ, terror, -error);
454 SOLD("BIND done");
455 return 0;
456 }
457 case T_CONN_REQ:
458 {
459 struct T_conn_req req;
460 unsigned short oldflags;
461 struct T_primsg *it;
462 SOLD("T_CONN_REQ");
463 if (sock->state != TS_UNBND && sock->state != TS_IDLE) {
464 timod_error(fd, T_CONN_REQ, TOUTSTATE, 0);
465 return 0;
466 }
467 SOLD("state ok");
468 if (copy_from_user(&req, ctl_buf, sizeof(req))) {
469 timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
470 return 0;
471 }
472 SOLD("got ctl req");
473 if (ctl_len > BUF_SIZE) {
474 timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
475 return 0;
476 }
477 SOLD("req size ok");
478 buf = getpage();
479 if (copy_from_user(buf, ctl_buf, ctl_len)) {
480 timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
481 putpage(buf);
482 return 0;
483 }
484#ifdef DEBUG_SOLARIS
485 {
486 char * ptr = buf;
487 int len = ctl_len;
488 printk("returned data (%d bytes): ",len);
489 while( len-- ) {
490 if (!(len & 7))
491 printk(" ");
492 printk("%02x",(unsigned char)*ptr++);
493 }
494 printk("\n");
495 }
496#endif
497 SOLD("got ctl data");
498 args[0] = fd;
499 args[1] = (long)buf+req.DEST_offset;
500 args[2] = req.DEST_length;
501 oldflags = filp->f_flags;
502 filp->f_flags &= ~O_NONBLOCK;
503 SOLD("calling CONNECT");
504 set_fs(KERNEL_DS);
505 error = sys_socketcall(SYS_CONNECT, args);
506 set_fs(old_fs);
507 filp->f_flags = oldflags;
508 SOLD("CONNECT done");
509 if (!error) {
510 struct T_conn_con *con;
511 SOLD("no error");
512 it = timod_mkctl(ctl_len);
513 if (!it) {
514 putpage(buf);
515 return -ENOMEM;
516 }
517 con = (struct T_conn_con *)&it->type;
518#ifdef DEBUG_SOLARIS
519 {
520 char * ptr = buf;
521 int len = ctl_len;
522 printk("returned data (%d bytes): ",len);
523 while( len-- ) {
524 if (!(len & 7))
525 printk(" ");
526 printk("%02x",(unsigned char)*ptr++);
527 }
528 printk("\n");
529 }
530#endif
531 memcpy(con, buf, ctl_len);
532 SOLD("copied ctl_buf");
533 con->PRIM_type = T_CONN_CON;
534 sock->state = TS_DATA_XFER;
535 } else {
536 struct T_discon_ind *dis;
537 SOLD("some error");
538 it = timod_mkctl(sizeof(*dis));
539 if (!it) {
540 putpage(buf);
541 return -ENOMEM;
542 }
543 SOLD("got primsg");
544 dis = (struct T_discon_ind *)&it->type;
545 dis->PRIM_type = T_DISCON_IND;
546 dis->DISCON_reason = -error; /* FIXME: convert this as in iABI_errors() */
547 dis->SEQ_number = 0;
548 }
549 putpage(buf);
550 timod_ok(fd, T_CONN_REQ);
551 it->pri = 0;
552 timod_queue_end(fd, it);
553 SOLD("CONNECT done");
554 return 0;
555 }
556 case T_OPTMGMT_REQ:
557 {
558 struct T_optmgmt_req req;
559 SOLD("OPTMGMT_REQ");
560 if (copy_from_user(&req, ctl_buf, sizeof(req)))
561 return -EFAULT;
562 SOLD("got req");
563 return timod_optmgmt(fd, req.MGMT_flags,
564 req.OPT_offset > 0 ? ctl_buf + req.OPT_offset : NULL,
565 req.OPT_length, 1);
566 }
567 case T_UNITDATA_REQ:
568 {
569 struct T_unitdata_req req;
570
571 int err;
572 SOLD("T_UNITDATA_REQ");
573 if (sock->state != TS_IDLE && sock->state != TS_DATA_XFER) {
574 timod_error(fd, T_CONN_REQ, TOUTSTATE, 0);
575 return 0;
576 }
577 SOLD("state ok");
578 if (copy_from_user(&req, ctl_buf, sizeof(req))) {
579 timod_error(fd, T_CONN_REQ, TSYSERR, EFAULT);
580 return 0;
581 }
582 SOLD("got ctl req");
583#ifdef DEBUG_SOLARIS
584 {
585 char * ptr = ctl_buf+req.DEST_offset;
586 int len = req.DEST_length;
587 printk("socket address (%d bytes): ",len);
588 while( len-- ) {
589 char c;
590 if (get_user(c,ptr))
591 printk("??");
592 else
593 printk("%02x",(unsigned char)c);
594 ptr++;
595 }
596 printk("\n");
597 }
598#endif
599 err = sys_sendto(fd, data_buf, data_len, 0, req.DEST_length > 0 ? (struct sockaddr __user *)(ctl_buf+req.DEST_offset) : NULL, req.DEST_length);
600 if (err == data_len)
601 return 0;
602 if(err >= 0) {
603 printk("timod: sendto failed to send all the data\n");
604 return 0;
605 }
606 timod_error(fd, T_CONN_REQ, TSYSERR, -err);
607 return 0;
608 }
609 default:
610 printk(KERN_INFO "timod_putmsg: unsupported command %u.\n", ret);
611 break;
612 }
613 return -EINVAL;
614}
615
616int timod_getmsg(unsigned int fd, char __user *ctl_buf, int ctl_maxlen, s32 __user *ctl_len,
617 char __user *data_buf, int data_maxlen, s32 __user *data_len, int *flags_p)
618{
619 int error;
620 int oldflags;
621 struct file *filp;
622 struct inode *ino;
623 struct sol_socket_struct *sock;
624 struct T_unitdata_ind udi;
625 mm_segment_t old_fs = get_fs();
626 long args[6];
627 char __user *tmpbuf;
628 int tmplen;
629 int (*sys_socketcall)(int, unsigned long __user *) =
630 (int (*)(int, unsigned long __user *))SYS(socketcall);
631 int (*sys_recvfrom)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *);
632
633 SOLD("entry");
634 SOLDD(("%u %p %d %p %p %d %p %d\n", fd, ctl_buf, ctl_maxlen, ctl_len, data_buf, data_maxlen, data_len, *flags_p));
635 filp = current->files->fd[fd];
636 ino = filp->f_dentry->d_inode;
637 sock = (struct sol_socket_struct *)filp->private_data;
638 SOLDD(("%p %p\n", sock->pfirst, sock->pfirst ? sock->pfirst->next : NULL));
639 if ( ctl_maxlen > 0 && !sock->pfirst && SOCKET_I(ino)->type == SOCK_STREAM
640 && sock->state == TS_IDLE) {
641 SOLD("calling LISTEN");
642 args[0] = fd;
643 args[1] = -1;
644 set_fs(KERNEL_DS);
645 sys_socketcall(SYS_LISTEN, args);
646 set_fs(old_fs);
647 SOLD("LISTEN done");
648 }
649 if (!(filp->f_flags & O_NONBLOCK)) {
650 struct poll_wqueues wait_table;
651 poll_table *wait;
652
653 poll_initwait(&wait_table);
654 wait = &wait_table.pt;
655 for(;;) {
656 SOLD("loop");
657 set_current_state(TASK_INTERRUPTIBLE);
658 /* ! ( l<0 || ( l>=0 && ( ! pfirst || (flags == HIPRI && pri != HIPRI) ) ) ) */
659 /* ( ! l<0 && ! ( l>=0 && ( ! pfirst || (flags == HIPRI && pri != HIPRI) ) ) ) */
660 /* ( l>=0 && ( ! l>=0 || ! ( ! pfirst || (flags == HIPRI && pri != HIPRI) ) ) ) */
661 /* ( l>=0 && ( l<0 || ( pfirst && ! (flags == HIPRI && pri != HIPRI) ) ) ) */
662 /* ( l>=0 && ( l<0 || ( pfirst && (flags != HIPRI || pri == HIPRI) ) ) ) */
663 /* ( l>=0 && ( pfirst && (flags != HIPRI || pri == HIPRI) ) ) */
664 if (ctl_maxlen >= 0 && sock->pfirst && (*flags_p != MSG_HIPRI || sock->pfirst->pri == MSG_HIPRI))
665 break;
666 SOLD("cond 1 passed");
667 if (
668 #if 1
669 *flags_p != MSG_HIPRI &&
670 #endif
671 ((filp->f_op->poll(filp, wait) & POLLIN) ||
672 (filp->f_op->poll(filp, NULL) & POLLIN) ||
673 signal_pending(current))
674 ) {
675 break;
676 }
677 if( *flags_p == MSG_HIPRI ) {
678 SOLD("avoiding lockup");
679 break ;
680 }
681 if(wait_table.error) {
682 SOLD("wait-table error");
683 poll_freewait(&wait_table);
684 return wait_table.error;
685 }
686 SOLD("scheduling");
687 schedule();
688 }
689 SOLD("loop done");
690 current->state = TASK_RUNNING;
691 poll_freewait(&wait_table);
692 if (signal_pending(current)) {
693 SOLD("signal pending");
694 return -EINTR;
695 }
696 }
697 if (ctl_maxlen >= 0 && sock->pfirst) {
698 struct T_primsg *it = sock->pfirst;
699 int l = min_t(int, ctl_maxlen, it->length);
700 SCHECK_MAGIC((char*)((u64)(((char *)&it->type)+sock->offset+it->length+7)&~7),MKCTL_MAGIC);
701 SOLD("purting ctl data");
702 if(copy_to_user(ctl_buf,
703 (char*)&it->type + sock->offset, l))
704 return -EFAULT;
705 SOLD("pur it");
706 if(put_user(l, ctl_len))
707 return -EFAULT;
708 SOLD("set ctl_len");
709 *flags_p = it->pri;
710 it->length -= l;
711 if (it->length) {
712 SOLD("more ctl");
713 sock->offset += l;
714 return MORECTL;
715 } else {
716 SOLD("removing message");
717 sock->pfirst = it->next;
718 if (!sock->pfirst)
719 sock->plast = NULL;
720 SOLDD(("getmsg kfree %016lx->%016lx\n", it, sock->pfirst));
721 mykfree(it);
722 sock->offset = 0;
723 SOLD("ctl done");
724 return 0;
725 }
726 }
727 *flags_p = 0;
728 if (ctl_maxlen >= 0) {
729 SOLD("ACCEPT perhaps?");
730 if (SOCKET_I(ino)->type == SOCK_STREAM && sock->state == TS_IDLE) {
731 struct T_conn_ind ind;
732 char *buf = getpage();
733 int len = BUF_SIZE;
734
735 SOLD("trying ACCEPT");
736 if (put_user(ctl_maxlen - sizeof(ind), ctl_len))
737 return -EFAULT;
738 args[0] = fd;
739 args[1] = (long)buf;
740 args[2] = (long)&len;
741 oldflags = filp->f_flags;
742 filp->f_flags |= O_NONBLOCK;
743 SOLD("calling ACCEPT");
744 set_fs(KERNEL_DS);
745 error = sys_socketcall(SYS_ACCEPT, args);
746 set_fs(old_fs);
747 filp->f_flags = oldflags;
748 if (error < 0) {
749 SOLD("some error");
750 putpage(buf);
751 return error;
752 }
753 if (error) {
754 SOLD("connect");
755 putpage(buf);
756 if (sizeof(ind) > ctl_maxlen) {
757 SOLD("generating CONN_IND");
758 ind.PRIM_type = T_CONN_IND;
759 ind.SRC_length = len;
760 ind.SRC_offset = sizeof(ind);
761 ind.OPT_length = ind.OPT_offset = 0;
762 ind.SEQ_number = error;
763 if(copy_to_user(ctl_buf, &ind, sizeof(ind))||
764 put_user(sizeof(ind)+ind.SRC_length,ctl_len))
765 return -EFAULT;
766 SOLD("CONN_IND created");
767 }
768 if (data_maxlen >= 0)
769 put_user(0, data_len);
770 SOLD("CONN_IND done");
771 return 0;
772 }
773 if (len>ctl_maxlen) {
774 SOLD("data don't fit");
775 putpage(buf);
776 return -EFAULT; /* XXX - is this ok ? */
777 }
778 if(copy_to_user(ctl_buf,buf,len) || put_user(len,ctl_len)){
779 SOLD("can't copy data");
780 putpage(buf);
781 return -EFAULT;
782 }
783 SOLD("ACCEPT done");
784 putpage(buf);
785 }
786 }
787 SOLD("checking data req");
788 if (data_maxlen <= 0) {
789 if (data_maxlen == 0)
790 put_user(0, data_len);
791 if (ctl_maxlen >= 0)
792 put_user(0, ctl_len);
793 return -EAGAIN;
794 }
795 SOLD("wants data");
796 if (ctl_maxlen > sizeof(udi) && sock->state == TS_IDLE) {
797 SOLD("udi fits");
798 tmpbuf = ctl_buf + sizeof(udi);
799 tmplen = ctl_maxlen - sizeof(udi);
800 } else {
801 SOLD("udi does not fit");
802 tmpbuf = NULL;
803 tmplen = 0;
804 }
805 if (put_user(tmplen, ctl_len))
806 return -EFAULT;
807 SOLD("set ctl_len");
808 oldflags = filp->f_flags;
809 filp->f_flags |= O_NONBLOCK;
810 SOLD("calling recvfrom");
811 sys_recvfrom = (int (*)(int, void __user *, size_t, unsigned, struct sockaddr __user *, int __user *))SYS(recvfrom);
812 error = sys_recvfrom(fd, data_buf, data_maxlen, 0, (struct sockaddr __user *)tmpbuf, ctl_len);
813 filp->f_flags = oldflags;
814 if (error < 0)
815 return error;
816 SOLD("error >= 0" ) ;
817 if (error && ctl_maxlen > sizeof(udi) && sock->state == TS_IDLE) {
818 SOLD("generating udi");
819 udi.PRIM_type = T_UNITDATA_IND;
820 if (get_user(udi.SRC_length, ctl_len))
821 return -EFAULT;
822 udi.SRC_offset = sizeof(udi);
823 udi.OPT_length = udi.OPT_offset = 0;
824 if (copy_to_user(ctl_buf, &udi, sizeof(udi)) ||
825 put_user(sizeof(udi)+udi.SRC_length, ctl_len))
826 return -EFAULT;
827 SOLD("udi done");
828 } else {
829 if (put_user(0, ctl_len))
830 return -EFAULT;
831 }
832 put_user(error, data_len);
833 SOLD("done");
834 return 0;
835}
836
837asmlinkage int solaris_getmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
838{
839 struct file *filp;
840 struct inode *ino;
841 struct strbuf __user *ctlptr;
842 struct strbuf __user *datptr;
843 struct strbuf ctl, dat;
844 int __user *flgptr;
845 int flags;
846 int error = -EBADF;
847
848 SOLD("entry");
849 lock_kernel();
850 if(fd >= NR_OPEN) goto out;
851
852 filp = current->files->fd[fd];
853 if(!filp) goto out;
854
855 ino = filp->f_dentry->d_inode;
856 if (!ino || !S_ISSOCK(ino->i_mode))
857 goto out;
858
859 ctlptr = (struct strbuf __user *)A(arg1);
860 datptr = (struct strbuf __user *)A(arg2);
861 flgptr = (int __user *)A(arg3);
862
863 error = -EFAULT;
864
865 if (ctlptr) {
866 if (copy_from_user(&ctl,ctlptr,sizeof(struct strbuf)) ||
867 put_user(-1,&ctlptr->len))
868 goto out;
869 } else
870 ctl.maxlen = -1;
871
872 if (datptr) {
873 if (copy_from_user(&dat,datptr,sizeof(struct strbuf)) ||
874 put_user(-1,&datptr->len))
875 goto out;
876 } else
877 dat.maxlen = -1;
878
879 if (get_user(flags,flgptr))
880 goto out;
881
882 switch (flags) {
883 case 0:
884 case MSG_HIPRI:
885 case MSG_ANY:
886 case MSG_BAND:
887 break;
888 default:
889 error = -EINVAL;
890 goto out;
891 }
892
893 error = timod_getmsg(fd,A(ctl.buf),ctl.maxlen,&ctlptr->len,
894 A(dat.buf),dat.maxlen,&datptr->len,&flags);
895
896 if (!error && put_user(flags,flgptr))
897 error = -EFAULT;
898out:
899 unlock_kernel();
900 SOLD("done");
901 return error;
902}
903
904asmlinkage int solaris_putmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
905{
906 struct file *filp;
907 struct inode *ino;
908 struct strbuf __user *ctlptr;
909 struct strbuf __user *datptr;
910 struct strbuf ctl, dat;
911 int flags = (int) arg3;
912 int error = -EBADF;
913
914 SOLD("entry");
915 lock_kernel();
916 if(fd >= NR_OPEN) goto out;
917
918 filp = current->files->fd[fd];
919 if(!filp) goto out;
920
921 ino = filp->f_dentry->d_inode;
922 if (!ino) goto out;
923
924 if (!S_ISSOCK(ino->i_mode) &&
925 (imajor(ino) != 30 || iminor(ino) != 1))
926 goto out;
927
928 ctlptr = A(arg1);
929 datptr = A(arg2);
930
931 error = -EFAULT;
932
933 if (ctlptr) {
934 if (copy_from_user(&ctl,ctlptr,sizeof(ctl)))
935 goto out;
936 if (ctl.len < 0 && flags) {
937 error = -EINVAL;
938 goto out;
939 }
940 } else {
941 ctl.len = 0;
942 ctl.buf = 0;
943 }
944
945 if (datptr) {
946 if (copy_from_user(&dat,datptr,sizeof(dat)))
947 goto out;
948 } else {
949 dat.len = 0;
950 dat.buf = 0;
951 }
952
953 error = timod_putmsg(fd,A(ctl.buf),ctl.len,
954 A(dat.buf),dat.len,flags);
955out:
956 unlock_kernel();
957 SOLD("done");
958 return error;
959}