summaryrefslogtreecommitdiff
path: root/Kernel/VM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-16 01:27:42 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-16 01:27:42 +0100
commita356e4815098e5398e103aa69865bd6c88f7ad36 (patch)
tree50437c6444405f12671bce7f04a8c1b10cff70f8 /Kernel/VM
parentd42f0f46616168bdff492f880b3ea432a49f7345 (diff)
downloadserenity-a356e4815098e5398e103aa69865bd6c88f7ad36.zip
Kernel: Move all code into the Kernel namespace
Diffstat (limited to 'Kernel/VM')
-rw-r--r--Kernel/VM/AnonymousVMObject.cpp4
-rw-r--r--Kernel/VM/AnonymousVMObject.h4
-rw-r--r--Kernel/VM/InodeVMObject.cpp4
-rw-r--r--Kernel/VM/InodeVMObject.h5
-rw-r--r--Kernel/VM/MemoryManager.cpp11
-rw-r--r--Kernel/VM/MemoryManager.h12
-rw-r--r--Kernel/VM/PageDirectory.cpp4
-rw-r--r--Kernel/VM/PageDirectory.h4
-rw-r--r--Kernel/VM/PhysicalPage.cpp4
-rw-r--r--Kernel/VM/PhysicalPage.h4
-rw-r--r--Kernel/VM/PhysicalRegion.cpp4
-rw-r--r--Kernel/VM/PhysicalRegion.h6
-rw-r--r--Kernel/VM/PurgeableVMObject.cpp4
-rw-r--r--Kernel/VM/PurgeableVMObject.h4
-rw-r--r--Kernel/VM/RangeAllocator.cpp4
-rw-r--r--Kernel/VM/RangeAllocator.h7
-rw-r--r--Kernel/VM/Region.cpp4
-rw-r--r--Kernel/VM/Region.h4
-rw-r--r--Kernel/VM/VMObject.cpp4
-rw-r--r--Kernel/VM/VMObject.h4
20 files changed, 93 insertions, 8 deletions
diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp
index 0cc0711d86..0bd8c24866 100644
--- a/Kernel/VM/AnonymousVMObject.cpp
+++ b/Kernel/VM/AnonymousVMObject.cpp
@@ -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));
}
+
+}
diff --git a/Kernel/VM/AnonymousVMObject.h b/Kernel/VM/AnonymousVMObject.h
index 2bdbb1cde6..3b9631c6f0 100644
--- a/Kernel/VM/AnonymousVMObject.h
+++ b/Kernel/VM/AnonymousVMObject.h
@@ -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; }
};
+
+}
diff --git a/Kernel/VM/InodeVMObject.cpp b/Kernel/VM/InodeVMObject.cpp
index 36a97b87bb..226675bd47 100644
--- a/Kernel/VM/InodeVMObject.cpp
+++ b/Kernel/VM/InodeVMObject.cpp
@@ -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;
}
+
+}
diff --git a/Kernel/VM/InodeVMObject.h b/Kernel/VM/InodeVMObject.h
index 3f5705948d..9c22320ed0 100644
--- a/Kernel/VM/InodeVMObject.h
+++ b/Kernel/VM/InodeVMObject.h
@@ -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;
};
+
+}
diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp
index a4433ed036..86122d83e7 100644
--- a/Kernel/VM/MemoryManager.cpp
+++ b/Kernel/VM/MemoryManager.cpp
@@ -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);
}
+
+}
diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h
index 9c6955507f..48d1ff5fa3 100644
--- a/Kernel/VM/MemoryManager.h
+++ b/Kernel/VM/MemoryManager.h
@@ -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();
}
+
+}
diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp
index 9bb56d7b79..3c8eb10934 100644
--- a/Kernel/VM/PageDirectory.cpp
+++ b/Kernel/VM/PageDirectory.cpp
@@ -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());
}
+
+}
diff --git a/Kernel/VM/PageDirectory.h b/Kernel/VM/PageDirectory.h
index 67dc21dd92..45a4b909c2 100644
--- a/Kernel/VM/PageDirectory.h
+++ b/Kernel/VM/PageDirectory.h
@@ -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;
};
+
+}
diff --git a/Kernel/VM/PhysicalPage.cpp b/Kernel/VM/PhysicalPage.cpp
index 36be738029..d2b67c1357 100644
--- a/Kernel/VM/PhysicalPage.cpp
+++ b/Kernel/VM/PhysicalPage.cpp
@@ -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
}
+
+}
diff --git a/Kernel/VM/PhysicalPage.h b/Kernel/VM/PhysicalPage.h
index 2606074daa..fe74ed6aff 100644
--- a/Kernel/VM/PhysicalPage.h
+++ b/Kernel/VM/PhysicalPage.h
@@ -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;
};
+
+}
diff --git a/Kernel/VM/PhysicalRegion.cpp b/Kernel/VM/PhysicalRegion.cpp
index cad0d255e2..558d8a51c4 100644
--- a/Kernel/VM/PhysicalRegion.cpp
+++ b/Kernel/VM/PhysicalRegion.cpp
@@ -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--;
}
+
+}
diff --git a/Kernel/VM/PhysicalRegion.h b/Kernel/VM/PhysicalRegion.h
index 2fdf2dcc9d..fcc7d0f19b 100644
--- a/Kernel/VM/PhysicalRegion.h
+++ b/Kernel/VM/PhysicalRegion.h
@@ -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;
};
+
+}
diff --git a/Kernel/VM/PurgeableVMObject.cpp b/Kernel/VM/PurgeableVMObject.cpp
index 4da63416bc..e293db8c2b 100644
--- a/Kernel/VM/PurgeableVMObject.cpp
+++ b/Kernel/VM/PurgeableVMObject.cpp
@@ -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;
}
+
+}
diff --git a/Kernel/VM/PurgeableVMObject.h b/Kernel/VM/PurgeableVMObject.h
index b58adec787..715df1d774 100644
--- a/Kernel/VM/PurgeableVMObject.h
+++ b/Kernel/VM/PurgeableVMObject.h
@@ -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 };
};
+
+}
diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp
index 5623147da9..95d34120e5 100644
--- a/Kernel/VM/RangeAllocator.cpp
+++ b/Kernel/VM/RangeAllocator.cpp
@@ -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
}
+
+}
diff --git a/Kernel/VM/RangeAllocator.h b/Kernel/VM/RangeAllocator.h
index a820348542..68e9d57152 100644
--- a/Kernel/VM/RangeAllocator.h
+++ b/Kernel/VM/RangeAllocator.h
@@ -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; }
};
}
+
diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp
index d07f0da383..8b7c935341 100644
--- a/Kernel/VM/Region.cpp
+++ b/Kernel/VM/Region.cpp
@@ -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;
}
+
+}
diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h
index 7d2032a6e2..f75a25d82c 100644
--- a/Kernel/VM/Region.h
+++ b/Kernel/VM/Region.h
@@ -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;
};
+
+}
diff --git a/Kernel/VM/VMObject.cpp b/Kernel/VM/VMObject.cpp
index 2fdd2b1043..4b4c92c93e 100644
--- a/Kernel/VM/VMObject.cpp
+++ b/Kernel/VM/VMObject.cpp
@@ -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);
}
+
+}
diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h
index d1eb409d22..67bb137850 100644
--- a/Kernel/VM/VMObject.h
+++ b/Kernel/VM/VMObject.h
@@ -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;
};
+
+}