aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/sys-i386/signal.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-10-16 04:27:15 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:07 -0400
commita5f6096c805e6d2fa03ee932f8c70af34cee41a0 (patch)
treec74d984c0e2fc2958425df65605dd3451adc6520 /arch/um/sys-i386/signal.c
parent189872f968def833727b6bfef83ebd7440c538e6 (diff)
uml: floating point signal delivery fixes
Handle floating point state in across signals correctly. UML/i386 needs to know whether the host does PTRACE_[GS]ETFPXREGS, so an arch_init_registers hook is added, which on x86_64 does nothing. UML doesn't save and restore floating point registers on kernel entry and exit, so they need to be copied between the host process and the sigcontext. save_fpx_registers and restore_fpx_registers are added for this purpose. save_fp_registers and restore_fp_registers already exist. There was a bunch of floating point state conversion code in arch/um/sys-i386/ptrace.c which isn't needed there, but is needed in signal.c, so it is moved over. The i386 code now distinguishes between fp and fpx state and handles them correctly. The x86_64 code just needs to copy state as-is between the host process and the stack. There are also some fixes there to pass the correct address of the floating point state around. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um/sys-i386/signal.c')
-rw-r--r--arch/um/sys-i386/signal.c223
1 files changed, 203 insertions, 20 deletions
diff --git a/arch/um/sys-i386/signal.c b/arch/um/sys-i386/signal.c
index 1eb21a023e33..0147227ce18d 100644
--- a/arch/um/sys-i386/signal.c
+++ b/arch/um/sys-i386/signal.c
@@ -32,25 +32,186 @@ void copy_sc(struct uml_pt_regs *regs, void *from)
32 REGS_SS(regs->gp) = sc->ss; 32 REGS_SS(regs->gp) = sc->ss;
33} 33}
34 34
35/*
36 * FPU tag word conversions.
37 */
38
39static inline unsigned short twd_i387_to_fxsr(unsigned short twd)
40{
41 unsigned int tmp; /* to avoid 16 bit prefixes in the code */
42
43 /* Transform each pair of bits into 01 (valid) or 00 (empty) */
44 tmp = ~twd;
45 tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */
46 /* and move the valid bits to the lower byte. */
47 tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */
48 tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */
49 tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */
50 return tmp;
51}
52
53static inline unsigned long twd_fxsr_to_i387(struct user_fxsr_struct *fxsave)
54{
55 struct _fpxreg *st = NULL;
56 unsigned long twd = (unsigned long) fxsave->twd;
57 unsigned long tag;
58 unsigned long ret = 0xffff0000;
59 int i;
60
61#define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16);
62
63 for (i = 0; i < 8; i++) {
64 if (twd & 0x1) {
65 st = (struct _fpxreg *) FPREG_ADDR(fxsave, i);
66
67 switch (st->exponent & 0x7fff) {
68 case 0x7fff:
69 tag = 2; /* Special */
70 break;
71 case 0x0000:
72 if ( !st->significand[0] &&
73 !st->significand[1] &&
74 !st->significand[2] &&
75 !st->significand[3] ) {
76 tag = 1; /* Zero */
77 } else {
78 tag = 2; /* Special */
79 }
80 break;
81 default:
82 if (st->significand[3] & 0x8000) {
83 tag = 0; /* Valid */
84 } else {
85 tag = 2; /* Special */
86 }
87 break;
88 }
89 } else {
90 tag = 3; /* Empty */
91 }
92 ret |= (tag << (2 * i));
93 twd = twd >> 1;
94 }
95 return ret;
96}
97
98static int convert_fxsr_to_user(struct _fpstate __user *buf,
99 struct user_fxsr_struct *fxsave)
100{
101 unsigned long env[7];
102 struct _fpreg __user *to;
103 struct _fpxreg *from;
104 int i;
105
106 env[0] = (unsigned long)fxsave->cwd | 0xffff0000ul;
107 env[1] = (unsigned long)fxsave->swd | 0xffff0000ul;
108 env[2] = twd_fxsr_to_i387(fxsave);
109 env[3] = fxsave->fip;
110 env[4] = fxsave->fcs | ((unsigned long)fxsave->fop << 16);
111 env[5] = fxsave->foo;
112 env[6] = fxsave->fos;
113
114 if (__copy_to_user(buf, env, 7 * sizeof(unsigned long)))
115 return 1;
116
117 to = &buf->_st[0];
118 from = (struct _fpxreg *) &fxsave->st_space[0];
119 for (i = 0; i < 8; i++, to++, from++) {
120 unsigned long __user *t = (unsigned long __user *)to;
121 unsigned long *f = (unsigned long *)from;
122
123 if (__put_user(*f, t) ||
124 __put_user(*(f + 1), t + 1) ||
125 __put_user(from->exponent, &to->exponent))
126 return 1;
127 }
128 return 0;
129}
130
131static int convert_fxsr_from_user(struct user_fxsr_struct *fxsave,
132 struct _fpstate __user *buf)
133{
134 unsigned long env[7];
135 struct _fpxreg *to;
136 struct _fpreg __user *from;
137 int i;
138
139 if (copy_from_user( env, buf, 7 * sizeof(long)))
140 return 1;
141
142 fxsave->cwd = (unsigned short)(env[0] & 0xffff);
143 fxsave->swd = (unsigned short)(env[1] & 0xffff);
144 fxsave->twd = twd_i387_to_fxsr((unsigned short)(env[2] & 0xffff));
145 fxsave->fip = env[3];
146 fxsave->fop = (unsigned short)((env[4] & 0xffff0000ul) >> 16);
147 fxsave->fcs = (env[4] & 0xffff);
148 fxsave->foo = env[5];
149 fxsave->fos = env[6];
150
151 to = (struct _fpxreg *) &fxsave->st_space[0];
152 from = &buf->_st[0];
153 for (i = 0; i < 8; i++, to++, from++) {
154 unsigned long *t = (unsigned long *)to;
155 unsigned long __user *f = (unsigned long __user *)from;
156
157 if (__get_user(*t, f) ||
158 __get_user(*(t + 1), f + 1) ||
159 __get_user(to->exponent, &from->exponent))
160 return 1;
161 }
162 return 0;
163}
164
165extern int have_fpx_regs;
166
35static int copy_sc_from_user(struct pt_regs *regs, 167static int copy_sc_from_user(struct pt_regs *regs,
36 struct sigcontext __user *from) 168 struct sigcontext __user *from)
37{ 169{
38 struct sigcontext sc; 170 struct sigcontext sc;
39 unsigned long fpregs[HOST_FP_SIZE];
40 int err; 171 int err;
41 172
42 err = copy_from_user(&sc, from, sizeof(sc)); 173 err = copy_from_user(&sc, from, sizeof(sc));
43 err |= copy_from_user(fpregs, sc.fpstate, sizeof(fpregs));
44 if (err) 174 if (err)
45 return err; 175 return err;
46 176
47 copy_sc(&regs->regs, &sc); 177 copy_sc(&regs->regs, &sc);
48 178 if (have_fpx_regs) {
49 err = restore_fp_registers(userspace_pid[0], fpregs); 179 struct user_fxsr_struct fpx;
50 if (err < 0) { 180
51 printk(KERN_ERR "copy_sc_from_user_skas - PTRACE_SETFPREGS " 181 err = copy_from_user(&fpx, &sc.fpstate->_fxsr_env[0],
52 "failed, errno = %d\n", -err); 182 sizeof(struct user_fxsr_struct));
53 return err; 183 if (err)
184 return 1;
185
186 err = convert_fxsr_from_user(&fpx, sc.fpstate);
187 if (err)
188 return 1;
189
190 err = restore_fpx_registers(userspace_pid[current_thread->cpu],
191 (unsigned long *) &fpx);
192 if (err < 0) {
193 printk(KERN_ERR "copy_sc_from_user - "
194 "restore_fpx_registers failed, errno = %d\n",
195 -err);
196 return 1;
197 }
198 }
199 else {
200 struct user_i387_struct fp;
201
202 err = copy_from_user(&fp, sc.fpstate,
203 sizeof(struct user_i387_struct));
204 if (err)
205 return 1;
206
207 err = restore_fp_registers(userspace_pid[current_thread->cpu],
208 (unsigned long *) &fp);
209 if (err < 0) {
210 printk(KERN_ERR "copy_sc_from_user - "
211 "restore_fp_registers failed, errno = %d\n",
212 -err);
213 return 1;
214 }
54 } 215 }
55 216
56 return 0; 217 return 0;
@@ -61,7 +222,6 @@ static int copy_sc_to_user(struct sigcontext __user *to,
61 unsigned long sp) 222 unsigned long sp)
62{ 223{
63 struct sigcontext sc; 224 struct sigcontext sc;
64 unsigned long fpregs[HOST_FP_SIZE];
65 struct faultinfo * fi = &current->thread.arch.faultinfo; 225 struct faultinfo * fi = &current->thread.arch.faultinfo;
66 int err; 226 int err;
67 227
@@ -86,20 +246,43 @@ static int copy_sc_to_user(struct sigcontext __user *to,
86 sc.err = fi->error_code; 246 sc.err = fi->error_code;
87 sc.trapno = fi->trap_no; 247 sc.trapno = fi->trap_no;
88 248
89 err = save_fp_registers(userspace_pid[0], fpregs);
90 if (err < 0) {
91 printk(KERN_ERR "copy_sc_to_user_skas - PTRACE_GETFPREGS "
92 "failed, errno = %d\n", err);
93 return 1;
94 }
95 to_fp = (to_fp ? to_fp : (struct _fpstate __user *) (to + 1)); 249 to_fp = (to_fp ? to_fp : (struct _fpstate __user *) (to + 1));
96 sc.fpstate = to_fp; 250 sc.fpstate = to_fp;
97 251
98 if (err) 252 if (have_fpx_regs) {
99 return err; 253 struct user_fxsr_struct fpx;
254
255 err = save_fpx_registers(userspace_pid[current_thread->cpu],
256 (unsigned long *) &fpx);
257 if (err < 0){
258 printk(KERN_ERR "copy_sc_to_user - save_fpx_registers "
259 "failed, errno = %d\n", err);
260 return 1;
261 }
262
263 err = convert_fxsr_to_user(to_fp, &fpx);
264 if (err)
265 return 1;
266
267 err |= __put_user(fpx.swd, &to_fp->status);
268 err |= __put_user(X86_FXSR_MAGIC, &to_fp->magic);
269 if (err)
270 return 1;
271
272 if (copy_to_user(&to_fp->_fxsr_env[0], &fpx,
273 sizeof(struct user_fxsr_struct)))
274 return 1;
275 }
276 else {
277 struct user_i387_struct fp;
278
279 err = save_fp_registers(userspace_pid[current_thread->cpu],
280 (unsigned long *) &fp);
281 if (copy_to_user(to_fp, &fp, sizeof(struct user_i387_struct)))
282 return 1;
283 }
100 284
101 return copy_to_user(to, &sc, sizeof(sc)) || 285 return copy_to_user(to, &sc, sizeof(sc));
102 copy_to_user(to_fp, fpregs, sizeof(fpregs));
103} 286}
104 287
105static int copy_ucontext_to_user(struct ucontext __user *uc, 288static int copy_ucontext_to_user(struct ucontext __user *uc,