ffitarget.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #define X86
  35. #endif
  36. #ifdef X86_WIN64
  37. #define FFI_SIZEOF_ARG 8
  38. #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
  39. #endif
  40. #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
  41. #ifndef _MSC_VER
  42. #define FFI_TARGET_HAS_COMPLEX_TYPE
  43. #endif
  44. /* ---- Generic type definitions ----------------------------------------- */
  45. #ifndef LIBFFI_ASM
  46. #ifdef X86_WIN64
  47. #ifdef _MSC_VER
  48. typedef unsigned __int64 ffi_arg;
  49. typedef __int64 ffi_sarg;
  50. #else
  51. typedef unsigned long long ffi_arg;
  52. typedef long long ffi_sarg;
  53. #endif
  54. #else
  55. #if defined __x86_64__ && defined __ILP32__
  56. #define FFI_SIZEOF_ARG 8
  57. #define FFI_SIZEOF_JAVA_RAW 4
  58. typedef unsigned long long ffi_arg;
  59. typedef long long ffi_sarg;
  60. #else
  61. typedef unsigned long ffi_arg;
  62. typedef signed long ffi_sarg;
  63. #endif
  64. #endif
  65. typedef enum ffi_abi {
  66. #if defined(X86_WIN64)
  67. FFI_FIRST_ABI = 0,
  68. FFI_WIN64, /* sizeof(long double) == 8 - microsoft compilers */
  69. FFI_GNUW64, /* sizeof(long double) == 16 - GNU compilers */
  70. FFI_LAST_ABI,
  71. #ifdef __GNUC__
  72. FFI_DEFAULT_ABI = FFI_GNUW64
  73. #else
  74. FFI_DEFAULT_ABI = FFI_WIN64
  75. #endif
  76. #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
  77. FFI_FIRST_ABI = 1,
  78. FFI_UNIX64,
  79. FFI_WIN64,
  80. FFI_EFI64 = FFI_WIN64,
  81. FFI_GNUW64,
  82. FFI_LAST_ABI,
  83. FFI_DEFAULT_ABI = FFI_UNIX64
  84. #elif defined(X86_WIN32)
  85. FFI_FIRST_ABI = 0,
  86. FFI_SYSV = 1,
  87. FFI_STDCALL = 2,
  88. FFI_THISCALL = 3,
  89. FFI_FASTCALL = 4,
  90. FFI_MS_CDECL = 5,
  91. FFI_PASCAL = 6,
  92. FFI_REGISTER = 7,
  93. FFI_LAST_ABI,
  94. FFI_DEFAULT_ABI = FFI_MS_CDECL
  95. #else
  96. FFI_FIRST_ABI = 0,
  97. FFI_SYSV = 1,
  98. FFI_THISCALL = 3,
  99. FFI_FASTCALL = 4,
  100. FFI_STDCALL = 5,
  101. FFI_PASCAL = 6,
  102. FFI_REGISTER = 7,
  103. FFI_MS_CDECL = 8,
  104. FFI_LAST_ABI,
  105. FFI_DEFAULT_ABI = FFI_SYSV
  106. #endif
  107. } ffi_abi;
  108. #endif
  109. /* ---- Definitions for closures ----------------------------------------- */
  110. #define FFI_CLOSURES 1
  111. #define FFI_GO_CLOSURES 1
  112. #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
  113. #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
  114. #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
  115. #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
  116. #if defined (X86_64) || defined(X86_WIN64) \
  117. || (defined (__x86_64__) && defined (X86_DARWIN))
  118. # define FFI_TRAMPOLINE_SIZE 24
  119. # define FFI_NATIVE_RAW_API 0
  120. #else
  121. # define FFI_TRAMPOLINE_SIZE 12
  122. # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
  123. #endif
  124. #endif