runtime/native/src/main.cpp
2024-06-08 04:46:07 -04:00

42 lines
933 B
C++

#include <unistd.h>
#include <cstring>
#include <cerrno>
#include <sys/wait.h>
#include "log.h"
#include "memory.h"
#include "trampoline.h"
#include "pipe.h"
#include "signals.h"
// Main
int main(__attribute__((unused)) int argc, char *argv[]) {
// Check Arguments
if (argc < 2) {
ERR("Invalid Arguments");
}
// Setup
init_pipe_common();
// Fork
pid_t pid = fork();
if (pid == -1) {
ERR("Unable To Fork Process: %s", strerror(errno));
} else if (pid == 0) {
// Setup
setpgid(0, 0);
init_pipe_guest();
// Execute Program
execvp(argv[1], (char *const *) &argv[1]);
ERR("Unable To Execute Program: %s: %s", argv[1], strerror(errno));
} else {
// Parent
// Setup Trampoline
init_signals(pid);
init_memory(pid);
init_trampoline();
// Start Pipes
init_pipe_host(pid);
}
}