move POSIX spawn, exec and child tracking into posixsrv, keep process transactions alive across reconnects and preserve stable PIDs across image replacement, flesh out spawn with ordered file actions, process-group selection and signal inheritance, implement execve with bootstrap validation and rollback before retiring the old process, add vfork children that share the native process while keeping separate POSIX descriptor and signal state, replace local spawn bookkeeping with child reaping, nonblocking and process-group waits and orphan cleanup, add signal dispositions, per-thread masks, pending delivery, process/group signalling and alarms, translate native exceptions into POSIX signals and inherit masks when creating threads, make pipe waits interruptible and raise SIGPIPE for broken pipes, pass arguments and environment into main and add getenv/environ, add direct user APC notifications that can run without an alertable wait, add current-thread capabilities and resume-and-wait, let accepted IPC endpoints open restricted peer process capabilities and preserve caller security during spawn and exec, make process preparation reusable and improve DLL lookup across current, executable and fallback directories, move keyboard repeat into RSSRV so PS/2 and USB share one repeat policy, fix video presentation, report launch failure stages and status codes, mooaaar tests.

This commit is contained in:
maksw committed 2026-09-23 09:39:42 +02:00
1 parent 73abd6f90d
commit 899225f551
57 files changed
+8817 -1216

No files matched your search

+77 -12
View File
@@ -13,6 +13,7 @@
#include <sys/wait.h>
#include <pthread.h>
#include <spawn.h>
#include <signal.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <sys/socket.h>
@@ -31,25 +32,27 @@
#define POSIX_PROCESS_STATE_MAGIC 0x50505243u
#define POSIX_THREAD_STATE_MAGIC 0x50544852u
#define POSIX_DLERROR_MAX 160u
#define POSIX_SPAWN_TABLE_SIZE 32u
#define POSIX_PTHREAD_TABLE_SIZE 32u
typedef struct POSIX_SPAWN_ENTRY {
pid_t Pid;
SYS_HANDLE Handle;
uint64_t FdInheritanceToken;
bool Used;
} POSIX_SPAWN_ENTRY;
typedef struct POSIX_PTHREAD_SLOT {
uint32_t Tid;
void* RetVal;
bool Used;
} POSIX_PTHREAD_SLOT;
typedef struct POSIX_SIGNAL_ACTION_STATE {
volatile uintptr_t Handler;
volatile uint64_t Mask;
volatile uint32_t Flags;
uint32_t Reserved;
} POSIX_SIGNAL_ACTION_STATE;
typedef struct POSIX_LOGICAL_PROCESS_STATE {
uint32_t PosixPid;
uint32_t Generation;
SYS_HANDLE FdLock;
POSIX_FD FdTable[POSIX_FD_MAX];
POSIX_SIGNAL_ACTION_STATE SignalActions[NTL_POSIX_SIGNAL_MAX + 1u];
} POSIX_LOGICAL_PROCESS_STATE;
typedef struct POSIX_PROCESS_STATE {
@@ -57,20 +60,40 @@ typedef struct POSIX_PROCESS_STATE {
SYS_PEB* Peb;
SYS_HANDLE ServerEndpoint;
POSIX_LOGICAL_PROCESS_STATE DefaultIdentity;
SYS_HANDLE FdLock;
POSIX_FD FdTable[POSIX_FD_MAX];
POSIX_SPAWN_ENTRY SpawnTable[POSIX_SPAWN_TABLE_SIZE];
uint64_t BootstrapToken;
uint32_t BootstrapPosixPid;
uint32_t BootstrapGeneration;
void* ExceptionHandlerHandle;
int ArgumentCount;
char** Arguments;
char** Environment;
char* CommandLine;
POSIX_PTHREAD_SLOT PthreadTable[POSIX_PTHREAD_TABLE_SIZE];
} POSIX_PROCESS_STATE;
typedef struct POSIX_VFORK_CHILD_STATE {
POSIX_LOGICAL_PROCESS_STATE LogicalProcess;
uint64_t ServerToken;
uint64_t FdInheritanceToken;
uint64_t InitialSignalMask;
} POSIX_VFORK_CHILD_STATE;
typedef struct POSIX_THREAD_STATE {
uint32_t Magic;
int ErrnoValue;
uint32_t NativeThreadId;
uint8_t DlErrorPending;
uint8_t Reserved[3];
uint8_t ServerRegistered;
uint8_t Reserved[2];
volatile uint64_t SignalBlocked;
volatile uint64_t SignalHandlerBlocked;
volatile uint64_t SignalPending;
volatile uint64_t SignalDeliveryCount;
SYS_HANDLE SignalWaitEvent;
char DlError[POSIX_DLERROR_MAX];
POSIX_PROCESS_STATE* NativeProcess;
POSIX_LOGICAL_PROCESS_STATE* LogicalProcess;
POSIX_VFORK_CHILD_STATE* BorrowedChild;
struct passwd PasswordResult;
char PasswordName[NTL_POSIX_IDENTITY_NAME_MAX + 1u];
char PasswordHome[NTL_POSIX_IDENTITY_HOME_MAX + 1u];
@@ -90,9 +113,42 @@ POSIX_PROCESS_STATE* PosixRuntimeProcessState(void);
// Returns the current thread state, attaching lazily when necessary.
POSIX_THREAD_STATE* PosixRuntimeThreadState(void);
// Returns the logical POSIX process selected by the current native thread.
POSIX_LOGICAL_PROCESS_STATE* PosixRuntimeLogicalProcessState(void);
// Attaches POSIX state to the current native TEB.
uint32_t PosixRuntimeAttachThread(void);
// Attaches a thread while seeding its inherited persistent signal mask.
uint32_t PosixRuntimeAttachThreadWithSignalMask(uint64_t signalMask);
// Allocates one borrowed logical child and pins its inherited descriptor snapshot.
KSTATUS PosixVforkBeginBorrowedChild(POSIX_VFORK_CHILD_STATE** childOut);
// Attaches the calling native thread to one prepared borrowed logical child.
KSTATUS PosixVforkAttachBorrowedChild(POSIX_VFORK_CHILD_STATE* child);
// Tears down the calling borrowed thread's local wrappers before its native thread exits.
void PosixVforkDetachBorrowedChildLocal(POSIX_VFORK_CHILD_STATE* child, bool releaseServerHolders);
// Cancels one borrowed child after setup failure or after its native thread has exited.
KSTATUS PosixVforkCancelBorrowedChild(POSIX_VFORK_CHILD_STATE* child);
// Records a genuine borrowed-child exit before its native thread terminates.
KSTATUS PosixVforkRecordExit(POSIX_VFORK_CHILD_STATE* child, int status);
// Returns whether the calling POSIX thread is one borrowed vfork child.
POSIX_VFORK_CHILD_STATE* PosixVforkCurrentBorrowedChild(void);
// Delivers one POSIX signal from the generic user-APC substrate.
void PosixSignalApc(void* signalValue, void* routeValue, void* reserved);
// Dispatches thread-pending signals made deliverable by a mask change.
void PosixSignalDispatchLocalPending(POSIX_THREAD_STATE* thread);
// Installs the POSIX exception-to-signal personality adapter.
KSTATUS PosixSignalInitializeExceptionTranslation(POSIX_PROCESS_STATE* process);
// Releases POSIX state owned by the current native TEB.
void PosixRuntimeDetachThread(void);
@@ -108,6 +164,15 @@ char* PosixRuntimeTakeDlError(void);
// Calls posixsrv over the registered process endpoint and validates one fixed-size reply.
KSTATUS PosixRuntimeCallServer(const NTL_POSIX_REQUEST* request, NTL_POSIX_REPLY* replyOut);
// Calls posixsrv through a temporary registered connection for operations that may block.
KSTATUS PosixRuntimeCallServerBlocking(const NTL_POSIX_REQUEST* request, NTL_POSIX_REPLY* replyOut);
// Calls posixsrv through a temporary registered connection while transferring capabilities.
KSTATUS PosixRuntimeCallServerBlockingWithHandles(const NTL_POSIX_REQUEST* request,
const SYS_PORT_HANDLE_TRANSFER* handles,
uint32_t handleCount,
NTL_POSIX_REPLY* replyOut);
// Calls posixsrv while transferring a bounded set of native capabilities.
KSTATUS PosixRuntimeCallServerWithHandles(const NTL_POSIX_REQUEST* request,
const SYS_PORT_HANDLE_TRANSFER* handles,