diff options
author | dzwdz | 2023-09-18 16:20:52 +0200 |
---|---|---|
committer | dzwdz | 2023-09-18 16:20:52 +0200 |
commit | 14fd2aecd074fb93bb509df0c1cedd1f1055a4a6 (patch) | |
tree | 10ecb45967748a6b65558074f22c8cdf52ee74ae /src/kernel/syscalls.c | |
parent | 730a929fffbaaaeb20529962654049fe26dd5dde (diff) |
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.
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r-- | src/kernel/syscalls.c | 13 |
1 files changed, 13 insertions, 0 deletions
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; |