add page cache with read-ahead and dirty writeback, file-backed and anonymous mmap with CoW, VAD-based virtual memory replacing the old user region model, PFN database with eviction and reclaim, file identity for cross-open section sharing, FAT32 path cache and per-file cluster chain cache, serial.sys for COM1 keyboard input, xHCI MSI with INTx and polled fallback, PciEnableMsiAuto, waitable input queue, KeWaitForAnyEvent, per-process thread info syscall, expanded kernel stats (PFN/PTE/VAD/file-cache/disk), pool allocation tags, async I/O user buffer locking, file flush on close, add docs.md.

This commit is contained in:
maksw committed 2026-06-20 13:17:39 +02:00
1 parent 61ec2442eb
commit 2c4a68a75f
114 files changed
+18069 -2620

No files matched your search

@@ -0,0 +1,176 @@
// Page-cache mmap->read reuse regression test.
// Faults file pages through mmap first, then verifies SysReadFile reuses those pages.
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <ntlite/syscall.h>
#define TEST_SIZE 8192u
static uint8_t gReadback[TEST_SIZE];
static void print(const char* s) {
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) };
SysWriteConsole(&req);
}
static void print_u64(uint64_t v) {
char buf[32];
int i = 0;
if (v == 0) { print("0"); return; }
while (v && i < (int)sizeof(buf)) {
buf[i++] = (char)('0' + (v % 10));
v /= 10;
}
while (i--) {
char c[2] = { buf[i], 0 };
print(c);
}
}
static void exit_now(int code) {
for (;;) SysExitProcess(code);
}
static void fail(const char* msg) {
print("pcache_mmap_read_reuse: ");
print(msg);
print("\n");
exit_now(1);
}
static void fail_status(const char* what, uint32_t status) {
print("pcache_mmap_read_reuse: ");
print(what);
print(" failed status=");
print_u64(status);
print("\n");
exit_now(1);
}
static uint32_t query_cache(SYS_FILE_CACHE_STATS* out) {
memset(out, 0, sizeof(*out));
return SysQueryKernelStats(SYS_KERNEL_STATS_FILE_CACHE, out, sizeof(*out), 0);
}
static uint32_t open_test_file(uint32_t* out, const char** pathOut) {
static const char* paths[] = {
"pcache_mmap_read_reuse.exe",
"/apps/pcache_mmap_read_reuse.exe",
"1:/apps/pcache_mmap_read_reuse.exe",
"0:/apps/pcache_mmap_read_reuse.exe",
"pcache_smoke.exe",
"/apps/pcache_smoke.exe",
"1:/apps/pcache_smoke.exe",
"0:/apps/pcache_smoke.exe",
"/system/init.exe",
"0:/system/init.exe",
"1:/system/init.exe",
"system/init.exe",
};
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); ++i) {
uint32_t h = 0;
SYS_PATH_HANDLE_REQUEST req = { SysSvFromCstr(paths[i]), &h };
uint32_t s = SysOpenFile(&req);
if (s == SYS_STATUS_SUCCESS) {
*out = h;
if (pathOut) *pathOut = paths[i];
return SYS_STATUS_SUCCESS;
}
}
return SYS_STATUS_NOT_FOUND;
}
int main(void) {
print("pcache_mmap_read_reuse: start\n");
SYS_FILE_CACHE_STATS before;
SYS_FILE_CACHE_STATS afterFault;
SYS_FILE_CACHE_STATS afterRead;
uint32_t s = query_cache(&before);
if (s != SYS_STATUS_SUCCESS) fail_status("query initial stats", s);
uint32_t file = 0;
const char* path = 0;
s = open_test_file(&file, &path);
if (s != SYS_STATUS_SUCCESS) fail_status("open test file", s);
uint64_t fileSize = SysGetFileSize(file);
if (fileSize < 4096) fail("test file too small");
size_t mapSize = (fileSize < TEST_SIZE) ? (size_t)fileSize : TEST_SIZE;
print("pcache_mmap_read_reuse: using ");
print(path ? path : "<unknown>");
print(" size=");
print_u64(fileSize);
print("\n");
uint32_t mapping = 0;
s = SysCreateFileMapping(file, SYS_VM_READ, SYS_MAP_FLAG_NONE, mapSize, &mapping);
if (s != SYS_STATUS_SUCCESS) fail_status("create mapping", s);
void* base = 0;
s = SysMapFile(mapping, 0, mapSize, SYS_MAP_ACCESS_READ, SYS_MAP_FLAG_NONE, &base);
SysCloseHandle(mapping);
if (s != SYS_STATUS_SUCCESS) fail_status("map file", s);
if (!base) fail("map returned null");
volatile uint8_t* view = (volatile uint8_t*)base;
for (size_t i = 0; i < mapSize; i += 4096)
(void)view[i];
(void)view[mapSize - 1];
s = query_cache(&afterFault);
if (s != SYS_STATUS_SUCCESS) fail_status("query after mmap faults", s);
if (afterFault.Loads <= before.Loads) {
SysFreeVm(base);
fail("mmap faults did not populate file cache");
}
s = SysSeekFile(file, 0);
if (s != SYS_STATUS_SUCCESS) {
SysFreeVm(base);
fail_status("seek", s);
}
size_t got = 0;
memset(gReadback, 0xCC, sizeof(gReadback));
SYS_FILE_IO_REQUEST readReq = SysMakeFileIoRequest(file, gReadback, mapSize, &got);
s = SysReadFile(&readReq);
if (s != SYS_STATUS_SUCCESS) {
SysFreeVm(base);
fail_status("read", s);
}
if (got != mapSize) {
SysFreeVm(base);
fail("read length mismatch");
}
if (memcmp(gReadback, (const void*)base, mapSize) != 0) {
SysFreeVm(base);
fail("read data differs from mapped data");
}
s = query_cache(&afterRead);
if (s != SYS_STATUS_SUCCESS) {
SysFreeVm(base);
fail_status("query after read", s);
}
if (afterRead.Hits <= afterFault.Hits) {
SysFreeVm(base);
fail("read did not reuse mmap-populated cache pages");
}
SysFreeVm(base);
SysCloseHandle(file);
print("pcache_mmap_read_reuse: loads+=");
print_u64(afterRead.Loads - before.Loads);
print(" hits+=");
print_u64(afterRead.Hits - before.Hits);
print("\n");
print("pcache_mmap_read_reuse: PASS\n");
exit_now(0);
return 0;
}