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

+22 -21
View File
@@ -1,5 +1,7 @@
// POSIX descriptor table and shared open-description implementation.
#include <ntlite/atomic.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@@ -9,7 +11,7 @@
#include "posix_fd.h"
// Maps one native status to the POSIX personality errno space.
int PosixStatusToErrno(uint32_t s) {
int PosixStatusToErrno(KSTATUS s) {
switch (s) {
case NTLSTATUS_SUCCESS: return 0;
case NTLSTATUS_TIMEOUT: return ETIMEDOUT;
@@ -76,7 +78,7 @@ static int PosixFdLock(POSIX_LOGICAL_PROCESS_STATE* process) {
errno = EIO;
return -1;
}
uint32_t status = SysWait(process->FdLock, SYS_WAIT_FLAG_NONE);
KSTATUS status = SysWait(process->FdLock, SYS_WAIT_FLAG_NONE);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
return -1;
@@ -86,13 +88,13 @@ static int PosixFdLock(POSIX_LOGICAL_PROCESS_STATE* process) {
// Unlocks one logical process descriptor table.
static void PosixFdUnlock(POSIX_LOGICAL_PROCESS_STATE* process) {
uint32_t status = SysReleaseMutex(process->FdLock);
KSTATUS status = SysReleaseMutex(process->FdLock);
if (status != NTLSTATUS_SUCCESS)
errno = PosixStatusToErrno(status);
}
// Returns whether one open-description type requires a retained native capability.
static int PosixOpenDescriptionNeedsHandle(POSIX_FD_TYPE type) {
static bool PosixOpenDescriptionNeedsHandle(POSIX_FD_TYPE type) {
return type == PosixFdFile || type == PosixFdSocket ||
type == PosixFdPipeRead || type == PosixFdPipeWrite;
}
@@ -262,15 +264,14 @@ static POSIX_OPEN_DESCRIPTION* PosixOpenDescriptionCreate(POSIX_FD_TYPE type,
// Adds one reference to an open description.
static void PosixFdReference(POSIX_OPEN_DESCRIPTION* description) {
if (description)
_InterlockedIncrement(&description->RefCount);
NtlAtomicIncrement32(&description->RefCount);
}
// Returns one atomic snapshot of server-owned shared open-description status flags.
int PosixFdGetStatusFlags(const POSIX_OPEN_DESCRIPTION* description) {
if (!description || !description->Shared)
return 0;
return (int)_InterlockedCompareExchange(
(volatile long*)&description->Shared->StatusFlags, 0, 0);
return (int)NtlAtomicLoadU32(&description->Shared->StatusFlags);
}
// Applies mutable status flags through posixsrv so native backing and shared state stay serialized.
@@ -306,7 +307,7 @@ int PosixFdSetStatusFlags(POSIX_OPEN_DESCRIPTION* description, int statusFlags)
// Releases one stable local wrapper without changing server holder ownership.
static void PosixFdReleaseLocal(POSIX_OPEN_DESCRIPTION* description) {
if (!description) return;
if (_InterlockedDecrement(&description->RefCount) != 0) return;
if (NtlAtomicDecrement32(&description->RefCount) != 0) return;
if (PosixOpenDescriptionNeedsHandle(description->Type) &&
description->KHandle != SYS_HANDLE_INVALID)
(void)SysCloseHandle(description->KHandle);
@@ -316,7 +317,7 @@ static void PosixFdReleaseLocal(POSIX_OPEN_DESCRIPTION* description) {
// Releases one stable local wrapper and its server holder at the final reference.
void PosixFdRelease(POSIX_OPEN_DESCRIPTION* description) {
if (!description) return;
if (_InterlockedDecrement(&description->RefCount) != 0) return;
if (NtlAtomicDecrement32(&description->RefCount) != 0) return;
if (PosixOpenDescriptionNeedsHandle(description->Type) &&
description->KHandle != SYS_HANDLE_INVALID)
(void)SysCloseHandle(description->KHandle);
@@ -375,8 +376,8 @@ static POSIX_OPEN_DESCRIPTION* PosixOpenDescriptionImport(POSIX_FD_TYPE type,
uint32_t khandle,
uint64_t descriptionId,
NTL_POSIX_SHARED_OPEN_DESCRIPTION* shared) {
int needsHandle = PosixOpenDescriptionNeedsHandle(type);
int isPipe = type == PosixFdPipeRead || type == PosixFdPipeWrite;
bool needsHandle = PosixOpenDescriptionNeedsHandle(type);
bool isPipe = type == PosixFdPipeRead || type == PosixFdPipeWrite;
if (descriptionId == 0 || !shared ||
(needsHandle && khandle == SYS_HANDLE_INVALID) ||
(!needsHandle && khandle != SYS_HANDLE_INVALID) ||
@@ -464,7 +465,7 @@ int PosixFdClose(int fd) {
}
// Installs one fixed standard descriptor during process initialization.
static uint32_t PosixFdInstallStandard(POSIX_LOGICAL_PROCESS_STATE* process,
static KSTATUS PosixFdInstallStandard(POSIX_LOGICAL_PROCESS_STATE* process,
int fd,
POSIX_FD_TYPE type,
int statusFlags) {
@@ -481,7 +482,7 @@ static uint32_t PosixFdInstallStandard(POSIX_LOGICAL_PROCESS_STATE* process,
}
// Reconstructs one exact descriptor table from a server-owned inheritance snapshot.
static uint32_t PosixFdImportInheritance(POSIX_LOGICAL_PROCESS_STATE* process, uint64_t token) {
static KSTATUS PosixFdImportInheritance(POSIX_LOGICAL_PROCESS_STATE* process, uint64_t token) {
if (!process || token == 0) return NTLSTATUS_INVALID_PARAMETER;
NTL_POSIX_FD_MANIFEST_ENTRY manifest[NTL_POSIX_FD_INHERIT_MAX];
@@ -494,7 +495,7 @@ static uint32_t PosixFdImportInheritance(POSIX_LOGICAL_PROCESS_STATE* process, u
uint32_t descriptionCount = 0;
uint32_t descriptionIndex = 0;
uint32_t descriptionTotal = UINT32_MAX;
uint32_t result = NTLSTATUS_SUCCESS;
KSTATUS result = NTLSTATUS_SUCCESS;
for (;;) {
NTL_POSIX_REQUEST request;
@@ -560,7 +561,7 @@ static uint32_t PosixFdImportInheritance(POSIX_LOGICAL_PROCESS_STATE* process, u
}
if (!KSUCCESS(result)) break;
POSIX_FD_TYPE type = (POSIX_FD_TYPE)entry->OpenDescriptionType;
int needsHandle = PosixOpenDescriptionNeedsHandle(type);
bool needsHandle = PosixOpenDescriptionNeedsHandle(type);
SYS_HANDLE handle = SYS_HANDLE_INVALID;
if (needsHandle) {
if (entry->HandleIndex >= handleCount || handleUsed[entry->HandleIndex]) {
@@ -634,12 +635,12 @@ static uint32_t PosixFdImportInheritance(POSIX_LOGICAL_PROCESS_STATE* process, u
}
// Initializes one logical process descriptor table and standard descriptors.
uint32_t PosixFdInitializeLogicalProcess(POSIX_LOGICAL_PROCESS_STATE* process, uint64_t inheritanceToken) {
KSTATUS PosixFdInitializeLogicalProcess(POSIX_LOGICAL_PROCESS_STATE* process, uint64_t inheritanceToken) {
if (!process)
return NTLSTATUS_INVALID_PARAMETER;
uint32_t lock = SYS_HANDLE_INVALID;
uint32_t status = SysCreateMutex(&lock);
KSTATUS status = SysCreateMutex(&lock);
if (status != NTLSTATUS_SUCCESS)
return status;
process->FdLock = lock;
@@ -757,7 +758,7 @@ static int PosixFlockRange(POSIX_OPEN_DESCRIPTION* description,
}
int64_t base = 0;
uint32_t status = NTLSTATUS_SUCCESS;
KSTATUS status = NTLSTATUS_SUCCESS;
if (lock->l_whence == SEEK_CUR) {
uint64_t current = 0;
status = SysGetFilePos(description->KHandle, &current);
@@ -828,7 +829,7 @@ static int PosixFdControlLock(POSIX_OPEN_DESCRIPTION* description, int command,
request.Offset = offset;
request.Length = length;
request.InfoOut = &info;
uint32_t status = SysQueryFileLock(&request);
KSTATUS status = SysQueryFileLock(&request);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
return -1;
@@ -854,7 +855,7 @@ static int PosixFdControlLock(POSIX_OPEN_DESCRIPTION* description, int command,
request.Flags = SYS_FILE_LOCK_FLAG_NONE;
request.Offset = offset;
request.Length = length;
uint32_t status = SysUnlockFile(&request);
KSTATUS status = SysUnlockFile(&request);
if (status == NTLSTATUS_SUCCESS || status == NTLSTATUS_NOT_FOUND)
return 0;
errno = PosixStatusToErrno(status);
@@ -889,7 +890,7 @@ static int PosixFdControlLock(POSIX_OPEN_DESCRIPTION* description, int command,
request.Offset = offset;
request.Length = length;
request.TimeoutMilliseconds = command == F_SETLKW ? SYS_WAIT_TIMEOUT_INFINITE : 0;
uint32_t status = SysLockFile(&request);
KSTATUS status = SysLockFile(&request);
if (status != NTLSTATUS_SUCCESS) {
errno = PosixStatusToErrno(status);
return -1;