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