From 62a2bcf2ff44ff7522887db87b9d5bb6844f33f7 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 15 Oct 2022 13:17:26 +0200 Subject: [PATCH] Kernel: Add a clock() system call --- kernel/include/sys/Syscall.h | 4 +++- kernel/src/sys/Syscall.cpp | 1 + kernel/src/sys/clock.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 kernel/src/sys/clock.cpp diff --git a/kernel/include/sys/Syscall.h b/kernel/include/sys/Syscall.h index c0955388..e92a795f 100644 --- a/kernel/include/sys/Syscall.h +++ b/kernel/include/sys/Syscall.h @@ -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); \ No newline at end of file +void sys_mprotect(Context* context, void* address, size_t size, int prot); +void sys_clock(Context* context); \ No newline at end of file diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index 4369f6a3..243756ed 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -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(); diff --git a/kernel/src/sys/clock.cpp b/kernel/src/sys/clock.cpp new file mode 100644 index 00000000..81123aae --- /dev/null +++ b/kernel/src/sys/clock.cpp @@ -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; +} \ No newline at end of file