feature (syscalls): implemented 'nx_pcreate'
This commit is contained in:
parent
12ff4ec3dd
commit
c0e1b688a4
|
@ -32,9 +32,12 @@ typedef enum {
|
||||||
SYSCALL_MEMORY_ACCESS = 0x0205,
|
SYSCALL_MEMORY_ACCESS = 0x0205,
|
||||||
|
|
||||||
SYSCALL_PROCESS_CREATE = 0x0301,
|
SYSCALL_PROCESS_CREATE = 0x0301,
|
||||||
SYSCALL_PROCESS_ENVFILE = 0x0302,
|
SYSCALL_PROCESS_ENV = 0x0302,
|
||||||
SYSCALL_PROCESS_START = 0x0303,
|
SYSCALL_PROCESS_SIGNAL = 0x0303,
|
||||||
SYSCALL_PROCESS_SIGNAL = 0x0304,
|
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_OPEN = 0x0401,
|
||||||
SYSCALL_RUNTIME_LINKER_CLOSE = 0x0402,
|
SYSCALL_RUNTIME_LINKER_CLOSE = 0x0402,
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "boot/config.h"
|
#include "boot/config.h"
|
||||||
#include "platform/interrupts.h"
|
#include "platform/interrupts.h"
|
||||||
#include "platform/gdt.h"
|
#include "platform/gdt.h"
|
||||||
|
#include "platform/syscall.h"
|
||||||
#include "mm/page_frame.h"
|
#include "mm/page_frame.h"
|
||||||
#include "mm/page_map.h"
|
#include "mm/page_map.h"
|
||||||
#include "mm/region.h"
|
#include "mm/region.h"
|
||||||
|
@ -64,16 +65,16 @@ void kmain(boot_info_T boot_info) {
|
||||||
|
|
||||||
log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n");
|
log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n");
|
||||||
|
|
||||||
void* buffer = vfs_resolve_path(&g_root_fs, "/initrd/shell.elf")->cache->buffer;
|
pid_t pid;
|
||||||
elf_executable_T* exec = elf_executable_create(buffer);
|
syscall_perform(SYSCALL_PROCESS_CREATE, (uint64_t)"/initrd/shell.elf", 0, (uint64_t)&pid, 0);
|
||||||
pid_t proc = process_spawn(PROCESS_KERNEL, "shell", exec, buffer);
|
|
||||||
|
|
||||||
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;
|
g_tty->output = &process->stdin;
|
||||||
process->stdout = &g_tty->input;
|
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
|
CORE_HALT_FOREVER
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,44 @@ void syscall_handle_nx_munmap(cpu_state_T* state) {
|
||||||
state->rax = STATUS_SUCCESS;
|
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* syscall_handle(cpu_state_T* state) {
|
||||||
cpu_state_T* return_state = state;
|
cpu_state_T* return_state = state;
|
||||||
|
@ -260,6 +298,12 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case SYSCALLS_PROC: {
|
case SYSCALLS_PROC: {
|
||||||
|
switch (state->rax) {
|
||||||
|
case SYSCALL_PROCESS_CREATE: {
|
||||||
|
syscall_handle_nx_pcreate(state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue