From 5a7c808cbacb8c0477395c5656c1eba3ef38cd6e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 10 Nov 2020 21:42:36 +0100 Subject: [PATCH 08/10] runtime: allow callback functions with up to 8 arguments on windows/arm Previously, windows/arm programs would abort when trying to use functions that took callbacks with more than 4 arguments. This caused issues when using SetWinEventHook, which receives 7 arguments. Add 4 more by pulling them off the stack. Change-Id: I15a6a3168237fd8bb1128cc2c11ff2d900d665d2 --- src/runtime/sys_windows_arm.s | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/runtime/sys_windows_arm.s b/src/runtime/sys_windows_arm.s index 256b5ff7f0..049c69ec88 100644 --- a/src/runtime/sys_windows_arm.s +++ b/src/runtime/sys_windows_arm.s @@ -315,10 +315,14 @@ GLOBL runtime·cbctxts(SB), NOPTR, $4 TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0 MOVM.DB.W [R4-R11, R14], (R13) // push {r4-r11, lr} - SUB $36, R13 // space for locals + SUB $52, R13 // space for locals - // save callback arguments to stack. We currently support up to 4 arguments + // save callback arguments to stack. We currently support up to 8 arguments ADD $16, R13, R4 + MOVM.IA.W [R0-R3], (R4) + // the remaining 4 arguments are on the stack + ADD $88, R13, R5 + MOVM.IA (R5), [R0-R3] MOVM.IA [R0-R3], (R4) // load cbctxts[i]. The trampoline in zcallback_windows.s puts the callback @@ -330,8 +334,8 @@ TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0 MOVW wincallbackcontext_argsize(R4), R5 MOVW wincallbackcontext_gobody(R4), R4 - // we currently support up to 4 arguments - CMP $(4 * 4), R5 + // we currently support up to 8 arguments + CMP $(4 * 8), R5 BL.GT runtime·abort(SB) // extend argsize by size of return value @@ -351,7 +355,7 @@ TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0 SUB $4, R1 // offset to return value MOVW R1<<0(R0), R0 // load return value - ADD $36, R13 // free locals + ADD $52, R13 // free locals MOVM.IA.W (R13), [R4-R11, R15] // pop {r4-r11, pc} // uint32 tstart_stdcall(M *newm); -- 2.29.2