refactor syscall ABI and FAT32 driver to use request structs and string views natively, enforce handle access rights on object lookup, add scheduler statistics tracking, fix KiSchedule to prevent 50% idle throttling on CPU-bound threads, better document x64 initial user stack alignment, fix process teardown to properly signal exit events and manage thread counts, optimize doom file I/O with a custom handle struct to internally track position and size, add SubsystemData to TEB for generic thread-local state, apply PAGE_NX to non-executable PE sections in the loader, update native apps, tests, and shells to match new APIs, update kernel32 directory retrieval.
This commit is contained in:
1 parent
603fbdfab1
commit
e1248f4afe
43 files changed
+2892
-1857
No files matched your search
+62
-27
@@ -19,7 +19,8 @@ int _fltused;
|
||||
// ---------------------------------------------------------------------------
|
||||
static void doom_print_wrapper(const char* msg)
|
||||
{
|
||||
SysWriteConsole(msg, strlen(msg));
|
||||
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(msg) };
|
||||
SysWriteConsole(&req);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -42,74 +43,108 @@ static void doom_free_wrapper(void* ptr)
|
||||
// ---------------------------------------------------------------------------
|
||||
// File I/O wrappers
|
||||
// ---------------------------------------------------------------------------
|
||||
typedef struct DOOM_FILE_HANDLE {
|
||||
uint32_t Handle;
|
||||
uint64_t Pos;
|
||||
uint64_t Size;
|
||||
} DOOM_FILE_HANDLE;
|
||||
|
||||
static void* doom_open_wrapper(const char* path, const char* mode)
|
||||
{
|
||||
uint32_t handle = 0;
|
||||
uint32_t result;
|
||||
|
||||
SYS_PATH_HANDLE_REQUEST req = { SysSvFromCstr(path), &handle };
|
||||
if (mode[0] == 'w') {
|
||||
result = SysCreateFile(path, &handle);
|
||||
result = SysCreateFile(&req);
|
||||
} else {
|
||||
result = SysOpenFile(path, &handle);
|
||||
result = SysOpenFile(&req);
|
||||
}
|
||||
if (result != 0) return 0;
|
||||
|
||||
DOOM_FILE_HANDLE* f = (DOOM_FILE_HANDLE*)SysAlloc(sizeof(DOOM_FILE_HANDLE));
|
||||
if (!f) {
|
||||
SysCloseHandle(handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (result == 0) ? (void*)(uintptr_t)handle : 0;
|
||||
f->Handle = handle;
|
||||
f->Pos = 0;
|
||||
f->Size = SysGetFileSize(handle);
|
||||
return f;
|
||||
}
|
||||
|
||||
static void doom_close_wrapper(void* handle)
|
||||
{
|
||||
SysCloseHandle((uint32_t)(uintptr_t)handle);
|
||||
if (!handle) return;
|
||||
DOOM_FILE_HANDLE* f = (DOOM_FILE_HANDLE*)handle;
|
||||
SysCloseHandle(f->Handle);
|
||||
SysFree(f);
|
||||
}
|
||||
|
||||
static int doom_read_wrapper(void* handle, void* buf, int count)
|
||||
{
|
||||
if (!handle || count <= 0) return 0;
|
||||
DOOM_FILE_HANDLE* f = (DOOM_FILE_HANDLE*)handle;
|
||||
size_t read = 0;
|
||||
SysReadFile((uint32_t)(uintptr_t)handle, buf, (size_t)count, &read);
|
||||
SysReadFile(f->Handle, buf, (size_t)count, &read);
|
||||
f->Pos += read;
|
||||
if (f->Pos > f->Size) f->Size = f->Pos;
|
||||
return (int)read;
|
||||
}
|
||||
|
||||
static int doom_write_wrapper(void* handle, const void* buf, int count)
|
||||
{
|
||||
if (!handle || count <= 0) return 0;
|
||||
DOOM_FILE_HANDLE* f = (DOOM_FILE_HANDLE*)handle;
|
||||
size_t written = 0;
|
||||
SysWriteFile((uint32_t)(uintptr_t)handle, buf, (size_t)count, &written);
|
||||
SysWriteFile(f->Handle, buf, (size_t)count, &written);
|
||||
f->Pos += written;
|
||||
if (f->Pos > f->Size) f->Size = f->Pos;
|
||||
return (int)written;
|
||||
}
|
||||
|
||||
static int doom_seek_wrapper(void* handle, int offset, doom_seek_t origin)
|
||||
{
|
||||
uint32_t h = (uint32_t)(uintptr_t)handle;
|
||||
uint64_t absolute_offset = 0;
|
||||
if (!handle) return -1;
|
||||
DOOM_FILE_HANDLE* f = (DOOM_FILE_HANDLE*)handle;
|
||||
int64_t base = 0;
|
||||
|
||||
switch (origin) {
|
||||
case DOOM_SEEK_SET:
|
||||
absolute_offset = (uint64_t)offset;
|
||||
case DOOM_SEEK_SET:
|
||||
base = 0;
|
||||
break;
|
||||
case DOOM_SEEK_CUR:
|
||||
absolute_offset = SysGetFilePos(h) + offset;
|
||||
case DOOM_SEEK_CUR:
|
||||
base = (int64_t)f->Pos;
|
||||
break;
|
||||
case DOOM_SEEK_END:
|
||||
absolute_offset = SysGetFileSize(h) + offset;
|
||||
case DOOM_SEEK_END:
|
||||
base = (int64_t)f->Size;
|
||||
break;
|
||||
default:
|
||||
absolute_offset = (uint64_t)offset;
|
||||
default:
|
||||
base = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
SysSeekFile(h, absolute_offset);
|
||||
|
||||
int64_t target = base + (int64_t)offset;
|
||||
if (target < 0) target = 0;
|
||||
|
||||
uint32_t s = SysSeekFile(f->Handle, (uint64_t)target);
|
||||
if (s != 0) return -1;
|
||||
f->Pos = (uint64_t)target;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int doom_tell_wrapper(void* handle)
|
||||
{
|
||||
return (int)SysGetFilePos((uint32_t)(uintptr_t)handle);
|
||||
if (!handle) return -1;
|
||||
return (int)((DOOM_FILE_HANDLE*)handle)->Pos;
|
||||
}
|
||||
|
||||
static int doom_eof_wrapper(void* handle)
|
||||
{
|
||||
uint32_t h = (uint32_t)(uintptr_t)handle;
|
||||
uint64_t size = SysGetFileSize(h);
|
||||
uint64_t pos = SysGetFilePos(h);
|
||||
return (pos >= size) ? 1 : 0;
|
||||
if (!handle) return 1;
|
||||
DOOM_FILE_HANDLE* f = (DOOM_FILE_HANDLE*)handle;
|
||||
return (f->Pos >= f->Size) ? 1 : 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -305,9 +340,9 @@ static int build_argv_from_command_line(const char* cmdline, char* storage, size
|
||||
// ---------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
const char* cmdline = SysGetPeb()->CommandLine;
|
||||
const char* cmdline = SysGetPeb()->CommandLine.Data;
|
||||
|
||||
SysWriteConsole("doom: starting\n", 15);
|
||||
do { SYS_WRITE_CONSOLE_REQUEST req = { SYS_SV_LITERAL("doom: starting\n") }; SysWriteConsole(&req); } while (0);
|
||||
|
||||
// Wire up PureDOOM core mechanics
|
||||
doom_set_print(doom_print_wrapper);
|
||||
@@ -339,7 +374,7 @@ int main(void)
|
||||
int argc = build_argv_from_command_line(cmdline, argvStorage, sizeof(argvStorage), argv, 32);
|
||||
doom_init(argc, argv, 0);
|
||||
|
||||
SysWriteConsole("doom: entering game loop\n", 25);
|
||||
do { SYS_WRITE_CONSOLE_REQUEST req = { SYS_SV_LITERAL("doom: entering game loop\n") }; SysWriteConsole(&req); } while (0);
|
||||
|
||||
// Core execution loop
|
||||
while (1) {
|
||||
|
||||
Reference in new issue
Block a user