mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
Kernel: Move all code into the Kernel namespace
This commit is contained in:
parent
d42f0f4661
commit
a356e48150
201 changed files with 907 additions and 111 deletions
|
@ -28,6 +28,8 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/PhysicalPage.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size)
|
||||
{
|
||||
return adopt(*new AnonymousVMObject(size));
|
||||
|
@ -79,3 +81,5 @@ NonnullRefPtr<VMObject> AnonymousVMObject::clone()
|
|||
{
|
||||
return adopt(*new AnonymousVMObject(*this));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <Kernel/VM/VMObject.h>
|
||||
#include <LibBareMetal/Memory/PhysicalAddress.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class AnonymousVMObject : public VMObject {
|
||||
public:
|
||||
virtual ~AnonymousVMObject() override;
|
||||
|
@ -51,3 +53,5 @@ private:
|
|||
|
||||
virtual bool is_anonymous() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/Region.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<InodeVMObject> InodeVMObject::create_with_inode(Inode& inode)
|
||||
{
|
||||
size_t size = inode.size();
|
||||
|
@ -195,3 +197,5 @@ u32 InodeVMObject::executable_mappings() const
|
|||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,9 +26,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Bitmap.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
#include <Kernel/VM/VMObject.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class InodeVMObject final : public VMObject {
|
||||
public:
|
||||
virtual ~InodeVMObject() override;
|
||||
|
@ -65,3 +68,5 @@ private:
|
|||
NonnullRefPtr<Inode> m_inode;
|
||||
Bitmap m_dirty_pages;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,12 @@
|
|||
//#define MM_DEBUG
|
||||
//#define PAGE_FAULT_DEBUG
|
||||
|
||||
extern uintptr_t start_of_kernel_text;
|
||||
extern uintptr_t start_of_kernel_data;
|
||||
extern uintptr_t end_of_kernel_bss;
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static MemoryManager* s_the;
|
||||
|
||||
MemoryManager& MM
|
||||
|
@ -64,8 +70,6 @@ MemoryManager::~MemoryManager()
|
|||
void MemoryManager::protect_kernel_image()
|
||||
{
|
||||
// Disable writing to the kernel text and rodata segments.
|
||||
extern uintptr_t start_of_kernel_text;
|
||||
extern uintptr_t start_of_kernel_data;
|
||||
for (size_t i = (uintptr_t)&start_of_kernel_text; i < (uintptr_t)&start_of_kernel_data; i += PAGE_SIZE) {
|
||||
auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||
pte.set_writable(false);
|
||||
|
@ -73,7 +77,6 @@ void MemoryManager::protect_kernel_image()
|
|||
|
||||
if (g_cpu_supports_nx) {
|
||||
// Disable execution of the kernel data and bss segments.
|
||||
extern uintptr_t end_of_kernel_bss;
|
||||
for (size_t i = (uintptr_t)&start_of_kernel_data; i < (uintptr_t)&end_of_kernel_bss; i += PAGE_SIZE) {
|
||||
auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||
pte.set_execute_disabled(true);
|
||||
|
@ -681,3 +684,5 @@ ProcessPagingScope::~ProcessPagingScope()
|
|||
current->tss().cr3 = m_previous_cr3;
|
||||
write_cr3(m_previous_cr3);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
#include <Kernel/VM/Region.h>
|
||||
#include <Kernel/VM/VMObject.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
#define PAGE_ROUND_UP(x) ((((u32)(x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
|
||||
|
||||
template<typename T>
|
||||
|
@ -71,7 +73,7 @@ inline u32 virtual_to_low_physical(u32 physical)
|
|||
class KBuffer;
|
||||
class SynthFSInode;
|
||||
|
||||
#define MM MemoryManager::the()
|
||||
#define MM Kernel::MemoryManager::the()
|
||||
|
||||
class MemoryManager {
|
||||
AK_MAKE_ETERNAL
|
||||
|
@ -138,8 +140,10 @@ private:
|
|||
MemoryManager();
|
||||
~MemoryManager();
|
||||
|
||||
enum class AccessSpace { Kernel, User };
|
||||
enum class AccessType { Read, Write };
|
||||
enum class AccessSpace { Kernel,
|
||||
User };
|
||||
enum class AccessType { Read,
|
||||
Write };
|
||||
template<AccessSpace, AccessType>
|
||||
bool validate_range(const Process&, VirtualAddress, size_t) const;
|
||||
|
||||
|
@ -232,3 +236,5 @@ inline bool PhysicalPage::is_shared_zero_page() const
|
|||
{
|
||||
return this == &MM.shared_zero_page();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/PageDirectory.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static const uintptr_t userspace_range_base = 0x00800000;
|
||||
static const uintptr_t userspace_range_ceiling = 0xbe000000;
|
||||
static const uintptr_t kernelspace_range_base = 0xc0800000;
|
||||
|
@ -117,3 +119,5 @@ PageDirectory::~PageDirectory()
|
|||
InterruptDisabler disabler;
|
||||
cr3_map().remove(cr3());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include <Kernel/VM/PhysicalPage.h>
|
||||
#include <Kernel/VM/RangeAllocator.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Process;
|
||||
|
||||
class PageDirectory : public RefCounted<PageDirectory> {
|
||||
|
@ -64,3 +66,5 @@ private:
|
|||
RefPtr<PhysicalPage> m_directory_pages[4];
|
||||
HashMap<unsigned, RefPtr<PhysicalPage>> m_physical_pages;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <Kernel/VM/PhysicalPage.h>
|
||||
#include <Kernel/Heap/kmalloc.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)
|
||||
{
|
||||
return adopt(*new PhysicalPage(paddr, supervisor, may_return_to_freelist));
|
||||
|
@ -57,3 +59,5 @@ void PhysicalPage::return_to_freelist() &&
|
|||
dbgprintf("MM: P%x released to freelist\n", m_paddr.get());
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <Kernel/Heap/SlabAllocator.h>
|
||||
#include <LibBareMetal/Memory/PhysicalAddress.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class PhysicalPage {
|
||||
friend class MemoryManager;
|
||||
friend class PageDirectory;
|
||||
|
@ -73,3 +75,5 @@ private:
|
|||
bool m_supervisor { false };
|
||||
PhysicalAddress m_paddr;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <Kernel/VM/PhysicalPage.h>
|
||||
#include <Kernel/VM/PhysicalRegion.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<PhysicalRegion> PhysicalRegion::create(PhysicalAddress lower, PhysicalAddress upper)
|
||||
{
|
||||
return adopt(*new PhysicalRegion(lower, upper));
|
||||
|
@ -112,3 +114,5 @@ void PhysicalRegion::return_page_at(PhysicalAddress addr)
|
|||
m_bitmap.set(page, false);
|
||||
m_used--;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Bitmap.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <Kernel/VM/PhysicalPage.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class PhysicalRegion : public RefCounted<PhysicalRegion> {
|
||||
AK_MAKE_ETERNAL
|
||||
|
||||
|
@ -62,3 +64,5 @@ private:
|
|||
unsigned m_last { 0 };
|
||||
Bitmap m_bitmap;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <Kernel/VM/PhysicalPage.h>
|
||||
#include <Kernel/VM/PurgeableVMObject.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<PurgeableVMObject> PurgeableVMObject::create_with_size(size_t size)
|
||||
{
|
||||
return adopt(*new PurgeableVMObject(size));
|
||||
|
@ -84,3 +86,5 @@ int PurgeableVMObject::purge_impl()
|
|||
|
||||
return purged_page_count;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <Kernel/VM/AnonymousVMObject.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class PurgeableVMObject final : public AnonymousVMObject {
|
||||
public:
|
||||
virtual ~PurgeableVMObject() override;
|
||||
|
@ -59,3 +61,5 @@ private:
|
|||
bool m_was_purged { false };
|
||||
bool m_volatile { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
//#define VRA_DEBUG
|
||||
#define VM_GUARD_PAGES
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
RangeAllocator::RangeAllocator()
|
||||
{
|
||||
}
|
||||
|
@ -194,3 +196,5 @@ void RangeAllocator::deallocate(Range range)
|
|||
dump();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibBareMetal/Memory/VirtualAddress.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Range {
|
||||
friend class RangeAllocator;
|
||||
|
||||
|
@ -100,9 +102,12 @@ inline const LogStream& operator<<(const LogStream& stream, const Range& value)
|
|||
return stream << String::format("Range(%x-%x)", value.base().get(), value.end().get() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
template<>
|
||||
struct Traits<Range> : public GenericTraits<Range> {
|
||||
struct Traits<Kernel::Range> : public GenericTraits<Kernel::Range> {
|
||||
static constexpr bool is_trivial() { return true; }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
//#define MM_DEBUG
|
||||
//#define PAGE_FAULT_DEBUG
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
Region::Region(const Range& range, const String& name, u8 access, bool cacheable)
|
||||
: m_range(range)
|
||||
, m_vmobject(AnonymousVMObject::create_with_size(size()))
|
||||
|
@ -500,3 +502,5 @@ PageFaultResponse Region::handle_inode_fault(size_t page_index_in_region)
|
|||
remap_page(page_index_in_region);
|
||||
return PageFaultResponse::Continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <Kernel/VM/PageDirectory.h>
|
||||
#include <Kernel/VM/RangeAllocator.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Inode;
|
||||
class VMObject;
|
||||
|
||||
|
@ -192,3 +194,5 @@ private:
|
|||
bool m_mmap { false };
|
||||
mutable OwnPtr<Bitmap> m_cow_map;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/VMObject.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
VMObject::VMObject(const VMObject& other)
|
||||
: m_physical_pages(other.m_physical_pages)
|
||||
{
|
||||
|
@ -45,3 +47,5 @@ VMObject::~VMObject()
|
|||
{
|
||||
MM.unregister_vmobject(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <AK/Weakable.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Inode;
|
||||
class PhysicalPage;
|
||||
|
||||
|
@ -76,3 +78,5 @@ private:
|
|||
VMObject& operator=(VMObject&&) = delete;
|
||||
VMObject(VMObject&&) = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue