diff --git a/inc/proc/process.h b/inc/proc/process.h index ec39459..bd7be7c 100644 --- a/inc/proc/process.h +++ b/inc/proc/process.h @@ -29,12 +29,26 @@ typedef enum { } process_blockers_E; typedef enum { - PROCESS_SIGNAL_START, // SIGSTART - PROCESS_SIGNAL_PAUSE, // SIGPAUSE - PROCESS_SIGNAL_KILL, // SIGKILL - PROCESS_SIGNAL_PFAULT, // SIGPFAULT + PROCESS_SIGNAL_START, // SIGSTART + PROCESS_SIGNAL_PAUSE, // SIGPAUSE + PROCESS_SIGNAL_KILL, // SIGKILL + PROCESS_SIGNAL_PAGEFAULT, // SIGPAGEFAULT + PROCESS_SIGNAL_MATHFAULT, // SIGMATHFAULT } process_signals_E; +typedef struct { + file_descriptor_t at_parent; + file_descriptor_t at_child; +}__attribute__((packed)) process_inherit_fd_T; + +typedef struct { + uint8_t privilege_level; + char name[80]; + file_descriptor_t executable; + uint16_t num_inherit_fds; + process_inherit_fd_T inherit_fds[]; +}__attribute__((packed)) process_config_T; + typedef struct process_T process_T; struct process_T { char name [128]; diff --git a/src/boot/kmain.c b/src/boot/kmain.c index ff142c0..4634798 100644 --- a/src/boot/kmain.c +++ b/src/boot/kmain.c @@ -72,21 +72,29 @@ void kmain(boot_info_T boot_info) { log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n"); -// pid_t pid; -// syscall_perform(SYSCALL_PROCESS_CREATE, (uint64_t)"/initrd/shell.elf", 0, (uint64_t)&pid, 0); -// -// process_T* process = scheduler_get_process(pid); -// -// scheduler_dump_info(scheduler_get_process(PROCESS_KERNEL), 0); -// -// g_tty->output = &process->stdin; -// process->stdout = &g_tty->input; -// -// syscall_perform(SYSCALL_PROCESS_SIGNAL, pid, PROCESS_SIGNAL_START, 0, 0); + file_descriptor_t fd; - driver_T* resolved = driver_lookup_pci_device(0x8086, 0x2922); + syscall_perform(SYSCALL_NX_FS_OPEN, (uint64_t)"/initrd/test.elf", 0, &fd, 0); + + pid_t pid; + process_config_T conf = { + .privilege_level = 0, + .executable = fd, + .num_inherit_fds = 0 + }; + memory_copy("test", conf.name, 5); + + syscall_perform(SYSCALL_NX_PROC_CREATE, (uint64_t)&conf, (uint64_t)&pid, 0, 0); + + process_T* process = scheduler_get_process(pid); + + scheduler_dump_info(scheduler_get_process(PROCESS_KERNEL), 0); + + g_tty->output = &process->stdin; + process->stdout = &g_tty->input; + + syscall_perform(SYSCALL_NX_PROC_SIGNAL_SEND, pid, PROCESS_SIGNAL_START, 0, 0); - DEBUG("resolved: 0x%x", resolved); CORE_HALT_FOREVER } diff --git a/src/platform/syscall.c b/src/platform/syscall.c index 2f3dbcf..dc49fe9 100644 --- a/src/platform/syscall.c +++ b/src/platform/syscall.c @@ -210,12 +210,12 @@ void syscall_handle_nx_mem_free(cpu_state_T* state) { void syscall_handle_nx_proc_create(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 + process_config_T* conf = (process_config_T*)state->rdi; // arg1 + pid_t* pid_ptr = (pid_t*)state->rsi; // arg2 - vfs_node_T* node = vfs_resolve_path(&g_root_fs, path); + process_T* parent = scheduler_get_current_process(); + + vfs_node_T* node = file_descriptor_resolve(parent->fd_array, conf->executable); if (node == NULL || node->type != VFS_NODE_FILE) { state->rax = STATUS_RESOURCE_NOT_AVAILABLE; return; @@ -231,18 +231,14 @@ void syscall_handle_nx_proc_create(cpu_state_T* state) { return; } - if (name == NULL) { - name = path; - } - - *pid = process_spawn(scheduler_get_current_process()->id, name, exec, buffer); - if (*pid == PROCESS_NONE) { + *pid_ptr = process_spawn(parent->id, conf->name, exec, buffer); + if (*pid_ptr == PROCESS_NONE) { state->rax = STATUS_GENERIC_ERROR; return; } void* entry = (void*)(symbol_resolve_from_name(&exec->symbol_table, "_start")->address + MEM_REGION_PROCESS_EXEC); - thread_spawn(*pid, entry); + thread_spawn(*pid_ptr, entry); state->rax = STATUS_SUCCESS; }