sgx_internal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 size_t pagesize;
  35. #undef IS_ALLOC_ALIGNED
  36. #undef IS_ALLOC_ALIGNED_PTR
  37. #undef ALLOC_ALIGN_UP
  38. #undef ALLOC_ALIGN_UP_PTR
  39. #undef ALLOC_ALIGN_DOWN
  40. #undef ALLOC_ALIGN_DOWN_PTR
  41. #define IS_ALLOC_ALIGNED(addr) IS_ALIGNED_POW2(addr, pagesize)
  42. #define IS_ALLOC_ALIGNED_PTR(addr) IS_ALIGNED_PTR_POW2(addr, pagesize)
  43. #define ALLOC_ALIGN_UP(addr) ALIGN_UP_POW2(addr, pagesize)
  44. #define ALLOC_ALIGN_UP_PTR(addr) ALIGN_UP_PTR_POW2(addr, pagesize)
  45. #define ALLOC_ALIGN_DOWN(addr) ALIGN_DOWN_POW2(addr, pagesize)
  46. #define ALLOC_ALIGN_DOWN_PTR(addr) ALIGN_DOWN_PTR_POW2(addr, pagesize)
  47. uint32_t htonl (uint32_t longval);
  48. uint16_t htons (uint16_t shortval);
  49. uint32_t ntohl (uint32_t longval);
  50. uint16_t ntohs (uint16_t shortval);
  51. extern struct pal_enclave {
  52. /* attributes */
  53. unsigned long baseaddr;
  54. unsigned long size;
  55. unsigned long thread_num;
  56. unsigned long ssaframesize;
  57. /* files */
  58. int manifest;
  59. int exec;
  60. int sigfile;
  61. int token;
  62. /* manifest */
  63. struct config_store * config;
  64. /* security information */
  65. struct pal_sec pal_sec;
  66. } pal_enclave;
  67. int open_gsgx (void);
  68. bool is_wrfsbase_supported (void);
  69. int read_enclave_token (int token_file, sgx_arch_token_t * token);
  70. int read_enclave_sigstruct (int sigfile, sgx_arch_enclave_css_t * sig);
  71. int create_enclave(sgx_arch_secs_t * secs,
  72. sgx_arch_token_t * token);
  73. enum sgx_page_type { SGX_PAGE_SECS, SGX_PAGE_TCS, SGX_PAGE_REG };
  74. int add_pages_to_enclave(sgx_arch_secs_t * secs,
  75. void * addr, void * user_addr,
  76. unsigned long size,
  77. enum sgx_page_type type, int prot,
  78. bool skip_eextend,
  79. const char * comment);
  80. int init_aesm_targetinfo(sgx_target_info_t* aesm_targetinfo);
  81. int retrieve_verified_quote(const sgx_spid_t* spid, const char* subkey, bool linkable,
  82. const sgx_report_t* report, const sgx_quote_nonce_t* nonce,
  83. sgx_attestation_t* attestation);
  84. int init_enclave(sgx_arch_secs_t * secs,
  85. sgx_arch_enclave_css_t * sigstruct,
  86. sgx_arch_token_t * token);
  87. int destroy_enclave(void * base_addr, size_t length);
  88. void exit_process (int status, uint64_t start_exiting);
  89. int sgx_ecall (long ecall_no, void * ms);
  90. int sgx_raise (int event);
  91. void async_exit_pointer (void);
  92. int interrupt_thread (void * tcs);
  93. int clone_thread (void);
  94. void create_tcs_mapper (void * tcs_base, unsigned int thread_num);
  95. int pal_thread_init(void* tcbptr);
  96. void map_tcs(unsigned int tid);
  97. void unmap_tcs(void);
  98. void thread_exit(int status);
  99. uint64_t sgx_edbgrd (void * addr);
  100. void sgx_edbgwr (void * addr, uint64_t data);
  101. int sgx_init_child_process (struct pal_sec * pal_sec);
  102. int sgx_signal_setup (void);
  103. int block_signals (bool block, const int * sigs, int nsig);
  104. int block_async_signals (bool block);
  105. #endif