Skip to content

Commit 42ced88

Browse files
authored
Fix stack alignment issue on ia32 (#1934)
The stack of Unix-like (GCC) system should be aligned on 16-byte boundary according to the x86-32 ABI specification.
1 parent c3e9b66 commit 42ced88

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/iwasm/common/arch/invokeNative_ia32.s

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ _invokeNative:
1616
push %ebp
1717
movl %esp, %ebp
1818
movl 16(%ebp), %ecx /* ecx = argc */
19-
movl 12(%ebp), %edx /* edx = argv */
19+
leal 2(%ecx), %edx /* edx = ecx + 2 (count return address and saved ebp) */
20+
andl $3, %edx /* edx = edx % 4 */
21+
jz stack_aligned /* if edx == 0, stack is already 16 bytes aligned */
22+
leal -16(%esp, %edx, 4), %esp /* esp = esp - 16 + edx * 4 */
23+
stack_aligned:
2024
test %ecx, %ecx
2125
jz skip_push_args /* if ecx == 0, skip pushing arguments */
26+
movl 12(%ebp), %edx /* edx = argv */
2227
leal -4(%edx,%ecx,4), %edx /* edx = edx + ecx * 4 - 4 */
2328
subl %esp, %edx /* edx = edx - esp */
2429
1:

0 commit comments

Comments
 (0)