Zydis  v2.0.0
CommonTypes.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 
3  Zyan Disassembler Library (Zydis)
4 
5  Original Author : Florian Bernd, Joel Hoener
6 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24 
25 ***************************************************************************************************/
26 
32 #ifndef ZYDIS_COMMONTYPES_H
33 #define ZYDIS_COMMONTYPES_H
34 
35 #include <Zydis/Defines.h>
36 
37 /* ============================================================================================== */
38 /* Integer types */
39 /* ============================================================================================== */
40 
41 #if !defined(ZYDIS_NO_LIBC)
42  // If is LibC present, we use stdint types.
43 # include <stdint.h>
44 # include <stddef.h>
45  typedef uint8_t ZydisU8;
46  typedef uint16_t ZydisU16;
47  typedef uint32_t ZydisU32;
48  typedef uint64_t ZydisU64;
49  typedef int8_t ZydisI8;
50  typedef int16_t ZydisI16;
51  typedef int32_t ZydisI32;
52  typedef int64_t ZydisI64;
53  typedef size_t ZydisUSize;
54  typedef ptrdiff_t ZydisISize;
55  typedef uintptr_t ZydisUPointer;
56  typedef intptr_t ZydisIPointer;
57 #else
58  // No LibC, use compiler built-in types / macros.
59 # if defined(ZYDIS_MSVC)
60  typedef unsigned __int8 ZydisU8;
61  typedef unsigned __int16 ZydisU16;
62  typedef unsigned __int32 ZydisU32;
63  typedef unsigned __int64 ZydisU64;
64  typedef signed __int8 ZydisI8;
65  typedef signed __int16 ZydisI16;
66  typedef signed __int32 ZydisI32;
67  typedef signed __int64 ZydisI64;
68 # if _WIN64
69  typedef ZydisU64 ZydisUSize;
70  typedef ZydisI64 ZydisISize;
71  typedef ZydisU64 ZydisUPointer;
72  typedef ZydisI64 ZydisIPointer;
73 # else
74  typedef ZydisU32 ZydisUSize;
75  typedef ZydisI32 ZydisISize;
76  typedef ZydisU32 ZydisUPointer;
77  typedef ZydisI32 ZydisIPointer;
78 # endif
79 # elif defined(ZYDIS_GNUC)
80  typedef __UINT8_TYPE__ ZydisU8;
81  typedef __UINT16_TYPE__ ZydisU16;
82  typedef __UINT32_TYPE__ ZydisU32;
83  typedef __UINT64_TYPE__ ZydisU64;
84  typedef __INT8_TYPE__ ZydisI8;
85  typedef __INT16_TYPE__ ZydisI16;
86  typedef __INT32_TYPE__ ZydisI32;
87  typedef __INT64_TYPE__ ZydisI64;
88  typedef __SIZE_TYPE__ ZydisUSize;
89  typedef __PTRDIFF_TYPE__ ZydisISize;
90  typedef __UINTPTR_TYPE__ ZydisUPointer;
91  typedef __INTPTR_TYPE__ ZydisIPointer;
92 # else
93 # error "Unsupported compiler for no-libc mode."
94 # endif
95 #endif
96 
97 // Verify size assumptions.
98 ZYDIS_STATIC_ASSERT(sizeof(ZydisU8 ) == 1 );
99 ZYDIS_STATIC_ASSERT(sizeof(ZydisU16 ) == 2 );
102 ZYDIS_STATIC_ASSERT(sizeof(ZydisI8 ) == 1 );
106 ZYDIS_STATIC_ASSERT(sizeof(ZydisUSize ) == sizeof(void*)); // TODO: This one is incorrect!
107 ZYDIS_STATIC_ASSERT(sizeof(ZydisISize ) == sizeof(void*)); // TODO: This one is incorrect!
108 ZYDIS_STATIC_ASSERT(sizeof(ZydisUPointer) == sizeof(void*));
109 ZYDIS_STATIC_ASSERT(sizeof(ZydisIPointer) == sizeof(void*));
110 
111 // Verify signedness assumptions (relies on size checks above).
112 ZYDIS_STATIC_ASSERT((ZydisI8 )-1 >> 1 < (ZydisI8 )((ZydisU8 )-1 >> 1));
113 ZYDIS_STATIC_ASSERT((ZydisI16)-1 >> 1 < (ZydisI16)((ZydisU16)-1 >> 1));
114 ZYDIS_STATIC_ASSERT((ZydisI32)-1 >> 1 < (ZydisI32)((ZydisU32)-1 >> 1));
115 ZYDIS_STATIC_ASSERT((ZydisI64)-1 >> 1 < (ZydisI64)((ZydisU64)-1 >> 1));
116 
117 /* ============================================================================================== */
118 /* NULL */
119 /* ============================================================================================== */
120 
121 #define ZYDIS_NULL ((void*)0)
122 
123 /* ============================================================================================== */
124 /* Boolean */
125 /* ============================================================================================== */
126 
127 #define ZYDIS_FALSE 0
128 #define ZYDIS_TRUE 1
129 
134 
135 /* ============================================================================================== */
136 
137 #endif /* ZYDIS_COMMONTYPES_H */
uint64_t ZydisU64
Definition: CommonTypes.h:48
uint8_t ZydisU8
Definition: CommonTypes.h:45
uint32_t ZydisU32
Definition: CommonTypes.h:47
int16_t ZydisI16
Definition: CommonTypes.h:50
int8_t ZydisI8
Definition: CommonTypes.h:49
int32_t ZydisI32
Definition: CommonTypes.h:51
intptr_t ZydisIPointer
Definition: CommonTypes.h:56
ptrdiff_t ZydisISize
Definition: CommonTypes.h:54
int64_t ZydisI64
Definition: CommonTypes.h:52
uintptr_t ZydisUPointer
Definition: CommonTypes.h:55
ZydisU8 ZydisBool
@briefs Defines the ZydisBool datatype.
Definition: CommonTypes.h:133
ZYDIS_STATIC_ASSERT(sizeof(ZydisU8)==1)
uint16_t ZydisU16
Definition: CommonTypes.h:46
size_t ZydisUSize
Definition: CommonTypes.h:53
General helper and platform detection macros.