mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
Move Region and Subregion out of Process and make them free classes.
This commit is contained in:
parent
3e532ac7b6
commit
fce81d376c
4 changed files with 45 additions and 44 deletions
|
@ -234,7 +234,7 @@ void MemoryManager::flushTLB(LinearAddress laddr)
|
||||||
asm volatile("invlpg %0": :"m" (*(char*)laddr.get()));
|
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;
|
InterruptDisabler disabler;
|
||||||
auto& zone = *region.zone;
|
auto& zone = *region.zone;
|
||||||
|
@ -282,7 +282,7 @@ LinearAddress MemoryManager::allocate_linear_address_range(size_t size)
|
||||||
return laddr;
|
return laddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* MemoryManager::create_kernel_alias_for_region(Process::Region& region)
|
byte* MemoryManager::create_kernel_alias_for_region(Region& region)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto laddr = allocate_linear_address_range(region.size);
|
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();
|
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);
|
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;
|
InterruptDisabler disabler;
|
||||||
auto& zone = *region.zone;
|
auto& zone = *region.zone;
|
||||||
|
@ -314,7 +314,7 @@ bool MemoryManager::unmapRegion(Process& process, Process::Region& region)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemoryManager::unmapSubregion(Process& process, Process::Subregion& subregion)
|
bool MemoryManager::unmapSubregion(Process& process, Subregion& subregion)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
size_t numPages = subregion.size / 4096;
|
size_t numPages = subregion.size / 4096;
|
||||||
|
@ -334,7 +334,7 @@ bool MemoryManager::unmapSubregion(Process& process, Process::Subregion& subregi
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemoryManager::mapSubregion(Process& process, Process::Subregion& subregion)
|
bool MemoryManager::mapSubregion(Process& process, Subregion& subregion)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto& region = *subregion.region;
|
auto& region = *subregion.region;
|
||||||
|
@ -357,7 +357,7 @@ bool MemoryManager::mapSubregion(Process& process, Process::Subregion& subregion
|
||||||
return true;
|
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);
|
map_region_at_address(process.m_pageDirectory, region, region.linearAddress, true);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "i386.h"
|
#include "i386.h"
|
||||||
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/Retainable.h>
|
#include <AK/Retainable.h>
|
||||||
#include <AK/RetainPtr.h>
|
#include <AK/RetainPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include "Process.h"
|
#include <AK/String.h>
|
||||||
|
|
||||||
class Process;
|
class Process;
|
||||||
|
extern Process* current;
|
||||||
|
|
||||||
enum class PageFaultResponse {
|
enum class PageFaultResponse {
|
||||||
ShouldCrash,
|
ShouldCrash,
|
||||||
|
@ -30,6 +32,26 @@ private:
|
||||||
Vector<PhysicalAddress> m_pages;
|
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()
|
#define MM MemoryManager::the()
|
||||||
|
|
||||||
class MemoryManager {
|
class MemoryManager {
|
||||||
|
@ -46,19 +68,19 @@ public:
|
||||||
|
|
||||||
RetainPtr<Zone> createZone(size_t);
|
RetainPtr<Zone> createZone(size_t);
|
||||||
|
|
||||||
bool mapSubregion(Process&, Process::Subregion&);
|
bool mapSubregion(Process&, Subregion&);
|
||||||
bool unmapSubregion(Process&, Process::Subregion&);
|
bool unmapSubregion(Process&, Subregion&);
|
||||||
|
|
||||||
bool mapRegion(Process&, Process::Region&);
|
bool mapRegion(Process&, Region&);
|
||||||
bool unmapRegion(Process&, Process::Region&);
|
bool unmapRegion(Process&, Region&);
|
||||||
|
|
||||||
void registerZone(Zone&);
|
void registerZone(Zone&);
|
||||||
void unregisterZone(Zone&);
|
void unregisterZone(Zone&);
|
||||||
|
|
||||||
void populate_page_directory(Process&);
|
void populate_page_directory(Process&);
|
||||||
|
|
||||||
byte* create_kernel_alias_for_region(Process::Region&);
|
byte* create_kernel_alias_for_region(Region&);
|
||||||
void remove_kernel_alias_for_region(Process::Region&, byte*);
|
void remove_kernel_alias_for_region(Region&, byte*);
|
||||||
|
|
||||||
void enter_kernel_paging_scope();
|
void enter_kernel_paging_scope();
|
||||||
void enter_process_paging_scope(Process&);
|
void enter_process_paging_scope(Process&);
|
||||||
|
@ -71,7 +93,7 @@ private:
|
||||||
~MemoryManager();
|
~MemoryManager();
|
||||||
|
|
||||||
LinearAddress allocate_linear_address_range(size_t);
|
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 unmap_range(dword* page_directory, LinearAddress, size_t);
|
||||||
|
|
||||||
void initializePaging();
|
void initializePaging();
|
||||||
|
|
|
@ -132,7 +132,7 @@ Vector<Process*> Process::allProcesses()
|
||||||
return processes;
|
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?
|
// FIXME: This needs sanity checks. What if this overlaps existing regions?
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ bool Process::deallocateRegion(Region& region)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::Region* Process::regionFromRange(LinearAddress laddr, size_t size)
|
Region* Process::regionFromRange(LinearAddress laddr, size_t size)
|
||||||
{
|
{
|
||||||
for (auto& region : m_regions) {
|
for (auto& region : m_regions) {
|
||||||
if (region->linearAddress == laddr && region->size == size)
|
if (region->linearAddress == laddr && region->size == size)
|
||||||
|
@ -1084,7 +1084,7 @@ Process* Process::kernelProcess()
|
||||||
return s_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)
|
: linearAddress(a)
|
||||||
, size(s)
|
, size(s)
|
||||||
, zone(move(z))
|
, 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)
|
: region(r)
|
||||||
, offset(o)
|
, offset(o)
|
||||||
, size(s)
|
, size(s)
|
||||||
|
@ -1105,8 +1105,7 @@ Process::Subregion::Subregion(Region& r, dword o, size_t s, LinearAddress l, Str
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Subregion::~Subregion()
|
||||||
Process::Subregion::~Subregion()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
#include "TTY.h"
|
#include "TTY.h"
|
||||||
|
|
||||||
class FileHandle;
|
class FileHandle;
|
||||||
|
class Region;
|
||||||
|
class Subregion;
|
||||||
class Zone;
|
class Zone;
|
||||||
|
|
||||||
class Process : public InlineLinkedListNode<Process> {
|
class Process : public InlineLinkedListNode<Process> {
|
||||||
friend class InlineLinkedListNode<Process>;
|
friend class InlineLinkedListNode<Process>;
|
||||||
struct Region;
|
|
||||||
struct Subregion;
|
|
||||||
public:
|
public:
|
||||||
static Process* createKernelProcess(void (*entry)(), String&& name);
|
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);
|
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 };
|
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);
|
||||||
Region* allocateRegion(size_t, String&& name, LinearAddress);
|
Region* allocateRegion(size_t, String&& name, LinearAddress);
|
||||||
bool deallocateRegion(Region& region);
|
bool deallocateRegion(Region& region);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue