sgx_internal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * pal_internal.h
  15. *
  16. * This file contains definition of functions, variables and data structures
  17. * for internal uses.
  18. */
  19. #ifndef SGX_INTERNAL_H
  20. #define SGX_INTERNAL_H
  21. #include "pal_linux.h"
  22. #include "pal_security.h"
  23. #include "api.h"
  24. #include "sysdep-x86_64.h"
  25. #include <sys/syscall.h>
  26. #define IS_ERR INTERNAL_SYSCALL_ERROR
  27. #define IS_ERR_P INTERNAL_SYSCALL_ERROR_P
  28. #define ERRNO INTERNAL_SYSCALL_ERRNO
  29. #define ERRNO_P INTERNAL_SYSCALL_ERRNO_P
  30. int printf(const char * fmt, ...) __attribute__((format(printf, 1, 2)));
  31. int snprintf(char * str, int size, const char * fmt, ...) __attribute__((format(printf, 3, 4)));
  32. /* constants and macros to help rounding addresses to page
  33. boundaries */
  34. extern unsigned long pagesize, pageshift, pagemask;
  35. #undef ALLOC_ALIGNDOWN
  36. #undef ALLOC_ALIGNUP
  37. #undef ALLOC_ALIGNED
  38. #define ALLOC_ALIGNDOWN(addr) \
  39. (pagesize ? ((unsigned long)(addr)) & pagemask : (unsigned long)(addr))
  40. #define ALLOC_ALIGNUP(addr) \
  41. (pagesize ? (((unsigned long)(addr)) + pageshift) & pagemask : (unsigned long)(addr))
  42. #define ALLOC_ALIGNED(addr) \
  43. (pagesize && ((unsigned long)(addr)) == (((unsigned long)(addr)) & pagemask))
  44. uint32_t htonl (uint32_t longval);
  45. uint16_t htons (uint16_t shortval);
  46. uint32_t ntohl (uint32_t longval);
  47. uint16_t ntohs (uint16_t shortval);
  48. struct pal_enclave {
  49. /* attributes */
  50. unsigned long baseaddr;
  51. unsigned long size;
  52. unsigned long thread_num;
  53. unsigned long ssaframesize;
  54. /* files */
  55. int manifest;
  56. int exec;
  57. int sigfile;
  58. int token;
  59. /* manifest */
  60. struct config_store * config;
  61. /* security information */
  62. struct pal_sec pal_sec;
  63. };
  64. int open_gsgx (void);
  65. bool is_wrfsbase_supported (void);
  66. int read_enclave_token (int token_file, sgx_arch_token_t * token);
  67. int read_enclave_sigstruct (int sigfile, sgx_arch_sigstruct_t * sig);
  68. int create_enclave(sgx_arch_secs_t * secs,
  69. unsigned long base,
  70. unsigned long size,
  71. sgx_arch_token_t * token);
  72. enum sgx_page_type { SGX_PAGE_SECS, SGX_PAGE_TCS, SGX_PAGE_REG };
  73. int add_pages_to_enclave(sgx_arch_secs_t * secs,
  74. void * addr, void * user_addr,
  75. unsigned long size,
  76. enum sgx_page_type type, int prot,
  77. bool skip_eextend,
  78. const char * comment);
  79. int init_enclave(sgx_arch_secs_t * secs,
  80. sgx_arch_sigstruct_t * sigstruct,
  81. sgx_arch_token_t * token);
  82. int destroy_enclave(void * base_addr, size_t length);
  83. void exit_process (int status, uint64_t start_exiting);
  84. int sgx_ecall (long ecall_no, void * ms);
  85. int sgx_raise (int event);
  86. void async_exit_pointer (void);
  87. int interrupt_thread (void * tcs);
  88. int clone_thread (void);
  89. void create_tcs_mapper (void * tcs_base, unsigned int thread_num);
  90. void map_tcs (unsigned int tid);
  91. void unmap_tcs (void);
  92. extern __thread struct pal_enclave * current_enclave;
  93. #define PAL_SEC() (&current_enclave->pal_sec)
  94. extern __thread sgx_arch_tcs_t * current_tcs
  95. __attribute__((tls_model ("initial-exec")));
  96. extern __thread unsigned long debug_register
  97. __attribute__((tls_model ("initial-exec")));
  98. uint64_t sgx_edbgrd (void * addr);
  99. void sgx_edbgwr (void * addr, uint64_t data);
  100. int sgx_init_child_process (struct pal_sec * pal_sec);
  101. int sgx_signal_setup (void);
  102. #endif