Skip to content

Commit 499b022

Browse files
committed
fix arm stack alignment
1 parent 15e4438 commit 499b022

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/libcore/rt/context.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ fn new_regs() -> ~Registers { ~([0, .. 32]) }
165165

166166
#[cfg(target_arch = "arm")]
167167
fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: *mut uint) {
168-
let sp = mut_offset(sp, -1);
168+
let sp = align_down(sp);
169+
// sp of arm eabi is 8-byte aligned
170+
let sp = mut_offset(sp, -2);
169171

170172
// The final return address. 0 indicates the bottom of the stack
171173
unsafe { *sp = 0; }

src/rt/arch/arm/context.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ void context::call(void *f, void *arg, void *stack)
2626

2727
// set up the stack
2828
uint32_t *sp = ( uint32_t *)stack;
29-
//sp = align_down(sp);
29+
sp = align_down(sp);
3030
// The final return address. 0 indicates the bottom of the stack
31-
*--sp = 0;
31+
// sp of arm eabi is 8-byte aligned
32+
sp -= 2;
33+
*sp = 0;
3234

3335
regs.data[0] = ( uint32_t )arg; // r0
3436
regs.data[13] = ( uint32_t )sp; //#52 sp, r13

0 commit comments

Comments
 (0)