From b1739f7f0db32ce2213f49b89514fcd1819d1595 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 15 Oct 2022 13:21:22 +0200 Subject: [PATCH] libc: Add support for the new clock() system call --- libs/libc/include/luna/syscall.h | 1 + libs/libc/include/time.h | 22 ++++++++++++++++++++++ libs/libc/src/time.cpp | 11 +++++++++++ libs/libc/src/unistd.cpp | 1 + 4 files changed, 35 insertions(+) create mode 100644 libs/libc/src/time.cpp diff --git a/libs/libc/include/luna/syscall.h b/libs/libc/include/luna/syscall.h index f721aa6e..6d92d320 100644 --- a/libs/libc/include/luna/syscall.h +++ b/libs/libc/include/luna/syscall.h @@ -16,6 +16,7 @@ #define SYS_exec 12 #define SYS_fcntl 13 #define SYS_mprotect 14 +#define SYS_clock 15 #ifndef __want_syscalls #ifdef __cplusplus diff --git a/libs/libc/include/time.h b/libs/libc/include/time.h index e69de29b..a59e7a89 100644 --- a/libs/libc/include/time.h +++ b/libs/libc/include/time.h @@ -0,0 +1,22 @@ +#ifndef _TIME_H +#define _TIME_H + +typedef long int clock_t; +typedef long int time_t; + +#define CLOCKS_PER_SEC 1000 + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Returns a number representing how much CPU time has been used by this process. Divide this by CLOCKS_PER_SEC to + * get the value in seconds. */ + clock_t clock(void); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/libs/libc/src/time.cpp b/libs/libc/src/time.cpp new file mode 100644 index 00000000..205a6668 --- /dev/null +++ b/libs/libc/src/time.cpp @@ -0,0 +1,11 @@ +#include +#include +#include + +extern "C" +{ + clock_t clock() + { + return syscall(SYS_clock); + } +} \ No newline at end of file diff --git a/libs/libc/src/unistd.cpp b/libs/libc/src/unistd.cpp index 0b2b85e2..86ac5df3 100644 --- a/libs/libc/src/unistd.cpp +++ b/libs/libc/src/unistd.cpp @@ -32,6 +32,7 @@ extern "C" va_start(ap, number); switch (number) { + case SYS_clock: case SYS_yield: case SYS_gettid: result = __luna_syscall0(number); break; case SYS_exit: