platform.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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
  16. #else
  17. // VisualStudio 2013+ -> C99 is supported
  18. #include <stdbool.h>
  19. #endif
  20. #else
  21. // not MSVC -> C99 is supported
  22. #include <stdbool.h>
  23. #endif
  24. // handle C99 issue (for pre-2013 VisualStudio)
  25. #if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE)))
  26. // this system does not have inttypes.h
  27. #if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE))
  28. // this system does not have stdint.h
  29. typedef signed char int8_t;
  30. typedef signed short int16_t;
  31. typedef signed int int32_t;
  32. typedef unsigned char uint8_t;
  33. typedef unsigned short uint16_t;
  34. typedef unsigned int uint32_t;
  35. typedef signed long long int64_t;
  36. typedef unsigned long long uint64_t;
  37. #define INT8_MIN (-127i8 - 1)
  38. #define INT16_MIN (-32767i16 - 1)
  39. #define INT32_MIN (-2147483647i32 - 1)
  40. #define INT64_MIN (-9223372036854775807i64 - 1)
  41. #define INT8_MAX 127i8
  42. #define INT16_MAX 32767i16
  43. #define INT32_MAX 2147483647i32
  44. #define INT64_MAX 9223372036854775807i64
  45. #define UINT8_MAX 0xffui8
  46. #define UINT16_MAX 0xffffui16
  47. #define UINT32_MAX 0xffffffffui32
  48. #define UINT64_MAX 0xffffffffffffffffui64
  49. #endif
  50. #define __PRI_8_LENGTH_MODIFIER__ "hh"
  51. #define __PRI_64_LENGTH_MODIFIER__ "ll"
  52. #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d"
  53. #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i"
  54. #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o"
  55. #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u"
  56. #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x"
  57. #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X"
  58. #define PRId16 "hd"
  59. #define PRIi16 "hi"
  60. #define PRIo16 "ho"
  61. #define PRIu16 "hu"
  62. #define PRIx16 "hx"
  63. #define PRIX16 "hX"
  64. #if defined(_MSC_VER) && _MSC_VER <= 1700
  65. #define PRId32 "ld"
  66. #define PRIi32 "li"
  67. #define PRIo32 "lo"
  68. #define PRIu32 "lu"
  69. #define PRIx32 "lx"
  70. #define PRIX32 "lX"
  71. #else // OSX
  72. #define PRId32 "d"
  73. #define PRIi32 "i"
  74. #define PRIo32 "o"
  75. #define PRIu32 "u"
  76. #define PRIx32 "x"
  77. #define PRIX32 "X"
  78. #endif
  79. #if defined(_MSC_VER) && _MSC_VER <= 1700
  80. // redefine functions from inttypes.h used in cstool
  81. #define strtoull _strtoui64
  82. #endif
  83. #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d"
  84. #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i"
  85. #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o"
  86. #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u"
  87. #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x"
  88. #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X"
  89. #else
  90. // this system has inttypes.h by default
  91. #include <inttypes.h>
  92. #endif
  93. #endif