summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/MemoryManager.cpp14
-rw-r--r--Kernel/MemoryManager.h38
-rw-r--r--Kernel/Process.cpp13
-rw-r--r--Kernel/Process.h24
4 files changed, 45 insertions, 44 deletions
diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp
index 74225b2fc7..a12bf28093 100644
--- a/Kernel/MemoryManager.cpp
+++ b/Kernel/MemoryManager.cpp
@@ -234,7 +234,7 @@ void MemoryManager::flushTLB(LinearAddress laddr)
asm volatile("invlpg %0": :"m" (*(char*)laddr.get()));
}
-void MemoryManager::map_region_at_address(dword* page_directory, Process::Region& region, LinearAddress laddr, bool user_allowed)
+void MemoryManager::map_region_at_address(dword* page_directory, Region& region, LinearAddress laddr, bool user_allowed)
{
InterruptDisabler disabler;
auto& zone = *region.zone;
@@ -282,7 +282,7 @@ LinearAddress MemoryManager::allocate_linear_address_range(size_t size)
return laddr;
}
-byte* MemoryManager::create_kernel_alias_for_region(Process::Region& region)
+byte* MemoryManager::create_kernel_alias_for_region(Region& region)
{
InterruptDisabler disabler;
auto laddr = allocate_linear_address_range(region.size);
@@ -290,12 +290,12 @@ byte* MemoryManager::create_kernel_alias_for_region(Process::Region& region)
return laddr.asPtr();
}
-void MemoryManager::remove_kernel_alias_for_region(Process::Region& region, byte* addr)
+void MemoryManager::remove_kernel_alias_for_region(Region& region, byte* addr)
{
unmap_range(m_kernel_page_directory, LinearAddress((dword)addr), region.size);
}
-bool MemoryManager::unmapRegion(Process& process, Process::Region& region)
+bool MemoryManager::unmapRegion(Process& process, Region& region)
{
InterruptDisabler disabler;
auto& zone = *region.zone;
@@ -314,7 +314,7 @@ bool MemoryManager::unmapRegion(Process& process, Process::Region& region)
return true;
}
-bool MemoryManager::unmapSubregion(Process& process, Process::Subregion& subregion)
+bool MemoryManager::unmapSubregion(Process& process, Subregion& subregion)
{
InterruptDisabler disabler;
size_t numPages = subregion.size / 4096;
@@ -334,7 +334,7 @@ bool MemoryManager::unmapSubregion(Process& process, Process::Subregion& subregi
return true;
}
-bool MemoryManager::mapSubregion(Process& process, Process::Subregion& subregion)
+bool MemoryManager::mapSubregion(Process& process, Subregion& subregion)
{
InterruptDisabler disabler;
auto& region = *subregion.region;
@@ -357,7 +357,7 @@ bool MemoryManager::mapSubregion(Process& process, Process::Subregion& subregion
return true;
}
-bool MemoryManager::mapRegion(Process& process, Process::Region& region)
+bool MemoryManager::mapRegion(Process& process, Region& region)
{
map_region_at_address(process.m_pageDirectory, region, region.linearAddress, true);
return true;
diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h
index f9d3d63e07..6b2611081b 100644
--- a/Kernel/MemoryManager.h
+++ b/Kernel/MemoryManager.h
@@ -2,13 +2,15 @@
#include "types.h"
#include "i386.h"
+#include <AK/ByteBuffer.h>
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/Vector.h>
#include <AK/HashTable.h>
-#include "Process.h"
+#include <AK/String.h>
class Process;
+extern Process* current;
enum class PageFaultResponse {
ShouldCrash,
@@ -30,6 +32,26 @@ private:
Vector<PhysicalAddress> m_pages;
};
+struct Region : public Retainable<Region> {
+ Region(LinearAddress, size_t, RetainPtr<Zone>&&, String&&);
+ ~Region();
+ LinearAddress linearAddress;
+ size_t size { 0 };
+ RetainPtr<Zone> zone;
+ String name;
+};
+
+struct Subregion {
+ Subregion(Region&, dword offset, size_t, LinearAddress, String&& name);
+ ~Subregion();
+
+ RetainPtr<Region> region;
+ dword offset;
+ size_t size { 0 };
+ LinearAddress linearAddress;
+ String name;
+};
+
#define MM MemoryManager::the()
class MemoryManager {
@@ -46,19 +68,19 @@ public:
RetainPtr<Zone> createZone(size_t);
- bool mapSubregion(Process&, Process::Subregion&);
- bool unmapSubregion(Process&, Process::Subregion&);
+ bool mapSubregion(Process&, Subregion&);
+ bool unmapSubregion(Process&, Subregion&);
- bool mapRegion(Process&, Process::Region&);
- bool unmapRegion(Process&, Process::Region&);
+ bool mapRegion(Process&, Region&);
+ bool unmapRegion(Process&, Region&);
void registerZone(Zone&);
void unregisterZone(Zone&);
void populate_page_directory(Process&);
- byte* create_kernel_alias_for_region(Process::Region&);
- void remove_kernel_alias_for_region(Process::Region&, byte*);
+ byte* create_kernel_alias_for_region(Region&);
+ void remove_kernel_alias_for_region(Region&, byte*);
void enter_kernel_paging_scope();
void enter_process_paging_scope(Process&);
@@ -71,7 +93,7 @@ private:
~MemoryManager();
LinearAddress allocate_linear_address_range(size_t);
- void map_region_at_address(dword* page_directory, Process::Region&, LinearAddress, bool user_accessible);
+ void map_region_at_address(dword* page_directory, Region&, LinearAddress, bool user_accessible);
void unmap_range(dword* page_directory, LinearAddress, size_t);
void initializePaging();
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 7da4ff1277..d64c602622 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -132,7 +132,7 @@ Vector<Process*> Process::allProcesses()
return processes;
}
-Process::Region* Process::allocateRegion(size_t size, String&& name)
+Region* Process::allocateRegion(size_t size, String&& name)
{
// FIXME: This needs sanity checks. What if this overlaps existing regions?
@@ -157,7 +157,7 @@ bool Process::deallocateRegion(Region& region)
return false;
}
-Process::Region* Process::regionFromRange(LinearAddress laddr, size_t size)
+Region* Process::regionFromRange(LinearAddress laddr, size_t size)
{
for (auto& region : m_regions) {
if (region->linearAddress == laddr && region->size == size)
@@ -1084,7 +1084,7 @@ Process* Process::kernelProcess()
return s_kernelProcess;
}
-Process::Region::Region(LinearAddress a, size_t s, RetainPtr<Zone>&& z, String&& n)
+Region::Region(LinearAddress a, size_t s, RetainPtr<Zone>&& z, String&& n)
: linearAddress(a)
, size(s)
, zone(move(z))
@@ -1092,11 +1092,11 @@ Process::Region::Region(LinearAddress a, size_t s, RetainPtr<Zone>&& z, String&&
{
}
-Process::Region::~Region()
+Region::~Region()
{
}
-Process::Subregion::Subregion(Region& r, dword o, size_t s, LinearAddress l, String&& n)\
+Subregion::Subregion(Region& r, dword o, size_t s, LinearAddress l, String&& n)\
: region(r)
, offset(o)
, size(s)
@@ -1105,8 +1105,7 @@ Process::Subregion::Subregion(Region& r, dword o, size_t s, LinearAddress l, Str
{
}
-
-Process::Subregion::~Subregion()
+Subregion::~Subregion()
{
}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 02fe7224d1..d4edfba82f 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -10,12 +10,12 @@
#include "TTY.h"
class FileHandle;
+class Region;
+class Subregion;
class Zone;
class Process : public InlineLinkedListNode<Process> {
friend class InlineLinkedListNode<Process>;
- struct Region;
- struct Subregion;
public:
static Process* createKernelProcess(void (*entry)(), String&& name);
static Process* createUserProcess(const String& path, uid_t, gid_t, pid_t parentPID, int& error, const char** args = nullptr, TTY* = nullptr);
@@ -179,26 +179,6 @@ private:
TTY* m_tty { nullptr };
- struct Region : public Retainable<Region> {
- Region(LinearAddress, size_t, RetainPtr<Zone>&&, String&&);
- ~Region();
- LinearAddress linearAddress;
- size_t size { 0 };
- RetainPtr<Zone> zone;
- String name;
- };
-
- struct Subregion {
- Subregion(Region&, dword offset, size_t, LinearAddress, String&& name);
- ~Subregion();
-
- RetainPtr<Region> region;
- dword offset;
- size_t size { 0 };
- LinearAddress linearAddress;
- String name;
- };
-
Region* allocateRegion(size_t, String&& name);
Region* allocateRegion(size_t, String&& name, LinearAddress);
bool deallocateRegion(Region& region);