From 6ac57a2f5cb8d713e3a7787b19ead888030683d8 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 22 Oct 2022 14:26:42 +0200 Subject: [PATCH] libc: Add support for pstat() --- libs/libc/include/luna/pstat.h | 36 +++++++++++++++++++++++++++++++++ libs/libc/include/sys/syscall.h | 1 + libs/libc/src/luna/pstat.cpp | 24 ++++++++++++++++++++++ libs/libc/src/syscall.cpp | 1 + 4 files changed, 62 insertions(+) create mode 100644 libs/libc/include/luna/pstat.h create mode 100644 libs/libc/src/luna/pstat.cpp diff --git a/libs/libc/include/luna/pstat.h b/libs/libc/include/luna/pstat.h new file mode 100644 index 00000000..be582f08 --- /dev/null +++ b/libs/libc/include/luna/pstat.h @@ -0,0 +1,36 @@ +#ifndef _LUNA_PSTAT_H +#define _LUNA_PSTAT_H + +#include + +struct pstat +{ + pid_t pt_pid; + pid_t pt_ppid; + char pt_name[128]; + int pt_state; + pid_t pt_time; +}; + +#define PT_IDLE 0 +#define PT_RUNNING 1 +#define PT_SLEEPING 2 +#define PT_ZOMBIE 3 +#define PT_WAITING 4 + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Returns information about the process with PID pid in buf, if buf is non-null. Luna-specific. */ + pid_t pstat(pid_t pid, struct pstat* buf); + + /* Returns a string representation of the process state in buf. */ + const char* pstname(struct pstat* buf); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/libs/libc/include/sys/syscall.h b/libs/libc/include/sys/syscall.h index 5f00f903..0966b6c1 100644 --- a/libs/libc/include/sys/syscall.h +++ b/libs/libc/include/sys/syscall.h @@ -22,5 +22,6 @@ #define SYS_waitpid 18 #define SYS_access 19 #define SYS_fstat 20 +#define SYS_pstat 21 #endif \ No newline at end of file diff --git a/libs/libc/src/luna/pstat.cpp b/libs/libc/src/luna/pstat.cpp new file mode 100644 index 00000000..99ee0299 --- /dev/null +++ b/libs/libc/src/luna/pstat.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +extern "C" +{ + pid_t pstat(pid_t pid, struct pstat* buf) + { + return syscall(SYS_pstat, pid, buf); + } + + const char* pstname(struct pstat* buf) + { + switch (buf->pt_state) + { + case PT_IDLE: return "Idle"; + case PT_RUNNING: return "Running"; + case PT_SLEEPING: return "Sleeping"; + case PT_WAITING: return "Waiting"; + case PT_ZOMBIE: return "Zombie"; + default: return "Unknown"; + } + } +} \ No newline at end of file diff --git a/libs/libc/src/syscall.cpp b/libs/libc/src/syscall.cpp index 0f7a363b..ad26bd66 100644 --- a/libs/libc/src/syscall.cpp +++ b/libs/libc/src/syscall.cpp @@ -24,6 +24,7 @@ extern "C" long syscall(long number, ...) case SYS_munmap: case SYS_access: case SYS_fstat: + case SYS_pstat: case SYS_open: { arg arg0 = va_arg(ap, arg); arg arg1 = va_arg(ap, arg);