um: Fix FP register size for XSTATE/XSAVE
authorThomas Meyer <thomas@m3y3r.de>
Sat, 29 Jul 2017 15:03:23 +0000 (17:03 +0200)
committerRichard Weinberger <richard@nod.at>
Wed, 13 Sep 2017 20:24:38 +0000 (22:24 +0200)
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 <thomas@m3y3r.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
arch/um/include/asm/thread_info.h
arch/um/include/shared/os.h
arch/um/kernel/process.c
arch/um/os-Linux/skas/process.c
arch/x86/um/os-Linux/registers.c
arch/x86/um/user-offsets.c

index 053baff036746f8360a6ff81034a6e3bcc332156..9300f7630d2ad8f0bfa6e3360bd5af5c04e98181 100644 (file)
@@ -11,6 +11,7 @@
 #include <asm/types.h>
 #include <asm/page.h>
 #include <asm/segment.h>
+#include <sysdep/ptrace_user.h>
 
 struct thread_info {
        struct task_struct      *task;          /* main task structure */
@@ -22,6 +23,8 @@ struct thread_info {
                                                   0-0xBFFFFFFF for user
                                                   0-0xFFFFFFFF for kernel */
        struct thread_info      *real_thread;    /* Points to non-IRQ stack */
+       unsigned long aux_fp_regs[FP_SIZE];     /* auxiliary fp_regs to save/restore
+                                                  them out-of-band */
 };
 
 #define INIT_THREAD_INFO(tsk)                  \
index 574e03fc7ba256d74e074c4762ced1f77d3cc0b1..d8ddaf9790d2bd858db7f4e41f45d43d1a49d0d0 100644 (file)
@@ -278,7 +278,7 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr,
 extern int is_skas_winch(int pid, int fd, void *data);
 extern int start_userspace(unsigned long stub_stack);
 extern int copy_context_skas0(unsigned long stack, int pid);
-extern void userspace(struct uml_pt_regs *regs);
+extern void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs);
 extern int map_stub_pages(int fd, unsigned long code, unsigned long data,
                          unsigned long stack);
 extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
index 2c7f721eccbcb2b45799a380cfddb9327c0d509c..691b83b10649c04e267c763f04776da70b2f6f03 100644 (file)
@@ -131,7 +131,7 @@ void new_thread_handler(void)
         * callback returns only if the kernel thread execs a process
         */
        n = fn(arg);
-       userspace(&current->thread.regs.regs);
+       userspace(&current->thread.regs.regs, current_thread_info()->aux_fp_regs);
 }
 
 /* Called magically, see new_thread_handler above */
@@ -150,7 +150,7 @@ void fork_handler(void)
 
        current->thread.prev_sched = NULL;
 
-       userspace(&current->thread.regs.regs);
+       userspace(&current->thread.regs.regs, current_thread_info()->aux_fp_regs);
 }
 
 int copy_thread(unsigned long clone_flags, unsigned long sp,
index 819d68656673c53f14ee38513a73f63f19f1ac64..c94c3bd70ccd797d03a53f7f9b7b5773ff274506 100644 (file)
@@ -88,12 +88,11 @@ bad_wait:
 
 extern unsigned long current_stub_stack(void);
 
-static void get_skas_faultinfo(int pid, struct faultinfo *fi)
+static void get_skas_faultinfo(int pid, struct faultinfo *fi, unsigned long *aux_fp_regs)
 {
        int err;
-       unsigned long fpregs[FP_SIZE];
 
-       err = get_fp_registers(pid, fpregs);
+       err = get_fp_registers(pid, aux_fp_regs);
        if (err < 0) {
                printk(UM_KERN_ERR "save_fp_registers returned %d\n",
                       err);
@@ -113,7 +112,7 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)
         */
        memcpy(fi, (void *)current_stub_stack(), sizeof(*fi));
 
-       err = put_fp_registers(pid, fpregs);
+       err = put_fp_registers(pid, aux_fp_regs);
        if (err < 0) {
                printk(UM_KERN_ERR "put_fp_registers returned %d\n",
                       err);
@@ -121,9 +120,9 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)
        }
 }
 
-static void handle_segv(int pid, struct uml_pt_regs * regs)
+static void handle_segv(int pid, struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
 {
-       get_skas_faultinfo(pid, &regs->faultinfo);
+       get_skas_faultinfo(pid, &regs->faultinfo, aux_fp_regs);
        segv(regs->faultinfo, 0, 1, NULL);
 }
 
@@ -332,7 +331,7 @@ int start_userspace(unsigned long stub_stack)
        return err;
 }
 
-void userspace(struct uml_pt_regs *regs)
+void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
 {
        int err, status, op, pid = userspace_pid[0];
        /* To prevent races if using_sysemu changes under us.*/
@@ -407,11 +406,11 @@ void userspace(struct uml_pt_regs *regs)
                        case SIGSEGV:
                                if (PTRACE_FULL_FAULTINFO) {
                                        get_skas_faultinfo(pid,
-                                                          &regs->faultinfo);
+                                                          &regs->faultinfo, aux_fp_regs);
                                        (*sig_info[SIGSEGV])(SIGSEGV, (struct siginfo *)&si,
                                                             regs);
                                }
-                               else handle_segv(pid, regs);
+                               else handle_segv(pid, regs, aux_fp_regs);
                                break;
                        case SIGTRAP + 0x80:
                                handle_trap(pid, regs, local_using_sysemu);
index 28775f55bde240fc29fcc2030748e2078c0747c5..3c423dfcd78bf0d7f96883266f15b50fd8ffa55c 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <errno.h>
+#include <stdlib.h>
 #include <sys/ptrace.h>
 #ifdef __i386__
 #include <sys/user.h>
@@ -31,7 +32,7 @@ int save_fp_registers(int pid, unsigned long *fp_regs)
 
        if (have_xstate_support) {
                iov.iov_base = fp_regs;
-               iov.iov_len = sizeof(struct _xstate);
+               iov.iov_len = FP_SIZE * sizeof(unsigned long);
                if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
                        return -errno;
                return 0;
@@ -51,10 +52,9 @@ int restore_fp_registers(int pid, unsigned long *fp_regs)
 {
 #ifdef PTRACE_SETREGSET
        struct iovec iov;
-
        if (have_xstate_support) {
                iov.iov_base = fp_regs;
-               iov.iov_len = sizeof(struct _xstate);
+               iov.iov_len = FP_SIZE * sizeof(unsigned long);
                if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
                        return -errno;
                return 0;
@@ -125,13 +125,19 @@ int put_fp_registers(int pid, unsigned long *regs)
 void arch_init_registers(int pid)
 {
 #ifdef PTRACE_GETREGSET
-       struct _xstate fp_regs;
+       void * fp_regs;
        struct iovec iov;
 
-       iov.iov_base = &fp_regs;
-       iov.iov_len = sizeof(struct _xstate);
+       fp_regs = malloc(FP_SIZE * sizeof(unsigned long));
+       if(fp_regs == NULL)
+               return;
+
+       iov.iov_base = fp_regs;
+       iov.iov_len = FP_SIZE * sizeof(unsigned long);
        if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
                have_xstate_support = 1;
+
+       free(fp_regs);
 #endif
 }
 #endif
index 02250b2633b839c7fa56704d804dd4953f244121..3099c209546f8722c03f84c25c9615adee9c4095 100644 (file)
@@ -51,7 +51,7 @@ void foo(void)
        DEFINE(HOST_ORIG_AX, ORIG_EAX);
 #else
 #ifdef FP_XSTATE_MAGIC1
-       DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
+       DEFINE_LONGS(HOST_FP_SIZE, 2696);
 #else
        DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
 #endif