libc: Add support for the new clock() system call

This commit is contained in:
apio 2022-10-15 13:21:22 +02:00
parent 62a2bcf2ff
commit b1739f7f0d
4 changed files with 35 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#define SYS_exec 12 #define SYS_exec 12
#define SYS_fcntl 13 #define SYS_fcntl 13
#define SYS_mprotect 14 #define SYS_mprotect 14
#define SYS_clock 15
#ifndef __want_syscalls #ifndef __want_syscalls
#ifdef __cplusplus #ifdef __cplusplus

View File

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

11
libs/libc/src/time.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
extern "C"
{
clock_t clock()
{
return syscall(SYS_clock);
}
}

View File

@ -32,6 +32,7 @@ extern "C"
va_start(ap, number); va_start(ap, number);
switch (number) switch (number)
{ {
case SYS_clock:
case SYS_yield: case SYS_yield:
case SYS_gettid: result = __luna_syscall0(number); break; case SYS_gettid: result = __luna_syscall0(number); break;
case SYS_exit: case SYS_exit: