feat: overhaul userspace heap and virtual memory

This commit is contained in:
daniel committed 2026-08-10 12:25:27 +02:00
1 parent 4ecec32c5c
commit 9b23d99082
21 files changed
+905 -451

No files matched your search

+7
View File
@@ -33,6 +33,9 @@ namespace Sched {
// failed bound check is recoverable (SYS_ALLOC returns null); allowing the
// heap to cross this boundary would silently replace library PTEs.
static constexpr uint64_t UserHeapLimit = 0x60000000ULL;
static constexpr uint64_t UserHeapPages =
(UserHeapLimit - UserHeapBase) / 0x1000ULL;
static constexpr uint64_t UserHeapBitmapWords = (UserHeapPages + 63) / 64;
// Surface mappings use reusable, fixed-size per-process slots instead of
// consuming heap VA forever. 64 * 32 MiB occupies [0x7000000000,
// 0x7080000000), comfortably below the main user stack.
@@ -191,6 +194,7 @@ namespace Sched {
// reservation is serialized across sibling threads and bounded below the
// fixed shared-library mappings.
bool ReserveUserHeapRange(int primarySlot, uint64_t size, uint64_t& outVa);
void ReleaseUserHeapRange(int primarySlot, uint64_t va, uint64_t size);
// Terminate the currently executing thread. If this is the main thread,
// the entire process exits (equivalent to ExitProcess).
@@ -258,5 +262,8 @@ namespace Sched {
// Per-process allocated page count (tracked by Heap syscalls, separate from Process struct)
inline uint64_t g_allocatedPages[MaxProcesses] = {};
// One bit per page in the bounded userspace heap. Unlike heapNext, this
// makes virtual ranges reusable after unmap and failed reservations.
inline uint64_t g_userHeapPageMap[MaxProcesses][UserHeapBitmapWords] = {};
}