From 71b0516d1a79772f12fc4be19adf522552d39bfa Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Thu, 30 Sep 2021 14:16:03 -0700 Subject: [PATCH] Fix Unix ARM64 RtlRestoreContext implementation The RtlRestoreContext sets SP before reading out PC from the context. That can lead to a corruption of the PC in the context if an async signal is delivered to the thread or the thread is interrupted by any other mean after the SP is set and before the value of PC is extracted from the context. This change fixes it by setting the SP after both PC and SP values are read from the context data structure. --- src/coreclr/pal/src/arch/arm64/context2.S | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreclr/pal/src/arch/arm64/context2.S b/src/coreclr/pal/src/arch/arm64/context2.S index 2ebce4b440048e..12e5acf305cfd9 100644 --- a/src/coreclr/pal/src/arch/arm64/context2.S +++ b/src/coreclr/pal/src/arch/arm64/context2.S @@ -204,12 +204,11 @@ LOCAL_LABEL(No_Restore_CONTEXT_INTEGER): ldr w17, [x16, CONTEXT_Cpsr] msr nzcv, x17 ldp fp, lr, [x16, CONTEXT_Fp] - ldr x17, [x16, CONTEXT_Sp] - mov sp, x17 - ldr x17, [x16, CONTEXT_Pc] + ldp x16, x17, [x16, CONTEXT_Sp] // Context_Pc is right after Context_Sp + mov sp, x16 br x17 LOCAL_LABEL(No_Restore_CONTEXT_CONTROL): - ret + ret LEAF_END RtlRestoreContext, _TEXT