clean up and standardize types across the codebase, unify atomic operations, improve UTF-8 handling throughout the system, remove obsolete input and named queue interfaces, redesign process preparation and creation, tighten IPC and service boundaries, improve error handling and reliability, minor documentation cleanup, fix doom surfaces, fix panic in ini parsing.

This commit is contained in:
maksw committed 2026-10-12 18:17:43 +02:00
1 parent 899225f551
commit c0ad63c27f
226 files changed
+6562 -4147

No files matched your search

+59 -52
View File
@@ -32,30 +32,30 @@ static void printUInt(uint32_t n);
static void printHex32(uint32_t v);
// Opens file.
static uint32_t open_file(const char* path, uint32_t* handleOut) {
static KSTATUS open_file(const char* path, uint32_t* handleOut) {
return NtlOpenFile(SysSvFromCstr(path), SYS_FILE_ACCESS_READ | SYS_FILE_ACCESS_QUERY,
SYS_FILE_OPEN_EXISTING, SYS_FILE_FLAG_NONE, handleOut);
}
// Creates file.
static uint32_t create_file(const char* path, uint32_t* handleOut) {
static KSTATUS create_file(const char* path, uint32_t* handleOut) {
return NtlOpenFile(SysSvFromCstr(path), SYS_FILE_ACCESS_WRITE | SYS_FILE_ACCESS_QUERY,
SYS_FILE_CREATE_ALWAYS, SYS_FILE_FLAG_NONE, handleOut);
}
// Opens dir.
static uint32_t open_dir(const char* path, uint32_t* handleOut) {
static KSTATUS open_dir(const char* path, uint32_t* handleOut) {
return NtlOpenDir(SysSvFromCstr(path), SYS_DIR_ACCESS_ENUMERATE | SYS_DIR_ACCESS_OPEN,
SYS_DIR_FLAG_NONE, handleOut);
}
// Updates cwd.
static uint32_t set_cwd(const char* path) {
static KSTATUS set_cwd(const char* path) {
return NtlSetCurrentDirectory(SysSvFromCstr(path));
}
// Releases file.
static uint32_t delete_file(const char* path) {
static KSTATUS delete_file(const char* path) {
return NtlDeleteFile(SysSvFromCstr(path));
}
@@ -759,6 +759,13 @@ static bool readLine(char* buf, int len) {
break;
}
if (key == INPUT_KEY_ESCAPE) {
shellEditorReplaceLine(&editor, "");
historyCursor = gHistoryCount;
historyDraft[0] = '\0';
continue;
}
if (key == INPUT_KEY_BACKSPACE) {
if (editor.Cursor > 0)
(void)shellEditorReplaceRange(&editor, editor.Cursor - 1, editor.Cursor, "");
@@ -1007,7 +1014,7 @@ static void cmd_stats(void) {
SYS_PTE_STATS pte;
SYS_SURFACE_STATS surface;
SYS_EXCEPTION_STATS exceptionStats;
uint32_t status;
KSTATUS status;
status = SysQueryKernelStats(SYS_KERNEL_STATS_SCHEDULER, &sched, sizeof(sched), NULL);
if (status != 0) {
@@ -1410,7 +1417,7 @@ static void cmd_stats(void) {
// Implements the cmd time operation.
static void cmd_time(void) {
SYS_SYSTEM_TIME t;
uint32_t status = SysGetSystemTime(&t);
KSTATUS status = SysGetSystemTime(&t);
if (status != 0) {
print("time: failed: ");
printUInt(status);
@@ -1470,7 +1477,7 @@ static void printDisplayStats(const char* title, const DISPLAY_STATS* st) {
// Implements the cmd display operation.
static void cmd_display(void) {
SYS_DISPLAY_INFO info;
uint32_t status = SysQueryDisplayInfo(&info);
KSTATUS status = SysQueryDisplayInfo(&info);
if (status != 0) {
print("display: query failed: ");
printUInt(status);
@@ -1495,7 +1502,7 @@ typedef struct SHELL_FB_BENCH_RESULT {
uint32_t Width;
uint32_t Height;
uint32_t Frames;
uint32_t Status;
KSTATUS Status;
uint64_t ElapsedTicks;
uint64_t Frequency;
uint64_t CommitBytes;
@@ -1548,7 +1555,7 @@ static void shellRunFramebufferBenchmark(uint32_t width,
create.Flags = SYS_SURFACE_FLAG_NONE;
create.HandleOut = &surface;
uint32_t status = SysCreateSurface(&create);
KSTATUS status = SysCreateSurface(&create);
if (status != NTLSTATUS_SUCCESS || !surface) {
result->Status = status ? status : NTLSTATUS_FAILURE;
return;
@@ -1619,7 +1626,7 @@ static void shellPrintFramebufferBenchmark(const char* name,
// Benchmarks surface commit bookkeeping without implying physical presentation.
static void cmd_surfbench(void) {
SYS_DISPLAY_INFO info;
uint32_t status = SysQueryDisplayInfo(&info);
KSTATUS status = SysQueryDisplayInfo(&info);
if (status != NTLSTATUS_SUCCESS) {
print("surfbench: display query failed status=0x"); printHex32(status); print("\n");
return;
@@ -1763,7 +1770,7 @@ static void cmd_ps(void) {
SYS_PROCESS_INFO procs[MAX_PROCS];
size_t count = 0;
uint32_t status = SysGetProcessList(procs, MAX_PROCS, &count);
KSTATUS status = SysGetProcessList(procs, MAX_PROCS, &count);
if (status != 0) {
print("ps: failed to retrieve process list\n");
return;
@@ -1826,7 +1833,7 @@ static void cmd_threads(const char* args) {
SYS_THREAD_INFO threads[MAX_THREADS];
size_t count = 0;
uint32_t status = SysGetThreadList(pid, threads, MAX_THREADS, &count);
KSTATUS status = SysGetThreadList(pid, threads, MAX_THREADS, &count);
if (status != 0) {
print("threads: query failed status=");
printUInt(status);
@@ -1890,7 +1897,7 @@ static void cmd_kill(const char* args) {
if (!parseUInt(args, &pid)) { print("kill: usage: kill <pid>\n"); return; }
uint32_t hProc = 0;
uint32_t status = SysOpenProcess(pid, SYS_PROCESS_RIGHT_TERMINATE, &hProc);
KSTATUS status = SysOpenProcess(pid, SYS_PROCESS_RIGHT_TERMINATE, &hProc);
if (status == 0) {
status = SysKillProcess(hProc, (int32_t)NTLSTATUS_PROCESS_KILLED);
SysCloseHandle(hProc);
@@ -1957,7 +1964,7 @@ static int shellCompareDirEntries(const SYS_DIR_ENTRY* a, const SYS_DIR_ENTRY* b
}
// Allocates a directory-entry array from VM so large listings do not consume stack.
static uint32_t shellAllocDirEntries(uint32_t capacity, SYS_DIR_ENTRY** entriesOut) {
static KSTATUS shellAllocDirEntries(uint32_t capacity, SYS_DIR_ENTRY** entriesOut) {
void* base = 0;
size_t bytes = (size_t)capacity * sizeof(SYS_DIR_ENTRY);
size_t pages = (bytes + 4095u) / 4096u;
@@ -1971,7 +1978,7 @@ static uint32_t shellAllocDirEntries(uint32_t capacity, SYS_DIR_ENTRY** entriesO
req.PageCount = pages;
req.BaseOut = &base;
uint32_t status = SysAllocVm(&req);
KSTATUS status = SysAllocVm(&req);
if (status != 0 || !base) {
*entriesOut = 0;
return status ? status : 1;
@@ -1982,11 +1989,11 @@ static uint32_t shellAllocDirEntries(uint32_t capacity, SYS_DIR_ENTRY** entriesO
}
// Grows a directory-entry array while preserving already-read entries.
static uint32_t shellGrowDirEntries(SYS_DIR_ENTRY** entries, uint32_t* capacity, uint32_t count) {
static KSTATUS shellGrowDirEntries(SYS_DIR_ENTRY** entries, uint32_t* capacity, uint32_t count) {
uint32_t oldCapacity = *capacity;
uint32_t newCapacity = oldCapacity ? oldCapacity * 2u : SHELL_DIR_INITIAL_CAPACITY;
SYS_DIR_ENTRY* next = 0;
uint32_t status = shellAllocDirEntries(newCapacity, &next);
KSTATUS status = shellAllocDirEntries(newCapacity, &next);
if (status != 0)
return status;
@@ -2080,7 +2087,7 @@ static void cmd_dir(const char* path) {
const char* target = (path && *path != '\0') ? path : ".";
if (shellTryResourceDir(target)) return;
uint32_t st = open_dir(target, &hDir);
KSTATUS st = open_dir(target, &hDir);
if (st != 0) {
print("dir: failed to open directory, status=0x");
printHex32(st);
@@ -2163,11 +2170,11 @@ static bool shellIsKeyDown(INPUT_KEY key) {
}
// Waits for a foreground process while polling Ctrl-C without consuming child input.
static uint32_t waitForegroundProcess(uint32_t hProc) {
static KSTATUS waitForegroundProcess(uint32_t hProc) {
bool sentBreak = false;
while (true) {
uint32_t status = SysWaitSingle(hProc,
KSTATUS status = SysWaitSingle(hProc,
SYS_WAIT_FLAG_NONE,
SHELL_FOREGROUND_POLL_MS);
if (status == NTLSTATUS_SUCCESS)
@@ -2179,7 +2186,7 @@ static uint32_t waitForegroundProcess(uint32_t hProc) {
if (!sentBreak && (modifiers & INPUT_MOD_CTRL) &&
shellIsKeyDown(INPUT_KEY_C)) {
print("^C\n");
uint32_t killStatus = SysKillProcess(
KSTATUS killStatus = SysKillProcess(
hProc,
(int32_t)NTLSTATUS_PROCESS_KILLED);
if (killStatus != NTLSTATUS_SUCCESS) {
@@ -2194,65 +2201,65 @@ static uint32_t waitForegroundProcess(uint32_t hProc) {
}
// Run one command.
static int runCommand(const char* cmd) {
if (!cmd || *cmd == '\0') return 0;
if (strcmp(cmd, "exit") == 0) return 1;
if (strcmp(cmd, "help") == 0) { cmd_help(); return 0; }
if (strcmp(cmd, "clear") == 0) { (void)NtlConsoleClear(SYS_HANDLE_INVALID, 0x012456); return 0; }
static bool runCommand(const char* cmd) {
if (!cmd || *cmd == '\0') return false;
if (strcmp(cmd, "exit") == 0) return true;
if (strcmp(cmd, "help") == 0) { cmd_help(); return false; }
if (strcmp(cmd, "clear") == 0) { (void)NtlConsoleClear(SYS_HANDLE_INVALID, 0x012456); return false; }
if (strncmp(cmd, "crash", 5) == 0) {
// Check the sub-option trailing "crash " (offset 6).
if (strcmp(cmd + 6, "void") == 0) {
// Jumping into the void.
void (*invalid_func)(void) = NULL;
invalid_func();
return 0;
return false;
}
else if (strcmp(cmd + 6, "noncanonical") == 0) {
// Non-canonical pointer dereference.
volatile int* ptr = (volatile int*)0x4242424242424242ULL;
*ptr = 1337;
return 0;
return false;
}
else if (strcmp(cmd + 6, "ud2") == 0) {
__ud2();
return 0;
return false;
}
else if (strcmp(cmd + 6, "nx") == 0) {
// NX / DEP Violation.
unsigned char code[] = { 0xC3 };
void (*execute_stack)(void) = (void (*)(void))code;
execute_stack();
return 0;
return false;
}
else if (strcmp(cmd + 6, "divzero") == 0) {
// Division by zero.
volatile int zero = 0;
volatile int result = 1 / zero;
(void)result;
return 0;
return false;
}
else {
// Default fallback if just "crash" or an unknown sub-option is passed.
*(volatile int*)0 = 42;
return 0;
return false;
}
}
if (strcmp(cmd, "mem") == 0) { cmd_mem(); return 0; }
if (strcmp(cmd, "time") == 0 || strcmp(cmd, "date") == 0) { cmd_time(); return 0; }
if (strcmp(cmd, "display") == 0 || strcmp(cmd, "gpu") == 0) { cmd_display(); return 0; }
if (strcmp(cmd, "surfbench") == 0) { cmd_surfbench(); return 0; }
if (strcmp(cmd, "volume") == 0) { cmd_volume(""); return 0; }
if (strncmp(cmd, "volume ", 7) == 0) { cmd_volume(cmd + 7); return 0; }
if (strcmp(cmd, "stats") == 0 || strcmp(cmd, "telemetry") == 0) { cmd_stats(); return 0; }
if (strcmp(cmd, "ps") == 0) { cmd_ps(); return 0; }
if (strncmp(cmd, "threads ", 8) == 0) { cmd_threads(cmd + 8); return 0; }
if (strncmp(cmd, "kill ", 5) == 0) { cmd_kill(cmd + 5); return 0; }
if (strcmp(cmd, "dir") == 0) { cmd_dir("."); return 0; }
if (strncmp(cmd, "dir ", 4) == 0) { cmd_dir(cmd + 4); return 0; }
if (strncmp(cmd, "cd ", 3) == 0) { if (set_cwd(cmd + 3) != 0) print("cd: failed\n"); return 0; }
if (strncmp(cmd, "del ", 4) == 0) { delete_file(cmd + 4); return 0; }
if (strncmp(cmd, "type ", 5) == 0) { cmd_type(cmd + 5); return 0; }
if (strncmp(cmd, "write ", 6) == 0) { cmd_write(cmd + 6); return 0; }
if (strcmp(cmd, "mem") == 0) { cmd_mem(); return false; }
if (strcmp(cmd, "time") == 0 || strcmp(cmd, "date") == 0) { cmd_time(); return false; }
if (strcmp(cmd, "display") == 0 || strcmp(cmd, "gpu") == 0) { cmd_display(); return false; }
if (strcmp(cmd, "surfbench") == 0) { cmd_surfbench(); return false; }
if (strcmp(cmd, "volume") == 0) { cmd_volume(""); return false; }
if (strncmp(cmd, "volume ", 7) == 0) { cmd_volume(cmd + 7); return false; }
if (strcmp(cmd, "stats") == 0 || strcmp(cmd, "telemetry") == 0) { cmd_stats(); return false; }
if (strcmp(cmd, "ps") == 0) { cmd_ps(); return false; }
if (strncmp(cmd, "threads ", 8) == 0) { cmd_threads(cmd + 8); return false; }
if (strncmp(cmd, "kill ", 5) == 0) { cmd_kill(cmd + 5); return false; }
if (strcmp(cmd, "dir") == 0) { cmd_dir("."); return false; }
if (strncmp(cmd, "dir ", 4) == 0) { cmd_dir(cmd + 4); return false; }
if (strncmp(cmd, "cd ", 3) == 0) { if (set_cwd(cmd + 3) != 0) print("cd: failed\n"); return false; }
if (strncmp(cmd, "del ", 4) == 0) { delete_file(cmd + 4); return false; }
if (strncmp(cmd, "type ", 5) == 0) { cmd_type(cmd + 5); return false; }
if (strncmp(cmd, "write ", 6) == 0) { cmd_write(cmd + 6); return false; }
// Make a local copy of the command line so we can mutate it safely if needed
char modifiedCmd[MAX_CMD];
@@ -2275,7 +2282,7 @@ static int runCommand(const char* cmd) {
}
char program[MAX_CMD];
if (!extractProgramPath(modifiedCmd, program, sizeof(program))) return 0;
if (!extractProgramPath(modifiedCmd, program, sizeof(program))) return false;
uint32_t hProc;
const char* launchFailureStage = NULL;
@@ -2289,7 +2296,7 @@ static int runCommand(const char* cmd) {
SysCloseHandle(hProc);
} else {
// Foreground mode: Wait for completion and flush standard keyboard stream.
uint32_t waitStatus = waitForegroundProcess(hProc);
KSTATUS waitStatus = waitForegroundProcess(hProc);
if (waitStatus != NTLSTATUS_SUCCESS) {
print("shell: wait failed: ");
printUInt(waitStatus);
@@ -2322,7 +2329,7 @@ static int runCommand(const char* cmd) {
printStatus(launchStatus);
print("\n");
}
return 0;
return false;
}
// Runs the requested operation.