Implemented getpid() and gettid()

This commit is contained in:
2022-05-26 11:48:14 +01:00
parent 8fc4d45edb
commit e1753d6c06
2 changed files with 26 additions and 0 deletions

View File

@@ -1,3 +1,6 @@
#include <magenta/object.h>
#include <magenta/bootstrap.h>
#include <magenta/errors.h>
#include <unistd.h>
#include <errno.h>
#include <mio/fs.h>
@@ -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;
}

View File

@@ -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