feature (syscalls): implemented 'nx_proc_create'

This commit is contained in:
antifallobst 2023-06-10 15:08:31 +02:00
parent 91f7aa4009
commit 81fc9ca9fc
3 changed files with 47 additions and 29 deletions

View File

@ -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];

View File

@ -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
}

View File

@ -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;
}