Compare commits
3 Commits
36a83b142b
...
4fef54084f
Author | SHA1 | Date |
---|---|---|
Drew Galbraith | 4fef54084f | |
Drew Galbraith | 164309eada | |
Drew Galbraith | 0b9e0adfbb |
|
@ -16,17 +16,12 @@ class CapabilityTable {
|
|||
uint64_t AddNewCapability(const RefPtr<T>& object, uint64_t permissions);
|
||||
uint64_t AddExistingCapability(const RefPtr<Capability>& cap);
|
||||
|
||||
// FIXME: Remove reliance on this.
|
||||
template <typename T>
|
||||
void AddNewCapabilityWithId(uint64_t id, const RefPtr<T>& object,
|
||||
uint64_t permissions);
|
||||
|
||||
RefPtr<Capability> GetCapability(uint64_t id);
|
||||
RefPtr<Capability> ReleaseCapability(uint64_t id);
|
||||
|
||||
private:
|
||||
Mutex lock_{"cap table"};
|
||||
// FIXME: store this id here rather than in the capability.
|
||||
// TODO: Do some randomization.
|
||||
uint64_t next_cap_id_ = 0x100;
|
||||
// FIXME: use a map data structure.
|
||||
struct CapEntry {
|
||||
|
@ -45,11 +40,3 @@ uint64_t CapabilityTable::AddNewCapability(const RefPtr<T>& object,
|
|||
{.id = id, .cap = MakeRefCounted<Capability>(object, permissions)});
|
||||
return id;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CapabilityTable::AddNewCapabilityWithId(uint64_t id,
|
||||
const RefPtr<T>& object,
|
||||
uint64_t permissions) {
|
||||
capabilities_.PushBack(
|
||||
{.id = id, .cap = MakeRefCounted<Capability>(object, permissions)});
|
||||
}
|
||||
|
|
|
@ -24,16 +24,6 @@
|
|||
namespace {
|
||||
|
||||
uint64_t PageAlign(uint64_t addr) { return addr & ~0xFFF; }
|
||||
uint64_t* PageAlign(uint64_t* addr) {
|
||||
return reinterpret_cast<uint64_t*>(reinterpret_cast<uint64_t>(addr) & ~0xFFF);
|
||||
}
|
||||
|
||||
void ZeroOutPage(uint64_t* ptr) {
|
||||
ptr = PageAlign(ptr);
|
||||
for (uint64_t i = 0; i < 512; i++) {
|
||||
ptr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ShiftForEntryIndexing(uint64_t addr, uint64_t offset) {
|
||||
addr &= ~0xFFFF0000'00000000;
|
||||
|
@ -126,21 +116,18 @@ void MapPage(uint64_t cr3, uint64_t vaddr, uint64_t paddr) {
|
|||
|
||||
uint64_t* pml4_entry = Pml4Entry(cr3, vaddr);
|
||||
if (!(*pml4_entry & PRESENT_BIT)) {
|
||||
uint64_t page = phys_mem::AllocatePage();
|
||||
uint64_t page = phys_mem::AllocateAndZeroPage();
|
||||
*pml4_entry = page | access_bits;
|
||||
ZeroOutPage(PageDirectoryPointerEntry(*pml4_entry, vaddr));
|
||||
}
|
||||
uint64_t* pdp_entry = PageDirectoryPointerEntry(*pml4_entry, vaddr);
|
||||
if (!(*pdp_entry & PRESENT_BIT)) {
|
||||
uint64_t page = phys_mem::AllocatePage();
|
||||
uint64_t page = phys_mem::AllocateAndZeroPage();
|
||||
*pdp_entry = page | access_bits;
|
||||
ZeroOutPage(PageDirectoryEntry(*pdp_entry, vaddr));
|
||||
}
|
||||
uint64_t* pd_entry = PageDirectoryEntry(*pdp_entry, vaddr);
|
||||
if (!(*pd_entry & PRESENT_BIT)) {
|
||||
uint64_t page = phys_mem::AllocatePage();
|
||||
uint64_t page = phys_mem::AllocateAndZeroPage();
|
||||
*(pd_entry) = page | access_bits;
|
||||
ZeroOutPage(PageTableEntry(*pd_entry, vaddr));
|
||||
}
|
||||
|
||||
uint64_t* pt_entry = PageTableEntry(*pd_entry, vaddr);
|
||||
|
@ -158,9 +145,7 @@ uint64_t AllocatePageIfNecessary(uint64_t addr) {
|
|||
return phys;
|
||||
}
|
||||
phys = phys_mem::AllocatePage();
|
||||
// FIXME: Maybe move this to the physical memory allocator.
|
||||
ZeroOutPage(
|
||||
reinterpret_cast<uint64_t*>(boot::GetHigherHalfDirectMap() + phys));
|
||||
|
||||
MapPage(cr3, addr, phys);
|
||||
return phys;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,17 @@
|
|||
namespace phys_mem {
|
||||
namespace {
|
||||
|
||||
uint64_t* PageAlign(uint64_t* addr) {
|
||||
return reinterpret_cast<uint64_t*>(reinterpret_cast<uint64_t>(addr) & ~0xFFF);
|
||||
}
|
||||
|
||||
void ZeroOutPage(uint64_t* ptr) {
|
||||
ptr = PageAlign(ptr);
|
||||
for (uint64_t i = 0; i < 512; i++) {
|
||||
ptr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct BootstrapMemory {
|
||||
uint64_t init_page = 0;
|
||||
uint64_t next_page = 0;
|
||||
|
@ -163,6 +174,13 @@ uint64_t AllocatePage() {
|
|||
return page;
|
||||
}
|
||||
|
||||
uint64_t AllocateAndZeroPage() {
|
||||
uint64_t paddr = AllocatePage();
|
||||
ZeroOutPage(
|
||||
reinterpret_cast<uint64_t*>(boot::GetHigherHalfDirectMap() + paddr));
|
||||
return paddr;
|
||||
}
|
||||
|
||||
uint64_t AllocateContinuous(uint64_t num_continuous) {
|
||||
if (gPmm == nullptr) {
|
||||
panic("No physical memory manager!");
|
||||
|
|
|
@ -10,9 +10,12 @@ namespace phys_mem {
|
|||
// to initialize so we need this first.
|
||||
void InitBootstrapPageAllocation();
|
||||
|
||||
// Initializes the main physical memory manager.
|
||||
void InitPhysicalMemoryManager();
|
||||
|
||||
uint64_t AllocatePage();
|
||||
uint64_t AllocateAndZeroPage();
|
||||
|
||||
uint64_t AllocateContinuous(uint64_t num_pages);
|
||||
void FreePage(uint64_t page);
|
||||
|
||||
|
|
|
@ -46,13 +46,6 @@ class Process : public KernelObject {
|
|||
}
|
||||
uint64_t AddExistingCapability(const RefPtr<Capability>& cap);
|
||||
|
||||
// FIXME: Eliminate reliance on this.
|
||||
template <typename T>
|
||||
void AddNewCapabilityWithId(uint64_t id, const RefPtr<T>& obj,
|
||||
uint64_t permissions) {
|
||||
return caps_.AddNewCapabilityWithId(id, obj, permissions);
|
||||
}
|
||||
|
||||
// Checks the state of all child threads and transitions to
|
||||
// finished if all have finished.
|
||||
void CheckState();
|
||||
|
|
Loading…
Reference in New Issue