Fix stream life-time race condition by reversing ownership
This commit is contained in:
@@ -60,7 +60,7 @@ struct proc* proc_from_elf(uint8_t* elf_contents) {
|
||||
proc->pdata.regs.rip = aux.entry;
|
||||
fx_init(proc->pdata.fx_env);
|
||||
|
||||
proc->exec_pid = -1;
|
||||
proc->exec_pid = proc->pid;
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
@@ -770,17 +770,11 @@ DEFINE_SYSCALL(sys_stream_write) {
|
||||
return SYSRESULT(ST_OK);
|
||||
}
|
||||
|
||||
/* int stream_read (int pgid, int rid, void* buffer, size_t size) */
|
||||
/* int stream_read (int rid, void* buffer, size_t size) */
|
||||
DEFINE_SYSCALL(sys_stream_read) {
|
||||
int pgid = (int)a1;
|
||||
int rid = (int)a2;
|
||||
uintptr_t uvaddr_buffer = a3;
|
||||
size_t buffer_size = (size_t)a4;
|
||||
|
||||
struct procgroup* target_procgroup = procgroup_find(pgid);
|
||||
|
||||
if (target_procgroup == NULL)
|
||||
return SYSRESULT(-ST_NOT_FOUND);
|
||||
int rid = (int)a1;
|
||||
uintptr_t uvaddr_buffer = a2;
|
||||
size_t buffer_size = (size_t)a3;
|
||||
|
||||
struct procgroup* procgroup = proc->procgroup;
|
||||
|
||||
@@ -789,7 +783,7 @@ DEFINE_SYSCALL(sys_stream_read) {
|
||||
if (buffer == NULL)
|
||||
return SYSRESULT(-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
struct proc_resource* stream_resource = proc_find_resource(target_procgroup, rid);
|
||||
struct proc_resource* stream_resource = proc_find_resource(procgroup, rid);
|
||||
|
||||
if (stream_resource == NULL)
|
||||
return SYSRESULT(-ST_NOT_FOUND);
|
||||
@@ -893,6 +887,13 @@ DEFINE_SYSCALL(sys_get_cmdline) {
|
||||
return SYSRESULT(procgroup->uvaddr_cmdline);
|
||||
}
|
||||
|
||||
/* int proc_is_alive(int pid) */
|
||||
DEFINE_SYSCALL(sys_proc_is_alive) {
|
||||
int pid = (int)a1;
|
||||
|
||||
return SYSRESULT(proc_find_pid(pid) != NULL ? 1 : 0);
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_QUIT] = &sys_quit,
|
||||
[SYS_TEST] = &sys_test,
|
||||
@@ -934,6 +935,7 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_VOLUME_DELETE] = &sys_volume_delete,
|
||||
[SYS_DATE_TIME] = &sys_date_time,
|
||||
[SYS_GET_CMDLINE] = &sys_get_cmdline,
|
||||
[SYS_PROC_IS_ALIVE] = &sys_proc_is_alive,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler(int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user