Move Region and Subregion out of Process and make them free classes.

This commit is contained in:
Andreas Kling 2018-11-01 13:21:02 +01:00
parent 3e532ac7b6
commit fce81d376c
Notes: sideshowbarker 2024-07-19 18:34:57 +09:00
4 changed files with 45 additions and 44 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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()
{
}

View file

@ -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);