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
@@ -27,6 +27,10 @@
|
||||
// Output helpers.
|
||||
static void print(const char* s) { (void)NtlConsoleWrite(SYS_HANDLE_INVALID, s, strlen(s), 0); }
|
||||
|
||||
// Numeric diagnostic helpers used before their definitions.
|
||||
static void printUInt(uint32_t n);
|
||||
static void printHex32(uint32_t v);
|
||||
|
||||
// Opens file.
|
||||
static uint32_t open_file(const char* path, uint32_t* handleOut) {
|
||||
return NtlOpenFile(SysSvFromCstr(path), SYS_FILE_ACCESS_READ | SYS_FILE_ACCESS_QUERY,
|
||||
@@ -55,11 +59,14 @@ static uint32_t delete_file(const char* path) {
|
||||
return NtlDeleteFile(SysSvFromCstr(path));
|
||||
}
|
||||
|
||||
// Creates process.
|
||||
static uint32_t create_process(const char* path, uint32_t* handleOut, const char* cmdline) {
|
||||
// Creates one process and reports which launch stage returned an error.
|
||||
static KSTATUS create_process(const char* path, uint32_t* handleOut, const char* cmdline,
|
||||
const char** failureStageOut) {
|
||||
if (failureStageOut) *failureStageOut = "open-image";
|
||||
|
||||
uint32_t imageFile = SYS_HANDLE_INVALID;
|
||||
uint32_t status = open_file(path, &imageFile);
|
||||
if (status != NTLSTATUS_SUCCESS) return status;
|
||||
KSTATUS status = open_file(path, &imageFile);
|
||||
if (!KSUCCESS(status)) return status;
|
||||
|
||||
NTL_CREATE_SYSTEM_PROCESS_REQUEST req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
@@ -71,8 +78,11 @@ static uint32_t create_process(const char* path, uint32_t* handleOut, const char
|
||||
req.SecurityContext = SYS_SECURITY_CONTEXT_CURRENT;
|
||||
req.ResolveModuleName = NtlResolveSystemModuleName;
|
||||
req.ProcessHandleOut = handleOut;
|
||||
|
||||
if (failureStageOut) *failureStageOut = "process-loader";
|
||||
status = NtlCreateSystemProcess(&req);
|
||||
(void)SysCloseHandle(imageFile);
|
||||
if (KSUCCESS(status) && failureStageOut) *failureStageOut = NULL;
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -151,6 +161,45 @@ static void printUInt64Width(uint64_t n, size_t width) {
|
||||
printUInt64(n);
|
||||
}
|
||||
|
||||
// Names common nt-lite status values used by shell diagnostics.
|
||||
static const char* statusName(KSTATUS status) {
|
||||
switch (status) {
|
||||
case NTLSTATUS_SUCCESS: return "success";
|
||||
case NTLSTATUS_FAILURE: return "failure";
|
||||
case NTLSTATUS_NOT_SUPPORTED: return "not-supported";
|
||||
case NTLSTATUS_INVALID_PARAMETER: return "invalid-parameter";
|
||||
case NTLSTATUS_INVALID_HANDLE: return "invalid-handle";
|
||||
case NTLSTATUS_BUFFER_TOO_SMALL: return "buffer-too-small";
|
||||
case NTLSTATUS_CHECKSUM_MISMATCH: return "checksum-mismatch";
|
||||
case NTLSTATUS_NO_MEMORY: return "no-memory";
|
||||
case NTLSTATUS_ACCESS_DENIED: return "access-denied";
|
||||
case NTLSTATUS_NOT_FOUND: return "not-found";
|
||||
case NTLSTATUS_ALREADY_EXISTS: return "already-exists";
|
||||
case NTLSTATUS_OBJECT_NAME_COLLISION: return "object-name-collision";
|
||||
case NTLSTATUS_OBJECT_DEAD: return "object-dead";
|
||||
case NTLSTATUS_LIMIT_REACHED: return "limit-reached";
|
||||
case NTLSTATUS_INVALID_IMAGE_FORMAT: return "invalid-image-format";
|
||||
case NTLSTATUS_NAME_TOO_LONG: return "name-too-long";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Prints one status with its stable numeric facility/code decomposition.
|
||||
static void printStatus(KSTATUS status) {
|
||||
print("0x");
|
||||
printHex32(status);
|
||||
const char* name = statusName(status);
|
||||
if (name) {
|
||||
print(" (");
|
||||
print(name);
|
||||
print(")");
|
||||
}
|
||||
print(" facility=");
|
||||
printUInt(KSTATUS_FACILITY(status));
|
||||
print(" code=");
|
||||
printUInt(KSTATUS_CODE(status));
|
||||
}
|
||||
|
||||
// Names nt-lite process-abort exit statuses.
|
||||
static const char* processExitStatusName(uint32_t code) {
|
||||
switch (code) {
|
||||
@@ -2229,7 +2278,9 @@ static int runCommand(const char* cmd) {
|
||||
if (!extractProgramPath(modifiedCmd, program, sizeof(program))) return 0;
|
||||
|
||||
uint32_t hProc;
|
||||
if (create_process(program, &hProc, modifiedCmd) == 0) {
|
||||
const char* launchFailureStage = NULL;
|
||||
KSTATUS launchStatus = create_process(program, &hProc, modifiedCmd, &launchFailureStage);
|
||||
if (KSUCCESS(launchStatus)) {
|
||||
if (background) {
|
||||
// Background mode: Clean up the handle immediately and skip waiting.
|
||||
print("[Launched in background, handle: ");
|
||||
@@ -2261,8 +2312,15 @@ static int runCommand(const char* cmd) {
|
||||
INPUT_KEY drainedKey;
|
||||
while (NtlInputPollKeyboard(&drainedKey) == NTLSTATUS_SUCCESS) (void)NtlInputReadKey(&drainedKey);
|
||||
}
|
||||
} else {
|
||||
print("shell: launch failed\n");
|
||||
} else {
|
||||
print("shell: launch failed");
|
||||
if (launchFailureStage) {
|
||||
print(" at ");
|
||||
print(launchFailureStage);
|
||||
}
|
||||
print(": ");
|
||||
printStatus(launchStatus);
|
||||
print("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user