1
0
Fork 0

Explain how trampolines work.

This commit is contained in:
whitequark 2016-08-12 23:47:11 +00:00 committed by edef
parent b79e7c0a9b
commit 145c18125a
2 changed files with 16 additions and 0 deletions

View File

@ -28,6 +28,14 @@
// after. A .cfi_def_* pseudoinstruction changes the CFA value similarly. // after. A .cfi_def_* pseudoinstruction changes the CFA value similarly.
// * Simulating return is as easy as restoring register values from the CFI table // * Simulating return is as easy as restoring register values from the CFI table
// and then setting stack pointer to CFA. // and then setting stack pointer to CFA.
//
// A high-level overview of the function of the trampolines is:
// * The 2nd init trampoline puts a controlled value (written in swap to `new_cfa`)
// into %ebx.
// * The 1st init trampoline tells the unwinder to set %esp to %ebx, thus continuing
// unwinding at the swap call site instead of falling off the end of context stack.
// * The 1st init trampoline together with the swap trampoline also restore %ebp
// when unwinding as well as returning normally, because LLVM does not do it for us.
use stack::Stack; use stack::Stack;
#[derive(Debug)] #[derive(Debug)]

View File

@ -32,6 +32,14 @@
// after. A .cfi_def_* pseudoinstruction changes the CFA value similarly. // after. A .cfi_def_* pseudoinstruction changes the CFA value similarly.
// * Simulating return is as easy as restoring register values from the CFI table // * Simulating return is as easy as restoring register values from the CFI table
// and then setting stack pointer to CFA. // and then setting stack pointer to CFA.
//
// A high-level overview of the function of the trampolines is:
// * The 2nd init trampoline puts a controlled value (written in swap to `new_cfa`)
// into %rbx.
// * The 1st init trampoline tells the unwinder to set %rsp to %rbx, thus continuing
// unwinding at the swap call site instead of falling off the end of context stack.
// * The 1st init trampoline together with the swap trampoline also restore %rbp
// when unwinding as well as returning normally, because LLVM does not do it for us.
use stack::Stack; use stack::Stack;
#[derive(Debug)] #[derive(Debug)]