Kernel: Add a clock() system call

This commit is contained in:
apio 2022-10-15 13:17:26 +02:00
parent 3a9dddaa57
commit 62a2bcf2ff
3 changed files with 13 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#define SYS_exec 12
#define SYS_fcntl 13
#define SYS_mprotect 14
#define SYS_clock 15
namespace Syscall
{
@ -39,4 +40,5 @@ void sys_close(Context* context, int fd);
void sys_seek(Context* context, int fd, long offset, int whence);
void sys_exec(Context* context, const char* pathname);
void sys_fcntl(Context* context, int fd, int command, uintptr_t arg);
void sys_mprotect(Context* context, void* address, size_t size, int prot);
void sys_mprotect(Context* context, void* address, size_t size, int prot);
void sys_clock(Context* context);

View File

@ -26,6 +26,7 @@ void Syscall::entry(Context* context)
case SYS_exec: sys_exec(context, (const char*)context->rdi); break;
case SYS_fcntl: sys_fcntl(context, (int)context->rdi, (int)context->rsi, context->rdx); break;
case SYS_mprotect: sys_mprotect(context, (void*)context->rdi, context->rsi, (int)context->rdx); break;
case SYS_clock: sys_clock(context); break;
default: context->rax = -ENOSYS; break;
}
VMM::exit_syscall_context();

9
kernel/src/sys/clock.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "interrupts/Context.h"
#include "thread/Scheduler.h"
void sys_clock(Context* context)
{
Task* current_task = Scheduler::current_task();
context->rax = (long)current_task->cpu_time;
return;
}