se_debugger_lib.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #ifndef _SEDEBUGGERLIB_H_
  32. #define _SEDEBUGGERLIB_H_
  33. #include "arch.h"
  34. #include "se_types.h"
  35. #include "se_macro.h"
  36. #include <stdlib.h>
  37. #define URTS_EXCEPTION_PRECREATEENCLAVE 0xa1a01ec0
  38. #define URTS_EXCEPTION_POSTINITENCLAVE 0xa1a01ec1
  39. #define URTS_EXCEPTION_PREREMOVEENCLAVE 0xa1a01ec3
  40. #define URTS_EXCEPTION_PREEENTER 0xa1a01ec7
  41. #define FIRST_CHANCE_EXCEPTION 1
  42. #define SECOND_CHANCE_EXCEPTION 0
  43. #define DBWIN_BUFFER 0xa1a01ec5
  44. #define CXX_EXCEPTION 0xe06d7363
  45. #define SE_UNICODE 1
  46. #define SE_ANSI 0
  47. #define DEBUGGER_ENABLED 1
  48. #define DEBUG_INFO_STRUCT_VERSION 0x83d0ce23
  49. const size_t BUF_SIZE = sizeof(void*);
  50. typedef struct _debug_tcs_info_t
  51. {
  52. struct _debug_tcs_info_t* next_tcs_info;
  53. void* TCS_address;
  54. uintptr_t ocall_frame; /* ocall_frame_t** */
  55. unsigned long thread_id;
  56. }debug_tcs_info_t;
  57. #define DEBUG_INFO_MAX_PARAMETERS 10
  58. typedef struct _debug_info_t
  59. {
  60. uintptr_t param_array[DEBUG_INFO_MAX_PARAMETERS];
  61. }debug_info_t;
  62. //enclave_type bit map
  63. #define ET_SIM_SHIFT 0 /*bits[0]=0 hw, bits[0]=1 sim*/
  64. #define ET_DEBUG_SHIFT 1 /*bits[1]=0 product enclave, bits[1]=1 debug enclave*/
  65. #define ET_SIM (1 << ET_SIM_SHIFT)
  66. #define ET_DEBUG (1 << ET_DEBUG_SHIFT)
  67. typedef struct _debug_enclave_info_t
  68. {
  69. PADDED_POINTER(struct _debug_enclave_info_t, next_enclave_info);
  70. PADDED_POINTER(void, start_addr);
  71. PADDED_POINTER(debug_tcs_info_t, tcs_list);
  72. uint32_t enclave_type;
  73. uint32_t file_name_size;
  74. PADDED_POINTER(void, lpFileName);
  75. PADDED_POINTER(void, g_peak_heap_used_addr);
  76. PADDED_POINTER(void, dyn_sec);
  77. sgx_misc_select_t misc_select;
  78. /* The following members are optional or unused */
  79. uint32_t struct_version;
  80. uint32_t unicode;
  81. }debug_enclave_info_t;
  82. typedef struct _ocall_frame_t
  83. {
  84. uintptr_t pre_last_frame;
  85. uintptr_t index;
  86. uintptr_t xbp;
  87. uintptr_t ret;
  88. }ocall_frame_t;
  89. static inline void destory_debug_info(debug_enclave_info_t *debug_info)
  90. {
  91. if(debug_info->lpFileName)
  92. {
  93. free(debug_info->lpFileName);
  94. debug_info->lpFileName = NULL;
  95. }
  96. /*tcs_list is just a pointer, the instance is maintained in CTrustThread, so don't free it.*/
  97. debug_info->tcs_list = NULL;
  98. }
  99. #endif /*_SEDEBUGGERLIB_H_*/