From e8b47fff6d53339a6b5aad71e7cf55beff2418a8 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Sat, 26 Jul 2025 01:07:42 +0200 Subject: [PATCH] __INTERNAL_fmt: Assure correct stack arguments are loaded if FD=stderr --- src/console.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/console.asm b/src/console.asm index b61abf9..aac5a3f 100644 --- a/src/console.asm +++ b/src/console.asm @@ -125,8 +125,8 @@ __INTERNAL_fmt: mov %1, [printfArgs + SIZE_QWORD * r14] jmp %%continue %%fromStack: - cmp r15, FD_stdout - je %%stackNoShift + cmp r15, FD_stderr + jle %%stackNoShift ;simple jle (for test r15,2); entry of this wrapper quits early if passed FD is less than 1, so this simple check is safe enough mov %1, [rbp + (RBP_OFFSET_CALLER*2 + SIZE_QWORD) + ((r14-5) * SIZE_QWORD)] ;non-printf functions calling __INTERNAL_fmt require RDI to be FD, all args shifted and rbp+RBP_OFFSET_CALLER to r9. Also requires function prologue and a CALL to __INTERNAL_fmt (not a JMP like in printf); hence the RBP_OFFSET_CALLER*2 jmp %%continue %%stackNoShift: