Kernel: Add fast page to page table

Add "fast page" to KERNEL_OFFSET. This is always present in page
tables and only requires changing the page table entry to map. This
requires no interrupts since it should only be for very operations
like memcpy.

I used to map all temporary mappings to vaddr 0, but this is much
better. C++ standard always says that nullptr access is undefined
and this gets rid of it.

Fixed some bugs I found along the way
This commit is contained in:
2023-10-30 19:02:09 +02:00
parent 6e676ee8c5
commit 42772611ce
9 changed files with 193 additions and 134 deletions

View File

@@ -38,6 +38,7 @@ namespace Kernel
BAN::RefPtr<Inode> m_inode;
const off_t m_offset;
// FIXME: is this even synchronized?
BAN::RefPtr<SharedFileData> m_shared_data;
};

View File

@@ -29,6 +29,24 @@ 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; }
// FIXME: implement sized checks, return span, etc
static void* fast_page_as_ptr(size_t offset = 0)
{
ASSERT(offset <= PAGE_SIZE);
return reinterpret_cast<void*>(fast_page() + offset);
}
template<typename T>
static T& fast_page_as(size_t offset = 0)
{
ASSERT(offset + sizeof(T) <= PAGE_SIZE);
return *reinterpret_cast<T*>(fast_page() + offset);
}
static bool is_valid_pointer(uintptr_t);
static BAN::ErrorOr<PageTable*> create_userspace();
@@ -64,7 +82,8 @@ namespace Kernel
uint64_t get_page_data(vaddr_t) const;
void initialize_kernel();
void map_kernel_memory();
void invalidate(vaddr_t);
void prepare_fast_page();
static void invalidate(vaddr_t);
private:
paddr_t m_highest_paging_struct { 0 };