Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JIT] Improve stack walker to use top-of-stack
It is impractical to know how many frames we can walk back safely, and we want to fail safely for the case that we are wrong (i.e. jit code frame is not on stack), Force -fno-omit-frame-pointer if the JIT is active. GNU make automatically uses on the correct invocation of 'as', so that helps, but I'm not sure how I'm going to configure MSVC just yet (uses ml64).
- Loading branch information
Showing
3 changed files
with
40 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
.intel_syntax noprefix | ||
.text | ||
.globl stack_find_return_address_in_frame_posix | ||
.globl _stack_find_return_address_in_frame_posix | ||
.intel_syntax noprefix | ||
.text | ||
.globl stack_find_return_address_in_frame_posix | ||
.globl _stack_find_return_address_in_frame_posix | ||
stack_find_return_address_in_frame_posix: | ||
_stack_find_return_address_in_frame_posix: | ||
mov rcx, rdi /* base pointer */ | ||
mov r8, rdx /* maximum number of steps */ | ||
mov rdx, rsi /* end pointer */ | ||
mov rcx, rdi /* arg0 = start-of-code region */ | ||
mov r8, rdx /* arg2 = stack base-pointer */ | ||
mov rdx, rsi /* arg1 = size-of-code */ | ||
_stack_find_return_address_in_frame_win64: | ||
/* rdi = base pointer, rsi = end pointer */ | ||
push rbp | ||
mov r9, rsp | ||
push rbp | ||
mov r9, rsp | ||
add rdx, rcx /* compute end-of-code region */ | ||
/* rcx = start, rdx = end, r8 = stack base, | ||
* r9 = next stack frame, ax = return address */ | ||
loop: | ||
dec r8 /* counter */ | ||
jz done | ||
mov rax, qword ptr [r9+0x8] | ||
mov r9, qword ptr [r9] | ||
cmp rax, rcx | ||
jl loop | ||
cmp rax, rdx | ||
jg loop | ||
cmp r8, r9 /* have we gone past our start-of-stack pointer? */ | ||
jle done /* stack grows downwards */ | ||
mov rax, qword ptr [r9+0x8] | ||
mov r9, qword ptr [r9] | ||
cmp rax, rcx | ||
jl loop | ||
cmp rax, rdx | ||
jg loop | ||
done: | ||
/* rax is now within range by definition, or, we're to deep */ | ||
pop rbp | ||
ret | ||
/* rax is now within range by definition, or, we're to deep */ | ||
pop rbp | ||
ret |