Compare commits

..

2 Commits

4 changed files with 60 additions and 10 deletions

View File

@ -32,9 +32,12 @@ typedef enum {
SYSCALL_MEMORY_ACCESS = 0x0205,
SYSCALL_PROCESS_CREATE = 0x0301,
SYSCALL_PROCESS_ENVFILE = 0x0302,
SYSCALL_PROCESS_START = 0x0303,
SYSCALL_PROCESS_SIGNAL = 0x0304,
SYSCALL_PROCESS_ENV = 0x0302,
SYSCALL_PROCESS_SIGNAL = 0x0303,
SYSCALL_PROCESS_THREAD_CREATE = 0x0304,
SYSCALL_PROCESS_THREAD_START = 0x0305,
SYSCALL_PROCESS_THREAD_PAUSE = 0x0306,
SYSCALL_PROCESS_THREAD_KILL = 0x0307,
SYSCALL_RUNTIME_LINKER_OPEN = 0x0401,
SYSCALL_RUNTIME_LINKER_CLOSE = 0x0402,

View File

@ -9,7 +9,9 @@ typedef enum {
STATUS_SUCCESS,
STATUS_PERMISSION_DENIED,
STATUS_RESOURCE_NOT_AVAILABLE
STATUS_RESOURCE_NOT_AVAILABLE,
STATUS_NOT_SUPPORTED,
STATUS_GENERIC_ERROR
} status_E;
extern string_t g_status_code_strings[3];

View File

@ -7,6 +7,7 @@
#include "boot/config.h"
#include "platform/interrupts.h"
#include "platform/gdt.h"
#include "platform/syscall.h"
#include "mm/page_frame.h"
#include "mm/page_map.h"
#include "mm/region.h"
@ -64,16 +65,16 @@ void kmain(boot_info_T boot_info) {
log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n");
void* buffer = vfs_resolve_path(&g_root_fs, "/initrd/shell.elf")->cache->buffer;
elf_executable_T* exec = elf_executable_create(buffer);
pid_t proc = process_spawn(PROCESS_KERNEL, "shell", exec, buffer);
pid_t pid;
syscall_perform(SYSCALL_PROCESS_CREATE, (uint64_t)"/initrd/shell.elf", 0, (uint64_t)&pid, 0);
process_T* process = scheduler_get_process(proc);
process_T* process = scheduler_get_process(pid);
thread_start(process->threads);
scheduler_dump_info(scheduler_get_process(PROCESS_KERNEL), 0);
g_tty->output = &process->stdin;
process->stdout = &g_tty->input;
thread_start(thread_spawn(proc, symbol_resolve_from_name(exec->symbols, exec->num_symbols, "_start")->address + MEM_REGION_PROCESS_EXEC));
CORE_HALT_FOREVER
}

View File

@ -207,6 +207,44 @@ void syscall_handle_nx_munmap(cpu_state_T* state) {
state->rax = STATUS_SUCCESS;
}
void syscall_handle_nx_pcreate(cpu_state_T* state) {
string_t path = (string_t)state->rdi; // arg1
uint64_t len = state->rsi; // arg2
pid_t* pid = (pid_t*)state->rdx; // arg3
string_t name = (string_t)state->rcx; // arg4
vfs_node_T* node = vfs_resolve_path(&g_root_fs, path);
if (node == NULL || node->type != VFS_NODE_FILE) {
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
return;
}
uint8_t* buffer = memory_allocate(node->size);
vfs_file_read(node, 0, node->size, buffer);
elf_executable_T* exec = elf_executable_create(buffer);
if (exec == NULL) {
memory_free(buffer);
state->rax = STATUS_NOT_SUPPORTED;
return;
}
if (name == NULL) {
name = path;
}
*pid = process_spawn(scheduler_get_current_process()->id, name, exec, buffer);
if (*pid == PROCESS_NONE) {
state->rax = STATUS_GENERIC_ERROR;
return;
}
void* entry = (void*)(symbol_resolve_from_name(exec->symbols, exec->num_symbols, "_start")->address + MEM_REGION_PROCESS_EXEC);
thread_spawn(*pid, entry);
state->rax = STATUS_SUCCESS;
}
cpu_state_T* syscall_handle(cpu_state_T* state) {
cpu_state_T* return_state = state;
@ -260,6 +298,12 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
}
case SYSCALLS_PROC: {
switch (state->rax) {
case SYSCALL_PROCESS_CREATE: {
syscall_handle_nx_pcreate(state);
break;
}
}
break;
}