From 8b54e281cafa03b498b146af517ecd7a83d4b5d1 Mon Sep 17 00:00:00 2001 From: "Xu, Zefan" Date: Wed, 11 Sep 2024 17:53:10 +0800 Subject: [PATCH] fix: segment fault when access CSR sscratch when V=1 (#38) When creating virtualized_csr_t for CSR sscratch, vsscratch has not been created yet. As a result, a NULL pointer is passed to virtualized_csr_t and Segment Fault occurs when accessing CSR sscratch when V=1. --- riscv/csr_init.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riscv/csr_init.cc b/riscv/csr_init.cc index 68f3c6958a..5f05e1ee39 100644 --- a/riscv/csr_init.cc +++ b/riscv/csr_init.cc @@ -151,8 +151,8 @@ void state_t::csr_init(processor_t* const proc, reg_t max_isa) add_hypervisor_csr(CSR_VSTVAL, vstval = std::make_shared(proc, CSR_VSTVAL, 0)); add_supervisor_csr(CSR_STVAL, stval = std::make_shared(proc, nonvirtual_stval, vstval)); nonvirtual_sscratch = std::make_shared(proc, CSR_SSCRATCH, 0); - add_supervisor_csr(CSR_SSCRATCH, sscratch = std::make_shared(proc, nonvirtual_sscratch, vsscratch)); add_hypervisor_csr(CSR_VSSCRATCH, vsscratch = std::make_shared(proc, CSR_VSSCRATCH, 0)); + add_supervisor_csr(CSR_SSCRATCH, sscratch = std::make_shared(proc, nonvirtual_sscratch, vsscratch)); nonvirtual_stvec = std::make_shared(proc, CSR_STVEC); add_hypervisor_csr(CSR_VSTVEC, vstvec = std::make_shared(proc, CSR_VSTVEC)); add_supervisor_csr(CSR_STVEC, stvec = std::make_shared(proc, nonvirtual_stvec, vstvec));