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

+21 -19
View File
@@ -1,5 +1,7 @@
// Userspace PE module registry and dependency loader. Kernel process objects know only VADs.
#include <ntlite/atomic.h>
#include <intrin.h>
#include <ntlite/module_loader.h>
#include <ntlite/pe_loader.h>
#include <ntlite/process_loader.h>
@@ -71,8 +73,8 @@ struct NTL_MODULE_CONTEXT {
};
static NTL_MODULE_CONTEXT gCurrentContext;
static volatile long gCurrentContextState;
static volatile long gCurrentContextBusy;
static volatile int32_t gCurrentContextState;
static volatile int32_t gCurrentContextBusy;
// Converts one ASCII character to lowercase for module-name comparisons.
static char NtlpLower(char c) {
@@ -80,14 +82,14 @@ static char NtlpLower(char c) {
}
// Compares one string view with a module name without case sensitivity.
static int NtlpViewEqualsNameI(SYS_STRING_VIEW view, const char* name) {
if (!name) return 0;
static bool NtlpViewEqualsNameI(SYS_STRING_VIEW view, const char* name) {
if (!name) return false;
size_t n = strlen(name);
if (view.Length != n) return 0;
if (view.Length != n) return false;
for (size_t i = 0; i < n; ++i) {
if (NtlpLower(view.Data[i]) != NtlpLower(name[i])) return 0;
if (NtlpLower(view.Data[i]) != NtlpLower(name[i])) return false;
}
return 1;
return true;
}
// Allocates page-backed userspace metadata and clears the complete allocation.
@@ -387,7 +389,7 @@ KSTATUS NtlpCreateModuleContext(SYS_HANDLE processHandle,
SYS_STRING_VIEW fallbackModuleDirectory,
NTL_MODULE_NAME_RESOLVER resolver,
void* resolverContext,
int seedCurrentProcess,
bool seedCurrentProcess,
NTL_MODULE_CONTEXT** contextOut) {
if (!contextOut || primaryModuleRootHandle == SYS_HANDLE_INVALID ||
!SysSvIsValid(primaryModuleDirectory) || SysSvContainsByte(primaryModuleDirectory, '\0') ||
@@ -830,14 +832,14 @@ static KSTATUS NtlpEnsureCurrentContext(SYS_HANDLE moduleRoot,
void* resolverContext,
NTL_MODULE_CONTEXT** contextOut) {
if (!contextOut) return NTLSTATUS_INVALID_PARAMETER;
if (_InterlockedCompareExchange(&gCurrentContextState, 1, 0) == 0) {
if (NtlAtomicCompareExchange32(&gCurrentContextState, 1, 0) == 0) {
NTL_MODULE_CONTEXT* temporary = 0;
KSTATUS status = NtlpCreateModuleContext(SYS_HANDLE_INVALID, moduleRoot, moduleDirectory,
SYS_HANDLE_INVALID, SysSvFromParts((const char*)0, 0),
SYS_HANDLE_INVALID, SysSvFromParts((const char*)0, 0),
resolver, resolverContext, 1, &temporary);
if (!KSUCCESS(status)) {
_InterlockedExchange(&gCurrentContextState, 0);
NtlAtomicExchange32(&gCurrentContextState, 0);
return status;
}
gCurrentContext = *temporary;
@@ -845,10 +847,10 @@ static KSTATUS NtlpEnsureCurrentContext(SYS_HANDLE moduleRoot,
temporary->Head = 0;
temporary->Magic = 0;
NtlpFree(temporary);
_InterlockedExchange(&gCurrentContextState, 2);
NtlAtomicExchange32(&gCurrentContextState, 2);
} else {
while (_InterlockedCompareExchange(&gCurrentContextState, 2, 2) == 1) SysYield();
if (_InterlockedCompareExchange(&gCurrentContextState, 2, 2) != 2)
while (NtlAtomicCompareExchange32(&gCurrentContextState, 2, 2) == 1) SysYield();
if (NtlAtomicCompareExchange32(&gCurrentContextState, 2, 2) != 2)
return NTLSTATUS_FAILURE;
gCurrentContext.PrimaryModuleRootHandle = moduleRoot;
gCurrentContext.PrimaryModuleDirectory = moduleDirectory;
@@ -865,13 +867,13 @@ static KSTATUS NtlpEnsureCurrentContext(SYS_HANDLE moduleRoot,
// Serializes current-process module mutations because loader metadata is process-global.
static KSTATUS NtlpEnterCurrent(void) {
while (_InterlockedCompareExchange(&gCurrentContextBusy, 1, 0) != 0) SysYield();
while (NtlAtomicCompareExchange32(&gCurrentContextBusy, 1, 0) != 0) SysYield();
return NTLSTATUS_SUCCESS;
}
// Releases the current-process loader serialization guard.
static void NtlpLeaveCurrent(void) {
_InterlockedExchange(&gCurrentContextBusy, 0);
NtlAtomicExchange32(&gCurrentContextBusy, 0);
}
// Loads or references one DLL-like PE in the current process through capability-relative I/O.
@@ -961,7 +963,7 @@ KSTATUS NtlLoadModuleAt(const NTL_LOAD_MODULE_AT_REQUEST* request) {
KSTATUS NtlUnloadModule(NTL_MODULE_HANDLE module) {
KSTATUS status = NtlpEnterCurrent();
if (!KSUCCESS(status)) return status;
if (_InterlockedCompareExchange(&gCurrentContextState, 2, 2) != 2) {
if (NtlAtomicCompareExchange32(&gCurrentContextState, 2, 2) != 2) {
NtlpLeaveCurrent();
return NTLSTATUS_INVALID_HANDLE;
}
@@ -985,7 +987,7 @@ KSTATUS NtlGetModuleInfo(NTL_MODULE_HANDLE module, NTL_MODULE_INFO* infoOut) {
if (!infoOut) return NTLSTATUS_INVALID_PARAMETER;
KSTATUS status = NtlpEnterCurrent();
if (!KSUCCESS(status)) return status;
if (_InterlockedCompareExchange(&gCurrentContextState, 2, 2) != 2) {
if (NtlAtomicCompareExchange32(&gCurrentContextState, 2, 2) != 2) {
NtlpLeaveCurrent();
return NTLSTATUS_INVALID_HANDLE;
}
@@ -1001,7 +1003,7 @@ KSTATUS NtlGetModuleExport(NTL_MODULE_HANDLE module, SYS_STRING_VIEW name, uintp
if (!addressOut) return NTLSTATUS_INVALID_PARAMETER;
KSTATUS status = NtlpEnterCurrent();
if (!KSUCCESS(status)) return status;
if (_InterlockedCompareExchange(&gCurrentContextState, 2, 2) != 2) {
if (NtlAtomicCompareExchange32(&gCurrentContextState, 2, 2) != 2) {
NtlpLeaveCurrent();
return NTLSTATUS_INVALID_HANDLE;
}
@@ -1017,7 +1019,7 @@ KSTATUS NtlGetModuleList(NTL_MODULE_INFO* modulesOut, size_t maxCount, size_t* c
if (!countOut) return NTLSTATUS_INVALID_PARAMETER;
KSTATUS status = NtlpEnterCurrent();
if (!KSUCCESS(status)) return status;
if (_InterlockedCompareExchange(&gCurrentContextState, 2, 2) != 2) {
if (NtlAtomicCompareExchange32(&gCurrentContextState, 2, 2) != 2) {
*countOut = 0;
NtlpLeaveCurrent();
return NTLSTATUS_SUCCESS;