Skip to content

Commit aa5be0d

Browse files
committed
adjust base pointer for sysv_amd64.
submit lib
1 parent fdeed8e commit aa5be0d

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

lib/sysv_amd64/libstackman.a

3.67 KB
Binary file not shown.

src/platforms/switch_x86_64_gcc.S

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,38 @@ stackman_switch:
3939
movq %rdi, %rax
4040
movq %rsi, %rcx
4141
#APP
42-
# 52 "switch_x86_64_gcc.h" 1
42+
# 56 "switch_x86_64_gcc.h" 1
4343
fstcw 10(%rsp)
4444
stmxcsr 12(%rsp)
4545

4646
# 0 "" 2
47-
# 58 "switch_x86_64_gcc.h" 1
48-
movq %rsp, %rdx
47+
# 62 "switch_x86_64_gcc.h" 1
48+
movq %rsp, %rbx
4949
# 0 "" 2
5050
#NO_APP
51+
movq %rbx, %rdx
5152
movl $0, %esi
52-
movq %rcx, %r14
53+
movq %rcx, %r15
5354
movq %rcx, %rdi
54-
movq %rax, %rbx
55+
movq %rax, %r14
5556
call *%rax
56-
movq %rax, %rdx
5757
#APP
58-
# 62 "switch_x86_64_gcc.h" 1
58+
# 67 "switch_x86_64_gcc.h" 1
5959
movq %rax, %rsp
6060
# 0 "" 2
6161
#NO_APP
62+
subq %rbx, %rax
63+
#APP
64+
# 68 "switch_x86_64_gcc.h" 1
65+
addq %rax, %rbp
66+
# 0 "" 2
67+
#NO_APP
68+
movq %rbx, %rdx
6269
movl $1, %esi
63-
movq %r14, %rdi
64-
call *%rbx
70+
movq %r15, %rdi
71+
call *%r14
6572
#APP
66-
# 66 "switch_x86_64_gcc.h" 1
73+
# 72 "switch_x86_64_gcc.h" 1
6774
ldmxcsr 12(%rsp)
6875
fldcw 10(%rsp)
6976

@@ -103,21 +110,21 @@ stackman_call:
103110
movq %rdi, %rax
104111
movq %rsi, %rdi
105112
#APP
106-
# 86 "switch_x86_64_gcc.h" 1
113+
# 92 "switch_x86_64_gcc.h" 1
107114
movq %rsp, %rbx
108115
# 0 "" 2
109-
# 87 "switch_x86_64_gcc.h" 1
116+
# 93 "switch_x86_64_gcc.h" 1
110117
movq %rsp, %rcx
111118
# 0 "" 2
112-
# 90 "switch_x86_64_gcc.h" 1
119+
# 96 "switch_x86_64_gcc.h" 1
113120
movq %rdx, %rsp
114121
# 0 "" 2
115122
#NO_APP
116123
movq %rcx, %rdx
117124
movl $2, %esi
118125
call *%rax
119126
#APP
120-
# 94 "switch_x86_64_gcc.h" 1
127+
# 100 "switch_x86_64_gcc.h" 1
121128
movq %rbx, %rsp
122129
# 0 "" 2
123130
#NO_APP
@@ -129,5 +136,5 @@ stackman_call:
129136
.cfi_endproc
130137
.LFE1:
131138
.size stackman_call, .-stackman_call
132-
.ident "GCC: (Ubuntu 9.3.0-10ubuntu2) 9.3.0"
139+
.ident "GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0"
133140
.section .note.GNU-stack,"",@progbits

src/platforms/switch_x86_64_gcc.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#if !__ASSEMBLER__ && !defined(STACKMAN_ASSEMBLY_SRC)
2727
/* inline assembly */
28+
#include <stddef.h>
2829
#include "../stackman_switch.h"
2930

3031
/*
@@ -48,7 +49,8 @@ __attribute__((optimize(OPTIMIZE)))
4849
STACKMAN_LINKAGE_SWITCH_INASM
4950
void *STACKMAN_SWITCH_INASM_NAME(stackman_cb_t callback, void *context)
5051
{
51-
void *stack_pointer;
52+
void *stack_pointer, *stack_pointer2;
53+
ptrdiff_t diff;
5254
/* assembly to save non-volatile registers, including x87 and mmx */
5355
int mxcsr; short x87cw;
5456
__asm__ volatile (
@@ -58,10 +60,12 @@ void *STACKMAN_SWITCH_INASM_NAME(stackman_cb_t callback, void *context)
5860

5961
/* sp = get stack pointer from assembly code */
6062
__asm__ ("movq %%rsp, %[result]" : [result] "=r" (stack_pointer));
61-
stack_pointer = callback(context, STACKMAN_OP_SAVE, stack_pointer);
63+
stack_pointer2 = callback(context, STACKMAN_OP_SAVE, stack_pointer);
64+
diff = stack_pointer2 - stack_pointer;
6265

6366
/* set stack pointer from sp using assembly */
64-
__asm__ ("movq %[result], %%rsp" :: [result] "r" (stack_pointer));
67+
__asm__ ("movq %[result], %%rsp" :: [result] "r" (stack_pointer2));
68+
__asm__ ("addq %[arg], %%rbp" :: [arg] "r" (diff));
6569

6670
stack_pointer = callback(context, STACKMAN_OP_RESTORE, stack_pointer);
6771
/* restore non-volatile registers from stack */

0 commit comments

Comments
 (0)