enter_enclave.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2011-2016 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. * Normal function enter/leave wrappers.
  33. * ------------------------------------------------------------
  34. */
  35. #ifndef _ENTER_ENCLAVE_H_
  36. #define _ENTER_ENCLAVE_H_
  37. #include "linux-regs.h"
  38. #include "rts_cmd.h"
  39. /* macro for enter_enclave
  40. * There is no .cfi_xxx to describe unwind information, because we want c++ exception can't across enclave boundary
  41. */
  42. .macro EENTER_PROLOG
  43. push %xbp
  44. mov %xsp, %xbp
  45. #if defined(__i386__)
  46. push %ebx
  47. push %esi
  48. push %edi
  49. /* These 3 wordsize buffer are used for paddings, so that the
  50. * stack-boundary can be kept 16-byte aligned.
  51. *
  52. * Note that, by default GCC assumes
  53. * -mpreferred-stack-boundary=4
  54. * which results to 16 (2^4) byte alignment of stack boundary.
  55. *
  56. * | parameters | <- previous frame
  57. * ==+================+======
  58. * | return address | ^
  59. * +----------------+ |
  60. * | ebp | |
  61. * +----------------+ 16 bytes <- current frame
  62. * | ebx | |
  63. * +----------------+ |
  64. * | esi | v
  65. * +----------------+ ----
  66. * | edi | 4 bytes
  67. * +----------------+
  68. * | paddings | 3*4 bytes
  69. * ==+================+======
  70. * | ENCLU |
  71. */
  72. sub $(3 * SE_WORDSIZE), %esp
  73. #elif defined(__x86_64__)
  74. push %rbx
  75. push %r12
  76. push %r13
  77. push %r14
  78. push %r15
  79. /*save 5 parameter*/
  80. push %r8
  81. push %rcx
  82. push %rdx
  83. push %rsi
  84. push %rdi
  85. #else
  86. # error unknown platform
  87. #endif
  88. .endm
  89. .macro EENTER_EPILOG
  90. #if defined(__i386__)
  91. mov -SE_WORDSIZE*1(%ebp), %ebx
  92. mov -SE_WORDSIZE*2(%ebp), %esi
  93. mov -SE_WORDSIZE*3(%ebp), %edi
  94. #elif defined(__x86_64__)
  95. mov -SE_WORDSIZE*1(%rbp), %rbx
  96. mov -SE_WORDSIZE*2(%rbp), %r12
  97. mov -SE_WORDSIZE*3(%rbp), %r13
  98. mov -SE_WORDSIZE*4(%rbp), %r14
  99. mov -SE_WORDSIZE*5(%rbp), %r15
  100. #else
  101. # error unknown platform
  102. #endif
  103. /* don't need recover rdi, rsi, rdx, rcx */
  104. mov %xbp, %xsp
  105. pop %xbp
  106. ret
  107. .endm
  108. #if defined(__i386__)
  109. #define frame_arg0 2*SE_WORDSIZE(%ebp)
  110. #define frame_arg1 3*SE_WORDSIZE(%ebp)
  111. #define frame_arg2 4*SE_WORDSIZE(%ebp)
  112. #define frame_arg3 5*SE_WORDSIZE(%ebp)
  113. #define frame_arg4 6*SE_WORDSIZE(%ebp)
  114. #elif defined(__x86_64__)
  115. #define frame_arg0 -10*SE_WORDSIZE(%rbp)
  116. #define frame_arg1 -9*SE_WORDSIZE(%rbp)
  117. #define frame_arg2 -8*SE_WORDSIZE(%rbp)
  118. #define frame_arg3 -7*SE_WORDSIZE(%rbp)
  119. #define frame_arg4 -6*SE_WORDSIZE(%rbp)
  120. #else
  121. # error unknown platform
  122. #endif
  123. //refer sgx_error.h
  124. #define SE_ERROR_READ_LOCK_FAIL 0xc0002202
  125. #endif