ffitest.h 2.8 KB

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