SmapDisabler.h 458 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <Kernel/Arch/x86/ASM_wrapper.h>
  8. namespace Kernel {
  9. class SmapDisabler {
  10. public:
  11. ALWAYS_INLINE SmapDisabler()
  12. : m_flags(cpu_flags())
  13. {
  14. stac();
  15. }
  16. ALWAYS_INLINE ~SmapDisabler()
  17. {
  18. if (!(m_flags & 0x40000))
  19. clac();
  20. }
  21. private:
  22. const FlatPtr m_flags;
  23. };
  24. }