sgx_trts_exception.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /**
  32. * File: sgx_trts_exception.h
  33. * Description:
  34. * Header file for custom exception handling support.
  35. */
  36. #ifndef _SGX_TRTS_EXCEPTION_H_
  37. #define _SGX_TRTS_EXCEPTION_H_
  38. #include <stdint.h>
  39. #include <stddef.h>
  40. #include "sgx_defs.h"
  41. #define EXCEPTION_CONTINUE_SEARCH 0
  42. #define EXCEPTION_CONTINUE_EXECUTION -1
  43. typedef enum _sgx_exception_vector_t
  44. {
  45. SGX_EXCEPTION_VECTOR_DE = 0, /* DIV and DIV instructions */
  46. SGX_EXCEPTION_VECTOR_DB = 1, /* For Intel use only */
  47. SGX_EXCEPTION_VECTOR_BP = 3, /* INT 3 instruction */
  48. SGX_EXCEPTION_VECTOR_BR = 5, /* BOUND instruction */
  49. SGX_EXCEPTION_VECTOR_UD = 6, /* UD2 instruction or reserved opcode */
  50. SGX_EXCEPTION_VECTOR_MF = 16, /* x87 FPU floating-point or WAIT/FWAIT instruction */
  51. SGX_EXCEPTION_VECTOR_AC = 17, /* Any data reference in memory */
  52. SGX_EXCEPTION_VECTOR_XM = 19, /* SSE/SSE2/SSE3 floating-point instruction */
  53. } sgx_exception_vector_t;
  54. typedef enum _sgx_exception_type_t
  55. {
  56. SGX_EXCEPTION_HARDWARE = 3,
  57. SGX_EXCEPTION_SOFTWARE = 6,
  58. } sgx_exception_type_t;
  59. #if defined (_M_X64) || defined (__x86_64__)
  60. typedef struct _cpu_context_t
  61. {
  62. uint64_t rax;
  63. uint64_t rcx;
  64. uint64_t rdx;
  65. uint64_t rbx;
  66. uint64_t rsp;
  67. uint64_t rbp;
  68. uint64_t rsi;
  69. uint64_t rdi;
  70. uint64_t r8;
  71. uint64_t r9;
  72. uint64_t r10;
  73. uint64_t r11;
  74. uint64_t r12;
  75. uint64_t r13;
  76. uint64_t r14;
  77. uint64_t r15;
  78. uint64_t rflags;
  79. uint64_t rip;
  80. } sgx_cpu_context_t;
  81. #else
  82. typedef struct _cpu_context_t
  83. {
  84. uint32_t eax;
  85. uint32_t ecx;
  86. uint32_t edx;
  87. uint32_t ebx;
  88. uint32_t esp;
  89. uint32_t ebp;
  90. uint32_t esi;
  91. uint32_t edi;
  92. uint32_t eflags;
  93. uint32_t eip;
  94. } sgx_cpu_context_t;
  95. #endif
  96. typedef struct _exception_info_t
  97. {
  98. sgx_cpu_context_t cpu_context;
  99. sgx_exception_vector_t exception_vector;
  100. sgx_exception_type_t exception_type;
  101. } sgx_exception_info_t;
  102. typedef int (*sgx_exception_handler_t)(sgx_exception_info_t *info);
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. /* sgx_register_exception_handler()
  107. * register a custom exception handler
  108. * Parameter
  109. * is_first_handler - the order in which the handler should be called.
  110. * If the parameter is nonzero, the handler is the first handler to be called.
  111. * If the parameter is zero, the handler is the last handler to be called.
  112. * exception_handler - a pointer to the handler to be called.
  113. * Return Value
  114. * handler - success
  115. * NULL - fail
  116. */
  117. void * SGXAPI sgx_register_exception_handler(int is_first_handler, sgx_exception_handler_t exception_handler);
  118. /* sgx_unregister_exception_handler()
  119. * unregister a custom exception handler.
  120. * Parameter
  121. * handler - a handler to the custom excepetion handler previously
  122. * registered using the sgx_register_exception_handler function.
  123. * Return Value
  124. * none zero - success
  125. * 0 - fail
  126. */
  127. int SGXAPI sgx_unregister_exception_handler(void *handler);
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif