From 91a0ce1f5dc76323af523ba9d9da50f063419c04 Mon Sep 17 00:00:00 2001 From: Timur Mustafin Date: Fri, 3 May 2024 16:40:32 +0300 Subject: [PATCH 1/2] [RISCV-V] Fix context restoration as 101709 --- src/coreclr/pal/src/arch/riscv64/context2.S | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreclr/pal/src/arch/riscv64/context2.S b/src/coreclr/pal/src/arch/riscv64/context2.S index 20273eb87d809..bfa22d48d7776 100644 --- a/src/coreclr/pal/src/arch/riscv64/context2.S +++ b/src/coreclr/pal/src/arch/riscv64/context2.S @@ -105,10 +105,13 @@ LOCAL_LABEL(No_Restore_CONTEXT_INTEGER): beqz t1, LOCAL_LABEL(No_Restore_CONTEXT_CONTROL) ld ra, (CONTEXT_Ra)(t4) + ld t1, (CONTEXT_T4)(t4) + ld fp, (CONTEXT_Sp)(t4) + sd t1, -8(fp) ld fp, (CONTEXT_Fp)(t4) - ld sp, (CONTEXT_Sp)(t4) ld t1, (CONTEXT_Pc)(t4) // Since we cannot control $pc directly, we're going to corrupt t1 - ld t4, (CONTEXT_T4)(t4) + ld sp, (CONTEXT_Sp)(t4) + ld t4, -8(sp) jr t1 LOCAL_LABEL(No_Restore_CONTEXT_CONTROL): From 35994296d28bef14ac79edc0022b3f8a47edaf5c Mon Sep 17 00:00:00 2001 From: Timur Mustafin Date: Mon, 24 Jun 2024 17:39:06 +0300 Subject: [PATCH 2/2] Feedback --- src/coreclr/pal/src/arch/riscv64/context2.S | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/pal/src/arch/riscv64/context2.S b/src/coreclr/pal/src/arch/riscv64/context2.S index bfa22d48d7776..725e4ec9f139a 100644 --- a/src/coreclr/pal/src/arch/riscv64/context2.S +++ b/src/coreclr/pal/src/arch/riscv64/context2.S @@ -110,8 +110,10 @@ LOCAL_LABEL(No_Restore_CONTEXT_INTEGER): sd t1, -8(fp) ld fp, (CONTEXT_Fp)(t4) ld t1, (CONTEXT_Pc)(t4) // Since we cannot control $pc directly, we're going to corrupt t1 - ld sp, (CONTEXT_Sp)(t4) - ld t4, -8(sp) + ld t4, (CONTEXT_Sp)(t4) + addi sp, t4, -8 + ld t4, (sp) + addi sp, sp, 8 jr t1 LOCAL_LABEL(No_Restore_CONTEXT_CONTROL):