aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-03-27 01:32:25 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-03-27 12:05:15 -0400
commitb92c4f922b2e8c70f8790d42e45bb9401c57be63 (patch)
treed7c1723382aa8eb983f216209c35a247d1bbc602 /arch/um/os-Linux
parent7632fc8f809a97f9d82ce125e8e3e579390ce2e5 (diff)
[PATCH] uml: use correct register file size everywhere
This patch uses MAX_REG_NR consistently to refer to the register file size. FRAME_SIZE isn't sufficient because on x86_64, it is smaller than the ptrace register file size. MAX_REG_NR was introduced as a consistent way to get the number of registers, but wasn't used everywhere it should be. When this causes a problem, it makes PTRACE_SETREGS fail on x86_64 because of a corrupted segment register value in the known-good register file. The patch also adds a register dump at that point in case there are any future problems here. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r--arch/um/os-Linux/skas/mem.c10
-rw-r--r--arch/um/os-Linux/skas/process.c6
-rw-r--r--arch/um/os-Linux/sys-i386/registers.c5
-rw-r--r--arch/um/os-Linux/sys-x86_64/registers.c4
4 files changed, 15 insertions, 10 deletions
diff --git a/arch/um/os-Linux/skas/mem.c b/arch/um/os-Linux/skas/mem.c
index b3c11cfa995..9383e8751ae 100644
--- a/arch/um/os-Linux/skas/mem.c
+++ b/arch/um/os-Linux/skas/mem.c
@@ -48,7 +48,7 @@ int multi_op_count = 0;
48static inline long do_syscall_stub(struct mm_id * mm_idp, void **addr) 48static inline long do_syscall_stub(struct mm_id * mm_idp, void **addr)
49{ 49{
50 unsigned long regs[MAX_REG_NR]; 50 unsigned long regs[MAX_REG_NR];
51 int n; 51 int n, i;
52 long ret, offset; 52 long ret, offset;
53 unsigned long * data; 53 unsigned long * data;
54 unsigned long * syscall; 54 unsigned long * syscall;
@@ -66,9 +66,13 @@ static inline long do_syscall_stub(struct mm_id * mm_idp, void **addr)
66 (unsigned long) &__syscall_stub_start); 66 (unsigned long) &__syscall_stub_start);
67 67
68 n = ptrace_setregs(pid, regs); 68 n = ptrace_setregs(pid, regs);
69 if(n < 0) 69 if(n < 0){
70 printk("Registers - \n");
71 for(i = 0; i < MAX_REG_NR; i++)
72 printk("\t%d\t0x%lx\n", i, regs[i]);
70 panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n", 73 panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n",
71 n); 74 -n);
75 }
72 76
73 wait_stub_done(pid, 0, "do_syscall_stub"); 77 wait_stub_done(pid, 0, "do_syscall_stub");
74 78
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index dda06789bcb..0564422c155 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -67,7 +67,7 @@ void wait_stub_done(int pid, int sig, char * fname)
67 67
68 if((n < 0) || !WIFSTOPPED(status) || 68 if((n < 0) || !WIFSTOPPED(status) ||
69 (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){ 69 (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){
70 unsigned long regs[HOST_FRAME_SIZE]; 70 unsigned long regs[MAX_REG_NR];
71 71
72 if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0) 72 if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
73 printk("Failed to get registers from stub, " 73 printk("Failed to get registers from stub, "
@@ -76,7 +76,7 @@ void wait_stub_done(int pid, int sig, char * fname)
76 int i; 76 int i;
77 77
78 printk("Stub registers -\n"); 78 printk("Stub registers -\n");
79 for(i = 0; i < HOST_FRAME_SIZE; i++) 79 for(i = 0; i < ARRAY_SIZE(regs); i++)
80 printk("\t%d - %lx\n", i, regs[i]); 80 printk("\t%d - %lx\n", i, regs[i]);
81 } 81 }
82 panic("%s : failed to wait for SIGUSR1/SIGTRAP, " 82 panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
@@ -328,7 +328,7 @@ void userspace(union uml_pt_regs *regs)
328int copy_context_skas0(unsigned long new_stack, int pid) 328int copy_context_skas0(unsigned long new_stack, int pid)
329{ 329{
330 int err; 330 int err;
331 unsigned long regs[HOST_FRAME_SIZE]; 331 unsigned long regs[MAX_REG_NR];
332 unsigned long fp_regs[HOST_FP_SIZE]; 332 unsigned long fp_regs[HOST_FP_SIZE];
333 unsigned long current_stack = current_stub_stack(); 333 unsigned long current_stack = current_stub_stack();
334 struct stub_data *data = (struct stub_data *) current_stack; 334 struct stub_data *data = (struct stub_data *) current_stack;
diff --git a/arch/um/os-Linux/sys-i386/registers.c b/arch/um/os-Linux/sys-i386/registers.c
index 79cd93c8c5e..84b44f9cd42 100644
--- a/arch/um/os-Linux/sys-i386/registers.c
+++ b/arch/um/os-Linux/sys-i386/registers.c
@@ -15,7 +15,7 @@
15 15
16/* These are set once at boot time and not changed thereafter */ 16/* These are set once at boot time and not changed thereafter */
17 17
18static unsigned long exec_regs[HOST_FRAME_SIZE]; 18static unsigned long exec_regs[MAX_REG_NR];
19static unsigned long exec_fp_regs[HOST_FP_SIZE]; 19static unsigned long exec_fp_regs[HOST_FP_SIZE];
20static unsigned long exec_fpx_regs[HOST_XFP_SIZE]; 20static unsigned long exec_fpx_regs[HOST_XFP_SIZE];
21static int have_fpx_regs = 1; 21static int have_fpx_regs = 1;
@@ -101,6 +101,7 @@ void init_registers(int pid)
101{ 101{
102 int err; 102 int err;
103 103
104 memset(exec_regs, 0, sizeof(exec_regs));
104 err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs); 105 err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
105 if(err) 106 if(err)
106 panic("check_ptrace : PTRACE_GETREGS failed, errno = %d", 107 panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
@@ -124,7 +125,7 @@ void init_registers(int pid)
124 125
125void get_safe_registers(unsigned long *regs, unsigned long *fp_regs) 126void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
126{ 127{
127 memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long)); 128 memcpy(regs, exec_regs, sizeof(exec_regs));
128 if(fp_regs != NULL) 129 if(fp_regs != NULL)
129 memcpy(fp_regs, exec_fp_regs, 130 memcpy(fp_regs, exec_fp_regs,
130 HOST_FP_SIZE * sizeof(unsigned long)); 131 HOST_FP_SIZE * sizeof(unsigned long));
diff --git a/arch/um/os-Linux/sys-x86_64/registers.c b/arch/um/os-Linux/sys-x86_64/registers.c
index a2d7e0c603f..e6fc2179d1b 100644
--- a/arch/um/os-Linux/sys-x86_64/registers.c
+++ b/arch/um/os-Linux/sys-x86_64/registers.c
@@ -14,7 +14,7 @@
14 14
15/* These are set once at boot time and not changed thereafter */ 15/* These are set once at boot time and not changed thereafter */
16 16
17static unsigned long exec_regs[HOST_FRAME_SIZE]; 17static unsigned long exec_regs[MAX_REG_NR];
18static unsigned long exec_fp_regs[HOST_FP_SIZE]; 18static unsigned long exec_fp_regs[HOST_FP_SIZE];
19 19
20void init_thread_registers(union uml_pt_regs *to) 20void init_thread_registers(union uml_pt_regs *to)
@@ -72,7 +72,7 @@ void init_registers(int pid)
72 72
73void get_safe_registers(unsigned long *regs, unsigned long *fp_regs) 73void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
74{ 74{
75 memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long)); 75 memcpy(regs, exec_regs, sizeof(exec_regs));
76 if(fp_regs != NULL) 76 if(fp_regs != NULL)
77 memcpy(fp_regs, exec_fp_regs, 77 memcpy(fp_regs, exec_fp_regs,
78 HOST_FP_SIZE * sizeof(unsigned long)); 78 HOST_FP_SIZE * sizeof(unsigned long));