Skip to content

Commit 6f602af

Browse files
thomasmeyrichardweinberger
authored andcommitted
um: Fix FP register size for XSTATE/XSAVE
Hard code max size. Taken from https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h Signed-off-by: Thomas Meyer <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 569dbb8 commit 6f602af

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

arch/um/include/asm/thread_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <asm/types.h>
1212
#include <asm/page.h>
1313
#include <asm/segment.h>
14+
#include <sysdep/ptrace_user.h>
1415

1516
struct thread_info {
1617
struct task_struct *task; /* main task structure */
@@ -22,6 +23,8 @@ struct thread_info {
2223
0-0xBFFFFFFF for user
2324
0-0xFFFFFFFF for kernel */
2425
struct thread_info *real_thread; /* Points to non-IRQ stack */
26+
unsigned long aux_fp_regs[FP_SIZE]; /* auxiliary fp_regs to save/restore
27+
them out-of-band */
2528
};
2629

2730
#define INIT_THREAD_INFO(tsk) \

arch/um/include/shared/os.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr,
278278
extern int is_skas_winch(int pid, int fd, void *data);
279279
extern int start_userspace(unsigned long stub_stack);
280280
extern int copy_context_skas0(unsigned long stack, int pid);
281-
extern void userspace(struct uml_pt_regs *regs);
281+
extern void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs);
282282
extern int map_stub_pages(int fd, unsigned long code, unsigned long data,
283283
unsigned long stack);
284284
extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));

arch/um/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void new_thread_handler(void)
131131
* callback returns only if the kernel thread execs a process
132132
*/
133133
n = fn(arg);
134-
userspace(&current->thread.regs.regs);
134+
userspace(&current->thread.regs.regs, current_thread_info()->aux_fp_regs);
135135
}
136136

137137
/* Called magically, see new_thread_handler above */
@@ -150,7 +150,7 @@ void fork_handler(void)
150150

151151
current->thread.prev_sched = NULL;
152152

153-
userspace(&current->thread.regs.regs);
153+
userspace(&current->thread.regs.regs, current_thread_info()->aux_fp_regs);
154154
}
155155

156156
int copy_thread(unsigned long clone_flags, unsigned long sp,

arch/um/os-Linux/skas/process.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@ void wait_stub_done(int pid)
8888

8989
extern unsigned long current_stub_stack(void);
9090

91-
static void get_skas_faultinfo(int pid, struct faultinfo *fi)
91+
static void get_skas_faultinfo(int pid, struct faultinfo *fi, unsigned long *aux_fp_regs)
9292
{
9393
int err;
94-
unsigned long fpregs[FP_SIZE];
9594

96-
err = get_fp_registers(pid, fpregs);
95+
err = get_fp_registers(pid, aux_fp_regs);
9796
if (err < 0) {
9897
printk(UM_KERN_ERR "save_fp_registers returned %d\n",
9998
err);
@@ -113,17 +112,17 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)
113112
*/
114113
memcpy(fi, (void *)current_stub_stack(), sizeof(*fi));
115114

116-
err = put_fp_registers(pid, fpregs);
115+
err = put_fp_registers(pid, aux_fp_regs);
117116
if (err < 0) {
118117
printk(UM_KERN_ERR "put_fp_registers returned %d\n",
119118
err);
120119
fatal_sigsegv();
121120
}
122121
}
123122

124-
static void handle_segv(int pid, struct uml_pt_regs * regs)
123+
static void handle_segv(int pid, struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
125124
{
126-
get_skas_faultinfo(pid, &regs->faultinfo);
125+
get_skas_faultinfo(pid, &regs->faultinfo, aux_fp_regs);
127126
segv(regs->faultinfo, 0, 1, NULL);
128127
}
129128

@@ -332,7 +331,7 @@ int start_userspace(unsigned long stub_stack)
332331
return err;
333332
}
334333

335-
void userspace(struct uml_pt_regs *regs)
334+
void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
336335
{
337336
int err, status, op, pid = userspace_pid[0];
338337
/* To prevent races if using_sysemu changes under us.*/
@@ -407,11 +406,11 @@ void userspace(struct uml_pt_regs *regs)
407406
case SIGSEGV:
408407
if (PTRACE_FULL_FAULTINFO) {
409408
get_skas_faultinfo(pid,
410-
&regs->faultinfo);
409+
&regs->faultinfo, aux_fp_regs);
411410
(*sig_info[SIGSEGV])(SIGSEGV, (struct siginfo *)&si,
412411
regs);
413412
}
414-
else handle_segv(pid, regs);
413+
else handle_segv(pid, regs, aux_fp_regs);
415414
break;
416415
case SIGTRAP + 0x80:
417416
handle_trap(pid, regs, local_using_sysemu);

arch/x86/um/os-Linux/registers.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <errno.h>
8+
#include <stdlib.h>
89
#include <sys/ptrace.h>
910
#ifdef __i386__
1011
#include <sys/user.h>
@@ -31,7 +32,7 @@ int save_fp_registers(int pid, unsigned long *fp_regs)
3132

3233
if (have_xstate_support) {
3334
iov.iov_base = fp_regs;
34-
iov.iov_len = sizeof(struct _xstate);
35+
iov.iov_len = FP_SIZE * sizeof(unsigned long);
3536
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
3637
return -errno;
3738
return 0;
@@ -51,10 +52,9 @@ int restore_fp_registers(int pid, unsigned long *fp_regs)
5152
{
5253
#ifdef PTRACE_SETREGSET
5354
struct iovec iov;
54-
5555
if (have_xstate_support) {
5656
iov.iov_base = fp_regs;
57-
iov.iov_len = sizeof(struct _xstate);
57+
iov.iov_len = FP_SIZE * sizeof(unsigned long);
5858
if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
5959
return -errno;
6060
return 0;
@@ -125,13 +125,19 @@ int put_fp_registers(int pid, unsigned long *regs)
125125
void arch_init_registers(int pid)
126126
{
127127
#ifdef PTRACE_GETREGSET
128-
struct _xstate fp_regs;
128+
void * fp_regs;
129129
struct iovec iov;
130130

131-
iov.iov_base = &fp_regs;
132-
iov.iov_len = sizeof(struct _xstate);
131+
fp_regs = malloc(FP_SIZE * sizeof(unsigned long));
132+
if(fp_regs == NULL)
133+
return;
134+
135+
iov.iov_base = fp_regs;
136+
iov.iov_len = FP_SIZE * sizeof(unsigned long);
133137
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
134138
have_xstate_support = 1;
139+
140+
free(fp_regs);
135141
#endif
136142
}
137143
#endif

arch/x86/um/user-offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void foo(void)
5151
DEFINE(HOST_ORIG_AX, ORIG_EAX);
5252
#else
5353
#ifdef FP_XSTATE_MAGIC1
54-
DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
54+
DEFINE_LONGS(HOST_FP_SIZE, 2696);
5555
#else
5656
DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
5757
#endif

0 commit comments

Comments
 (0)