| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
- #include "platform_api_vmcore.h"
- #define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
- #define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
- int
- ocall_clock_gettime(int *p_ret, unsigned clock_id, void *tp_buf,
- unsigned int tp_buf_size);
- int
- ocall_clock_getres(int *p_ret, int clock_id, void *res_buf,
- unsigned int res_buf_size);
- int
- ocall_utimensat(int *p_ret, int dirfd, const char *pathname,
- const void *times_buf, unsigned int times_buf_size, int flags);
- int
- ocall_futimens(int *p_ret, int fd, const void *times_buf,
- unsigned int times_buf_size);
- int
- ocall_clock_nanosleep(int *p_ret, unsigned clock_id, int flags,
- const void *req_buf, unsigned int req_buf_size,
- const void *rem_buf, unsigned int rem_buf_size);
- uint64
- os_time_get_boot_us()
- {
- #ifndef SGX_DISABLE_WASI
- struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
- return 0;
- }
- return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
- #else
- return 0;
- #endif
- }
- uint64
- os_time_thread_cputime_us(void)
- {
- #ifndef SGX_DISABLE_WASI
- struct timespec ts;
- if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {
- return 0;
- }
- return ((uint64)ts.tv_sec) * 1000 * 1000 + ((uint64)ts.tv_nsec) / 1000;
- #else
- return 0;
- #endif
- }
- #ifndef SGX_DISABLE_WASI
- int
- clock_getres(int clock_id, struct timespec *res)
- {
- int ret;
- if (ocall_clock_getres(&ret, clock_id, (void *)res, sizeof(struct timespec))
- != SGX_SUCCESS) {
- TRACE_OCALL_FAIL();
- return -1;
- }
- if (ret == -1)
- errno = get_errno();
- return ret;
- }
- int
- clock_gettime(clockid_t clock_id, struct timespec *tp)
- {
- int ret;
- if (ocall_clock_gettime(&ret, clock_id, (void *)tp, sizeof(struct timespec))
- != SGX_SUCCESS) {
- TRACE_OCALL_FAIL();
- return -1;
- }
- if (ret == -1)
- errno = get_errno();
- return ret;
- }
- int
- utimensat(int dirfd, const char *pathname, const struct timespec times[2],
- int flags)
- {
- int ret;
- if (ocall_utimensat(&ret, dirfd, pathname, (void *)times,
- sizeof(struct timespec) * 2, flags)
- != SGX_SUCCESS) {
- TRACE_OCALL_FAIL();
- return -1;
- }
- if (ret == -1)
- errno = get_errno();
- return ret;
- }
- int
- futimens(int fd, const struct timespec times[2])
- {
- int ret;
- if (ocall_futimens(&ret, fd, (void *)times, sizeof(struct timespec) * 2)
- != SGX_SUCCESS) {
- TRACE_OCALL_FAIL();
- return -1;
- }
- if (ret == -1)
- errno = get_errno();
- return ret;
- }
- int
- clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request,
- struct timespec *remain)
- {
- int ret;
- if (ocall_clock_nanosleep(&ret, clock_id, flags, (void *)request,
- sizeof(struct timespec), (void *)remain,
- sizeof(struct timespec))
- != SGX_SUCCESS) {
- TRACE_OCALL_FAIL();
- return -1;
- }
- if (ret == -1)
- errno = get_errno();
- return ret;
- }
- #endif
|