major restructuring, prepare for smp
This commit is contained in:
1 parent
b3569a2b90
commit
6bff37746d
229 files changed
+1617
-1489
No files matched your search
@@ -0,0 +1,96 @@
|
||||
// init.c - first user-mode process
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <ntlite/syscall.h>
|
||||
|
||||
#define STATUS_SUCCESS 0u
|
||||
|
||||
void itoa(int num, char* str) {
|
||||
int i = 0;
|
||||
int is_negative = 0;
|
||||
|
||||
// Handle 0 explicitly
|
||||
if (num == 0) {
|
||||
str[i++] = '0';
|
||||
str[i] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle negative numbers
|
||||
if (num < 0) {
|
||||
is_negative = 1;
|
||||
num = -num;
|
||||
}
|
||||
|
||||
// Process individual digits (result is in reverse)
|
||||
while (num != 0) {
|
||||
int rem = num % 10;
|
||||
str[i++] = rem + '0';
|
||||
num = num / 10;
|
||||
}
|
||||
|
||||
if (is_negative) {
|
||||
str[i++] = '-';
|
||||
}
|
||||
|
||||
str[i] = '\0'; // Null terminate
|
||||
|
||||
// Reverse the string
|
||||
int start = 0;
|
||||
int end = i - 1;
|
||||
while (start < end) {
|
||||
char temp = str[start];
|
||||
str[start] = str[end];
|
||||
str[end] = temp;
|
||||
start++;
|
||||
end--;
|
||||
}
|
||||
}
|
||||
|
||||
static void debug_print(const char* s) {
|
||||
SYS_DEBUG_PRINT_REQUEST req = { SysSvFromCstr(s) };
|
||||
(void)SysDebugPrint(&req);
|
||||
}
|
||||
|
||||
void _start(void)
|
||||
{
|
||||
SYS_STRING_VIEW args = SysGetPeb()->CommandLine;
|
||||
uint32_t h = 0;
|
||||
uint32_t s = 0;
|
||||
|
||||
while (true) {
|
||||
debug_print("[init] starting\n");
|
||||
SYS_CREATE_PROCESS_REQUEST cp = { args, SysSvFromParts(0, 0), &h };
|
||||
s = SysCreateProcess(&cp);
|
||||
if (s != STATUS_SUCCESS) {
|
||||
debug_print("[init] FATAL: failed to start!\n");
|
||||
char buffer[12];
|
||||
itoa(s, buffer);
|
||||
debug_print(buffer);
|
||||
debug_print("\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
debug_print("[init] waiting\n");
|
||||
s = SysWaitForProcess(h);
|
||||
if (s != STATUS_SUCCESS)
|
||||
debug_print("[init] WARNING: SysWaitForProcess returned error\n");
|
||||
|
||||
int exitCode = 0;
|
||||
if (SysGetProcessExitCode(h, &exitCode) != STATUS_SUCCESS) {
|
||||
debug_print("[init] WARNING: failed to read exit code\n");
|
||||
exitCode = 1;
|
||||
}
|
||||
|
||||
SysCloseHandle(h);
|
||||
|
||||
if (exitCode == 0)
|
||||
break;
|
||||
|
||||
debug_print("[init] child crashed, restarting\n");
|
||||
}
|
||||
|
||||
debug_print("[init] done\n");
|
||||
SysExitProcess(0);
|
||||
}
|
||||
Reference in new issue
Block a user