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