utils.cpp 1.2 KB

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