Open wangbj opened 5 years ago
I really like the "simulated double return" solution, to allow us to continue to use CALLQ (and thereby reuse trampolines across multiple call sites).
For the alignment, it sounds like we:
Is that right? So that's essentially the (variable sized) "stack frame" associated with the trampoline itself.
Yes that has been done: https://github.com/iu-parfunc/systrace/blob/bac4b39fdf21921cc30542b1a74a567b68d05436/src/trampoline.S#L60
I hope @devietti can review the code :)
Looks good to me, though I am far from an expert here!
when we jump into our temperorily trampoline, we have two choices use either
jmpq
(e9
)orcallq
(e8
). It seemsrr
andliteinst
both usejmpq
, but we're usingcallq
.There're two reasons I can think of why
jmpq
is used:1) when patching a sequence like:
with
callq
, we have a double return issue - though it can be solved, because we just have to pop the return address saved by our generatedcallq
, but it looks more confusing thanjmpq
solution2) stack alignment
callq
pushes return address (8B) on to stack, meaning we must do stack alignment by ourself -- before calling any high level functions - it is fine by our trampoline, because it is entirely assembly, and does not use SSE instruction who requires stack alignment.We do have our own benefits by using
callq
, because we don't have to worry about return address, so we have much less interim trampoline to generate, because we can reuse them, we can also pre-populate our interim trampolines, rather than generate them on the fly, this makes our code base smaller, and easier to implement.