ffitarget.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* -----------------------------------------------------------------*-C-*-
  2. ffitarget.h - Copyright (c) 2012, 2014, 2018 Anthony Green
  3. Copyright (c) 1996-2003, 2010 Red Hat, Inc.
  4. Copyright (C) 2008 Free Software Foundation, Inc.
  5. Target configuration macros for x86 and x86-64.
  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. ``Software''), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:
  13. The above copyright notice and this permission notice shall be included
  14. in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. DEALINGS IN THE SOFTWARE.
  23. ----------------------------------------------------------------------- */
  24. #ifndef LIBFFI_TARGET_H
  25. #define LIBFFI_TARGET_H
  26. #ifndef LIBFFI_H
  27. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  28. #endif
  29. /* ---- System specific configurations ----------------------------------- */
  30. /* For code common to all platforms on x86 and x86_64. */
  31. #define X86_ANY
  32. #if defined (X86_64) && defined (__i386__)
  33. #undef X86_64
  34. #warning ******************************************************
  35. #warning ********** X86 IS DEFINED ****************************
  36. #warning ******************************************************
  37. #define X86
  38. #endif
  39. #ifdef X86_WIN64
  40. #define FFI_SIZEOF_ARG 8
  41. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  42. #endif
  43. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  44. #ifndef _MSC_VER
  45. #define FFI_TARGET_HAS_COMPLEX_TYPE
  46. #endif
  47. /* ---- Generic type definitions ----------------------------------------- */
  48. #ifndef LIBFFI_ASM
  49. #ifdef X86_WIN64
  50. #ifdef _MSC_VER
  51. typedef unsigned __int64 ffi_arg;
  52. typedef __int64 ffi_sarg;
  53. #else
  54. typedef unsigned long long ffi_arg;
  55. typedef long long ffi_sarg;
  56. #endif
  57. #else
  58. #if defined __x86_64__ && defined __ILP32__
  59. #define FFI_SIZEOF_ARG 8
  60. #define FFI_SIZEOF_JAVA_RAW 4
  61. typedef unsigned long long ffi_arg;
  62. typedef long long ffi_sarg;
  63. #else
  64. typedef unsigned long ffi_arg;
  65. typedef signed long ffi_sarg;
  66. #endif
  67. #endif
  68. typedef enum ffi_abi {
  69. #if defined(X86_WIN64)
  70. FFI_FIRST_ABI = 0,
  71. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  72. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  73. FFI_LAST_ABI,
  74. #ifdef __GNUC__
  75. FFI_DEFAULT_ABI = FFI_GNUW64
  76. #else
  77. FFI_DEFAULT_ABI = FFI_WIN64
  78. #endif
  79. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  80. FFI_FIRST_ABI = 1,
  81. FFI_UNIX64,
  82. FFI_WIN64,
  83. FFI_EFI64 = FFI_WIN64,
  84. FFI_GNUW64,
  85. FFI_LAST_ABI,
  86. FFI_DEFAULT_ABI = FFI_UNIX64
  87. #elif defined(X86_WIN32)
  88. FFI_FIRST_ABI = 0,
  89. FFI_SYSV = 1,
  90. FFI_STDCALL = 2,
  91. FFI_THISCALL = 3,
  92. FFI_FASTCALL = 4,
  93. FFI_MS_CDECL = 5,
  94. FFI_PASCAL = 6,
  95. FFI_REGISTER = 7,
  96. FFI_LAST_ABI,
  97. FFI_DEFAULT_ABI = FFI_MS_CDECL
  98. #else
  99. FFI_FIRST_ABI = 0,
  100. FFI_SYSV = 1,
  101. FFI_THISCALL = 3,
  102. FFI_FASTCALL = 4,
  103. FFI_STDCALL = 5,
  104. FFI_PASCAL = 6,
  105. FFI_REGISTER = 7,
  106. FFI_MS_CDECL = 8,
  107. FFI_LAST_ABI,
  108. FFI_DEFAULT_ABI = FFI_SYSV
  109. #endif
  110. } ffi_abi;
  111. #endif
  112. /* ---- Definitions for closures ----------------------------------------- */
  113. #define FFI_CLOSURES 1
  114. #define FFI_GO_CLOSURES 1
  115. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  116. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  117. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  118. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  119. #if defined (X86_64) || defined(X86_WIN64) \
  120. || (defined (__x86_64__) && defined (X86_DARWIN))
  121. /* 4 bytes of ENDBR64 + 7 bytes of LEA + 6 bytes of JMP + 7 bytes of NOP
  122. + 8 bytes of pointer. */
  123. # define FFI_TRAMPOLINE_SIZE 32
  124. # define FFI_NATIVE_RAW_API 0
  125. #else
  126. /* 4 bytes of ENDBR32 + 5 bytes of MOV + 5 bytes of JMP + 2 unused
  127. bytes. */
  128. # define FFI_TRAMPOLINE_SIZE 16
  129. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  130. #endif
  131. #if !defined(GENERATE_LIBFFI_MAP) && defined(__CET__)
  132. # include <cet.h>
  133. # if (__CET__ & 1) != 0
  134. # define ENDBR_PRESENT
  135. # endif
  136. # define _CET_NOTRACK notrack
  137. #else
  138. # define _CET_ENDBR
  139. # define _CET_NOTRACK
  140. #endif
  141. #endif