Pointers.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 "../App.h"
  32. #include "Enclave_u.h"
  33. /* edger8r_pointer_attributes:
  34. * Invokes the ECALLs declared with pointer attributes.
  35. */
  36. void edger8r_pointer_attributes(void)
  37. {
  38. int val = 0;
  39. sgx_status_t ret = SGX_ERROR_UNEXPECTED;
  40. char c[128] = {0};
  41. size_t len = 0;
  42. memset(c, 0xe, 128);
  43. ret = ecall_pointer_user_check(global_eid, &len, &c, 128);
  44. if (ret != SGX_SUCCESS)
  45. abort();
  46. assert(strcmp(c, "SGX_SUCCESS") == 0);
  47. val = 0;
  48. ret = ecall_pointer_in(global_eid, &val);
  49. if (ret != SGX_SUCCESS)
  50. abort();
  51. assert(val == 0);
  52. val = 0;
  53. ret = ecall_pointer_out(global_eid, &val);
  54. if (ret != SGX_SUCCESS)
  55. abort();
  56. assert(val == 1234);
  57. val = 0;
  58. ret = ecall_pointer_in_out(global_eid, &val);
  59. if (ret != SGX_SUCCESS)
  60. abort();
  61. assert(val == 1234);
  62. ret = ocall_pointer_attr(global_eid);
  63. if (ret != SGX_SUCCESS)
  64. abort();
  65. char str1[] = "1234567890";
  66. ret = ecall_pointer_string(global_eid, str1);
  67. if (ret != SGX_SUCCESS)
  68. abort();
  69. assert(memcmp(str1, "0987654321", strlen(str1)) == 0);
  70. const char str2[] = "1234567890";
  71. ret = ecall_pointer_string_const(global_eid, str2);
  72. if (ret != SGX_SUCCESS)
  73. abort();
  74. assert(memcmp(str2, "1234567890", strlen(str2)) == 0);
  75. char str3[] = "1234567890";
  76. ret = ecall_pointer_size(global_eid, (void*)str3, strlen(str3));
  77. if (ret != SGX_SUCCESS)
  78. abort();
  79. assert(memcmp(str3, "0987654321", strlen(str3)) == 0);
  80. char str4[] = "1234567890";
  81. ret = ecall_pointer_isptr_readonly(global_eid, (buffer_t)str4, strlen(str4));
  82. if (ret != SGX_SUCCESS)
  83. abort();
  84. assert(memcmp(str4, "1234567890", strlen(str4)) == 0);
  85. int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  86. ret = ecall_pointer_count(global_eid, arr, 10);
  87. if (ret != SGX_SUCCESS)
  88. abort();
  89. for (int i = 0; i < 10; i++)
  90. assert(arr[i] == (9 - i));
  91. memset(arr, 0x0, sizeof(arr));
  92. ret = ecall_pointer_sizefunc(global_eid, (char *)arr);
  93. if (ret != SGX_SUCCESS)
  94. abort();
  95. for (int i = 0; i < 10; i++)
  96. assert(arr[i] == i);
  97. return;
  98. }
  99. /* ocall_pointer_user_check:
  100. * The OCALL declared with [user_check].
  101. */
  102. void ocall_pointer_user_check(int* val)
  103. {
  104. (void)val;
  105. assert(val != NULL);
  106. }
  107. /* ocall_pointer_in:
  108. * The OCALL declared with [in].
  109. */
  110. void ocall_pointer_in(int* val)
  111. {
  112. *val = 1234;
  113. }
  114. /* ocall_pointer_out:
  115. * The OCALL declared with [out].
  116. */
  117. void ocall_pointer_out(int* val)
  118. {
  119. *val = 1234;
  120. }
  121. /* ocall_pointer_in_out:
  122. * The OCALL declared with [in, out].
  123. */
  124. void ocall_pointer_in_out(int* val)
  125. {
  126. *val = 1234;
  127. }