From e1753d6c06bd584f6f30be5fd4d90432f136f248 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 26 May 2022 11:48:14 +0100 Subject: [PATCH] Implemented getpid() and gettid() --- photon/libc/sys/horizon/unistd.c | 23 +++++++++++++++++++++++ photon/libc/sys/horizon/unistd.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/photon/libc/sys/horizon/unistd.c b/photon/libc/sys/horizon/unistd.c index 3382f75..9ab59e5 100644 --- a/photon/libc/sys/horizon/unistd.c +++ b/photon/libc/sys/horizon/unistd.c @@ -1,3 +1,6 @@ +#include +#include +#include #include #include #include @@ -61,3 +64,23 @@ int close(int fd) __set_errno(0); return ret; } + +pid_t getpid(void) +{ + mx_info_task_t task_info; + mx_status_t status = mx_object_get_info( + mx_bootstrap_handle_get(MX_B_TASK_SELF), + MX_INFO_TASK, + &task_info, sizeof task_info); + return status == MX_OK ? task_info.leader_id : (pid_t)-1; +} + +pid_t gettid(void) +{ + mx_info_task_t task_info; + mx_status_t status = mx_object_get_info( + mx_bootstrap_handle_get(MX_B_TASK_SELF), + MX_INFO_TASK, + &task_info, sizeof task_info); + return status == MX_OK ? task_info.id : (pid_t)-1; +} diff --git a/photon/libc/sys/horizon/unistd.h b/photon/libc/sys/horizon/unistd.h index acec6d4..2dce1e4 100644 --- a/photon/libc/sys/horizon/unistd.h +++ b/photon/libc/sys/horizon/unistd.h @@ -18,4 +18,7 @@ extern int close(int fd); extern off_t lseek(int fd, off_t off, int whence); +extern pid_t getpid(void); +extern pid_t gettid(void); + #endif