Path: blob/main/cranelift/codegen/src/isa/x64/inst/stack_switch.rs
1693 views
use crate::{isa::x64::inst::regs, machinst::Reg};12/// The `stack_switch` instruction loads information about the stack to switch3/// to and stores information about the current stack by receiving pointers to4/// memory laid out as in the struct `ControlContext` below.5///6/// The instruction is only supported on x64 Linux at the moment.7///8/// ```9/// #[repr(C)]10/// pub struct ControlContext {11/// pub stack_pointer: *mut u8,12/// pub frame_pointer: *mut u8,13/// pub instruction_pointer: *mut u8,14/// }15/// ```16///17/// Note that this layout is deliberately chosen to make frame pointer walking18/// possible, if desired: The layout enables stack layouts where a19/// `ControlContext` is part of a frame pointer chain, putting the frame pointer20/// next to the corresponding IP.21///22/// We never actually interact with values of that type in Cranelift, but are23/// only interested in its layout for the purposes of generating code.24pub struct ControlContextLayout {25pub stack_pointer_offset: usize,26pub frame_pointer_offset: usize,27pub ip_offset: usize,28}2930pub fn control_context_layout() -> ControlContextLayout {31ControlContextLayout {32stack_pointer_offset: 0,33frame_pointer_offset: 8,34ip_offset: 16,35}36}3738/// The register used for handing over the payload when switching stacks.39///40/// We must use a fixed register for sending and receiving the payload: When41/// switching from one stack to another using two matching``stack_switch``42/// instructions, they must agree on the register where the payload is, similar43/// to a calling convention. The same holds when `stack_switch`-ing to a newly44/// initialized stack, where the entry trampoline must know which register the45/// payload is in.46pub fn payload_register() -> Reg {47regs::rdi()48}495051