Commit 75e29b18 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

[PATCH] uml: stack usage reduction

The KSTK_* macros used an inordinate amount of stack.  In order to overcome
an impedance mismatch between their interface, which just returns a single
register value, and the interface of get_thread_regs, which took a full
pt_regs, the implementation created an on-stack pt_regs, filled it in, and
returned one field.  do_task_stat calls KSTK_* twice, resulting in two
local pt_regs, blowing out the stack.

This patch changes the interface (and name) of get_thread_regs to just
return a single register from a jmp_buf.

The include of archsetjmp.h" in registers.h to get the definition of
jmp_buf exposed a bogus include of <setjmp.h> in start_up.c.  <setjmp.h>
shouldn't be used anywhere any more since UML uses the klibc
setjmp/longjmp.
Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent bf61f50d
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#define __REGISTERS_H #define __REGISTERS_H
#include "sysdep/ptrace.h" #include "sysdep/ptrace.h"
#include "sysdep/archsetjmp.h"
extern void init_thread_registers(union uml_pt_regs *to); extern void init_thread_registers(union uml_pt_regs *to);
extern int save_fp_registers(int pid, unsigned long *fp_regs); extern int save_fp_registers(int pid, unsigned long *fp_regs);
...@@ -15,6 +16,6 @@ extern void save_registers(int pid, union uml_pt_regs *regs); ...@@ -15,6 +16,6 @@ extern void save_registers(int pid, union uml_pt_regs *regs);
extern void restore_registers(int pid, union uml_pt_regs *regs); extern void restore_registers(int pid, union uml_pt_regs *regs);
extern void init_registers(int pid); extern void init_registers(int pid);
extern void get_safe_registers(unsigned long * regs, unsigned long * fp_regs); extern void get_safe_registers(unsigned long * regs, unsigned long * fp_regs);
extern void get_thread_regs(union uml_pt_regs *uml_regs, void *buffer); extern unsigned long get_thread_reg(int reg, jmp_buf *buf);
#endif #endif
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include <sched.h> #include <sched.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <setjmp.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mman.h> #include <sys/mman.h>
......
...@@ -130,11 +130,14 @@ void get_safe_registers(unsigned long *regs, unsigned long *fp_regs) ...@@ -130,11 +130,14 @@ void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
HOST_FP_SIZE * sizeof(unsigned long)); HOST_FP_SIZE * sizeof(unsigned long));
} }
void get_thread_regs(union uml_pt_regs *uml_regs, void *buffer) unsigned long get_thread_reg(int reg, jmp_buf *buf)
{ {
struct __jmp_buf *jmpbuf = buffer; switch(reg){
case EIP: return buf[0]->__eip;
UPT_SET(uml_regs, EIP, jmpbuf->__eip); case UESP: return buf[0]->__esp;
UPT_SET(uml_regs, UESP, jmpbuf->__esp); case EBP: return buf[0]->__ebp;
UPT_SET(uml_regs, EBP, jmpbuf->__ebp); default:
printk("get_thread_regs - unknown register %d\n", reg);
return 0;
}
} }
...@@ -78,11 +78,14 @@ void get_safe_registers(unsigned long *regs, unsigned long *fp_regs) ...@@ -78,11 +78,14 @@ void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
HOST_FP_SIZE * sizeof(unsigned long)); HOST_FP_SIZE * sizeof(unsigned long));
} }
void get_thread_regs(union uml_pt_regs *uml_regs, void *buffer) unsigned long get_thread_reg(int reg, jmp_buf *buf)
{ {
struct __jmp_buf *jmpbuf = buffer; switch(reg){
case RIP: return buf[0]->__rip;
UPT_SET(uml_regs, RIP, jmpbuf->__rip); case RSP: return buf[0]->__rsp;
UPT_SET(uml_regs, RSP, jmpbuf->__rsp); case RBP: return buf[0]->__rbp;
UPT_SET(uml_regs, RBP, jmpbuf->__rbp); default:
printk("get_thread_regs - unknown register %d\n", reg);
return 0;
}
} }
...@@ -138,9 +138,7 @@ extern struct cpuinfo_um cpu_data[]; ...@@ -138,9 +138,7 @@ extern struct cpuinfo_um cpu_data[];
#ifdef CONFIG_MODE_SKAS #ifdef CONFIG_MODE_SKAS
#define KSTK_REG(tsk, reg) \ #define KSTK_REG(tsk, reg) \
({ union uml_pt_regs regs; \ get_thread_reg(reg, tsk->thread.mode.skas.switch_buf)
get_thread_regs(&regs, tsk->thread.mode.skas.switch_buf); \
UPT_REG(&regs, reg); })
#else #else
#define KSTK_REG(tsk, reg) (0xbadbabe) #define KSTK_REG(tsk, reg) (0xbadbabe)
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment