ocall_types.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /*
  4. * This is for enclave to make ocalls to untrusted runtime.
  5. */
  6. #include "linux_types.h"
  7. /*
  8. * GCC's structure padding may cause leaking from uninialized
  9. * regions (https://arxiv.org/abs/1710.09061).
  10. * A simple contermeasure is to enable packing for all ocall
  11. * argument structures.
  12. */
  13. #pragma pack(push, 1)
  14. typedef int (*sgx_ocall_fn_t)(void*);
  15. enum {
  16. OCALL_EXIT = 0,
  17. OCALL_PRINT_STRING,
  18. OCALL_ALLOC_UNTRUSTED,
  19. OCALL_MAP_UNTRUSTED,
  20. OCALL_UNMAP_UNTRUSTED,
  21. OCALL_CPUID,
  22. OCALL_OPEN,
  23. OCALL_CLOSE,
  24. OCALL_READ,
  25. OCALL_WRITE,
  26. OCALL_FSTAT,
  27. OCALL_FIONREAD,
  28. OCALL_FSETNONBLOCK,
  29. OCALL_FCHMOD,
  30. OCALL_FSYNC,
  31. OCALL_FTRUNCATE,
  32. OCALL_MKDIR,
  33. OCALL_GETDENTS,
  34. OCALL_WAKE_THREAD,
  35. OCALL_CREATE_PROCESS,
  36. OCALL_FUTEX,
  37. OCALL_SOCKETPAIR,
  38. OCALL_SOCK_LISTEN,
  39. OCALL_SOCK_ACCEPT,
  40. OCALL_SOCK_CONNECT,
  41. OCALL_SOCK_RECV,
  42. OCALL_SOCK_SEND,
  43. OCALL_SOCK_RECV_FD,
  44. OCALL_SOCK_SEND_FD,
  45. OCALL_SOCK_SETOPT,
  46. OCALL_SOCK_SHUTDOWN,
  47. OCALL_GETTIME,
  48. OCALL_SLEEP,
  49. OCALL_POLL,
  50. OCALL_RENAME,
  51. OCALL_DELETE,
  52. OCALL_LOAD_DEBUG,
  53. OCALL_NR,
  54. };
  55. #define OCALL_NO_TIMEOUT ((uint64_t)-1)
  56. typedef struct {
  57. const char * ms_str;
  58. unsigned int ms_length;
  59. } ms_ocall_print_string_t;
  60. typedef struct {
  61. uint64_t ms_size;
  62. void * ms_mem;
  63. } ms_ocall_alloc_untrusted_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_map_untrusted_t;
  71. typedef struct {
  72. const void * ms_mem;
  73. uint64_t ms_size;
  74. } ms_ocall_unmap_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. struct stat ms_stat;
  101. } ms_ocall_fstat_t;
  102. typedef struct {
  103. int ms_fd;
  104. } ms_ocall_fionread_t;
  105. typedef struct {
  106. int ms_fd;
  107. int ms_nonblocking;
  108. } ms_ocall_fsetnonblock_t;
  109. typedef struct {
  110. int ms_fd;
  111. unsigned short ms_mode;
  112. } ms_ocall_fchmod_t;
  113. typedef struct {
  114. int ms_fd;
  115. } ms_ocall_fsync_t;
  116. typedef struct {
  117. int ms_fd;
  118. uint64_t ms_length;
  119. } ms_ocall_ftruncate_t;
  120. typedef struct {
  121. const char * ms_pathname;
  122. unsigned short ms_mode;
  123. } ms_ocall_mkdir_t;
  124. typedef struct {
  125. int ms_fd;
  126. struct linux_dirent64 * ms_dirp;
  127. unsigned int ms_size;
  128. } ms_ocall_getdents_t;
  129. typedef struct {
  130. unsigned int ms_pid;
  131. const char * ms_uri;
  132. int ms_proc_fds[3];
  133. int ms_nargs;
  134. const char * ms_args[];
  135. } ms_ocall_create_process_t;
  136. typedef struct {
  137. int * ms_futex;
  138. int ms_op, ms_val;
  139. uint64_t ms_timeout;
  140. } ms_ocall_futex_t;
  141. typedef struct {
  142. int ms_domain, ms_type, ms_protocol;
  143. int ms_sockfds[2];
  144. } ms_ocall_socketpair_t;
  145. typedef struct {
  146. int ms_domain, ms_type, ms_protocol;
  147. const struct sockaddr * ms_addr;
  148. unsigned int ms_addrlen;
  149. struct sockopt ms_sockopt;
  150. } ms_ocall_sock_listen_t;
  151. typedef struct {
  152. int ms_sockfd;
  153. struct sockaddr * ms_addr;
  154. unsigned int ms_addrlen;
  155. struct sockopt ms_sockopt;
  156. } ms_ocall_sock_accept_t;
  157. typedef struct {
  158. int ms_domain, ms_type, ms_protocol;
  159. const struct sockaddr * ms_addr;
  160. unsigned int ms_addrlen;
  161. struct sockaddr * ms_bind_addr;
  162. unsigned int ms_bind_addrlen;
  163. struct sockopt ms_sockopt;
  164. } ms_ocall_sock_connect_t;
  165. typedef struct {
  166. int ms_sockfd;
  167. void * ms_buf;
  168. unsigned int ms_count;
  169. struct sockaddr * ms_addr;
  170. unsigned int ms_addrlen;
  171. } ms_ocall_sock_recv_t;
  172. typedef struct {
  173. int ms_sockfd;
  174. const void * ms_buf;
  175. unsigned int ms_count;
  176. const struct sockaddr * ms_addr;
  177. unsigned int ms_addrlen;
  178. } ms_ocall_sock_send_t;
  179. typedef struct {
  180. int ms_sockfd;
  181. void * ms_buf;
  182. unsigned int ms_count;
  183. unsigned int * ms_fds;
  184. unsigned int ms_nfds;
  185. } ms_ocall_sock_recv_fd_t;
  186. typedef struct {
  187. int ms_sockfd;
  188. const void * ms_buf;
  189. unsigned int ms_count;
  190. const unsigned int * ms_fds;
  191. unsigned int ms_nfds;
  192. } ms_ocall_sock_send_fd_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_sock_setopt_t;
  200. typedef struct {
  201. int ms_sockfd;
  202. int ms_how;
  203. } ms_ocall_sock_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. uint64_t ms_timeout;
  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. unsigned int ms_tid;
  224. } ms_ocall_schedule_t;
  225. #pragma pack(pop)