shim_time.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * shim_time.c
  17. *
  18. * Implementation of system call "gettimeofday", "time" and "clock_gettime".
  19. */
  20. #include <shim_internal.h>
  21. #include <shim_table.h>
  22. #include <shim_handle.h>
  23. #include <shim_fs.h>
  24. #include <pal.h>
  25. #include <pal_error.h>
  26. #include <errno.h>
  27. int shim_do_gettimeofday (struct __kernel_timeval * tv,
  28. struct __kernel_timezone * tz)
  29. {
  30. if (!tv)
  31. return -EINVAL;
  32. long time = DkSystemTimeQuery();
  33. if (time == -1)
  34. return -PAL_ERRNO;
  35. tv->tv_sec = time / 1000000;
  36. tv->tv_usec = time % 1000000;
  37. return 0;
  38. }
  39. time_t shim_do_time (time_t * tloc)
  40. {
  41. long time = DkSystemTimeQuery();
  42. if (time == -1)
  43. return -PAL_ERRNO;
  44. time_t t = time / 1000000;
  45. if (tloc)
  46. *tloc = t;
  47. return t;
  48. }
  49. int shim_do_clock_gettime (clockid_t which_clock,
  50. struct timespec * tp)
  51. {
  52. /* all clock are the same */
  53. if (!tp)
  54. return -EINVAL;
  55. long time = DkSystemTimeQuery();
  56. if (time == -1)
  57. return -PAL_ERRNO;
  58. tp->tv_sec = time / 1000000;
  59. tp->tv_nsec = (time % 1000000) * 1000;
  60. return 0;
  61. }
  62. int shim_do_clock_getres (clockid_t which_clock,
  63. struct timespec * tp)
  64. {
  65. /* all clock are the same */
  66. if (!tp)
  67. return -EINVAL;
  68. tp->tv_sec = 0;
  69. tp->tv_nsec = 1000;
  70. return 0;
  71. }