sgx_time.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef SGX_DISABLE_WASI
  27. int clock_getres(int clock_id, struct timespec *res)
  28. {
  29. int ret;
  30. if (ocall_clock_getres(&ret, clock_id, (void *)res,
  31. sizeof(struct timespec)) != SGX_SUCCESS) {
  32. TRACE_OCALL_FAIL();
  33. return -1;
  34. }
  35. if (ret == -1)
  36. errno = get_errno();
  37. return ret;
  38. }
  39. int clock_gettime(clockid_t clock_id, struct timespec *tp)
  40. {
  41. int ret;
  42. if(ocall_clock_gettime(&ret, clock_id, (void *)tp,
  43. sizeof(struct timespec)) != SGX_SUCCESS) {
  44. TRACE_OCALL_FAIL();
  45. return -1;
  46. }
  47. if (ret == -1)
  48. errno = get_errno();
  49. return ret;
  50. }
  51. int utimensat(int dirfd, const char *pathname,
  52. const struct timespec times[2], int flags)
  53. {
  54. int ret;
  55. if (ocall_utimensat(&ret, dirfd, pathname, (void *)times,
  56. sizeof(struct timespec) * 2,
  57. flags) != SGX_SUCCESS) {
  58. TRACE_OCALL_FAIL();
  59. return -1;
  60. }
  61. if (ret == -1)
  62. errno = get_errno();
  63. return ret;
  64. }
  65. int futimens(int fd, const struct timespec times[2])
  66. {
  67. int ret;
  68. if (ocall_futimens(&ret, fd, (void *)times,
  69. sizeof(struct timespec) * 2) != SGX_SUCCESS) {
  70. TRACE_OCALL_FAIL();
  71. return -1;
  72. }
  73. if (ret == -1)
  74. errno = get_errno();
  75. return ret;
  76. }
  77. int clock_nanosleep(clockid_t clock_id, int flags,
  78. const struct timespec *request,
  79. struct timespec *remain)
  80. {
  81. int ret;
  82. if (ocall_clock_nanosleep(&ret, clock_id, flags, (void *)request,
  83. sizeof(struct timespec),
  84. (void *)remain,
  85. sizeof(struct timespec)) != SGX_SUCCESS) {
  86. TRACE_OCALL_FAIL();
  87. return -1;
  88. }
  89. if (ret == -1)
  90. errno = get_errno();
  91. return ret;
  92. }
  93. #endif