Browse Source

feat(syscall): impl MONOTONIC clock for gettime

greatbridf 11 months ago
parent
commit
b12cf751c9
2 changed files with 7 additions and 3 deletions
  1. 1 0
      gblibc/include/time.h
  2. 6 3
      src/kernel/syscall.cpp

+ 1 - 0
gblibc/include/time.h

@@ -9,6 +9,7 @@ extern "C" {
 #endif
 
 #define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
 typedef int clockid_t;
 
 #ifdef __cplusplus

+ 6 - 3
src/kernel/syscall.cpp

@@ -558,11 +558,14 @@ int _syscall_clock_gettime64(interrupt_stack* data)
     SYSCALL_ARG2(timespec* __user, tp);
 
     // TODO: check privilege of tp
-    if (clk_id != CLOCK_REALTIME || !tp)
+    if ((clk_id != CLOCK_REALTIME && clk_id != CLOCK_MONOTONIC) || !tp) {
+        NOT_IMPLEMENTED;
         return -EINVAL;
+    }
 
-    tp->tv_sec = 10 + current_ticks();
-    tp->tv_nsec = 0;
+    int time = current_ticks();
+    tp->tv_sec = time / 1000;;
+    tp->tv_nsec = 1000000 * (time % 1000);
 
     return 0;
 }