Make init execute files from /
This commit is contained in:
+1
-4
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user