utils.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "utils.hpp"
  2. /*
  3. * printf:
  4. * Invokes OCALL to display the enclave buffer to the terminal.
  5. */
  6. void printf(const char *fmt, ...)
  7. {
  8. char buf[BUFSIZ] = {'\0'};
  9. va_list ap;
  10. va_start(ap, fmt);
  11. vsnprintf(buf, BUFSIZ, fmt, ap);
  12. va_end(ap);
  13. ocall_print_string(buf);
  14. }
  15. /*
  16. * printf_with_rtclock:
  17. * Invokes OCALL to display the enclave buffer to the terminal with a
  18. * timestamp and returns the timestamp.
  19. */
  20. unsigned long printf_with_rtclock(const char *fmt, ...)
  21. {
  22. unsigned long ret;
  23. char buf[BUFSIZ] = {'\0'};
  24. va_list ap;
  25. va_start(ap, fmt);
  26. vsnprintf(buf, BUFSIZ, fmt, ap);
  27. va_end(ap);
  28. ocall_print_string_with_rtclock(&ret, buf);
  29. return ret;
  30. }
  31. /*
  32. * printf_with_rtclock_diff:
  33. * Invokes OCALL to display the enclave buffer to the terminal with a
  34. * timestamp and returns the timestamp. Also prints the difference from
  35. * the before timestamp.
  36. */
  37. unsigned long printf_with_rtclock_diff(unsigned long before, const char *fmt, ...)
  38. {
  39. unsigned long ret;
  40. char buf[BUFSIZ] = {'\0'};
  41. va_list ap;
  42. va_start(ap, fmt);
  43. vsnprintf(buf, BUFSIZ, fmt, ap);
  44. va_end(ap);
  45. ocall_print_string_with_rtclock_diff(&ret, buf, before);
  46. return ret;
  47. }