ocall_types.h 5.1 KB

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