ffitest.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <ffi.h>
  6. #define HAVE_STDINT_H
  7. #define HAVE_INTTYPES_H
  8. #ifndef _MSC_VER
  9. #define HAVE_MMAP_ANON
  10. #endif
  11. #if defined HAVE_STDINT_H
  12. #include <stdint.h>
  13. #endif
  14. #if defined HAVE_INTTYPES_H
  15. #include <inttypes.h>
  16. #endif
  17. #define MAX_ARGS 256
  18. #define CHECK(x) (void)(!(x) ? (abort(), 1) : 0)
  19. /* Define macros so that compilers other than gcc can run the tests. */
  20. #undef __UNUSED__
  21. #if defined(__GNUC__)
  22. #define __UNUSED__ __attribute__((__unused__))
  23. #define __STDCALL__ __attribute__((stdcall))
  24. #define __THISCALL__ __attribute__((thiscall))
  25. #define __FASTCALL__ __attribute__((fastcall))
  26. #define __MSABI__ __attribute__((ms_abi))
  27. #else
  28. #define __UNUSED__
  29. #define __STDCALL__ __stdcall
  30. #define __THISCALL__ __thiscall
  31. #define __FASTCALL__ __fastcall
  32. #endif
  33. #ifndef ABI_NUM
  34. #define ABI_NUM FFI_DEFAULT_ABI
  35. #define ABI_ATTR
  36. #endif
  37. /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
  38. file open. */
  39. #ifdef HAVE_MMAP_ANON
  40. # undef HAVE_MMAP_DEV_ZERO
  41. # include <sys/mman.h>
  42. # ifndef MAP_FAILED
  43. # define MAP_FAILED -1
  44. # endif
  45. # if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
  46. # define MAP_ANONYMOUS MAP_ANON
  47. # endif
  48. # define USING_MMAP
  49. #endif
  50. #ifdef HAVE_MMAP_DEV_ZERO
  51. # include <sys/mman.h>
  52. # ifndef MAP_FAILED
  53. # define MAP_FAILED -1
  54. # endif
  55. # define USING_MMAP
  56. #endif
  57. /* MinGW kludge. */
  58. #if defined(_WIN64) | defined(_WIN32)
  59. #define PRIdLL "I64d"
  60. #define PRIuLL "I64u"
  61. #else
  62. #define PRIdLL "lld"
  63. #define PRIuLL "llu"
  64. #endif
  65. /* Tru64 UNIX kludge. */
  66. #if defined(__alpha__) && defined(__osf__)
  67. /* Tru64 UNIX V4.0 doesn't support %lld/%lld, but long is 64-bit. */
  68. #undef PRIdLL
  69. #define PRIdLL "ld"
  70. #undef PRIuLL
  71. #define PRIuLL "lu"
  72. #define PRId8 "hd"
  73. #define PRIu8 "hu"
  74. #define PRId64 "ld"
  75. #define PRIu64 "lu"
  76. #define PRIuPTR "lu"
  77. #endif
  78. /* PA HP-UX kludge. */
  79. #if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR)
  80. #define PRIuPTR "lu"
  81. #endif
  82. /* IRIX kludge. */
  83. #if defined(__sgi)
  84. /* IRIX 6.5 <inttypes.h> provides all definitions, but only for C99
  85. compilations. */
  86. #define PRId8 "hhd"
  87. #define PRIu8 "hhu"
  88. #if (_MIPS_SZLONG == 32)
  89. #define PRId64 "lld"
  90. #define PRIu64 "llu"
  91. #endif
  92. /* This doesn't match <inttypes.h>, which always has "lld" here, but the
  93. arguments are uint64_t, int64_t, which are unsigned long, long for
  94. 64-bit in <sgidefs.h>. */
  95. #if (_MIPS_SZLONG == 64)
  96. #define PRId64 "ld"
  97. #define PRIu64 "lu"
  98. #endif
  99. /* This doesn't match <inttypes.h>, which has "u" here, but the arguments
  100. are uintptr_t, which is always unsigned long. */
  101. #define PRIuPTR "lu"
  102. #endif
  103. /* Solaris < 10 kludge. */
  104. #if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR)
  105. #if defined(__arch64__) || defined (__x86_64__)
  106. #define PRIuPTR "lu"
  107. #else
  108. #define PRIuPTR "u"
  109. #endif
  110. #endif
  111. /* MSVC kludge. */
  112. #if defined _MSC_VER
  113. #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
  114. #define PRIuPTR "lu"
  115. #define PRIu8 "u"
  116. #define PRId8 "d"
  117. #define PRIu64 "I64u"
  118. #define PRId64 "I64d"
  119. #endif
  120. #endif
  121. #ifndef PRIuPTR
  122. #define PRIuPTR "u"
  123. #endif