platform.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Capstone Disassembly Engine */
  2. /* By Axel Souchet & Nguyen Anh Quynh, 2014 */
  3. #ifndef CAPSTONE_PLATFORM_H
  4. #define CAPSTONE_PLATFORM_H
  5. // handle C99 issue (for pre-2013 VisualStudio)
  6. #if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64))
  7. // MSVC
  8. // stdbool.h
  9. #if (_MSC_VER < 1800) || defined(_KERNEL_MODE)
  10. // this system does not have stdbool.h
  11. #ifndef __cplusplus
  12. typedef unsigned char bool;
  13. #define false 0
  14. #define true 1
  15. #endif // __cplusplus
  16. #else
  17. // VisualStudio 2013+ -> C99 is supported
  18. #include <stdbool.h>
  19. #endif // (_MSC_VER < 1800) || defined(_KERNEL_MODE)
  20. #else
  21. // not MSVC -> C99 is supported
  22. #include <stdbool.h>
  23. #endif // !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64))
  24. // handle inttypes.h / stdint.h compatibility
  25. #if defined(_WIN32_WCE) && (_WIN32_WCE < 0x800)
  26. #include "windowsce/stdint.h"
  27. #endif // defined(_WIN32_WCE) && (_WIN32_WCE < 0x800)
  28. #if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE)))
  29. // this system does not have inttypes.h
  30. #if defined(_MSC_VER) && (_MSC_VER <= 1600 || defined(_KERNEL_MODE))
  31. // this system does not have stdint.h
  32. typedef signed char int8_t;
  33. typedef signed short int16_t;
  34. typedef signed int int32_t;
  35. typedef unsigned char uint8_t;
  36. typedef unsigned short uint16_t;
  37. typedef unsigned int uint32_t;
  38. typedef signed long long int64_t;
  39. typedef unsigned long long uint64_t;
  40. #endif // defined(_MSC_VER) && (_MSC_VER <= 1600 || defined(_KERNEL_MODE))
  41. #if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE))
  42. #define INT8_MIN (-127i8 - 1)
  43. #define INT16_MIN (-32767i16 - 1)
  44. #define INT32_MIN (-2147483647i32 - 1)
  45. #define INT64_MIN (-9223372036854775807i64 - 1)
  46. #define INT8_MAX 127i8
  47. #define INT16_MAX 32767i16
  48. #define INT32_MAX 2147483647i32
  49. #define INT64_MAX 9223372036854775807i64
  50. #define UINT8_MAX 0xffui8
  51. #define UINT16_MAX 0xffffui16
  52. #define UINT32_MAX 0xffffffffui32
  53. #define UINT64_MAX 0xffffffffffffffffui64
  54. #endif // defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE))
  55. #ifdef CAPSTONE_HAS_OSXKERNEL
  56. // this system has stdint.h
  57. #include <stdint.h>
  58. #endif
  59. #define __PRI_8_LENGTH_MODIFIER__ "hh"
  60. #define __PRI_64_LENGTH_MODIFIER__ "ll"
  61. #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d"
  62. #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i"
  63. #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o"
  64. #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u"
  65. #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x"
  66. #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X"
  67. #define PRId16 "hd"
  68. #define PRIi16 "hi"
  69. #define PRIo16 "ho"
  70. #define PRIu16 "hu"
  71. #define PRIx16 "hx"
  72. #define PRIX16 "hX"
  73. #if defined(_MSC_VER) && _MSC_VER <= 1700
  74. #define PRId32 "ld"
  75. #define PRIi32 "li"
  76. #define PRIo32 "lo"
  77. #define PRIu32 "lu"
  78. #define PRIx32 "lx"
  79. #define PRIX32 "lX"
  80. #else // OSX
  81. #define PRId32 "d"
  82. #define PRIi32 "i"
  83. #define PRIo32 "o"
  84. #define PRIu32 "u"
  85. #define PRIx32 "x"
  86. #define PRIX32 "X"
  87. #endif // defined(_MSC_VER) && _MSC_VER <= 1700
  88. #if defined(_MSC_VER) && _MSC_VER <= 1700
  89. // redefine functions from inttypes.h used in cstool
  90. #define strtoull _strtoui64
  91. #endif
  92. #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d"
  93. #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i"
  94. #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o"
  95. #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u"
  96. #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x"
  97. #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X"
  98. #else
  99. // this system has inttypes.h by default
  100. #include <inttypes.h>
  101. #endif // defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE)))
  102. #endif