feat: overhaul userspace heap and virtual memory
This commit is contained in:
1 parent
4ecec32c5c
commit
9b23d99082
21 files changed
+905
-451
No files matched your search
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <Sched/Scheduler.hpp>
|
||||
#include <Memory/Paging.hpp>
|
||||
#include <Api/Heap.hpp>
|
||||
|
||||
namespace montauk::abi::UserMemory {
|
||||
|
||||
@@ -32,6 +33,21 @@ namespace montauk::abi::UserMemory {
|
||||
uint64_t pml4Phys = CurrentPml4();
|
||||
if (pml4Phys == 0) return false;
|
||||
|
||||
if (Memory::VMM::Paging::IsUserRangeAccessible(pml4Phys, addr, size, requireWrite))
|
||||
return true;
|
||||
|
||||
// Anonymous VMAs are demand-committed. Validation precedes the actual
|
||||
// kernel copy, so materialize missing pages here with the same access
|
||||
// type that the copy will perform.
|
||||
uint64_t page = addr & ~0xFFFULL;
|
||||
uint64_t last = (addr + size - 1) & ~0xFFFULL;
|
||||
for (;;) {
|
||||
if (!Memory::VMM::Paging::IsUserRangeAccessible(pml4Phys, page, 1, requireWrite) &&
|
||||
!TryHandleAnonymousPageFault(page, requireWrite ? 2ULL : 0ULL))
|
||||
return false;
|
||||
if (page == last) break;
|
||||
page += 0x1000ULL;
|
||||
}
|
||||
return Memory::VMM::Paging::IsUserRangeAccessible(pml4Phys, addr, size, requireWrite);
|
||||
}
|
||||
|
||||
@@ -58,7 +74,7 @@ namespace montauk::abi::UserMemory {
|
||||
const char* str = (const char*)addr;
|
||||
for (uint64_t i = 0; i < maxLen; i++) {
|
||||
if (!Memory::VMM::Paging::IsUserRangeAccessible(pml4Phys, addr + i, 1, false)) {
|
||||
return false;
|
||||
if (!TryHandleAnonymousPageFault(addr + i, 0)) return false;
|
||||
}
|
||||
if (str[i] == '\0') return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user