sgx_internal.h 4.2 KB

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