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:
1 parent
73abd6f90d
commit
899225f551
57 files changed
+8817
-1216
No files matched your search
@@ -70,8 +70,8 @@ int PosixStatusToErrno(uint32_t s) {
|
||||
}
|
||||
}
|
||||
|
||||
// Locks the process descriptor table.
|
||||
static int PosixFdLock(POSIX_PROCESS_STATE* process) {
|
||||
// Locks one logical process descriptor table.
|
||||
static int PosixFdLock(POSIX_LOGICAL_PROCESS_STATE* process) {
|
||||
if (!process || process->FdLock == SYS_HANDLE_INVALID) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
@@ -84,8 +84,8 @@ static int PosixFdLock(POSIX_PROCESS_STATE* process) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Unlocks the process descriptor table.
|
||||
static void PosixFdUnlock(POSIX_PROCESS_STATE* process) {
|
||||
// Unlocks one logical process descriptor table.
|
||||
static void PosixFdUnlock(POSIX_LOGICAL_PROCESS_STATE* process) {
|
||||
uint32_t status = SysReleaseMutex(process->FdLock);
|
||||
if (status != NTLSTATUS_SUCCESS)
|
||||
errno = PosixStatusToErrno(status);
|
||||
@@ -134,12 +134,12 @@ void PosixFdReleaseServerDescription(uint64_t descriptionId) {
|
||||
(void)PosixRuntimeCallServer(&request, &reply);
|
||||
}
|
||||
|
||||
// Captures process-local descriptor numbers/flags while posixsrv pins unique descriptions.
|
||||
// Captures logical-process descriptor numbers/flags while posixsrv pins unique descriptions.
|
||||
KSTATUS PosixFdCreateInheritanceSnapshot(uint32_t flags, uint64_t* tokenOut) {
|
||||
if (!tokenOut || (flags & ~POSIX_FD_INHERIT_SKIP_CLOEXEC) != 0)
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
*tokenOut = 0;
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (!process) return NTLSTATUS_NOT_FOUND;
|
||||
if (PosixFdLock(process) != 0) return NTLSTATUS_FAILURE;
|
||||
|
||||
@@ -177,30 +177,6 @@ KSTATUS PosixFdCreateInheritanceSnapshot(uint32_t flags, uint64_t* tokenOut) {
|
||||
return NTLSTATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Arms one snapshot to a concrete native child lifetime before the parent returns from spawn.
|
||||
KSTATUS PosixFdArmInheritanceSnapshot(uint64_t token, SYS_HANDLE processHandle) {
|
||||
if (token == 0 || processHandle == SYS_HANDLE_INVALID) return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
NTL_POSIX_REQUEST request;
|
||||
memset(&request, 0, sizeof(request));
|
||||
request.Size = sizeof(request);
|
||||
request.Version = NTL_POSIX_PROTOCOL_VERSION;
|
||||
request.Operation = NTL_POSIX_OP_ARM_FD_INHERITANCE;
|
||||
request.Flags = NTL_POSIX_REQUEST_FLAG_NONE;
|
||||
request.FdInheritanceToken = token;
|
||||
|
||||
SYS_PORT_HANDLE_TRANSFER transfer;
|
||||
memset(&transfer, 0, sizeof(transfer));
|
||||
transfer.Handle = processHandle;
|
||||
transfer.DesiredRights = SYS_RIGHT_QUERY | SYS_RIGHT_WAIT;
|
||||
transfer.Flags = SYS_PORT_TRANSFER_FLAG_NONE;
|
||||
|
||||
NTL_POSIX_REPLY reply;
|
||||
KSTATUS status = PosixRuntimeCallServerWithHandles(&request, &transfer, 1u, &reply);
|
||||
if (!KSUCCESS(status)) return status;
|
||||
return reply.Status;
|
||||
}
|
||||
|
||||
// Cancels one snapshot when native process construction failed before a child could claim it.
|
||||
void PosixFdCancelInheritanceSnapshot(uint64_t token) {
|
||||
if (token == 0) return;
|
||||
@@ -327,13 +303,20 @@ int PosixFdSetStatusFlags(POSIX_OPEN_DESCRIPTION* description, int statusFlags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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 (PosixOpenDescriptionNeedsHandle(description->Type) &&
|
||||
description->KHandle != SYS_HANDLE_INVALID)
|
||||
(void)SysCloseHandle(description->KHandle);
|
||||
free(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 (!description) return;
|
||||
if (_InterlockedDecrement(&description->RefCount) != 0) return;
|
||||
if (PosixOpenDescriptionNeedsHandle(description->Type) &&
|
||||
description->KHandle != SYS_HANDLE_INVALID)
|
||||
(void)SysCloseHandle(description->KHandle);
|
||||
@@ -342,7 +325,7 @@ void PosixFdRelease(POSIX_OPEN_DESCRIPTION* description) {
|
||||
}
|
||||
|
||||
// Installs a description at the lowest free descriptor at or above minFd.
|
||||
static int PosixFdInstall(POSIX_PROCESS_STATE* process,
|
||||
static int PosixFdInstall(POSIX_LOGICAL_PROCESS_STATE* process,
|
||||
POSIX_OPEN_DESCRIPTION* description,
|
||||
int minFd,
|
||||
int descriptorFlags) {
|
||||
@@ -371,7 +354,7 @@ static int PosixFdInstall(POSIX_PROCESS_STATE* process,
|
||||
|
||||
// Creates and installs one new open description.
|
||||
int PosixFdCreate(POSIX_FD_TYPE type, uint32_t khandle, int statusFlags) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (!process) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
@@ -427,7 +410,7 @@ static POSIX_OPEN_DESCRIPTION* PosixOpenDescriptionImport(POSIX_FD_TYPE type,
|
||||
// Installs one process-local wrapper for a server-created shared open description.
|
||||
int PosixFdImport(POSIX_FD_TYPE type, uint32_t khandle, uint64_t descriptionId,
|
||||
NTL_POSIX_SHARED_OPEN_DESCRIPTION* shared, int descriptorFlags) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (!process) { errno = EIO; return -1; }
|
||||
POSIX_OPEN_DESCRIPTION* description =
|
||||
PosixOpenDescriptionImport(type, khandle, descriptionId, shared);
|
||||
@@ -439,7 +422,7 @@ int PosixFdImport(POSIX_FD_TYPE type, uint32_t khandle, uint64_t descriptionId,
|
||||
|
||||
// Acquires a stable reference to the open description backing fd.
|
||||
POSIX_OPEN_DESCRIPTION* PosixFdAcquire(int fd) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (!process || fd < 0 || fd >= POSIX_FD_MAX) {
|
||||
errno = EBADF;
|
||||
return (POSIX_OPEN_DESCRIPTION*)0;
|
||||
@@ -459,7 +442,7 @@ POSIX_OPEN_DESCRIPTION* PosixFdAcquire(int fd) {
|
||||
|
||||
// Removes one descriptor and releases its table-owned reference.
|
||||
int PosixFdClose(int fd) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (!process || fd < 0 || fd >= POSIX_FD_MAX) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
@@ -481,7 +464,7 @@ int PosixFdClose(int fd) {
|
||||
}
|
||||
|
||||
// Installs one fixed standard descriptor during process initialization.
|
||||
static uint32_t PosixFdInstallStandard(POSIX_PROCESS_STATE* process,
|
||||
static uint32_t PosixFdInstallStandard(POSIX_LOGICAL_PROCESS_STATE* process,
|
||||
int fd,
|
||||
POSIX_FD_TYPE type,
|
||||
int statusFlags) {
|
||||
@@ -498,7 +481,7 @@ static uint32_t PosixFdInstallStandard(POSIX_PROCESS_STATE* process,
|
||||
}
|
||||
|
||||
// Reconstructs one exact descriptor table from a server-owned inheritance snapshot.
|
||||
static uint32_t PosixFdImportInheritance(POSIX_PROCESS_STATE* process, uint64_t token) {
|
||||
static uint32_t 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];
|
||||
@@ -650,8 +633,8 @@ static uint32_t PosixFdImportInheritance(POSIX_PROCESS_STATE* process, uint64_t
|
||||
return result;
|
||||
}
|
||||
|
||||
// Initializes the process descriptor table and standard descriptors.
|
||||
uint32_t PosixFdInitializeProcess(POSIX_PROCESS_STATE* process, uint64_t inheritanceToken) {
|
||||
// Initializes one logical process descriptor table and standard descriptors.
|
||||
uint32_t PosixFdInitializeLogicalProcess(POSIX_LOGICAL_PROCESS_STATE* process, uint64_t inheritanceToken) {
|
||||
if (!process)
|
||||
return NTLSTATUS_INVALID_PARAMETER;
|
||||
|
||||
@@ -664,7 +647,7 @@ uint32_t PosixFdInitializeProcess(POSIX_PROCESS_STATE* process, uint64_t inherit
|
||||
|
||||
if (inheritanceToken != 0) {
|
||||
status = PosixFdImportInheritance(process, inheritanceToken);
|
||||
if (status != NTLSTATUS_SUCCESS) PosixFdDestroyProcess(process);
|
||||
if (status != NTLSTATUS_SUCCESS) PosixFdDestroyLogicalProcess(process);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -674,15 +657,13 @@ uint32_t PosixFdInitializeProcess(POSIX_PROCESS_STATE* process, uint64_t inherit
|
||||
if (status == NTLSTATUS_SUCCESS)
|
||||
status = PosixFdInstallStandard(process, 2, PosixFdConsoleWrite, O_WRONLY);
|
||||
if (status != NTLSTATUS_SUCCESS)
|
||||
PosixFdDestroyProcess(process);
|
||||
PosixFdDestroyLogicalProcess(process);
|
||||
return status;
|
||||
}
|
||||
|
||||
// Releases descriptor-table resources during failed process startup.
|
||||
void PosixFdDestroyProcess(POSIX_PROCESS_STATE* process) {
|
||||
if (!process)
|
||||
return;
|
||||
|
||||
void PosixFdDestroyLogicalProcess(POSIX_LOGICAL_PROCESS_STATE* process) {
|
||||
if (!process) return;
|
||||
for (int fd = 0; fd < POSIX_FD_MAX; fd++) {
|
||||
POSIX_OPEN_DESCRIPTION* description = process->FdTable[fd].Description;
|
||||
process->FdTable[fd].Description = (POSIX_OPEN_DESCRIPTION*)0;
|
||||
@@ -695,6 +676,21 @@ void PosixFdDestroyProcess(POSIX_PROCESS_STATE* process) {
|
||||
}
|
||||
}
|
||||
|
||||
// Drops inherited local aliases after borrowed exec without releasing committed server holders.
|
||||
void PosixFdDestroyLogicalProcessLocal(POSIX_LOGICAL_PROCESS_STATE* process) {
|
||||
if (!process) return;
|
||||
for (int fd = 0; fd < POSIX_FD_MAX; fd++) {
|
||||
POSIX_OPEN_DESCRIPTION* description = process->FdTable[fd].Description;
|
||||
process->FdTable[fd].Description = (POSIX_OPEN_DESCRIPTION*)0;
|
||||
process->FdTable[fd].DescriptorFlags = 0;
|
||||
PosixFdReleaseLocal(description);
|
||||
}
|
||||
if (process->FdLock != SYS_HANDLE_INVALID) {
|
||||
(void)SysCloseHandle(process->FdLock);
|
||||
process->FdLock = SYS_HANDLE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
// Duplicates oldfd into the lowest free descriptor at or above minFd.
|
||||
static int PosixFdDuplicateFrom(int oldfd, int minFd) {
|
||||
if (minFd < 0 || minFd >= POSIX_FD_MAX) {
|
||||
@@ -704,7 +700,7 @@ static int PosixFdDuplicateFrom(int oldfd, int minFd) {
|
||||
POSIX_OPEN_DESCRIPTION* description = PosixFdAcquire(oldfd);
|
||||
if (!description)
|
||||
return -1;
|
||||
int result = PosixFdInstall(PosixRuntimeProcessState(), description, minFd, 0);
|
||||
int result = PosixFdInstall(PosixRuntimeLogicalProcessState(), description, minFd, 0);
|
||||
PosixFdRelease(description);
|
||||
return result;
|
||||
}
|
||||
@@ -729,7 +725,7 @@ NTL_POSIX_API int dup2(int oldfd, int newfd) {
|
||||
return newfd;
|
||||
}
|
||||
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (PosixFdLock(process) != 0) {
|
||||
PosixFdRelease(description);
|
||||
return -1;
|
||||
@@ -903,7 +899,7 @@ static int PosixFdControlLock(POSIX_OPEN_DESCRIPTION* description, int command,
|
||||
|
||||
// Implements descriptor and open-description file-control operations.
|
||||
NTL_POSIX_API int fcntl(int fd, int command, ...) {
|
||||
POSIX_PROCESS_STATE* process = PosixRuntimeProcessState();
|
||||
POSIX_LOGICAL_PROCESS_STATE* process = PosixRuntimeLogicalProcessState();
|
||||
if (!process || fd < 0 || fd >= POSIX_FD_MAX) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
|
||||
Reference in new issue
Block a user