mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-24 21:55:57 +00:00
Merge PR #762: align the stack of Linux fibers to the System V ABI (deadlynch)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f2a59e92d6
1 file changed
+7
-1
@@ -270,7 +270,8 @@ int plat_intr_resume(PlatIntr *t, uint64_t to) {
|
|||||||
// ---- fibers: a stack switch of our own. glibc's swapcontext saves and restores the signal mask with a system call
|
// ---- fibers: a stack switch of our own. glibc's swapcontext saves and restores the signal mask with a system call
|
||||||
// on every switch, and the game switches fibers often. fiber_swap saves the callee-saved registers, the MXCSR and the
|
// on every switch, and the game switches fibers often. fiber_swap saves the callee-saved registers, the MXCSR and the
|
||||||
// x87 control word on the current stack, stores the stack pointer in *save and loads the other one. A new fiber's
|
// x87 control word on the current stack, stores the stack pointer in *save and loads the other one. A new fiber's
|
||||||
// stack is laid out as fiber_swap leaves one, returning into fiber_entry, which calls fn(arg) (r12 and r13).
|
// stack is laid out as fiber_swap leaves one, returning into fiber_entry, which realigns the stack and calls fn(arg)
|
||||||
|
// (r12 and r13).
|
||||||
struct PlatFiber {
|
struct PlatFiber {
|
||||||
void *sp;
|
void *sp;
|
||||||
void *stack; // mapped stack (NULL for a thread's own context)
|
void *stack; // mapped stack (NULL for a thread's own context)
|
||||||
@@ -312,6 +313,11 @@ __asm__(".text\n"
|
|||||||
".type plat_fiber_entry, @function\n"
|
".type plat_fiber_entry, @function\n"
|
||||||
".p2align 4\n"
|
".p2align 4\n"
|
||||||
"plat_fiber_entry:\n"
|
"plat_fiber_entry:\n"
|
||||||
|
// fiber_swap's ret lands here with rsp = top - 8, as at the entry of a called function. The call below must
|
||||||
|
// be made with rsp 16-byte aligned so that fn starts with rsp = 8 mod 16, as the System V ABI demands; without
|
||||||
|
// the realignment every 16-byte local of fn is off by 8, which the VEX instructions of a v3 build tolerate
|
||||||
|
// but the SSE ones of a v2 or k10 build (movdqa, pcmpeqb with a memory operand) fault on.
|
||||||
|
" andq $-16, %rsp\n"
|
||||||
" movq %r13, %rdi\n"
|
" movq %r13, %rdi\n"
|
||||||
" callq *%r12\n"
|
" callq *%r12\n"
|
||||||
" ud2\n"
|
" ud2\n"
|
||||||
|
|||||||
Reference in new issue
Block a user