Partial exec, environment variables
This commit is contained in:
@@ -396,6 +396,101 @@ DEFINE_SYSCALL (sys_exec) {
|
||||
return SYSRESULT (pid);
|
||||
}
|
||||
|
||||
/* int exec_partial (char* volume, char* path) */
|
||||
DEFINE_SYSCALL (sys_exec_partial) {
|
||||
uint64_t fpg, fp;
|
||||
|
||||
uintptr_t uvaddr_volume = a1;
|
||||
uintptr_t uvaddr_path = a2;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
uintptr_t out_paddr;
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
struct procgroup* procgroup = proc->procgroup;
|
||||
int pid1 = proc->pid;
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
spin_lock (&procgroup->lock, &fpg);
|
||||
out_paddr = mm_v2p (&procgroup->pd, uvaddr_path);
|
||||
spin_unlock (&procgroup->lock, fpg);
|
||||
|
||||
if (out_paddr == 0)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
spin_lock (&procgroup->lock, &fpg);
|
||||
|
||||
out_paddr = mm_v2p (&procgroup->pd, uvaddr_volume);
|
||||
|
||||
if (out_paddr == 0) {
|
||||
spin_unlock (&procgroup->lock, fpg);
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
}
|
||||
|
||||
const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
struct proc* new = proc_from_file (proc, volume, path, rctx);
|
||||
|
||||
if (new == NULL) {
|
||||
spin_unlock (&procgroup->lock, fpg);
|
||||
return SYSRESULT (-ST_EXEC_ERROR);
|
||||
}
|
||||
|
||||
spin_unlock (&procgroup->lock, fpg);
|
||||
|
||||
int pid = new->pid;
|
||||
new->exec_pid = pid1;
|
||||
new->state = PROC_PARTIAL;
|
||||
|
||||
proc_register_partial (new);
|
||||
|
||||
return SYSRESULT (pid);
|
||||
}
|
||||
|
||||
/* int exec_partial_fini (int pid) */
|
||||
DEFINE_SYSCALL (sys_exec_partial_fini) {
|
||||
uint64_t fp, fc;
|
||||
|
||||
int pid = (int)a1;
|
||||
|
||||
struct proc* target_proc = proc_find_pid (pid);
|
||||
|
||||
if (target_proc == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
spin_lock (&target_proc->lock, &fp);
|
||||
|
||||
if (target_proc->state != PROC_PARTIAL) {
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
return SYSRESULT (-ST_NOT_PARTIAL);
|
||||
}
|
||||
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
|
||||
struct cpu* cpu = cpu_find_lightest ();
|
||||
|
||||
spin_lock (&cpu->lock, &fc);
|
||||
spin_lock (&target_proc->lock, &fp);
|
||||
|
||||
target_proc->cpu = cpu;
|
||||
target_proc->state = PROC_READY;
|
||||
|
||||
cpu->proc_run_q_count++;
|
||||
list_append (cpu->proc_run_q, &target_proc->cpu_run_q_link);
|
||||
if (cpu->proc_current == NULL)
|
||||
cpu->proc_current = target_proc;
|
||||
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
spin_unlock (&cpu->lock, fc);
|
||||
|
||||
rctx_insert_cpu (rctx, cpu);
|
||||
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int volume_open (char* volume) */
|
||||
DEFINE_SYSCALL (sys_volume_open) {
|
||||
uint64_t fpg, fp;
|
||||
@@ -688,8 +783,6 @@ DEFINE_SYSCALL (sys_wait_for_pid) {
|
||||
|
||||
/* int kill (int pid) */
|
||||
DEFINE_SYSCALL (sys_kill) {
|
||||
uint64_t fp;
|
||||
|
||||
int pid = (int)a1;
|
||||
|
||||
struct proc* target_proc = proc_find_pid (pid);
|
||||
@@ -810,21 +903,28 @@ DEFINE_SYSCALL (sys_create_volume) {
|
||||
return SYSRESULT (vfs_create_volume (proc, rctx, key, type, device, false));
|
||||
}
|
||||
|
||||
/* int env_set (char* key, void* buffer, size_t size) */
|
||||
/* int env_set (int pid, char* key, void* buffer, size_t size) */
|
||||
DEFINE_SYSCALL (sys_env_set) {
|
||||
uint64_t fp, fpg;
|
||||
|
||||
uintptr_t uvaddr_key = a1;
|
||||
uintptr_t uvaddr_buffer = a2;
|
||||
size_t size = (size_t)a3;
|
||||
int pid = (int)a1;
|
||||
uintptr_t uvaddr_key = a2;
|
||||
uintptr_t uvaddr_buffer = a3;
|
||||
size_t size = (size_t)a4;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
struct proc* target_proc = proc_find_pid (pid);
|
||||
|
||||
if (target_proc == NULL) {
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
}
|
||||
|
||||
uintptr_t out_paddr;
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
struct procgroup* procgroup = proc->procgroup;
|
||||
spin_unlock (&proc->lock, fp);
|
||||
spin_lock (&target_proc->lock, &fp);
|
||||
struct procgroup* procgroup = target_proc->procgroup;
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
|
||||
spin_lock (&procgroup->lock, &fpg);
|
||||
|
||||
@@ -844,24 +944,31 @@ DEFINE_SYSCALL (sys_env_set) {
|
||||
if (buffer == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
return SYSRESULT (proc_env_set (proc, key, buffer, size));
|
||||
return SYSRESULT (proc_env_set (target_proc, key, buffer, size));
|
||||
}
|
||||
|
||||
/* int env_get (char* key, void* buffer, size_t size) */
|
||||
/* int env_get (int pid, char* key, void* buffer, size_t size) */
|
||||
DEFINE_SYSCALL (sys_env_get) {
|
||||
uint64_t fp, fpg;
|
||||
|
||||
uintptr_t uvaddr_key = a1;
|
||||
uintptr_t uvaddr_buffer = a2;
|
||||
size_t size = (size_t)a3;
|
||||
int pid = (int)a1;
|
||||
uintptr_t uvaddr_key = a2;
|
||||
uintptr_t uvaddr_buffer = a3;
|
||||
size_t size = (size_t)a4;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
struct proc* target_proc = proc_find_pid (pid);
|
||||
|
||||
if (target_proc == NULL) {
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
}
|
||||
|
||||
uintptr_t out_paddr;
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
struct procgroup* procgroup = proc->procgroup;
|
||||
spin_unlock (&proc->lock, fp);
|
||||
spin_lock (&target_proc->lock, &fp);
|
||||
struct procgroup* procgroup = target_proc->procgroup;
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
|
||||
spin_lock (&procgroup->lock, &fpg);
|
||||
|
||||
@@ -881,7 +988,7 @@ DEFINE_SYSCALL (sys_env_get) {
|
||||
if (buffer == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
return SYSRESULT (proc_env_set (proc, key, buffer, size));
|
||||
return SYSRESULT (proc_env_set (target_proc, key, buffer, size));
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
@@ -916,6 +1023,8 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_CREATE_VOLUME] = &sys_create_volume,
|
||||
[SYS_ENV_SET] = &sys_env_set,
|
||||
[SYS_ENV_GET] = &sys_env_get,
|
||||
[SYS_EXEC_PARTIAL] = &sys_exec_partial,
|
||||
[SYS_EXEC_PARTIAL_FINI] = &sys_exec_partial_fini,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user