diff --git a/Kernel/Arch/riscv64/SmapDisabler.cpp b/Kernel/Arch/riscv64/SmapDisabler.cpp new file mode 100644 index 0000000000..324ca3ed95 --- /dev/null +++ b/Kernel/Arch/riscv64/SmapDisabler.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023, Sönke Holz + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Kernel { + +SmapDisabler::SmapDisabler() + : m_flags(RISCV64::CSR::read_and_set_bits(RISCV64::CSR::Address::SSTATUS, 1 << to_underlying(RISCV64::CSR::SSTATUS::Offset::SUM))) +{ +} + +SmapDisabler::~SmapDisabler() +{ + if ((m_flags & (1 << to_underlying(RISCV64::CSR::SSTATUS::Offset::SUM))) == 0) + RISCV64::CSR::clear_bits(RISCV64::CSR::Address::SSTATUS, 1 << to_underlying(RISCV64::CSR::SSTATUS::Offset::SUM)); +} + +}