|
From: Thomas M. <th...@m3...> - 2017-07-06 21:04:23
|
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 <th...@m3...> --- arch/x86/um/os-Linux/registers.c | 9 ++++----- arch/x86/um/user-offsets.c | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c index 00f54a91bb4b..7265511d8e3b 100644 --- a/arch/x86/um/os-Linux/registers.c +++ b/arch/x86/um/os-Linux/registers.c @@ -30,7 +30,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; @@ -49,10 +49,9 @@ int restore_i387_registers(int pid, unsigned long *fp_regs) int restore_fp_registers(int pid, unsigned long *fp_regs) { 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; @@ -122,11 +121,11 @@ int put_fp_registers(int pid, unsigned long *regs) void arch_init_registers(int pid) { - struct _xstate fp_regs; + unsigned long fp_regs[FP_SIZE]; struct iovec iov; 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) have_xstate_support = 1; } diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c index cb3c22370cf5..c0111f093361 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -50,7 +50,7 @@ void foo(void) DEFINE(HOST_GS, GS); DEFINE(HOST_ORIG_AX, ORIG_EAX); #else - DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long)); + DEFINE_LONGS(HOST_FP_SIZE, 2696); DEFINE_LONGS(HOST_BX, RBX); DEFINE_LONGS(HOST_CX, RCX); DEFINE_LONGS(HOST_DI, RDI); -- 2.13.0 |
|
From: Richard W. <ric...@gm...> - 2017-07-07 09:26:13
|
On Thu, Jul 6, 2017 at 11:04 PM, Thomas Meyer <th...@m3...> wrote: > 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 <th...@m3...> > --- > arch/x86/um/os-Linux/registers.c | 9 ++++----- > arch/x86/um/user-offsets.c | 2 +- > 2 files changed, 5 insertions(+), 6 deletions(-) Applied. Thanks a lot for taking care of this nasty issue! -- Thanks, //richard |
|
From: Richard W. <ric...@gm...> - 2017-07-07 09:49:28
|
On Fri, Jul 7, 2017 at 11:26 AM, Richard Weinberger <ric...@gm...> wrote: > On Thu, Jul 6, 2017 at 11:04 PM, Thomas Meyer <th...@m3...> wrote: >> 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 <th...@m3...> >> --- >> arch/x86/um/os-Linux/registers.c | 9 ++++----- >> arch/x86/um/user-offsets.c | 2 +- >> 2 files changed, 5 insertions(+), 6 deletions(-) > > Applied. Thanks a lot for taking care of this nasty issue! Erm, did you notice the scary compiler warning produced by this commit? :-( -- Thanks, //richard |
|
From: Thomas M. <th...@m3...> - 2017-07-07 21:01:42
|
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 <th...@m3...> --- arch/um/os-Linux/skas/process.c | 22 ++++++++++++++++++---- arch/x86/um/os-Linux/registers.c | 16 +++++++++++----- arch/x86/um/user-offsets.c | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index 03b3c4cc7735..1a7cce387950 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -91,19 +91,25 @@ extern unsigned long current_stub_stack(void); static void get_skas_faultinfo(int pid, struct faultinfo *fi) { int err; - unsigned long fpregs[FP_SIZE]; + void * fpregs; + + fpregs = malloc(FP_SIZE * sizeof(unsigned long)); + if(fpregs == NULL) { + printk(UM_KERN_ERR "cannot alloc memory for save_fp_registers!"); + goto errout; + } err = get_fp_registers(pid, fpregs); if (err < 0) { printk(UM_KERN_ERR "save_fp_registers returned %d\n", err); - fatal_sigsegv(); + goto errout; } err = ptrace(PTRACE_CONT, pid, 0, SIGSEGV); if (err) { printk(UM_KERN_ERR "Failed to continue stub, pid = %d, " "errno = %d\n", pid, errno); - fatal_sigsegv(); + goto errout; } wait_stub_done(pid); @@ -117,8 +123,16 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi) if (err < 0) { printk(UM_KERN_ERR "put_fp_registers returned %d\n", err); - fatal_sigsegv(); + goto errout; } + return; + + errout: + if(fpregs != NULL) { + free(fpregs); + } + fatal_sigsegv(); + } static void handle_segv(int pid, struct uml_pt_regs * regs) diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c index 00f54a91bb4b..e972c3d3b7b1 100644 --- a/arch/x86/um/os-Linux/registers.c +++ b/arch/x86/um/os-Linux/registers.c @@ -5,6 +5,7 @@ */ #include <errno.h> +#include <stdlib.h> #include <sys/ptrace.h> #ifdef __i386__ #include <sys/user.h> @@ -30,7 +31,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; @@ -49,10 +50,9 @@ int restore_i387_registers(int pid, unsigned long *fp_regs) int restore_fp_registers(int pid, unsigned long *fp_regs) { 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; @@ -122,13 +122,19 @@ int put_fp_registers(int pid, unsigned long *regs) void arch_init_registers(int pid) { - struct _xstate fp_regs; + void * fp_regs; struct iovec iov; + fp_regs = malloc(FP_SIZE * sizeof(unsigned long)); + if(fp_regs == NULL) + return; + 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) have_xstate_support = 1; + + free(fp_regs); } #endif diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c index cb3c22370cf5..c0111f093361 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -50,7 +50,7 @@ void foo(void) DEFINE(HOST_GS, GS); DEFINE(HOST_ORIG_AX, ORIG_EAX); #else - DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long)); + DEFINE_LONGS(HOST_FP_SIZE, 2696); DEFINE_LONGS(HOST_BX, RBX); DEFINE_LONGS(HOST_CX, RCX); DEFINE_LONGS(HOST_DI, RDI); -- 2.13.0 |
|
From: Richard W. <ric...@gm...> - 2017-07-07 22:13:45
|
Thomas, On Fri, Jul 7, 2017 at 11:01 PM, Thomas Meyer <th...@m3...> wrote: > 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 <th...@m3...> > --- > arch/um/os-Linux/skas/process.c | 22 ++++++++++++++++++---- > arch/x86/um/os-Linux/registers.c | 16 +++++++++++----- > arch/x86/um/user-offsets.c | 2 +- > 3 files changed, 30 insertions(+), 10 deletions(-) > > diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c > index 03b3c4cc7735..1a7cce387950 100644 > --- a/arch/um/os-Linux/skas/process.c > +++ b/arch/um/os-Linux/skas/process.c > @@ -91,19 +91,25 @@ extern unsigned long current_stub_stack(void); > static void get_skas_faultinfo(int pid, struct faultinfo *fi) > { > int err; > - unsigned long fpregs[FP_SIZE]; > + void * fpregs; > + > + fpregs = malloc(FP_SIZE * sizeof(unsigned long)); > + if(fpregs == NULL) { > + printk(UM_KERN_ERR "cannot alloc memory for save_fp_registers!"); > + goto errout; > + } Having a malloc() here is rather expensive. I suggest to allocate a buffer in userspace() that can be used in get_skas_faultinfo(). Thanks, //richard -- Thanks, //richard |
|
From: Thomas M. <th...@m3...> - 2017-07-09 22:33:16
|
Hard code max size. Taken from https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h v3: use static fp_regs for get_skas_faultinfo Signed-off-by: Thomas Meyer <th...@m3...> --- arch/um/os-Linux/skas/process.c | 7 ++++--- arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------ arch/x86/um/user-offsets.c | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index 03b3c4cc7735..b5fdef795985 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -88,12 +88,13 @@ void wait_stub_done(int pid) extern unsigned long current_stub_stack(void); +static unsigned long skas_faultinfo_fpregs[FP_SIZE]; + static void get_skas_faultinfo(int pid, struct faultinfo *fi) { int err; - unsigned long fpregs[FP_SIZE]; - err = get_fp_registers(pid, fpregs); + err = get_fp_registers(pid, skas_faultinfo_fpregs); if (err < 0) { printk(UM_KERN_ERR "save_fp_registers returned %d\n", err); @@ -113,7 +114,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, skas_faultinfo_fpregs); if (err < 0) { printk(UM_KERN_ERR "put_fp_registers returned %d\n", err); diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c index 00f54a91bb4b..2717911d1bef 100644 --- a/arch/x86/um/os-Linux/registers.c +++ b/arch/x86/um/os-Linux/registers.c @@ -5,6 +5,7 @@ */ #include <errno.h> +#include <stdlib.h> #include <sys/ptrace.h> #ifdef __i386__ #include <sys/user.h> @@ -30,7 +31,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; @@ -49,10 +50,9 @@ int restore_i387_registers(int pid, unsigned long *fp_regs) int restore_fp_registers(int pid, unsigned long *fp_regs) { 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; @@ -122,13 +122,19 @@ int put_fp_registers(int pid, unsigned long *regs) void arch_init_registers(int pid) { - 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 diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c index cb3c22370cf5..c0111f093361 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -50,7 +50,7 @@ void foo(void) DEFINE(HOST_GS, GS); DEFINE(HOST_ORIG_AX, ORIG_EAX); #else - DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long)); + DEFINE_LONGS(HOST_FP_SIZE, 2696); DEFINE_LONGS(HOST_BX, RBX); DEFINE_LONGS(HOST_CX, RCX); DEFINE_LONGS(HOST_DI, RDI); -- 2.13.0 |
|
From: Richard W. <ri...@no...> - 2017-07-10 19:06:47
|
Thomas, Am 10.07.2017 um 00:33 schrieb Thomas Meyer: > Hard code max size. Taken from > https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h > > v3: use static fp_regs for get_skas_faultinfo > > Signed-off-by: Thomas Meyer <th...@m3...> > --- > arch/um/os-Linux/skas/process.c | 7 ++++--- > arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------ > arch/x86/um/user-offsets.c | 2 +- > 3 files changed, 17 insertions(+), 10 deletions(-) > > diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c > index 03b3c4cc7735..b5fdef795985 100644 > --- a/arch/um/os-Linux/skas/process.c > +++ b/arch/um/os-Linux/skas/process.c > @@ -88,12 +88,13 @@ void wait_stub_done(int pid) > > extern unsigned long current_stub_stack(void); > > +static unsigned long skas_faultinfo_fpregs[FP_SIZE]; > + Uhmm, are you sure that this does not race with other userspace() instances? Thanks, //richard |