Kernel: Fix all broken locks from new mutexes
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
#include <BAN/NoCopyMove.h>
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <kernel/Lock/SpinLock.h>
|
||||
#include <kernel/Memory/PhysicalRange.h>
|
||||
#include <kernel/SpinLock.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <BAN/Errors.h>
|
||||
#include <BAN/Traits.h>
|
||||
#include <kernel/CriticalScope.h>
|
||||
#include <kernel/Lock/SpinLock.h>
|
||||
#include <kernel/Memory/Types.h>
|
||||
#include <kernel/SpinLock.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
@@ -15,6 +15,12 @@ namespace Kernel
|
||||
requires BAN::is_same_v<decltype(func()), void>;
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
concept with_fast_page_callback_error = requires(F func)
|
||||
{
|
||||
requires BAN::is_same_v<decltype(func()), BAN::ErrorOr<void>>;
|
||||
};
|
||||
|
||||
class PageTable
|
||||
{
|
||||
public:
|
||||
@@ -37,19 +43,27 @@ namespace Kernel
|
||||
static PageTable& kernel();
|
||||
static PageTable& current();
|
||||
|
||||
static void map_fast_page(paddr_t);
|
||||
static void unmap_fast_page();
|
||||
static constexpr vaddr_t fast_page() { return KERNEL_OFFSET; }
|
||||
|
||||
template<with_fast_page_callback F>
|
||||
static void with_fast_page(paddr_t paddr, F callback)
|
||||
{
|
||||
CriticalScope _;
|
||||
SpinLockGuard _(s_fast_page_lock);
|
||||
map_fast_page(paddr);
|
||||
callback();
|
||||
unmap_fast_page();
|
||||
}
|
||||
|
||||
template<with_fast_page_callback_error F>
|
||||
static BAN::ErrorOr<void> with_fast_page(paddr_t paddr, F callback)
|
||||
{
|
||||
SpinLockGuard _(s_fast_page_lock);
|
||||
map_fast_page(paddr);
|
||||
auto ret = callback();
|
||||
unmap_fast_page();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// FIXME: implement sized checks, return span, etc
|
||||
static void* fast_page_as_ptr(size_t offset = 0)
|
||||
{
|
||||
@@ -97,8 +111,8 @@ namespace Kernel
|
||||
|
||||
void load();
|
||||
|
||||
void lock() const { m_lock.lock(); }
|
||||
void unlock() const { m_lock.unlock(); }
|
||||
InterruptState lock() const { return m_lock.lock(); }
|
||||
void unlock(InterruptState state) const { m_lock.unlock(state); }
|
||||
|
||||
void debug_dump();
|
||||
|
||||
@@ -110,9 +124,13 @@ namespace Kernel
|
||||
void prepare_fast_page();
|
||||
static void invalidate(vaddr_t);
|
||||
|
||||
static void map_fast_page(paddr_t);
|
||||
static void unmap_fast_page();
|
||||
|
||||
private:
|
||||
paddr_t m_highest_paging_struct { 0 };
|
||||
mutable RecursiveSpinLock m_lock;
|
||||
static SpinLock s_fast_page_lock;
|
||||
};
|
||||
|
||||
static constexpr size_t range_page_count(vaddr_t start, size_t bytes)
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <kernel/CriticalScope.h>
|
||||
#include <kernel/LockGuard.h>
|
||||
#include <kernel/Memory/PageTable.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
class PageTableScope
|
||||
{
|
||||
public:
|
||||
PageTableScope(PageTable& page_table)
|
||||
: m_guard(page_table)
|
||||
, m_old(PageTable::current())
|
||||
, m_temp(page_table)
|
||||
{
|
||||
if (&m_old != &m_temp)
|
||||
m_temp.load();
|
||||
}
|
||||
~PageTableScope()
|
||||
{
|
||||
if (&m_old != &m_temp)
|
||||
m_old.load();
|
||||
}
|
||||
private:
|
||||
LockGuard<PageTable> m_guard;
|
||||
CriticalScope m_scope;
|
||||
PageTable& m_old;
|
||||
PageTable& m_temp;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user