infoops.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <bits/alltypes.h>
  2. #include <time.h>
  3. #include <kernel/hw/timer.hpp>
  4. #include <kernel/log.hpp>
  5. #include <kernel/process.hpp>
  6. #include <kernel/syscall.hpp>
  7. #define NOT_IMPLEMENTED not_implemented(__FILE__, __LINE__)
  8. static inline void not_implemented(const char* pos, int line)
  9. {
  10. kmsgf("[kernel] the function at %s:%d is not implemented, killing the pid%d...",
  11. pos, line, current_process->pid);
  12. current_thread->send_signal(SIGSYS);
  13. }
  14. int kernel::syscall::do_clock_gettime(clockid_t clk_id, timespec __user* tp)
  15. {
  16. if (clk_id != CLOCK_REALTIME && clk_id != CLOCK_MONOTONIC) {
  17. NOT_IMPLEMENTED;
  18. return -EINVAL;
  19. }
  20. if (!tp)
  21. return -EFAULT;
  22. auto time = hw::timer::current_ticks();
  23. // TODO: copy_to_user
  24. tp->tv_sec = time / 100;
  25. tp->tv_nsec = 10000000 * (time % 100);
  26. return 0;
  27. }
  28. int kernel::syscall::do_gettimeofday(timeval __user* tv, void __user* tz)
  29. {
  30. // TODO: return time of the day, not time from this boot
  31. if (tz) [[unlikely]]
  32. return -EINVAL;
  33. if (tv) {
  34. // TODO: use copy_to_user
  35. auto ticks = kernel::hw::timer::current_ticks();
  36. tv->tv_sec = ticks / 100;
  37. tv->tv_usec = ticks * 10 * 1000;
  38. }
  39. return 0;
  40. }