Arrays.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2011-2018 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. /* Test Array Attributes */
  32. #include "sgx_trts.h"
  33. #include "../Enclave.h"
  34. #include "Enclave_t.h"
  35. /* ecall_array_user_check:
  36. * [user_check] parameter does not perfrom copy operations.
  37. */
  38. void ecall_array_user_check(int arr[4])
  39. {
  40. if (sgx_is_outside_enclave(arr, 4 * sizeof(int)) != 1)
  41. abort();
  42. for (int i = 0; i < 4; i++) {
  43. assert(arr[i] == i);
  44. arr[i] = 3 - i;
  45. }
  46. }
  47. /* ecall_array_in:
  48. * arr[] is copied to trusted domain, but modified
  49. * results will not be reflected to the untrusted side.
  50. */
  51. void ecall_array_in(int arr[4])
  52. {
  53. for (int i = 0; i < 4; i++) {
  54. assert(arr[i] == i);
  55. arr[i] = (3 - i);
  56. }
  57. }
  58. /* ecall_array_out:
  59. * arr[] is allocated inside the enclave, and it will be copied
  60. * to the untrusted side
  61. */
  62. void ecall_array_out(int arr[4])
  63. {
  64. for (int i = 0; i < 4; i++) {
  65. /* arr is not copied from App */
  66. assert(arr[i] == 0);
  67. arr[i] = (3 - i);
  68. }
  69. }
  70. /* ecall_array_in_out:
  71. * arr[] will be allocated inside the enclave, content of arr[] will be copied either.
  72. * After ECALL returns, the results will be copied to the outside.
  73. */
  74. void ecall_array_in_out(int arr[4])
  75. {
  76. for (int i = 0; i < 4; i++) {
  77. assert(arr[i] == i);
  78. arr[i] = (3 - i);
  79. }
  80. }
  81. /* ecall_array_isary:
  82. * [isary] tells Edger8r that user defined 'array_t' is an array type.
  83. */
  84. void ecall_array_isary(array_t arr)
  85. {
  86. if (sgx_is_outside_enclave(arr, sizeof(array_t)) != 1)
  87. abort();
  88. int n = sizeof(array_t)/sizeof(arr[0]);
  89. for (int i = 0; i < n; i++) {
  90. assert(arr[i] == i);
  91. arr[i] = (n - 1 - i);
  92. }
  93. }