From d86a32bbb2ff79232bf3edc0f475062f45b6ea90 Mon Sep 17 00:00:00 2001 From: Jyun-Yan You Date: Tue, 21 May 2013 11:58:08 +0800 Subject: [PATCH] fix mips stack alignment --- src/libcore/rt/context.rs | 4 +++- src/rt/arch/mips/context.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libcore/rt/context.rs b/src/libcore/rt/context.rs index 2add314fd1196..f60ce3429579d 100644 --- a/src/libcore/rt/context.rs +++ b/src/libcore/rt/context.rs @@ -183,7 +183,9 @@ fn new_regs() -> ~Registers { ~([0, .. 32]) } #[cfg(target_arch = "mips")] fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: *mut uint) { - let sp = mut_offset(sp, -1); + let sp = align_down(sp); + // sp of mips o32 is 8-byte aligned + let sp = mut_offset(sp, -2); // The final return address. 0 indicates the bottom of the stack unsafe { *sp = 0; } diff --git a/src/rt/arch/mips/context.cpp b/src/rt/arch/mips/context.cpp index 7347a92e98b92..e1e5776bc1a65 100644 --- a/src/rt/arch/mips/context.cpp +++ b/src/rt/arch/mips/context.cpp @@ -34,9 +34,11 @@ void context::call(void *f, void *arg, void *stack) // set up the stack uint32_t *sp = (uint32_t *)stack; - //sp = align_down(sp); + sp = align_down(sp); // The final return address. 0 indicates the bottom of the stack - *--sp = 0; + // sp of mips o32 is 8-byte aligned + sp -= 2; + *sp = 0; regs.data[4] = (uint32_t)arg; regs.data[29] = (uint32_t)sp;