From 145c18125a5aefd1a6f96ff0a62cd85f55bff423 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 12 Aug 2016 23:47:11 +0000 Subject: [PATCH] Explain how trampolines work. --- src/arch/x86.rs | 8 ++++++++ src/arch/x86_64.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 75c8fea..e15d054 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -28,6 +28,14 @@ // after. A .cfi_def_* pseudoinstruction changes the CFA value similarly. // * Simulating return is as easy as restoring register values from the CFI table // 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; #[derive(Debug)] diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index ee6510b..6ecc588 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -32,6 +32,14 @@ // after. A .cfi_def_* pseudoinstruction changes the CFA value similarly. // * Simulating return is as easy as restoring register values from the CFI table // 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; #[derive(Debug)]