From 35293c222967990a0990c64da183b5b9e8e24d78 Mon Sep 17 00:00:00 2001 From: Xu Liangyu Date: Sat, 16 Mar 2024 12:13:53 +0800 Subject: [PATCH] [LoongArch64] Fix hijack. (#99853) --- src/coreclr/unwinder/loongarch64/unwinder.cpp | 4 +++- src/coreclr/vm/loongarch64/asmhelpers.S | 12 ++++++------ src/coreclr/vm/loongarch64/cgencpu.h | 18 +++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/coreclr/unwinder/loongarch64/unwinder.cpp b/src/coreclr/unwinder/loongarch64/unwinder.cpp index 93cc2a7aee65c..2a263f0516ac9 100644 --- a/src/coreclr/unwinder/loongarch64/unwinder.cpp +++ b/src/coreclr/unwinder/loongarch64/unwinder.cpp @@ -106,7 +106,9 @@ do { if (ARGUMENT_PRESENT(Params)) { \ PT_KNONVOLATILE_CONTEXT_POINTERS ContextPointers = (Params)->ContextPointers; \ if (ARGUMENT_PRESENT(ContextPointers)) { \ - if (RegisterNumber == 22) \ + if (RegisterNumber == 1) \ + ContextPointers->Ra = (PDWORD64)Address; \ + else if (RegisterNumber == 22) \ ContextPointers->Fp = (PDWORD64)Address; \ else if (RegisterNumber >= 23 && RegisterNumber <= 31) { \ (&ContextPointers->S0)[RegisterNumber - 23] = (PDWORD64)Address; \ diff --git a/src/coreclr/vm/loongarch64/asmhelpers.S b/src/coreclr/vm/loongarch64/asmhelpers.S index 56fb0c0b9247a..3f1f7b827e6d2 100644 --- a/src/coreclr/vm/loongarch64/asmhelpers.S +++ b/src/coreclr/vm/loongarch64/asmhelpers.S @@ -822,13 +822,13 @@ NESTED_ENTRY OnHijackTripThread, _TEXT, NoHandler PROLOG_SAVE_REG_PAIR 25, 26, 32 PROLOG_SAVE_REG_PAIR 27, 28, 48 PROLOG_SAVE_REG_PAIR 29, 30, 64 - PROLOG_SAVE_REG 31, 80 + PROLOG_SAVE_REG_PAIR 31, 2, 80 // save any integral return value(s) st.d $a0, $sp, 96 st.d $a1, $sp, 104 - // save any FP/HFA return value(s) + // save any FP return value(s) fst.d $f0, $sp, 112 fst.d $f1, $sp, 120 @@ -841,15 +841,15 @@ NESTED_ENTRY OnHijackTripThread, _TEXT, NoHandler ld.d $a0, $sp, 96 ld.d $a1, $sp, 104 - // restore any FP/HFA return value(s) - fst.d $f0, $sp, 112 - fst.d $f1, $sp, 120 + // restore any FP return value(s) + fld.d $f0, $sp, 112 + fld.d $f1, $sp, 120 EPILOG_RESTORE_REG_PAIR 23, 24, 16 EPILOG_RESTORE_REG_PAIR 25, 26, 32 EPILOG_RESTORE_REG_PAIR 27, 28, 48 EPILOG_RESTORE_REG_PAIR 29, 30, 64 - EPILOG_RESTORE_REG 31, 80 + EPILOG_RESTORE_REG_PAIR 31, 2, 80 // $fp,$ra EPILOG_RESTORE_REG_PAIR_INDEXED 22, 1, 0x80 EPILOG_RETURN diff --git a/src/coreclr/vm/loongarch64/cgencpu.h b/src/coreclr/vm/loongarch64/cgencpu.h index 6979fa11a9675..0c3a7ca83a8d0 100644 --- a/src/coreclr/vm/loongarch64/cgencpu.h +++ b/src/coreclr/vm/loongarch64/cgencpu.h @@ -448,11 +448,18 @@ struct DECLSPEC_ALIGN(16) UMEntryThunkCode struct HijackArgs { + DWORD64 Fp; // frame pointer + union + { + DWORD64 Ra; + size_t ReturnAddress; + }; + DWORD64 S0, S1, S2, S3, S4, S5, S6, S7, S8, Tp; union { struct { - DWORD64 V0; - DWORD64 V1; + DWORD64 A0; + DWORD64 A1; }; size_t ReturnValue[2]; }; @@ -464,13 +471,6 @@ struct HijackArgs }; size_t FPReturnValue[2]; }; - DWORD64 S0, S1, S2, S3, S4, S5, S6, S7, S8, Tp; - DWORD64 Fp; // frame pointer - union - { - DWORD64 Ra; - size_t ReturnAddress; - }; }; EXTERN_C VOID STDCALL PrecodeFixupThunk();