The Pedigree Project 0.1
payload-page-regressions.cc
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted.
6 */
7
8#include "pedigree/kernel/Log.h"
9#include "pedigree/kernel/process/Event.h"
10#include "pedigree/kernel/processor/PhysicalMemoryManager.h"
11#include "pedigree/kernel/processor/VirtualAddressSpace.h"
12#include "pedigree/kernel/utilities/MemoryPool.h"
13
14static_assert(Event::getHostedHandlerBufferSize(1024) == EVENT_LIMIT);
15static_assert(Event::getHostedHandlerBufferSize(4096) == EVENT_LIMIT);
16static_assert(Event::getHostedHandlerBufferSize(16384) == 16384);
17
18namespace {
19bool check(bool condition, const char* test, const char* detail) {
20 if (condition) {
21 return true;
22 }
23 ERROR("HOSTED-WAIT-TEST: FAIL " << test << ": " << detail);
24 return false;
25}
26
27bool eventPayloadGeometry() {
28 constexpr const char* Test = "event-payload-page-span";
29 const size_t pageSize = PhysicalMemoryManager::getPageSize();
30 const size_t pageCount = (EVENT_LIMIT / pageSize) + ((EVENT_LIMIT % pageSize) ? 1 : 0);
31 const size_t expectedSpan = pageCount * pageSize;
32
33 bool passed = true;
34 passed &= check(Event::getHostedHandlerBufferSize(1024) == EVENT_LIMIT, Test,
35 "a 4 KiB event did not span four 1 KiB pages");
36 passed &= check(Event::getHostedHandlerBufferSize(4096) == EVENT_LIMIT, Test,
37 "the 4 KiB target changed its event slot size");
38 passed &= check(Event::getHostedHandlerBufferSize(16384) == 16384, Test,
39 "a sub-page event slot was not rounded to one target page");
40 passed &= check(Event::getHandlerBufferSize() == expectedSpan, Test,
41 "the live event slot does not match target-page geometry");
43 (EVENT_TID_MAX * MAX_NESTED_EVENTS * expectedSpan),
44 Test, "the reserved handler-buffer range does not use the rounded slot span");
45 if (passed) {
46 NOTICE("HOSTED-WAIT-TEST: PASS event-payload-page-span");
47 }
48 return passed;
49}
50
51bool multiPagePoolMapping() {
52 constexpr const char* Test = "memory-pool-page-span";
53 constexpr size_t PageCount = 4;
54 const size_t pageSize = PhysicalMemoryManager::getPageSize();
55 if (pageSize > (~size_t{0} / PageCount)) {
56 return check(false, Test, "the target page size overflows the regression buffer");
57 }
58
59 MemoryPool pool("hosted-payload-page-regression");
60 if (!pool.initialise(PageCount, PageCount * pageSize)) {
61 return check(false, Test, "the multi-page pool could not be initialised");
62 }
63
64 const uintptr_t buffer = pool.allocateNow();
65 bool passed = check(buffer != 0, Test, "the multi-page buffer could not be allocated");
67 if (buffer) {
68 for (size_t page = 0; page < PageCount; ++page) {
69 passed &= check(va.isMapped(reinterpret_cast<void*>(buffer + (page * pageSize))), Test,
70 "allocation left part of the buffer unmapped");
71 }
72
73 pool.free(buffer);
74 passed &= check(pool.trim(), Test, "the released multi-page buffer was not reclaimed");
75 for (size_t page = 0; page < PageCount; ++page) {
76 passed &= check(!va.isMapped(reinterpret_cast<void*>(buffer + (page * pageSize))), Test,
77 "trim left part of the buffer mapped");
78 }
79 }
80
81 if (passed) {
82 NOTICE("HOSTED-WAIT-TEST: PASS memory-pool-page-span");
83 }
84 return passed;
85}
86
87} // namespace
88
89bool runHostedPayloadPageRegressions() {
90 return eventPayloadGeometry() && multiPagePoolMapping();
91}
static size_t getHandlerBufferSize()
Definition Event.cc:217
static uintptr_t getLastHandlerBuffer()
Definition Event.cc:221
static uintptr_t getHandlerBuffer()
Definition Event.cc:213
virtual bool isMapped(void *virtualAddress)=0
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()