diff --git a/kernel/syscall/dev.c b/kernel/syscall/dev.c index 911cc10..00011da 100644 --- a/kernel/syscall/dev.c +++ b/kernel/syscall/dev.c @@ -15,7 +15,8 @@ int32_t SYSCALL2(sys_dev_gethandle, dev1, devname1) { int32_t ret = E_OK; spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); char *ident = (char *)devname1; @@ -108,7 +109,8 @@ int32_t SYSCALL4(sys_dev_cmd, dev1, cmd1, argbuf1, len1) { int32_t ret = E_OK; spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); if (devh == NULL) { diff --git a/kernel/syscall/fs.c b/kernel/syscall/fs.c index 3218ae4..0337665 100644 --- a/kernel/syscall/fs.c +++ b/kernel/syscall/fs.c @@ -8,6 +8,7 @@ #include "kprintf.h" #include "proc/proc.h" #include "spinlock/spinlock.h" +#include "util/util.h" #define _MP_MAX 0xff #define _PATH_MAX VFS_PATH_MAX @@ -35,7 +36,8 @@ int32_t SYSCALL2(sys_fs_openf, opath1, oflags1) { } spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); for (size_t i = 0; i < PROC_VFSHANDLES_MAX; i++) { @@ -62,7 +64,8 @@ int32_t SYSCALL1(sys_fs_closef, fsh1) { } spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); VfsObj *vobj = proc->vobjs[fsh]; @@ -99,7 +102,8 @@ int32_t SYSCALL4(sys_fs_write, fsh1, buffer1, len1, off1) { } spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); VfsObj *vobj = proc->vobjs[fsh]; @@ -134,7 +138,8 @@ int32_t SYSCALL4(sys_fs_read, fsh1, buffer1, len1, off1) { } spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); VfsObj *vobj = proc->vobjs[fsh]; diff --git a/kernel/syscall/ipcpipe.c b/kernel/syscall/ipcpipe.c index 0597efc..fd20dc7 100644 --- a/kernel/syscall/ipcpipe.c +++ b/kernel/syscall/ipcpipe.c @@ -15,9 +15,7 @@ int32_t SYSCALL4(sys_ipc_piperead, pid1, pipenum1, buffer1, len1) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - spinlock_acquire(&PROCS.spinlock); - pid = PROCS.current->pid; - spinlock_release(&PROCS.spinlock); + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); @@ -61,9 +59,7 @@ int32_t SYSCALL4(sys_ipc_pipewrite, pid1, pipenum1, buffer1, len1) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - spinlock_acquire(&PROCS.spinlock); - pid = PROCS.current->pid; - spinlock_release(&PROCS.spinlock); + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); @@ -106,7 +102,8 @@ int32_t SYSCALL1(sys_ipc_pipemake, pipenum1) { int32_t ret = E_OK; spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); if (pipenum >= PROC_PIPEHANDLES_MAX) { @@ -147,7 +144,8 @@ int32_t SYSCALL1(sys_ipc_pipedelete, pipenum1) { int32_t ret = E_OK; spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); if (pipenum >= PROC_PIPEHANDLES_MAX) { @@ -174,9 +172,7 @@ int32_t SYSCALL4(sys_ipc_pipeconnect, pid1, pipenum1, pid2, pipenum2) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - spinlock_acquire(&PROCS.spinlock); - pid = PROCS.current->pid; - spinlock_release(&PROCS.spinlock); + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); diff --git a/kernel/syscall/mman.c b/kernel/syscall/mman.c index 87a85ea..5968b33 100644 --- a/kernel/syscall/mman.c +++ b/kernel/syscall/mman.c @@ -31,7 +31,8 @@ int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) { hal_memset(VIRT(phys), 0, pages * HAL_PAGE_SIZE); spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); uint8_t *virt = NULL; @@ -78,7 +79,8 @@ int32_t SYSCALL1(sys_mman_unmap, addr1) { } spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); VasRange *tofree = NULL; diff --git a/kernel/syscall/proc.c b/kernel/syscall/proc.c index 50b413f..51751d0 100644 --- a/kernel/syscall/proc.c +++ b/kernel/syscall/proc.c @@ -20,7 +20,7 @@ int32_t SYSCALL1(sys_proc_kill, pid1) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - pid = PROCS.current->pid; + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); @@ -38,7 +38,8 @@ int32_t SYSCALL3(sys_proc_spawn, opath1, args1, argslen1) { int32_t ret = E_OK; spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); const char *opath = (const char *)opath1; @@ -87,7 +88,7 @@ int32_t SYSCALL1(sys_proc_pollstate, pid1) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - pid = PROCS.current->pid; + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); @@ -107,15 +108,7 @@ done: } int32_t SYSCALL0(sys_proc_getpid) { - int32_t ret = E_OK; - - spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; - spinlock_release(&PROCS.spinlock); - - ret = proc->pid; - - return ret; + return _caller_pid; } int32_t SYSCALL1(sys_proc_run, pid1) { @@ -143,7 +136,7 @@ int32_t SYSCALL1(sys_proc_arglen, pid1) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - pid = PROCS.current->pid; + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); @@ -160,7 +153,7 @@ int32_t SYSCALL4(sys_proc_argv, pid1, argslen1, argbuf1, maxargs1) { int32_t ret = E_OK; if (pid == (uint64_t)-1) { - pid = PROCS.current->pid; + pid = _caller_pid; } spinlock_acquire(&PROCS.spinlock); diff --git a/kernel/syscall/vfs.c b/kernel/syscall/vfs.c index 5bdb426..803fae4 100644 --- a/kernel/syscall/vfs.c +++ b/kernel/syscall/vfs.c @@ -11,6 +11,7 @@ #include "dev/dev.h" #include "proc/proc.h" #include "storedev/storedev.h" +#include "util/util.h" int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1) { int32_t ret = E_OK; @@ -35,7 +36,8 @@ int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1) { } spinlock_acquire(&PROCS.spinlock); - Proc *proc = PROCS.current; + Proc *proc = NULL; + LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid); spinlock_release(&PROCS.spinlock); Dev *dp = proc->devs[*dev];