From: Matthias Kruk Date: Fri, 4 Oct 2019 06:37:58 +0000 (+0900) Subject: Add process_flookup() and process_get_current() functions X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=6270d592fb1f2ee59d5338f861702bd797763ef3;p=corax Add process_flookup() and process_get_current() functions --- diff --git a/kernel/core/process.c b/kernel/core/process.c index 06b00c8..f57276e 100644 --- a/kernel/core/process.c +++ b/kernel/core/process.c @@ -135,3 +135,35 @@ int process_ffree(process_t *proc, int fd) return(ret_val); } + +int process_flookup(process_t *proc, int procfd) +{ + int ret_val; + + ret_val = -EINVAL; + + if(procfd >= 0 && procfd < (sizeof(proc->p_fds) / sizeof(proc->p_fds[0]))) { + ret_val = -EBADF; + + if(proc->p_fds[procfd].fd_flags & FD_VALID) { + ret_val = proc->p_fds[procfd].fd_socknum; + } + } + + return(ret_val); +} + +process_t* process_get_current(void) +{ + process_t *ret_val; + task_t *ctask; + + ret_val = NULL; + ctask = task_get_current(); + + if(ctask) { + ret_val = (process_t*)ctask->t_proc; + } + + return(ret_val); +} diff --git a/kernel/include/process.h b/kernel/include/process.h index 3b1e566..9c398f7 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -28,5 +28,8 @@ int process_switch(process_t*); int process_falloc(process_t*, int); int process_ffree(process_t*, int); +int process_flookup(process_t*, int); + +process_t* process_get_current(void); #endif /* __PROCESS_H */