diff --git a/AK/Singleton.h b/AK/Singleton.h index 353102a83bd..4ffb0c15c8f 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -11,7 +11,7 @@ #include #ifdef KERNEL # include -# include +# include #endif #ifndef __serenity__ diff --git a/AK/Weakable.h b/AK/Weakable.h index f093af8a2a2..5a98b24a62d 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -13,7 +13,7 @@ #include "StdLibExtras.h" #ifdef KERNEL # include -# include +# include #endif namespace AK { diff --git a/Kernel/Arch/ScopedCritical.h b/Kernel/Arch/ScopedCritical.h new file mode 100644 index 00000000000..678069e4f6f --- /dev/null +++ b/Kernel/Arch/ScopedCritical.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Kernel { + +class ScopedCritical { + AK_MAKE_NONCOPYABLE(ScopedCritical); + +public: + ScopedCritical(); + ~ScopedCritical(); + ScopedCritical(ScopedCritical&& from); + + ScopedCritical& operator=(ScopedCritical&& from); + + void leave(); + void enter(); + +private: + bool m_valid { false }; +}; + +} diff --git a/Kernel/Arch/aarch64/ScopedCritical.cpp b/Kernel/Arch/aarch64/ScopedCritical.cpp new file mode 100644 index 00000000000..47650112a47 --- /dev/null +++ b/Kernel/Arch/aarch64/ScopedCritical.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +#include + +namespace Kernel { + +ScopedCritical::ScopedCritical() +{ +} + +ScopedCritical::~ScopedCritical() +{ +} + +ScopedCritical::ScopedCritical(ScopedCritical&& /*from*/) +{ +} + +ScopedCritical& ScopedCritical::operator=(ScopedCritical&& /*from*/) +{ + return *this; +} + +void ScopedCritical::leave() { } + +void ScopedCritical::enter() { } + +} diff --git a/Kernel/Arch/x86/ScopedCritical.cpp b/Kernel/Arch/x86/ScopedCritical.cpp new file mode 100644 index 00000000000..5b1698e525a --- /dev/null +++ b/Kernel/Arch/x86/ScopedCritical.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +#include + +namespace Kernel { + +ScopedCritical::ScopedCritical() +{ + enter(); +} + +ScopedCritical::~ScopedCritical() +{ + if (m_valid) + leave(); +} + +ScopedCritical::ScopedCritical(ScopedCritical&& from) + : m_valid(exchange(from.m_valid, false)) +{ +} + +ScopedCritical& ScopedCritical::operator=(ScopedCritical&& from) +{ + if (&from != this) { + m_valid = exchange(from.m_valid, false); + } + return *this; +} + +void ScopedCritical::leave() +{ + VERIFY(m_valid); + m_valid = false; + Processor::leave_critical(); +} + +void ScopedCritical::enter() +{ + VERIFY(!m_valid); + m_valid = true; + Processor::enter_critical(); +} + +} diff --git a/Kernel/Arch/x86/ScopedCritical.h b/Kernel/Arch/x86/ScopedCritical.h deleted file mode 100644 index 5abf896b3f8..00000000000 --- a/Kernel/Arch/x86/ScopedCritical.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -#include - -namespace Kernel { - -class ScopedCritical { - AK_MAKE_NONCOPYABLE(ScopedCritical); - -public: - ScopedCritical() - { - enter(); - } - - ~ScopedCritical() - { - if (m_valid) - leave(); - } - - ScopedCritical(ScopedCritical&& from) - : m_valid(exchange(from.m_valid, false)) - { - } - - ScopedCritical& operator=(ScopedCritical&& from) - { - if (&from != this) { - m_valid = exchange(from.m_valid, false); - } - return *this; - } - - void leave() - { - VERIFY(m_valid); - m_valid = false; - Processor::leave_critical(); - } - - void enter() - { - VERIFY(!m_valid); - m_valid = true; - Processor::enter_critical(); - } - -private: - bool m_valid { false }; -}; - -} diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index 34d36f3f5ad..c0ca3f21452 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -16,13 +16,13 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 3c3970d23bd..fc31dffc6b6 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -288,6 +288,11 @@ set(KERNEL_SOURCES ) if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64") + set(KERNEL_SOURCES + ${KERNEL_SOURCES} + Arch/x86/ScopedCritical.cpp + ) + set(KERNEL_SOURCES ${KERNEL_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/ASM_wrapper.cpp @@ -361,7 +366,11 @@ if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64") else() set(SOURCES ${SOURCES} + ${AK_SOURCES} + Arch/aarch64/dummy.cpp + Arch/aarch64/ScopedCritical.cpp + UBSanitizer.cpp ) diff --git a/Kernel/Library/ThreadSafeNonnullRefPtr.h b/Kernel/Library/ThreadSafeNonnullRefPtr.h index 9cd44d4a040..e12bb05a7fa 100644 --- a/Kernel/Library/ThreadSafeNonnullRefPtr.h +++ b/Kernel/Library/ThreadSafeNonnullRefPtr.h @@ -13,7 +13,7 @@ #include #ifdef KERNEL # include -# include +# include #endif #define THREADSAFENONNULLREFPTR_SCRUB_BYTE 0xa1 diff --git a/Kernel/Library/ThreadSafeRefPtr.h b/Kernel/Library/ThreadSafeRefPtr.h index 2adf13ed33d..50971a53d95 100644 --- a/Kernel/Library/ThreadSafeRefPtr.h +++ b/Kernel/Library/ThreadSafeRefPtr.h @@ -16,7 +16,7 @@ #ifdef KERNEL # include # include -# include +# include #endif #define THREADSAFEREFPTR_SCRUB_BYTE 0xa0