Pointers.edl 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. /* Pointers.edl - Samples for pointer attributes. */
  32. enclave {
  33. /*
  34. * Following keywords/attributes are supported for pointers in Edger8r:
  35. * in, out, user_check,
  36. * string, wstring,
  37. * const, size, count, isptr, readonly
  38. */
  39. trusted {
  40. /*
  41. * [user_check]:
  42. * the pointer won't be validated, and the buffer pointed by
  43. * 'val' is not copied into the enclave either. But Enclave
  44. * can modify the memory pointed by 'val'.
  45. */
  46. public size_t ecall_pointer_user_check([user_check] void *val, size_t sz);
  47. /*
  48. * [in]:
  49. * buffer with the same size will be allocated inside the enclave,
  50. * content pointed by 'val' will be copied into the new allocated
  51. * memory inside. Any changes performed inside the enclave will not
  52. * affect the buffer outside.
  53. */
  54. public void ecall_pointer_in([in] int *val);
  55. /*
  56. * [out]:
  57. * buffer with the same size will be allocated inside the enclave,
  58. * but the content pointed by 'val' won't be copied. But after return,
  59. * the buffer inside the enclave will copied into outside 'val'.
  60. */
  61. public void ecall_pointer_out([out] int *val);
  62. /*
  63. * [in, out]:
  64. * buffer with the same size will be allocated inside the enclave,
  65. * the content pointed by 'val' will be copied either. After return,
  66. * the buffer inside the enclave will by copied into outside 'val' again.
  67. */
  68. public void ecall_pointer_in_out([in, out] int *val);
  69. /*
  70. * [string]:
  71. * the attribute tells Edger8r 'str' is NULL terminated string, so strlen
  72. * will be used to count the length of buffer pointed by 'str'.
  73. */
  74. public void ecall_pointer_string([in, out, string] char *str);
  75. /*
  76. * [const]:
  77. * the attribute tells Edger8r the buffer pointed by 'str' cannot be modified,
  78. * so users cannot decorate 'str' with [out] attribute anymore.
  79. */
  80. public void ecall_pointer_string_const([in, string] const char *str);
  81. /*
  82. * [size]:
  83. * the attribute tells Edger8r the length of buffer in byte pointed by 'ptr'
  84. * (shall be copied or not).
  85. * Note: Users shall not specify [size] on [string] parameters.
  86. */
  87. public void ecall_pointer_size([in, out, size=len] void *ptr, size_t len);
  88. /*
  89. * [count]:
  90. * the attribute tells Edger8r the number of integers to be copied from 'arr'.
  91. */
  92. public void ecall_pointer_count([in, out, count=cnt] int *arr, int cnt);
  93. /*
  94. * [isptr]:
  95. * tells Edger8r the user defined type is a pointer;
  96. * [readonly]:
  97. * forbids the buffer allocated inside the enclave to be copied back to App
  98. * (cannot use with [out]).
  99. */
  100. public void ecall_pointer_isptr_readonly([in, isptr, readonly, size=len] buffer_t buf, size_t len);
  101. };
  102. /*
  103. * Users can define multiple trusted/untrusted blocks,
  104. * edger8r will merged them into one trusted/untrusted block.
  105. */
  106. trusted {
  107. /*
  108. * Test pointer attributes in OCALLs
  109. */
  110. public void ocall_pointer_attr(void);
  111. };
  112. untrusted {
  113. /*
  114. * [user_check]:
  115. * the pointer won't be valified, and the buffer pointed by 'val' is not
  116. * copied to outside buffer either. Besides 'App' cannot modify the memory
  117. * pointer by 'val'.
  118. */
  119. void ocall_pointer_user_check([user_check] int *val);
  120. /*
  121. * [in]:
  122. * buffer with the same size will be allocated in 'App' side, the content
  123. * pointed by 'val' will be copied into the new allocated memory outside.
  124. * Any changes performed by 'App' will not affect the buffer pointed by 'val'.
  125. */
  126. void ocall_pointer_in([in] int *val);
  127. /*
  128. * [out]:
  129. * buffer with the same size will be allocated in 'App' side, the content
  130. * pointed by 'val' won't be copied. But after return, the buffer outside
  131. * will be copied into the enclave.
  132. */
  133. void ocall_pointer_out([out] int *val);
  134. /*
  135. * [in, out]:
  136. * buffer with the same size will be allocated in 'App' side, the content
  137. * pointed by 'val' will be copied either. After return, the buffer outside
  138. * will copied into the enclave.
  139. */
  140. void ocall_pointer_in_out([in, out] int *val);
  141. };
  142. };