ocall_types.h 5.2 KB

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