x86-64
Guidelines that apply only to x86-64 code under ostd/src/arch/x86/.
Align the stack to 16 bytes before a call (16b-align-rsp-before-call)
The System V AMD64 ABI requires %rsp to be 16-byte aligned at the point of a call,
so that the callee sees a 16-byte-aligned frame once the return address is pushed.
In hand-written assembly that calls into Rust or C,
keep %rsp 16-byte aligned immediately before each call:
when an entry or trap path has pushed an odd number of 8-byte values,
push one more (a scratch register, or a dummy) to restore the alignment.
A misaligned stack is undefined behavior —
the Rust or C callee may use SSE instructions such as movaps that fault on an unaligned operand.
See also:
the System V AMD64 ABI (§3.2.2, “The Stack Frame”);
ostd/src/arch/x86/trap/syscall.S, which pushes an extra register to keep %rsp aligned before calling into Rust.