Kernel: Remove CriticalScopes from memory handing code
This commit is contained in:
parent
682de62c57
commit
ec0cb5fd54
|
@ -17,7 +17,7 @@ extern uint8_t g_userspace_end[];
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
SpinLock PageTable::s_fast_page_lock;
|
RecursiveSpinLock PageTable::s_fast_page_lock;
|
||||||
|
|
||||||
static PageTable* s_kernel = nullptr;
|
static PageTable* s_kernel = nullptr;
|
||||||
static PageTable* s_current = nullptr;
|
static PageTable* s_current = nullptr;
|
||||||
|
@ -209,7 +209,8 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
ASSERT(s_kernel);
|
ASSERT(s_kernel);
|
||||||
ASSERT_NEQ(paddr, 0);
|
ASSERT_NEQ(paddr, 0);
|
||||||
ASSERT(!interrupts_enabled());
|
|
||||||
|
SpinLockGuard _(s_fast_page_lock);
|
||||||
|
|
||||||
constexpr vaddr_t uc_vaddr = uncanonicalize(fast_page());
|
constexpr vaddr_t uc_vaddr = uncanonicalize(fast_page());
|
||||||
constexpr uint64_t pml4e = (uc_vaddr >> 39) & 0x1FF;
|
constexpr uint64_t pml4e = (uc_vaddr >> 39) & 0x1FF;
|
||||||
|
@ -231,7 +232,8 @@ namespace Kernel
|
||||||
void PageTable::unmap_fast_page()
|
void PageTable::unmap_fast_page()
|
||||||
{
|
{
|
||||||
ASSERT(s_kernel);
|
ASSERT(s_kernel);
|
||||||
ASSERT(!interrupts_enabled());
|
|
||||||
|
SpinLockGuard _(s_fast_page_lock);
|
||||||
|
|
||||||
constexpr vaddr_t uc_vaddr = uncanonicalize(fast_page());
|
constexpr vaddr_t uc_vaddr = uncanonicalize(fast_page());
|
||||||
constexpr uint64_t pml4e = (uc_vaddr >> 39) & 0x1FF;
|
constexpr uint64_t pml4e = (uc_vaddr >> 39) & 0x1FF;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <BAN/Errors.h>
|
#include <BAN/Errors.h>
|
||||||
#include <BAN/Traits.h>
|
#include <BAN/Traits.h>
|
||||||
#include <kernel/CriticalScope.h>
|
|
||||||
#include <kernel/Lock/SpinLock.h>
|
#include <kernel/Lock/SpinLock.h>
|
||||||
#include <kernel/Memory/Types.h>
|
#include <kernel/Memory/Types.h>
|
||||||
|
|
||||||
|
@ -130,7 +129,7 @@ namespace Kernel
|
||||||
private:
|
private:
|
||||||
paddr_t m_highest_paging_struct { 0 };
|
paddr_t m_highest_paging_struct { 0 };
|
||||||
mutable RecursiveSpinLock m_lock;
|
mutable RecursiveSpinLock m_lock;
|
||||||
static SpinLock s_fast_page_lock;
|
static RecursiveSpinLock s_fast_page_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr size_t range_page_count(vaddr_t start, size_t bytes)
|
static constexpr size_t range_page_count(vaddr_t start, size_t bytes)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <kernel/CriticalScope.h>
|
|
||||||
#include <kernel/Lock/LockGuard.h>
|
#include <kernel/Lock/LockGuard.h>
|
||||||
#include <kernel/Memory/FileBackedRegion.h>
|
#include <kernel/Memory/FileBackedRegion.h>
|
||||||
#include <kernel/Memory/Heap.h>
|
#include <kernel/Memory/Heap.h>
|
||||||
|
@ -83,12 +82,9 @@ namespace Kernel
|
||||||
if (pages[page_index] == 0)
|
if (pages[page_index] == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
{
|
PageTable::with_fast_page(pages[page_index], [&] {
|
||||||
CriticalScope _;
|
memcpy(page_buffer, PageTable::fast_page_as_ptr(), PAGE_SIZE);
|
||||||
PageTable::with_fast_page(pages[page_index], [&] {
|
});
|
||||||
memcpy(page_buffer, PageTable::fast_page_as_ptr(), PAGE_SIZE);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto ret = inode->write(page_index * PAGE_SIZE, BAN::ConstByteSpan::from(page_buffer)); ret.is_error())
|
if (auto ret = inode->write(page_index * PAGE_SIZE, BAN::ConstByteSpan::from(page_buffer)); ret.is_error())
|
||||||
dwarnln("{}", ret.error());
|
dwarnln("{}", ret.error());
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <kernel/CriticalScope.h>
|
|
||||||
#include <kernel/Lock/LockGuard.h>
|
#include <kernel/Lock/LockGuard.h>
|
||||||
#include <kernel/Memory/Heap.h>
|
#include <kernel/Memory/Heap.h>
|
||||||
#include <kernel/Memory/MemoryBackedRegion.h>
|
#include <kernel/Memory/MemoryBackedRegion.h>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <kernel/CriticalScope.h>
|
|
||||||
#include <kernel/Lock/LockGuard.h>
|
#include <kernel/Lock/LockGuard.h>
|
||||||
#include <kernel/Memory/Heap.h>
|
#include <kernel/Memory/Heap.h>
|
||||||
#include <kernel/Memory/VirtualRange.h>
|
#include <kernel/Memory/VirtualRange.h>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include <BAN/Errors.h>
|
#include <BAN/Errors.h>
|
||||||
#include <kernel/CriticalScope.h>
|
|
||||||
#include <kernel/kprint.h>
|
#include <kernel/kprint.h>
|
||||||
#include <kernel/Memory/kmalloc.h>
|
#include <kernel/Memory/kmalloc.h>
|
||||||
|
|
||||||
|
@ -81,6 +80,8 @@ struct kmalloc_info
|
||||||
};
|
};
|
||||||
static kmalloc_info s_kmalloc_info;
|
static kmalloc_info s_kmalloc_info;
|
||||||
|
|
||||||
|
static Kernel::SpinLock s_kmalloc_lock;
|
||||||
|
|
||||||
template<size_t SIZE>
|
template<size_t SIZE>
|
||||||
struct kmalloc_fixed_node
|
struct kmalloc_fixed_node
|
||||||
{
|
{
|
||||||
|
@ -144,6 +145,8 @@ void kmalloc_initialize()
|
||||||
|
|
||||||
void kmalloc_dump_info()
|
void kmalloc_dump_info()
|
||||||
{
|
{
|
||||||
|
Kernel::SpinLockGuard _(s_kmalloc_lock);
|
||||||
|
|
||||||
kprintln("kmalloc: 0x{8H}->0x{8H}", s_kmalloc_info.base, s_kmalloc_info.end);
|
kprintln("kmalloc: 0x{8H}->0x{8H}", s_kmalloc_info.base, s_kmalloc_info.end);
|
||||||
kprintln(" used: 0x{8H}", s_kmalloc_info.used);
|
kprintln(" used: 0x{8H}", s_kmalloc_info.used);
|
||||||
kprintln(" free: 0x{8H}", s_kmalloc_info.free);
|
kprintln(" free: 0x{8H}", s_kmalloc_info.free);
|
||||||
|
@ -155,6 +158,7 @@ void kmalloc_dump_info()
|
||||||
|
|
||||||
static bool is_corrupted()
|
static bool is_corrupted()
|
||||||
{
|
{
|
||||||
|
Kernel::SpinLockGuard _(s_kmalloc_lock);
|
||||||
auto& info = s_kmalloc_info;
|
auto& info = s_kmalloc_info;
|
||||||
auto* temp = info.first();
|
auto* temp = info.first();
|
||||||
for (; temp->end() <= info.end; temp = temp->after());
|
for (; temp->end() <= info.end; temp = temp->after());
|
||||||
|
@ -163,6 +167,8 @@ static bool is_corrupted()
|
||||||
|
|
||||||
[[maybe_unused]] static void debug_dump()
|
[[maybe_unused]] static void debug_dump()
|
||||||
{
|
{
|
||||||
|
Kernel::SpinLockGuard _(s_kmalloc_lock);
|
||||||
|
|
||||||
auto& info = s_kmalloc_info;
|
auto& info = s_kmalloc_info;
|
||||||
|
|
||||||
uint32_t used = 0;
|
uint32_t used = 0;
|
||||||
|
@ -181,6 +187,8 @@ static bool is_corrupted()
|
||||||
|
|
||||||
static void* kmalloc_fixed()
|
static void* kmalloc_fixed()
|
||||||
{
|
{
|
||||||
|
Kernel::SpinLockGuard _(s_kmalloc_lock);
|
||||||
|
|
||||||
auto& info = s_kmalloc_fixed_info;
|
auto& info = s_kmalloc_fixed_info;
|
||||||
|
|
||||||
if (!info.free_list_head)
|
if (!info.free_list_head)
|
||||||
|
@ -223,6 +231,8 @@ static void* kmalloc_impl(size_t size, size_t align)
|
||||||
ASSERT(align % s_kmalloc_min_align == 0);
|
ASSERT(align % s_kmalloc_min_align == 0);
|
||||||
ASSERT(size % s_kmalloc_min_align == 0);
|
ASSERT(size % s_kmalloc_min_align == 0);
|
||||||
|
|
||||||
|
Kernel::SpinLockGuard _(s_kmalloc_lock);
|
||||||
|
|
||||||
auto& info = s_kmalloc_info;
|
auto& info = s_kmalloc_info;
|
||||||
|
|
||||||
for (auto* node = info.first(); node->end() <= info.end; node = node->after())
|
for (auto* node = info.first(); node->end() <= info.end; node = node->after())
|
||||||
|
@ -304,8 +314,6 @@ void* kmalloc(size_t size, size_t align, bool force_identity_map)
|
||||||
align = s_kmalloc_min_align;
|
align = s_kmalloc_min_align;
|
||||||
ASSERT(align <= PAGE_SIZE);
|
ASSERT(align <= PAGE_SIZE);
|
||||||
|
|
||||||
Kernel::CriticalScope critical;
|
|
||||||
|
|
||||||
if (size == 0 || size >= info.size)
|
if (size == 0 || size >= info.size)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
|
@ -338,7 +346,7 @@ void kfree(void* address)
|
||||||
uintptr_t address_uint = (uintptr_t)address;
|
uintptr_t address_uint = (uintptr_t)address;
|
||||||
ASSERT(address_uint % s_kmalloc_min_align == 0);
|
ASSERT(address_uint % s_kmalloc_min_align == 0);
|
||||||
|
|
||||||
Kernel::CriticalScope critical;
|
Kernel::SpinLockGuard _(s_kmalloc_lock);
|
||||||
|
|
||||||
if (s_kmalloc_fixed_info.base <= address_uint && address_uint < s_kmalloc_fixed_info.end)
|
if (s_kmalloc_fixed_info.base <= address_uint && address_uint < s_kmalloc_fixed_info.end)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue