sgx_pthread.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include "sgx_pthread.h"
  7. #include "sgx_error.h"
  8. #define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
  9. #define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
  10. int ocall_pthread_rwlock_init(int *p_ret, void **rwlock, void *attr);
  11. int ocall_pthread_rwlock_destroy(int *p_ret, void **rwlock);
  12. int ocall_pthread_rwlock_rdlock(int *p_ret, void **rwlock);
  13. int ocall_pthread_rwlock_wrlock(int *p_ret, void **rwlock);
  14. int ocall_pthread_rwlock_unlock(int *p_ret, void **rwlock);
  15. int pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr)
  16. {
  17. int ret = -1;
  18. if (ocall_pthread_rwlock_init(&ret, (void **)rwlock, NULL)
  19. != SGX_SUCCESS) {
  20. TRACE_OCALL_FAIL();
  21. return -1;
  22. }
  23. (void)attr;
  24. return ret;
  25. }
  26. int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
  27. {
  28. int ret = -1;
  29. if (ocall_pthread_rwlock_destroy(&ret, (void *)*rwlock) != SGX_SUCCESS) {
  30. TRACE_OCALL_FAIL();
  31. }
  32. return ret;
  33. }
  34. int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
  35. {
  36. int ret = -1;
  37. if (ocall_pthread_rwlock_rdlock(&ret, (void*)*rwlock) != SGX_SUCCESS) {
  38. TRACE_OCALL_FAIL();
  39. }
  40. return ret;
  41. }
  42. int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
  43. {
  44. int ret = -1;
  45. if (ocall_pthread_rwlock_wrlock(&ret, (void*)*rwlock) != SGX_SUCCESS) {
  46. TRACE_OCALL_FAIL();
  47. }
  48. return ret;
  49. }
  50. int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
  51. {
  52. int ret = -1;
  53. if (ocall_pthread_rwlock_unlock(&ret, (void*)*rwlock) != SGX_SUCCESS) {
  54. TRACE_OCALL_FAIL();
  55. }
  56. return ret;
  57. }