Libcxx.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include <stdio.h>
  32. #include "../App.h"
  33. #include "Enclave_u.h"
  34. #include <thread>
  35. /* ecall_libcxx_functions:
  36. * Invokes standard C++11 functions.
  37. */
  38. //This function is part of mutex demo
  39. void demo_counter_without_mutex()
  40. {
  41. sgx_status_t ret = SGX_ERROR_UNEXPECTED;
  42. ret = ecall_mutex_demo_no_protection(global_eid);
  43. if (ret != SGX_SUCCESS)
  44. abort();
  45. }
  46. //This function is part of mutex demo
  47. void demo_counter_mutex()
  48. {
  49. sgx_status_t ret = SGX_ERROR_UNEXPECTED;
  50. ret = ecall_mutex_demo(global_eid);
  51. if (ret != SGX_SUCCESS)
  52. abort();
  53. }
  54. //This function is used by processing thread of condition variable demo
  55. void demo_cond_var_run()
  56. {
  57. sgx_status_t ret = SGX_ERROR_UNEXPECTED;
  58. ret = ecall_condition_variable_run(global_eid);
  59. if (ret != SGX_SUCCESS)
  60. abort();
  61. }
  62. //This function is used by the loader thread of condition variable demo
  63. void demo_cond_var_load()
  64. {
  65. sgx_status_t ret = SGX_ERROR_UNEXPECTED;
  66. ret = ecall_condition_variable_load(global_eid);
  67. if (ret != SGX_SUCCESS)
  68. abort();
  69. }
  70. // Examples for C++11 library and compiler features
  71. void ecall_libcxx_functions(void)
  72. {
  73. sgx_status_t ret = SGX_ERROR_UNEXPECTED;
  74. // Example for lambda function feature:
  75. ret = ecall_lambdas_demo(global_eid);
  76. if (ret != SGX_SUCCESS)
  77. abort();
  78. // Example for auto feature:
  79. ret = ecall_auto_demo(global_eid);
  80. if (ret != SGX_SUCCESS)
  81. abort();
  82. // Example for decltype:
  83. ret = ecall_decltype_demo(global_eid);
  84. if (ret != SGX_SUCCESS)
  85. abort();
  86. // Example for strongly_typed_enum:
  87. ret = ecall_strongly_typed_enum_demo(global_eid);
  88. if (ret != SGX_SUCCESS)
  89. abort();
  90. // Example for range based for loops:
  91. ret = ecall_range_based_for_loops_demo(global_eid);
  92. if (ret != SGX_SUCCESS)
  93. abort();
  94. // Example for static_assert:
  95. ret = ecall_static_assert_demo(global_eid);
  96. if (ret != SGX_SUCCESS)
  97. abort();
  98. // Example for virtual function controls : override, final, default, and delete
  99. ret = ecall_virtual_function_control_demo(global_eid);
  100. if (ret != SGX_SUCCESS)
  101. abort();
  102. // Example for delegating_constructors:
  103. ret = ecall_delegating_constructors_demo(global_eid);
  104. if (ret != SGX_SUCCESS)
  105. abort();
  106. // Example for std::function:
  107. ret = ecall_std_function_demo(global_eid);
  108. if (ret != SGX_SUCCESS)
  109. abort();
  110. // Example for algorithms (std::all_of, std::any_of, std::none_of):
  111. ret = ecall_cxx11_algorithms_demo(global_eid);
  112. if (ret != SGX_SUCCESS)
  113. abort();
  114. // Example for variadic_templates feature:
  115. ret = ecall_variadic_templates_demo(global_eid);
  116. if (ret != SGX_SUCCESS)
  117. abort();
  118. // Example for SFINAE:
  119. ret = ecall_SFINAE_demo(global_eid);
  120. if (ret != SGX_SUCCESS)
  121. abort();
  122. // Example for initializer_list:
  123. ret = ecall_initializer_list_demo(global_eid);
  124. if (ret != SGX_SUCCESS)
  125. abort();
  126. // Example for rvalue:
  127. ret = ecall_rvalue_demo(global_eid);
  128. if (ret != SGX_SUCCESS)
  129. abort();
  130. // Example for nullptr:
  131. ret = ecall_nullptr_demo(global_eid);
  132. if (ret != SGX_SUCCESS)
  133. abort();
  134. // Example for enum class:
  135. ret = ecall_enum_class_demo(global_eid);
  136. if (ret != SGX_SUCCESS)
  137. abort();
  138. // Example for new container classes (unordered_set, unordered_map, unordered_multiset, and unordered_multimap):
  139. ret = ecall_new_container_classes_demo(global_eid);
  140. if (ret != SGX_SUCCESS)
  141. abort();
  142. // Example for tuple:
  143. ret = ecall_tuple_demo(global_eid);
  144. if (ret != SGX_SUCCESS)
  145. abort();
  146. // Example for shared_ptr:
  147. ret = ecall_shared_ptr_demo(global_eid);
  148. if (ret != SGX_SUCCESS)
  149. abort();
  150. // Example for atomic:
  151. ret = ecall_atomic_demo(global_eid);
  152. if (ret != SGX_SUCCESS)
  153. abort();
  154. //The following threads are part of mutex demo
  155. std::thread t1(demo_counter_without_mutex);
  156. std::thread t2(demo_counter_without_mutex);
  157. std::thread t3(demo_counter_without_mutex);
  158. t1.join();
  159. t2.join();
  160. t3.join();
  161. ret = ecall_print_final_value_no_protection(global_eid);
  162. if (ret != SGX_SUCCESS)
  163. abort();
  164. //The following threads are part of mutex demo
  165. std::thread tm1(demo_counter_mutex);
  166. std::thread tm2(demo_counter_mutex);
  167. std::thread tm3(demo_counter_mutex);
  168. tm1.join();
  169. tm2.join();
  170. tm3.join();
  171. ret = ecall_print_final_value_mutex_demo(global_eid);
  172. if (ret != SGX_SUCCESS)
  173. abort();
  174. //The following threads are part of condition variable demo
  175. std::thread th1(demo_cond_var_run);
  176. std::thread th2(demo_cond_var_load);
  177. th2.join();
  178. th1.join();
  179. }