From 14fd2aecd074fb93bb509df0c1cedd1f1055a4a6 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 18 Sep 2023 16:20:52 +0200 Subject: kernel: implement _sys_time() After some consideration this seems like the most fitting way to handle timekeeping. Directly, the syscall is only useful for keeping time within a single process, but it is meant to be used for e.g. NTP clients, which will provide the real time through the VFS. --- src/kernel/syscalls.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/kernel/syscalls.c') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index a2e0e27..3350796 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -418,6 +418,18 @@ hid_t _sys_getprocfs(int flags) { SYSCALL_RETURN(hid); } +uint64_t _sys_time(int flags) { + if (flags != 0) { + SYSCALL_RETURN(-ENOSYS); + } + + uint64_t now = uptime_ns(); + if (proc_cur->basetime == 0) { + proc_cur->basetime = now; + } + SYSCALL_RETURN(now - proc_cur->basetime); +} + long _sys_execbuf(void __user *ubuf, size_t len) { if (len == 0) SYSCALL_RETURN(0); if (len > EXECBUF_MAX_LEN) @@ -473,6 +485,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) { break; case _SYS_GETPPID: _sys_getppid(); break; case _SYS_WAIT2: _sys_wait2(a, b, (userptr_t)c); break; case _SYS_GETPROCFS: _sys_getprocfs(a); + break; case _SYS_TIME: _sys_time(a); break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b); break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b); break; -- cgit v1.2.3