summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2015-04-20 16:07:24 +0200
committerMichael Brown2015-04-20 22:28:15 +0200
commit2deedd22f1a9f889c0377094b02cf81b479ca778 (patch)
tree060ae93c76117661a6aa92ec2517559944fa84e1
parent[build] Remove reference to private upload server (diff)
downloadmemtest86-2deedd22f1a9f889c0377094b02cf81b479ca778.tar.gz
memtest86-2deedd22f1a9f889c0377094b02cf81b479ca778.tar.xz
memtest86-2deedd22f1a9f889c0377094b02cf81b479ca778.zip
[build] Allow sufficient stack space for memsize_e820()
The functions memsize_e820() (and its inlined sanitize_e820_map()) use around 9.5kb of stack space, which overflows the 8kB per-CPU stack and so overwrites random variables in .bss, leading to undefined behaviour. Fix by reordering the per-CPU stacks so that the boot processor uses the highest stack. This provides additional space during the start-of-day call to memsize_e820(), using stack space which will subsequently be reused for other CPUs' stacks. Note that we cannot simply increase the per-CPU stack size to 16kB, since that would cause the .bss section to exceed the limits of base memory. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--main.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/main.c b/main.c
index 0bc7ca0..75fb5e5 100644
--- a/main.c
+++ b/main.c
@@ -231,11 +231,9 @@ switch_to_main_stack(unsigned cpu_num)
extern uintptr_t boot_stack_top;
uintptr_t *src, *dst;
int offs;
- uint8_t * stackAddr, *stackTop;
+ uint8_t *stackTop;
- stackAddr = (uint8_t *) &stacks[cpu_num][0];
-
- stackTop = stackAddr + STACKSIZE;
+ stackTop = (uint8_t *) &stacks[MAX_CPUS - cpu_num][0];
src = (uintptr_t*)&boot_stack_top;
dst = (uintptr_t*)stackTop;