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:
1 parent
61ec2442eb
commit
2c4a68a75f
114 files changed
+18069
-2620
No files matched your search
@@ -0,0 +1,156 @@
|
||||
// Read-only page-cache smoke test.
|
||||
// Verifies that ReadFile and file-backed mappings share the same cached pages.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <ntlite/syscall.h>
|
||||
|
||||
#define TEST_SIZE 8192u
|
||||
|
||||
static uint8_t gA[TEST_SIZE];
|
||||
static uint8_t gB[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 = buf[i];
|
||||
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromParts(&c, 1) };
|
||||
SysWriteConsole(&req);
|
||||
}
|
||||
}
|
||||
|
||||
static void exit_now(int code) {
|
||||
for (;;) SysExitProcess(code);
|
||||
}
|
||||
|
||||
static void fail(const char* msg) {
|
||||
print("pcache_smoke: ");
|
||||
print(msg);
|
||||
print("\n");
|
||||
exit_now(1);
|
||||
}
|
||||
|
||||
static void fail_status(const char* what, uint32_t s) {
|
||||
print("pcache_smoke: "); print(what); print(" failed status="); print_u64(s); 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_self(uint32_t* out) {
|
||||
static const char* paths[] = {
|
||||
"pcache_smoke.exe",
|
||||
"/apps/pcache_smoke.exe",
|
||||
"Y:/apps/pcache_smoke.exe",
|
||||
"0:/apps/pcache_smoke.exe",
|
||||
"1:/apps/pcache_smoke.exe",
|
||||
"/apps/shell_native.exe",
|
||||
"0:/apps/shell_native.exe",
|
||||
"1:/apps/shell_native.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;
|
||||
print("pcache_smoke: using "); print(paths[i]); print("\n");
|
||||
return SYS_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return SYS_STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
print("pcache_smoke: start\n");
|
||||
|
||||
SYS_FILE_CACHE_STATS before, afterFirst, afterSecond, afterMap;
|
||||
uint32_t s = query_cache(&before);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("query initial stats", s);
|
||||
|
||||
uint32_t file = 0;
|
||||
s = open_self(&file);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("open test file", s);
|
||||
|
||||
size_t gotA = 0;
|
||||
memset(gA, 0xA5, sizeof(gA));
|
||||
SYS_FILE_IO_REQUEST readReqA = SysMakeFileIoRequest(file, gA, sizeof(gA), &gotA);
|
||||
s = SysReadFile(&readReqA);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("first read", s);
|
||||
if (gotA < 4096) fail("first read too short");
|
||||
print("pcache_smoke: first read OK\n");
|
||||
|
||||
s = query_cache(&afterFirst);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("query after first read", s);
|
||||
if (afterFirst.Loads <= before.Loads)
|
||||
fail("first read did not load file-cache pages");
|
||||
|
||||
s = SysSeekFile(file, 0);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("seek", s);
|
||||
|
||||
size_t gotB = 0;
|
||||
memset(gB, 0x5A, sizeof(gB));
|
||||
SYS_FILE_IO_REQUEST readReqB = SysMakeFileIoRequest(file, gB, sizeof(gB), &gotB);
|
||||
s = SysReadFile(&readReqB);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("second read", s);
|
||||
if (gotB != gotA) fail("second read length mismatch");
|
||||
if (memcmp(gA, gB, gotA) != 0) fail("second read data mismatch");
|
||||
print("pcache_smoke: second read OK\n");
|
||||
|
||||
s = query_cache(&afterSecond);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("query after second read", s);
|
||||
if (afterSecond.Hits <= afterFirst.Hits)
|
||||
fail("second read did not hit file cache");
|
||||
|
||||
uint32_t mapping = 0;
|
||||
s = SysCreateFileMapping(file, SYS_VM_READ, SYS_MAP_FLAG_NONE, sizeof(gA), &mapping);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("create mapping", s);
|
||||
SysCloseHandle(file);
|
||||
file = 0;
|
||||
|
||||
void* base = 0;
|
||||
s = SysMapFile(mapping, 0, sizeof(gA), 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;
|
||||
(void)view[0];
|
||||
(void)view[4096];
|
||||
print("pcache_smoke: mmap faults OK\n");
|
||||
|
||||
if (memcmp((const void*)base, gA, gotA) != 0) {
|
||||
SysFreeVm(base);
|
||||
fail("mapped data mismatch");
|
||||
}
|
||||
|
||||
s = query_cache(&afterMap);
|
||||
if (s != SYS_STATUS_SUCCESS) fail_status("query after map", s);
|
||||
if (afterMap.Hits <= afterSecond.Hits)
|
||||
fail("mmap faults did not hit already cached pages");
|
||||
|
||||
SysFreeVm(base);
|
||||
|
||||
print("pcache_smoke: stats loads="); print_u64(afterMap.Loads - before.Loads);
|
||||
print(" hits="); print_u64(afterMap.Hits - before.Hits);
|
||||
print(" resident="); print_u64(afterMap.ResidentPages); print("\n");
|
||||
print("pcache_smoke: PASS\n");
|
||||
exit_now(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user