diff options
author | Jeff Dike <jdike@addtoit.com> | 2007-10-16 04:27:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-16 12:43:07 -0400 |
commit | a5f6096c805e6d2fa03ee932f8c70af34cee41a0 (patch) | |
tree | c74d984c0e2fc2958425df65605dd3451adc6520 | |
parent | 189872f968def833727b6bfef83ebd7440c538e6 (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>
-rw-r--r-- | arch/um/include/registers.h | 2 | ||||
-rw-r--r-- | arch/um/include/sysdep-i386/ptrace.h | 2 | ||||
-rw-r--r-- | arch/um/include/sysdep-x86_64/ptrace.h | 4 | ||||
-rw-r--r-- | arch/um/os-Linux/registers.c | 2 | ||||
-rw-r--r-- | arch/um/os-Linux/sys-i386/registers.c | 35 | ||||
-rw-r--r-- | arch/um/sys-i386/ptrace.c | 79 | ||||
-rw-r--r-- | arch/um/sys-i386/signal.c | 223 | ||||
-rw-r--r-- | arch/um/sys-x86_64/signal.c | 53 |
8 files changed, 284 insertions, 116 deletions
diff --git a/arch/um/include/registers.h b/arch/um/include/registers.h index 8e8ea9651189..0e27406a43a4 100644 --- a/arch/um/include/registers.h +++ b/arch/um/include/registers.h | |||
@@ -12,6 +12,8 @@ | |||
12 | extern void init_thread_registers(struct uml_pt_regs *to); | 12 | extern void init_thread_registers(struct uml_pt_regs *to); |
13 | extern int save_fp_registers(int pid, unsigned long *fp_regs); | 13 | extern int save_fp_registers(int pid, unsigned long *fp_regs); |
14 | extern int restore_fp_registers(int pid, unsigned long *fp_regs); | 14 | extern int restore_fp_registers(int pid, unsigned long *fp_regs); |
15 | extern int save_fpx_registers(int pid, unsigned long *fp_regs); | ||
16 | extern int restore_fpx_registers(int pid, unsigned long *fp_regs); | ||
15 | extern void save_registers(int pid, struct uml_pt_regs *regs); | 17 | extern void save_registers(int pid, struct uml_pt_regs *regs); |
16 | extern void restore_registers(int pid, struct uml_pt_regs *regs); | 18 | extern void restore_registers(int pid, struct uml_pt_regs *regs); |
17 | extern void init_registers(int pid); | 19 | extern void init_registers(int pid); |
diff --git a/arch/um/include/sysdep-i386/ptrace.h b/arch/um/include/sysdep-i386/ptrace.h index edb9393283b5..c16d739d2089 100644 --- a/arch/um/include/sysdep-i386/ptrace.h +++ b/arch/um/include/sysdep-i386/ptrace.h | |||
@@ -168,4 +168,6 @@ struct syscall_args { | |||
168 | 168 | ||
169 | #define UPT_FAULTINFO(r) (&(r)->faultinfo) | 169 | #define UPT_FAULTINFO(r) (&(r)->faultinfo) |
170 | 170 | ||
171 | extern void arch_init_registers(int pid); | ||
172 | |||
171 | #endif | 173 | #endif |
diff --git a/arch/um/include/sysdep-x86_64/ptrace.h b/arch/um/include/sysdep-x86_64/ptrace.h index 2ae04480ac81..7848b7dce715 100644 --- a/arch/um/include/sysdep-x86_64/ptrace.h +++ b/arch/um/include/sysdep-x86_64/ptrace.h | |||
@@ -234,4 +234,8 @@ struct syscall_args { | |||
234 | 234 | ||
235 | #define UPT_FAULTINFO(r) (&(r)->faultinfo) | 235 | #define UPT_FAULTINFO(r) (&(r)->faultinfo) |
236 | 236 | ||
237 | static inline void arch_init_registers(int pid) | ||
238 | { | ||
239 | } | ||
240 | |||
237 | #endif | 241 | #endif |
diff --git a/arch/um/os-Linux/registers.c b/arch/um/os-Linux/registers.c index b06c780e8dba..a32ba6ab1211 100644 --- a/arch/um/os-Linux/registers.c +++ b/arch/um/os-Linux/registers.c | |||
@@ -47,6 +47,8 @@ void init_registers(int pid) | |||
47 | if (err) | 47 | if (err) |
48 | panic("check_ptrace : PTRACE_GETREGS failed, errno = %d", | 48 | panic("check_ptrace : PTRACE_GETREGS failed, errno = %d", |
49 | errno); | 49 | errno); |
50 | |||
51 | arch_init_registers(pid); | ||
50 | } | 52 | } |
51 | 53 | ||
52 | void get_safe_registers(unsigned long *regs) | 54 | void get_safe_registers(unsigned long *regs) |
diff --git a/arch/um/os-Linux/sys-i386/registers.c b/arch/um/os-Linux/sys-i386/registers.c index f171204caa4e..8f1f0ab639b9 100644 --- a/arch/um/os-Linux/sys-i386/registers.c +++ b/arch/um/os-Linux/sys-i386/registers.c | |||
@@ -8,9 +8,6 @@ | |||
8 | #include "longjmp.h" | 8 | #include "longjmp.h" |
9 | #include "user.h" | 9 | #include "user.h" |
10 | 10 | ||
11 | /* XXX These need to use [GS]ETFPXREGS and copy_sc_{to,from}_user_skas needs | ||
12 | * to pass in a sufficiently large buffer | ||
13 | */ | ||
14 | int save_fp_registers(int pid, unsigned long *fp_regs) | 11 | int save_fp_registers(int pid, unsigned long *fp_regs) |
15 | { | 12 | { |
16 | if(ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0) | 13 | if(ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0) |
@@ -25,6 +22,20 @@ int restore_fp_registers(int pid, unsigned long *fp_regs) | |||
25 | return 0; | 22 | return 0; |
26 | } | 23 | } |
27 | 24 | ||
25 | int save_fpx_registers(int pid, unsigned long *fp_regs) | ||
26 | { | ||
27 | if(ptrace(PTRACE_GETFPXREGS, pid, 0, fp_regs) < 0) | ||
28 | return -errno; | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | int restore_fpx_registers(int pid, unsigned long *fp_regs) | ||
33 | { | ||
34 | if(ptrace(PTRACE_SETFPXREGS, pid, 0, fp_regs) < 0) | ||
35 | return -errno; | ||
36 | return 0; | ||
37 | } | ||
38 | |||
28 | unsigned long get_thread_reg(int reg, jmp_buf *buf) | 39 | unsigned long get_thread_reg(int reg, jmp_buf *buf) |
29 | { | 40 | { |
30 | switch(reg){ | 41 | switch(reg){ |
@@ -36,3 +47,21 @@ unsigned long get_thread_reg(int reg, jmp_buf *buf) | |||
36 | return 0; | 47 | return 0; |
37 | } | 48 | } |
38 | } | 49 | } |
50 | |||
51 | int have_fpx_regs = 1; | ||
52 | |||
53 | void arch_init_registers(int pid) | ||
54 | { | ||
55 | unsigned long fpx_regs[HOST_XFP_SIZE]; | ||
56 | int err; | ||
57 | |||
58 | err = ptrace(PTRACE_GETFPXREGS, pid, 0, fpx_regs); | ||
59 | if(!err) | ||
60 | return; | ||
61 | |||
62 | if(errno != EIO) | ||
63 | panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d", | ||
64 | errno); | ||
65 | |||
66 | have_fpx_regs = 0; | ||
67 | } | ||
diff --git a/arch/um/sys-i386/ptrace.c b/arch/um/sys-i386/ptrace.c index 178f894384f4..cb899dd1c6b5 100644 --- a/arch/um/sys-i386/ptrace.c +++ b/arch/um/sys-i386/ptrace.c | |||
@@ -144,85 +144,6 @@ int peek_user(struct task_struct *child, long addr, long data) | |||
144 | return put_user(tmp, (unsigned long __user *) data); | 144 | return put_user(tmp, (unsigned long __user *) data); |
145 | } | 145 | } |
146 | 146 | ||
147 | struct i387_fxsave_struct { | ||
148 | unsigned short cwd; | ||
149 | unsigned short swd; | ||
150 | unsigned short twd; | ||
151 | unsigned short fop; | ||
152 | long fip; | ||
153 | long fcs; | ||
154 | long foo; | ||
155 | long fos; | ||
156 | long mxcsr; | ||
157 | long reserved; | ||
158 | long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */ | ||
159 | long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */ | ||
160 | long padding[56]; | ||
161 | }; | ||
162 | |||
163 | /* | ||
164 | * FPU tag word conversions. | ||
165 | */ | ||
166 | |||
167 | static inline unsigned short twd_i387_to_fxsr( unsigned short twd ) | ||
168 | { | ||
169 | unsigned int tmp; /* to avoid 16 bit prefixes in the code */ | ||
170 | |||
171 | /* Transform each pair of bits into 01 (valid) or 00 (empty) */ | ||
172 | tmp = ~twd; | ||
173 | tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ | ||
174 | /* and move the valid bits to the lower byte. */ | ||
175 | tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ | ||
176 | tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ | ||
177 | tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ | ||
178 | return tmp; | ||
179 | } | ||
180 | |||
181 | static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct *fxsave ) | ||
182 | { | ||
183 | struct _fpxreg *st = NULL; | ||
184 | unsigned long twd = (unsigned long) fxsave->twd; | ||
185 | unsigned long tag; | ||
186 | unsigned long ret = 0xffff0000; | ||
187 | int i; | ||
188 | |||
189 | #define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16); | ||
190 | |||
191 | for ( i = 0 ; i < 8 ; i++ ) { | ||
192 | if ( twd & 0x1 ) { | ||
193 | st = (struct _fpxreg *) FPREG_ADDR( fxsave, i ); | ||
194 | |||
195 | switch ( st->exponent & 0x7fff ) { | ||
196 | case 0x7fff: | ||
197 | tag = 2; /* Special */ | ||
198 | break; | ||
199 | case 0x0000: | ||
200 | if ( !st->significand[0] && | ||
201 | !st->significand[1] && | ||
202 | !st->significand[2] && | ||
203 | !st->significand[3] ) { | ||
204 | tag = 1; /* Zero */ | ||
205 | } else { | ||
206 | tag = 2; /* Special */ | ||
207 | } | ||
208 | break; | ||
209 | default: | ||
210 | if ( st->significand[3] & 0x8000 ) { | ||
211 | tag = 0; /* Valid */ | ||
212 | } else { | ||
213 | tag = 2; /* Special */ | ||
214 | } | ||
215 | break; | ||
216 | } | ||
217 | } else { | ||
218 | tag = 3; /* Empty */ | ||
219 | } | ||
220 | ret |= (tag << (2 * i)); | ||
221 | twd = twd >> 1; | ||
222 | } | ||
223 | return ret; | ||
224 | } | ||
225 | |||
226 | static inline int convert_fxsr_to_user(struct _fpstate __user *buf, | 147 | static inline int convert_fxsr_to_user(struct _fpstate __user *buf, |
227 | struct pt_regs *regs) | 148 | struct pt_regs *regs) |
228 | { | 149 | { |
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 | |||
39 | static 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 | |||
53 | static 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 | |||
98 | static 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 | |||
131 | static 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 | |||
165 | extern int have_fpx_regs; | ||
166 | |||
35 | static int copy_sc_from_user(struct pt_regs *regs, | 167 | static 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(®s->regs, &sc); | 177 | copy_sc(®s->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 = ¤t->thread.arch.faultinfo; | 225 | struct faultinfo * fi = ¤t->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 | ||
105 | static int copy_ucontext_to_user(struct ucontext __user *uc, | 288 | static int copy_ucontext_to_user(struct ucontext __user *uc, |
diff --git a/arch/um/sys-x86_64/signal.c b/arch/um/sys-x86_64/signal.c index c98dd7f31396..a8e5fd7b2adb 100644 --- a/arch/um/sys-x86_64/signal.c +++ b/arch/um/sys-x86_64/signal.c | |||
@@ -42,8 +42,10 @@ void copy_sc(struct uml_pt_regs *regs, void *from) | |||
42 | } | 42 | } |
43 | 43 | ||
44 | static int copy_sc_from_user(struct pt_regs *regs, | 44 | static int copy_sc_from_user(struct pt_regs *regs, |
45 | struct sigcontext __user *from) | 45 | struct sigcontext __user *from, |
46 | struct _fpstate __user *fpp) | ||
46 | { | 47 | { |
48 | struct user_i387_struct fp; | ||
47 | int err = 0; | 49 | int err = 0; |
48 | 50 | ||
49 | #define GETREG(regs, regno, sc, regname) \ | 51 | #define GETREG(regs, regno, sc, regname) \ |
@@ -69,10 +71,25 @@ static int copy_sc_from_user(struct pt_regs *regs, | |||
69 | err |= GETREG(regs, RIP, from, rip); | 71 | err |= GETREG(regs, RIP, from, rip); |
70 | err |= GETREG(regs, EFLAGS, from, eflags); | 72 | err |= GETREG(regs, EFLAGS, from, eflags); |
71 | err |= GETREG(regs, CS, from, cs); | 73 | err |= GETREG(regs, CS, from, cs); |
74 | if (err) | ||
75 | return 1; | ||
72 | 76 | ||
73 | #undef GETREG | 77 | #undef GETREG |
74 | 78 | ||
75 | return err; | 79 | err = copy_from_user(&fp, fpp, sizeof(struct user_i387_struct)); |
80 | if (err) | ||
81 | return 1; | ||
82 | |||
83 | err = restore_fp_registers(userspace_pid[current_thread->cpu], | ||
84 | (unsigned long *) &fp); | ||
85 | if (err < 0) { | ||
86 | printk(KERN_ERR "copy_sc_from_user - " | ||
87 | "restore_fp_registers failed, errno = %d\n", | ||
88 | -err); | ||
89 | return 1; | ||
90 | } | ||
91 | |||
92 | return 0; | ||
76 | } | 93 | } |
77 | 94 | ||
78 | static int copy_sc_to_user(struct sigcontext __user *to, | 95 | static int copy_sc_to_user(struct sigcontext __user *to, |
@@ -80,6 +97,7 @@ static int copy_sc_to_user(struct sigcontext __user *to, | |||
80 | unsigned long mask, unsigned long sp) | 97 | unsigned long mask, unsigned long sp) |
81 | { | 98 | { |
82 | struct faultinfo * fi = ¤t->thread.arch.faultinfo; | 99 | struct faultinfo * fi = ¤t->thread.arch.faultinfo; |
100 | struct user_i387_struct fp; | ||
83 | int err = 0; | 101 | int err = 0; |
84 | 102 | ||
85 | err |= __put_user(0, &to->gs); | 103 | err |= __put_user(0, &to->gs); |
@@ -120,6 +138,19 @@ static int copy_sc_to_user(struct sigcontext __user *to, | |||
120 | #undef PUTREG | 138 | #undef PUTREG |
121 | 139 | ||
122 | err |= __put_user(mask, &to->oldmask); | 140 | err |= __put_user(mask, &to->oldmask); |
141 | if (err) | ||
142 | return 1; | ||
143 | |||
144 | err = save_fp_registers(userspace_pid[current_thread->cpu], | ||
145 | (unsigned long *) &fp); | ||
146 | if (err < 0) { | ||
147 | printk(KERN_ERR "copy_sc_from_user - restore_fp_registers " | ||
148 | "failed, errno = %d\n", -err); | ||
149 | return 1; | ||
150 | } | ||
151 | |||
152 | if (copy_to_user(to_fp, &fp, sizeof(struct user_i387_struct))) | ||
153 | return 1; | ||
123 | 154 | ||
124 | return(err); | 155 | return(err); |
125 | } | 156 | } |
@@ -129,6 +160,7 @@ struct rt_sigframe | |||
129 | char __user *pretcode; | 160 | char __user *pretcode; |
130 | struct ucontext uc; | 161 | struct ucontext uc; |
131 | struct siginfo info; | 162 | struct siginfo info; |
163 | struct _fpstate fpstate; | ||
132 | }; | 164 | }; |
133 | 165 | ||
134 | #define round_down(m, n) (((m) / (n)) * (n)) | 166 | #define round_down(m, n) (((m) / (n)) * (n)) |
@@ -138,7 +170,6 @@ int setup_signal_stack_si(unsigned long stack_top, int sig, | |||
138 | siginfo_t *info, sigset_t *set) | 170 | siginfo_t *info, sigset_t *set) |
139 | { | 171 | { |
140 | struct rt_sigframe __user *frame; | 172 | struct rt_sigframe __user *frame; |
141 | struct _fpstate __user *fp = NULL; | ||
142 | unsigned long save_sp = PT_REGS_RSP(regs); | 173 | unsigned long save_sp = PT_REGS_RSP(regs); |
143 | int err = 0; | 174 | int err = 0; |
144 | struct task_struct *me = current; | 175 | struct task_struct *me = current; |
@@ -148,13 +179,6 @@ int setup_signal_stack_si(unsigned long stack_top, int sig, | |||
148 | /* Subtract 128 for a red zone and 8 for proper alignment */ | 179 | /* Subtract 128 for a red zone and 8 for proper alignment */ |
149 | frame = (struct rt_sigframe __user *) ((unsigned long) frame - 128 - 8); | 180 | frame = (struct rt_sigframe __user *) ((unsigned long) frame - 128 - 8); |
150 | 181 | ||
151 | if (!access_ok(VERIFY_WRITE, fp, sizeof(struct _fpstate))) | ||
152 | goto out; | ||
153 | |||
154 | #if 0 /* XXX */ | ||
155 | if (save_i387(fp) < 0) | ||
156 | err |= -1; | ||
157 | #endif | ||
158 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | 182 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
159 | goto out; | 183 | goto out; |
160 | 184 | ||
@@ -181,9 +205,9 @@ int setup_signal_stack_si(unsigned long stack_top, int sig, | |||
181 | err |= __put_user(sas_ss_flags(save_sp), | 205 | err |= __put_user(sas_ss_flags(save_sp), |
182 | &frame->uc.uc_stack.ss_flags); | 206 | &frame->uc.uc_stack.ss_flags); |
183 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); | 207 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); |
184 | err |= copy_sc_to_user(&frame->uc.uc_mcontext, fp, regs, set->sig[0], | 208 | err |= copy_sc_to_user(&frame->uc.uc_mcontext, &frame->fpstate, regs, |
185 | save_sp); | 209 | set->sig[0], save_sp); |
186 | err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate); | 210 | err |= __put_user(&frame->fpstate, &frame->uc.uc_mcontext.fpstate); |
187 | if (sizeof(*set) == 16) { | 211 | if (sizeof(*set) == 16) { |
188 | __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]); | 212 | __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]); |
189 | __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]); | 213 | __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]); |
@@ -246,7 +270,8 @@ long sys_rt_sigreturn(struct pt_regs *regs) | |||
246 | recalc_sigpending(); | 270 | recalc_sigpending(); |
247 | spin_unlock_irq(¤t->sighand->siglock); | 271 | spin_unlock_irq(¤t->sighand->siglock); |
248 | 272 | ||
249 | if (copy_sc_from_user(¤t->thread.regs, &uc->uc_mcontext)) | 273 | if (copy_sc_from_user(¤t->thread.regs, &uc->uc_mcontext, |
274 | &frame->fpstate)) | ||
250 | goto segfault; | 275 | goto segfault; |
251 | 276 | ||
252 | /* Avoid ERESTART handling */ | 277 | /* Avoid ERESTART handling */ |