sgx_time.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "platform_api_vmcore.h"
  6. #define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
  7. #define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
  8. int ocall_clock_gettime(int *p_ret, unsigned clock_id,
  9. void *tp_buf, unsigned int tp_buf_size);
  10. int ocall_clock_getres(int *p_ret, int clock_id,
  11. void *res_buf, unsigned int res_buf_size);
  12. int ocall_utimensat(int *p_ret, int dirfd, const char *pathname,
  13. const void *times_buf, unsigned int times_buf_size,
  14. int flags);
  15. int ocall_futimens(int *p_ret, int fd,
  16. const void *times_buf, unsigned int times_buf_size);
  17. int ocall_clock_nanosleep(int *p_ret, unsigned clock_id, int flags,
  18. const void *req_buf, unsigned int req_buf_size,
  19. const void *rem_buf, unsigned int rem_buf_size);
  20. uint64
  21. os_time_get_boot_microsecond()
  22. {
  23. /* TODO */
  24. return 0;
  25. }
  26. int clock_getres(int clock_id, struct timespec *res)
  27. {
  28. int ret;
  29. if (ocall_clock_getres(&ret, clock_id, (void *)res,
  30. sizeof(struct timespec)) != SGX_SUCCESS) {
  31. TRACE_OCALL_FAIL();
  32. return -1;
  33. }
  34. if (ret == -1)
  35. errno = get_errno();
  36. return ret;
  37. }
  38. int clock_gettime(clockid_t clock_id, struct timespec *tp)
  39. {
  40. int ret;
  41. if(ocall_clock_gettime(&ret, clock_id, (void *)tp,
  42. sizeof(struct timespec)) != SGX_SUCCESS) {
  43. TRACE_OCALL_FAIL();
  44. return -1;
  45. }
  46. if (ret == -1)
  47. errno = get_errno();
  48. return ret;
  49. }
  50. int utimensat(int dirfd, const char *pathname,
  51. const struct timespec times[2], int flags)
  52. {
  53. int ret;
  54. if (ocall_utimensat(&ret, dirfd, pathname, (void *)times,
  55. sizeof(struct timespec) * 2,
  56. flags) != SGX_SUCCESS) {
  57. TRACE_OCALL_FAIL();
  58. return -1;
  59. }
  60. if (ret == -1)
  61. errno = get_errno();
  62. return ret;
  63. }
  64. int futimens(int fd, const struct timespec times[2])
  65. {
  66. int ret;
  67. if (ocall_futimens(&ret, fd, (void *)times,
  68. sizeof(struct timespec) * 2) != SGX_SUCCESS) {
  69. TRACE_OCALL_FAIL();
  70. return -1;
  71. }
  72. if (ret == -1)
  73. errno = get_errno();
  74. return ret;
  75. }
  76. int clock_nanosleep(clockid_t clock_id, int flags,
  77. const struct timespec *request,
  78. struct timespec *remain)
  79. {
  80. int ret;
  81. if (ocall_clock_nanosleep(&ret, clock_id, flags, (void *)request,
  82. sizeof(struct timespec),
  83. (void *)remain,
  84. sizeof(struct timespec)) != SGX_SUCCESS) {
  85. TRACE_OCALL_FAIL();
  86. return -1;
  87. }
  88. if (ret == -1)
  89. errno = get_errno();
  90. return ret;
  91. }