Kernel/LibC: add clock_gettime() for CLOCK_MONOTONIC

This gets the number of milliseconds since boot
This commit is contained in:
Bananymous
2023-07-06 00:38:29 +03:00
parent 4086d7c3be
commit 1fb305fa45
7 changed files with 40 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ set(LIBC_SOURCES
sys/stat.cpp
sys/wait.cpp
termios.cpp
time.cpp
unistd.cpp
math.S
icxxabi.cpp

View File

@@ -38,6 +38,7 @@ __BEGIN_DECLS
#define SYS_GET_EGID 31
#define SYS_GET_PWD 32
#define SYS_SET_PWD 33
#define SYS_CLOCK_GETTIME 34
__END_DECLS

8
libc/time.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
int clock_gettime(clockid_t clock_id, struct timespec* tp)
{
return syscall(SYS_CLOCK_GETTIME, clock_id, tp);
}

View File

@@ -244,6 +244,13 @@ long syscall(long syscall, ...)
ret = Kernel::syscall(SYS_SET_PWD, (uintptr_t)path);
break;
}
case SYS_CLOCK_GETTIME:
{
clockid_t clock_id = va_arg(args, clockid_t);
timespec* tp = va_arg(args, timespec*);
ret = Kernel::syscall(SYS_CLOCK_GETTIME, clock_id, (uintptr_t)tp);
break;
}
default:
puts("LibC: Unhandeled syscall");
ret = -ENOSYS;