Skip to content

Commit

Permalink
fix: segment fault when access CSR sscratch when V=1 (#38)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cebarobot committed Sep 11, 2024
1 parent 35cd965 commit 8b54e28
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion riscv/csr_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<basic_csr_t>(proc, CSR_VSTVAL, 0));
add_supervisor_csr(CSR_STVAL, stval = std::make_shared<virtualized_csr_t>(proc, nonvirtual_stval, vstval));
nonvirtual_sscratch = std::make_shared<basic_csr_t>(proc, CSR_SSCRATCH, 0);
add_supervisor_csr(CSR_SSCRATCH, sscratch = std::make_shared<virtualized_csr_t>(proc, nonvirtual_sscratch, vsscratch));
add_hypervisor_csr(CSR_VSSCRATCH, vsscratch = std::make_shared<basic_csr_t>(proc, CSR_VSSCRATCH, 0));
add_supervisor_csr(CSR_SSCRATCH, sscratch = std::make_shared<virtualized_csr_t>(proc, nonvirtual_sscratch, vsscratch));
nonvirtual_stvec = std::make_shared<tvec_csr_t>(proc, CSR_STVEC);
add_hypervisor_csr(CSR_VSTVEC, vstvec = std::make_shared<tvec_csr_t>(proc, CSR_VSTVEC));
add_supervisor_csr(CSR_STVEC, stvec = std::make_shared<virtualized_csr_t>(proc, nonvirtual_stvec, vstvec));
Expand Down

0 comments on commit 8b54e28

Please sign in to comment.