ocall_types.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * This is for enclave to make ocalls to untrusted runtime.
  3. */
  4. #include <stdbool.h>
  5. #include <stddef.h>
  6. #include <sys/types.h>
  7. #include "linux_types.h"
  8. #include "pal.h"
  9. #include "sgx_arch.h"
  10. #include "sgx_attest.h"
  11. /*
  12. * GCC's structure padding may cause leaking from uninialized
  13. * regions (https://arxiv.org/abs/1710.09061).
  14. * A simple contermeasure is to enable packing for all ocall
  15. * argument structures.
  16. */
  17. #pragma pack(push, 1)
  18. typedef long (*sgx_ocall_fn_t)(void*);
  19. enum {
  20. OCALL_EXIT = 0,
  21. OCALL_MMAP_UNTRUSTED,
  22. OCALL_MUNMAP_UNTRUSTED,
  23. OCALL_CPUID,
  24. OCALL_OPEN,
  25. OCALL_CLOSE,
  26. OCALL_READ,
  27. OCALL_WRITE,
  28. OCALL_PREAD,
  29. OCALL_PWRITE,
  30. OCALL_FSTAT,
  31. OCALL_FIONREAD,
  32. OCALL_FSETNONBLOCK,
  33. OCALL_FCHMOD,
  34. OCALL_FSYNC,
  35. OCALL_FTRUNCATE,
  36. OCALL_MKDIR,
  37. OCALL_GETDENTS,
  38. OCALL_RESUME_THREAD,
  39. OCALL_CLONE_THREAD,
  40. OCALL_CREATE_PROCESS,
  41. OCALL_FUTEX,
  42. OCALL_SOCKETPAIR,
  43. OCALL_LISTEN,
  44. OCALL_ACCEPT,
  45. OCALL_CONNECT,
  46. OCALL_RECV,
  47. OCALL_SEND,
  48. OCALL_SETSOCKOPT,
  49. OCALL_SHUTDOWN,
  50. OCALL_GETTIME,
  51. OCALL_SLEEP,
  52. OCALL_POLL,
  53. OCALL_RENAME,
  54. OCALL_DELETE,
  55. OCALL_LOAD_DEBUG,
  56. OCALL_GET_ATTESTATION,
  57. OCALL_EVENTFD,
  58. OCALL_NR,
  59. };
  60. typedef struct {
  61. int ms_exitcode;
  62. int ms_is_exitgroup;
  63. } ms_ocall_exit_t;
  64. typedef struct {
  65. int ms_fd;
  66. uint64_t ms_offset;
  67. uint64_t ms_size;
  68. unsigned short ms_prot;
  69. void * ms_mem;
  70. } ms_ocall_mmap_untrusted_t;
  71. typedef struct {
  72. const void * ms_mem;
  73. uint64_t ms_size;
  74. } ms_ocall_munmap_untrusted_t;
  75. typedef struct {
  76. unsigned int ms_leaf;
  77. unsigned int ms_subleaf;
  78. unsigned int ms_values[4];
  79. } ms_ocall_cpuid_t;
  80. typedef struct {
  81. const char * ms_pathname;
  82. int ms_flags;
  83. unsigned short ms_mode;
  84. } ms_ocall_open_t;
  85. typedef struct {
  86. int ms_fd;
  87. } ms_ocall_close_t;
  88. typedef struct {
  89. int ms_fd;
  90. void * ms_buf;
  91. unsigned int ms_count;
  92. } ms_ocall_read_t;
  93. typedef struct {
  94. int ms_fd;
  95. const void * ms_buf;
  96. unsigned int ms_count;
  97. } ms_ocall_write_t;
  98. typedef struct {
  99. int ms_fd;
  100. void* ms_buf;
  101. size_t ms_count;
  102. off_t ms_offset;
  103. } ms_ocall_pread_t;
  104. typedef struct {
  105. int ms_fd;
  106. const void* ms_buf;
  107. size_t ms_count;
  108. off_t ms_offset;
  109. } ms_ocall_pwrite_t;
  110. typedef struct {
  111. int ms_fd;
  112. struct stat ms_stat;
  113. } ms_ocall_fstat_t;
  114. typedef struct {
  115. int ms_fd;
  116. } ms_ocall_fionread_t;
  117. typedef struct {
  118. int ms_fd;
  119. int ms_nonblocking;
  120. } ms_ocall_fsetnonblock_t;
  121. typedef struct {
  122. int ms_fd;
  123. unsigned short ms_mode;
  124. } ms_ocall_fchmod_t;
  125. typedef struct {
  126. int ms_fd;
  127. } ms_ocall_fsync_t;
  128. typedef struct {
  129. int ms_fd;
  130. uint64_t ms_length;
  131. } ms_ocall_ftruncate_t;
  132. typedef struct {
  133. const char * ms_pathname;
  134. unsigned short ms_mode;
  135. } ms_ocall_mkdir_t;
  136. typedef struct {
  137. int ms_fd;
  138. struct linux_dirent64 * ms_dirp;
  139. unsigned int ms_size;
  140. } ms_ocall_getdents_t;
  141. typedef struct {
  142. unsigned int ms_pid;
  143. const char * ms_uri;
  144. int ms_stream_fd;
  145. int ms_cargo_fd;
  146. int ms_nargs;
  147. const char * ms_args[];
  148. } ms_ocall_create_process_t;
  149. typedef struct {
  150. int* ms_futex;
  151. int ms_op, ms_val;
  152. int64_t ms_timeout_us;
  153. } ms_ocall_futex_t;
  154. typedef struct {
  155. int ms_domain, ms_type, ms_protocol;
  156. int ms_sockfds[2];
  157. } ms_ocall_socketpair_t;
  158. typedef struct {
  159. int ms_domain;
  160. int ms_type;
  161. int ms_protocol;
  162. int ms_ipv6_v6only;
  163. const struct sockaddr* ms_addr;
  164. unsigned int ms_addrlen;
  165. struct sockopt ms_sockopt;
  166. } ms_ocall_listen_t;
  167. typedef struct {
  168. int ms_sockfd;
  169. struct sockaddr * ms_addr;
  170. unsigned int ms_addrlen;
  171. struct sockopt ms_sockopt;
  172. } ms_ocall_accept_t;
  173. typedef struct {
  174. int ms_domain;
  175. int ms_type;
  176. int ms_protocol;
  177. int ms_ipv6_v6only;
  178. const struct sockaddr* ms_addr;
  179. unsigned int ms_addrlen;
  180. struct sockaddr* ms_bind_addr;
  181. unsigned int ms_bind_addrlen;
  182. struct sockopt ms_sockopt;
  183. } ms_ocall_connect_t;
  184. typedef struct {
  185. PAL_IDX ms_sockfd;
  186. void * ms_buf;
  187. unsigned int ms_count;
  188. struct sockaddr * ms_addr;
  189. unsigned int ms_addrlen;
  190. void * ms_control;
  191. uint64_t ms_controllen;
  192. } ms_ocall_recv_t;
  193. typedef struct {
  194. PAL_IDX ms_sockfd;
  195. const void * ms_buf;
  196. unsigned int ms_count;
  197. const struct sockaddr * ms_addr;
  198. unsigned int ms_addrlen;
  199. void * ms_control;
  200. uint64_t ms_controllen;
  201. } ms_ocall_send_t;
  202. typedef struct {
  203. int ms_sockfd;
  204. int ms_level;
  205. int ms_optname;
  206. const void * ms_optval;
  207. unsigned int ms_optlen;
  208. } ms_ocall_setsockopt_t;
  209. typedef struct {
  210. int ms_sockfd;
  211. int ms_how;
  212. } ms_ocall_shutdown_t;
  213. typedef struct {
  214. unsigned long ms_microsec;
  215. } ms_ocall_gettime_t;
  216. typedef struct {
  217. unsigned long ms_microsec;
  218. } ms_ocall_sleep_t;
  219. typedef struct {
  220. struct pollfd* ms_fds;
  221. int ms_nfds;
  222. int64_t ms_timeout_us;
  223. } ms_ocall_poll_t;
  224. typedef struct {
  225. const char * ms_oldpath;
  226. const char * ms_newpath;
  227. } ms_ocall_rename_t;
  228. typedef struct {
  229. const char * ms_pathname;
  230. } ms_ocall_delete_t;
  231. typedef struct {
  232. sgx_spid_t ms_spid;
  233. const char* ms_subkey;
  234. bool ms_linkable;
  235. sgx_report_t ms_report;
  236. sgx_quote_nonce_t ms_nonce;
  237. sgx_attestation_t ms_attestation;
  238. } ms_ocall_get_attestation_t;
  239. typedef struct {
  240. unsigned int ms_initval;
  241. int ms_flags;
  242. } ms_ocall_eventfd_t;
  243. #pragma pack(pop)