Skip to content

Commit 27bf645

Browse files
committed
sysv_386: make stack aligned in stackman_call
Incoming stack pointer must be adjusted to make this happen. Also adjust old stack pointer to make it correspond to incoming stack pointer.
1 parent f80c744 commit 27bf645

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/sysv_i386/libstackman.a

16 Bytes
Binary file not shown.

src/platforms/switch_x86_gcc.S

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,25 @@ stackman_call:
8282
# 108 "switch_x86_gcc.h" 1
8383
movl %esp, %ebx
8484
# 0 "" 2
85-
# 109 "switch_x86_gcc.h" 1
86-
movl %esp, %eax
85+
# 110 "switch_x86_gcc.h" 1
86+
leal 4(%esp), %eax
8787
# 0 "" 2
8888
#NO_APP
8989
movl 16(%ebp), %edx
9090
#APP
91-
# 112 "switch_x86_gcc.h" 1
91+
# 113 "switch_x86_gcc.h" 1
9292
movl %edx, %esp
9393
# 0 "" 2
94+
# 115 "switch_x86_gcc.h" 1
95+
subl $4, %esp
96+
# 0 "" 2
9497
#NO_APP
9598
pushl %eax
9699
pushl $2
97100
pushl 12(%ebp)
98101
call *8(%ebp)
99102
#APP
100-
# 116 "switch_x86_gcc.h" 1
103+
# 119 "switch_x86_gcc.h" 1
101104
movl %ebx, %esp
102105
# 0 "" 2
103106
#NO_APP

src/platforms/switch_x86_gcc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer)
106106

107107
/* sp = store stack pointer in ebx */
108108
__asm__ ("movl %%esp, %%ebx" : : : "ebx");
109-
__asm__ ("movl %%esp, %[sp]" : [sp] "=r" (old_sp));
109+
/* save old stack pointer at same offset as new stack pointer */
110+
__asm__ ("leal 4(%%esp), %[sp]" : [sp] "=r" (old_sp));
110111

111112
/* set stack pointer from provided using assembly */
112113
__asm__ ("movl %[sp], %%esp" :: [sp] "r" (stack_pointer));
114+
/* subtract 4 bytes to make it 16 byte alighed after pushing 3 args */
115+
__asm__ ("subl $4, %esp");
113116

114117
result = callback(context, STACKMAN_OP_CALL, old_sp);
115118
/* restore stack pointer */

0 commit comments

Comments
 (0)