bh_thread.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "bh_thread.h"
  6. #include "bh_assert.h"
  7. #include "bh_memory.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sgx_thread.h>
  11. int _vm_thread_sys_init()
  12. {
  13. return 0;
  14. }
  15. void vm_thread_sys_destroy(void)
  16. {
  17. }
  18. int _vm_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
  19. void *arg, unsigned int stack_size, int prio)
  20. {
  21. return BHT_ERROR;
  22. // return BHT_OK;
  23. }
  24. int _vm_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
  25. unsigned int stack_size)
  26. {
  27. return _vm_thread_create_with_prio(tid, start, arg, stack_size,
  28. BH_THREAD_DEFAULT_PRIORITY);
  29. }
  30. korp_tid _vm_self_thread()
  31. {
  32. return sgx_thread_self();
  33. }
  34. void vm_thread_exit(void * code)
  35. {
  36. }
  37. // storage for one thread
  38. static __thread void *_tls_store = NULL;
  39. void *_vm_tls_get(unsigned idx)
  40. {
  41. return _tls_store;
  42. }
  43. int _vm_tls_put(unsigned idx, void * tls)
  44. {
  45. _tls_store = tls;
  46. return BHT_OK;
  47. //return BHT_ERROR;
  48. }
  49. int _vm_mutex_init(korp_mutex *mutex)
  50. {
  51. sgx_thread_mutex_t m = SGX_THREAD_MUTEX_INITIALIZER;
  52. *mutex = m;
  53. return BHT_OK;
  54. }
  55. int _vm_recursive_mutex_init(korp_mutex *mutex)
  56. {
  57. sgx_thread_mutex_t m = SGX_THREAD_RECURSIVE_MUTEX_INITIALIZER;
  58. *mutex = m;
  59. return BHT_OK;
  60. }
  61. int _vm_mutex_destroy(korp_mutex *mutex)
  62. {
  63. sgx_thread_mutex_destroy(mutex);
  64. return BHT_OK;
  65. }
  66. /* Returned error (EINVAL, EAGAIN and EDEADLK) from
  67. locking the mutex indicates some logic error present in
  68. the program somewhere.
  69. Don't try to recover error for an existing unknown error.*/
  70. void vm_mutex_lock(korp_mutex *mutex)
  71. {
  72. sgx_thread_mutex_lock(mutex);
  73. }
  74. int vm_mutex_trylock(korp_mutex *mutex)
  75. {
  76. return (sgx_thread_mutex_trylock(mutex) == 0? BHT_OK: BHT_ERROR);
  77. }
  78. /* Returned error (EINVAL, EAGAIN and EPERM) from
  79. unlocking the mutex indicates some logic error present
  80. in the program somewhere.
  81. Don't try to recover error for an existing unknown error.*/
  82. void vm_mutex_unlock(korp_mutex *mutex)
  83. {
  84. sgx_thread_mutex_unlock(mutex);
  85. }
  86. int _vm_sem_init(korp_sem* sem, unsigned int c)
  87. {
  88. return BHT_OK;
  89. //return BHT_ERROR;
  90. }
  91. int _vm_sem_destroy(korp_sem *sem)
  92. {
  93. return BHT_OK;
  94. //return BHT_ERROR;
  95. }
  96. int _vm_sem_wait(korp_sem *sem)
  97. {
  98. return BHT_OK;
  99. //return BHT_ERROR;
  100. }
  101. int _vm_sem_reltimedwait(korp_sem *sem, int mills)
  102. {
  103. return BHT_OK;
  104. //return BHT_ERROR;
  105. }
  106. int _vm_sem_post(korp_sem *sem)
  107. {
  108. return BHT_OK;
  109. //return BHT_ERROR;
  110. }
  111. int _vm_cond_init(korp_cond *cond)
  112. {
  113. return BHT_OK;
  114. //return BHT_ERROR;
  115. }
  116. int _vm_cond_destroy(korp_cond *cond)
  117. {
  118. return BHT_OK;
  119. //return BHT_ERROR;
  120. }
  121. int _vm_cond_wait(korp_cond *cond, korp_mutex *mutex)
  122. {
  123. return BHT_OK;
  124. //return BHT_ERROR;
  125. }
  126. int _vm_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int mills)
  127. {
  128. return BHT_OK;
  129. //return BHT_ERROR;
  130. }
  131. int _vm_cond_signal(korp_cond *cond)
  132. {
  133. return BHT_OK;
  134. //return BHT_ERROR;
  135. }
  136. int _vm_cond_broadcast(korp_cond *cond)
  137. {
  138. return BHT_OK;
  139. //return BHT_ERROR;
  140. }
  141. int _vm_thread_cancel(korp_tid thread)
  142. {
  143. return 0;
  144. }
  145. int _vm_thread_join(korp_tid thread, void **value_ptr, int mills)
  146. {
  147. return 0;
  148. }
  149. int _vm_thread_detach(korp_tid thread)
  150. {
  151. return 0;
  152. }