Make init execute files from /

This commit is contained in:
Mark
2020-01-04 18:41:43 +02:00
parent c5875c4639
commit 091975dd1c
2 changed files with 27 additions and 4 deletions
+1 -4
View File
@@ -42,11 +42,8 @@ static void sys_sigret(void);
__attribute__((noreturn)) void amd64_syscall_yield_stopped(void);
uint64_t syscall_last_time = 0;
uint64_t syscall_count = 0;
intptr_t amd64_syscall(uintptr_t rdi, uintptr_t rsi, uintptr_t rdx, uintptr_t rcx, uintptr_t r10, uintptr_t rax) {
++syscall_count;
asm volatile ("cli");
switch (rax) {
case SYSCALL_NR_READ:
return sys_read((int) rdi, (void *) rsi, (size_t) rdx);
+26
View File
@@ -328,6 +328,32 @@ static int cmd_exec(const char *line) {
}
}
// Try to execute binary from /
struct stat st;
char path[64] = "/";
strcat(path, cmd);
if (stat(path, &st) == 0) {
const char *argp[] = {
e, NULL
};
int pid = fork();
switch (pid) {
case -1:
perror("fork()");
return -1;
case 0:
if (execve(path, argp, NULL) != 0) {
perror("execve()");
}
exit(-1);
default:
// TODO: waitpid
return 0;
}
}
printf("%s: Unknown command\n", cmd);
return -1;
}