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