Skip to content

Commit f80c744

Browse files
committed
Update x86_gcc.
send 16 bit aligned stack to callbacks. Don´t include callback arguments in callback stack. Update base pointe when switching stack.
1 parent f7b7f3e commit f80c744

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

lib/sysv_i386/libstackman.a

2.61 KB
Binary file not shown.

src/platforms/switch_x86_gcc.S

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@ stackman_switch:
3030
movl 8(%ebp), %eax
3131
movl 12(%ebp), %edx
3232
#APP
33-
# 48 "switch_x86_gcc.h" 1
34-
subl $12, %esp
33+
# 50 "switch_x86_gcc.h" 1
34+
subl $0x1a, %esp
3535
movl %eax, %esi
3636
movl %edx, %edi
37-
movl %esp, 8(%esp)
37+
leal 0x10(%esp), %ebx
38+
movl %ebx, 8(%esp)
3839
movl $0, 4(%esp)
3940
movl %edi, 0(%esp)
4041
call *%esi
41-
movl %eax, %esp
42+
leal -0x10(%eax), %esp
43+
subl %ebx, %eax
44+
addl %eax, %ebp
45+
leal 0x10(%esp), %eax
4246
movl %eax, 8(%esp)
4347
movl $1, 4(%esp)
4448
movl %edi, 0(%esp)
4549
call *%esi
4650
movl %eax, %eax
47-
addl $12, %esp
51+
addl $0x1a, %esp
4852

4953
# 0 "" 2
5054
#NO_APP
@@ -75,16 +79,16 @@ stackman_call:
7579
subl $8, %esp
7680
.cfi_offset 3, -12
7781
#APP
78-
# 96 "switch_x86_gcc.h" 1
82+
# 108 "switch_x86_gcc.h" 1
7983
movl %esp, %ebx
8084
# 0 "" 2
81-
# 97 "switch_x86_gcc.h" 1
85+
# 109 "switch_x86_gcc.h" 1
8286
movl %esp, %eax
8387
# 0 "" 2
8488
#NO_APP
8589
movl 16(%ebp), %edx
8690
#APP
87-
# 100 "switch_x86_gcc.h" 1
91+
# 112 "switch_x86_gcc.h" 1
8892
movl %edx, %esp
8993
# 0 "" 2
9094
#NO_APP
@@ -93,7 +97,7 @@ stackman_call:
9397
pushl 12(%ebp)
9498
call *8(%ebp)
9599
#APP
96-
# 104 "switch_x86_gcc.h" 1
100+
# 116 "switch_x86_gcc.h" 1
97101
movl %ebx, %esp
98102
# 0 "" 2
99103
#NO_APP
@@ -106,5 +110,5 @@ stackman_call:
106110
.cfi_endproc
107111
.LFE1:
108112
.size stackman_call, .-stackman_call
109-
.ident "GCC: (Ubuntu 9.3.0-10ubuntu2) 9.3.0"
113+
.ident "GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0"
110114
.section .note.GNU-stack,"",@progbits

src/platforms/switch_x86_gcc.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,41 @@ void *result;
5252
/* adjust stack pointer to be 16 byte (4 quad) aligned with
5353
* room for call args
5454
* since the call instruction, 5 quads have
55-
* been pushed (ip, bp, bx, si, di), need extra 3 quads
55+
* been pushed (ip, bp, bx, si, di), need extra 3 quads (0xa)
5656
* for alignment, which fits our three quad call args.
57+
* Add another 16 (0x10) bytes, so that we can pass to the callbacks
58+
* a 16 byte boundary that lies above the pushed arguments
59+
* so that the call arguments of the functions aren't clobbered
60+
* by memory transfer.
5761
*/
58-
"subl $12, %%esp\n"
62+
"subl $0x1a, %%esp\n"
5963
"movl %[cb], %%esi\n" /* save 'callback' for later */
6064
"movl %[ctx], %%edi\n" /* save 'context' for later */
6165

62-
/* first call */
63-
"movl %%esp, 8(%%esp)\n" /* arg 2 sp */
66+
/* first call */
67+
"leal 0x10(%%esp), %%ebx\n" /* arg 2 adjusted sp (also in nv. reg) */
68+
"movl %%ebx, 8(%%esp)\n"
6469
"movl $0, 4(%%esp)\n" /* arg 1 opcode STACKMAN_OP_SAVE */
6570
"movl %%edi, 0(%%esp)\n" /* arg 0 context */
6671
"call *%%esi\n"
6772

68-
/* restore esp */
69-
"movl %%eax, %%esp\n"
73+
/* restore esp, re-adding shadow space */
74+
"leal -0x10(%%eax), %%esp\n"
75+
76+
/* and adjust ebp with difference between new and old */
77+
"subl %%ebx, %%eax\n"
78+
"addl %%eax, %%ebp\n"
7079

7180
/* second call */
72-
"movl %%eax, 8(%%esp)\n" /* arg 2 sp */
81+
"leal 0x10(%%esp), %%eax\n" /* arg 2 sp */
82+
"movl %%eax, 8(%%esp)\n"
7383
"movl $1, 4(%%esp)\n" /* arg 1 opcode STACKMAN_OP_RESTORE */
7484
"movl %%edi, 0(%%esp)\n" /* arg 0 context */
7585
"call *%%esi\n"
7686

7787
"movl %%eax, %[result]\n"
7888

79-
"addl $12, %%esp\n"
89+
"addl $0x1a, %%esp\n"
8090
: [result] "=r" (result) /* output variables */
8191
: [cb] "r" (callback), /* input variables */
8292
[ctx] "r" (context)

0 commit comments

Comments
 (0)