Rizin
unix-like reverse engineering framework and cli tools
rz_types_base.h
Go to the documentation of this file.
1
#ifndef RZ_TYPES_BASE_H
2
#define RZ_TYPES_BASE_H
3
4
#include <ctype.h>
5
#include <sys/types.h>
6
#include <limits.h>
7
8
#define cut8 const unsigned char
9
#define ut64 unsigned long long
10
#define st64 long long
11
#define ut32 unsigned int
12
#define st32 int
13
#define ut16 unsigned short
14
#define st16 short
15
#define ut8 unsigned char
16
#define st8 signed char
17
#define boolt int
18
19
#if defined(_MSC_VER)
20
typedef
intptr_t
ssize_t
;
21
#endif
22
23
#if defined(_MSC_VER)
24
#define RZ_ALIGNED(x) __declspec(align(x))
25
#else
26
#define RZ_ALIGNED(x) __attribute__((aligned(x)))
27
#endif
28
29
typedef
RZ_ALIGNED
(1)
ut16
uut16;
30
typedef
RZ_ALIGNED
(1)
ut32
uut32;
31
typedef
RZ_ALIGNED
(1)
ut64
uut64;
32
typedef
RZ_ALIGNED
(1)
st16
ust16;
33
typedef
RZ_ALIGNED
(1)
st32
ust32;
34
typedef
RZ_ALIGNED
(1)
st64
ust64;
35
36
typedef union {
37
ut8
v8
;
38
ut16
v16
;
39
ut32
v32
;
40
ut64
v64
;
41
}
utAny
;
42
43
typedef
struct
_ut80
{
44
ut64
Low
;
45
ut16
High
;
46
}
ut80
;
47
typedef
struct
_ut96
{
48
ut64
Low
;
49
ut32
High
;
50
}
ut96
;
51
typedef
struct
_ut128
{
52
ut64
Low
;
53
st64
High
;
54
}
ut128
;
55
typedef
struct
_ut256
{
56
ut128
Low
;
57
ut128
High
;
58
}
ut256
;
59
typedef
struct
_utX
{
60
ut80
v80
;
61
ut96
v96
;
62
ut128
v128
;
63
ut256
v256
;
64
}
utX
;
65
66
#include <stdbool.h>
67
68
#define RZ_EMPTY \
69
{ 0 }
70
#define RZ_EMPTY2 \
71
{ \
72
{ 0 } \
73
}
74
75
/* limits */
76
#undef UT64_MAX
77
#undef UT64_GT0
78
#undef UT64_LT0
79
#undef UT64_MIN
80
#undef UT32_MAX
81
#undef UT32_MIN
82
#undef UT16_MIN
83
#undef UT8_MIN
84
#define ST64_MAX ((st64)0x7FFFFFFFFFFFFFFFULL)
85
#define ST64_MIN ((st64)(-ST64_MAX - 1))
86
#define UT64_MAX 0xFFFFFFFFFFFFFFFFULL
87
#define UT64_GT0 0x8000000000000000ULL
88
#define UT64_LT0 0x7FFFFFFFFFFFFFFFULL
89
#define UT64_MIN 0ULL
90
#define UT64_32U 0xFFFFFFFF00000000ULL
91
#define UT64_16U 0xFFFFFFFFFFFF0000ULL
92
#define UT64_8U 0xFFFFFFFFFFFFFF00ULL
93
#define UT32_MIN 0U
94
#define UT16_MIN 0U
95
#define UT32_GT0 0x80000000U
96
#define UT32_LT0 0x7FFFFFFFU
97
#define ST32_MAX 0x7FFFFFFF
98
#define ST32_MIN (-ST32_MAX - 1)
99
#define UT32_MAX 0xFFFFFFFFU
100
#define ST16_MAX 0x7FFF
101
#define ST16_MIN (-ST16_MAX - 1)
102
#define UT16_GT0 0x8000U
103
#define UT16_MAX 0xFFFFU
104
#define ST8_MAX 0x7F
105
#define ST8_MIN (-ST8_MAX - 1)
106
#define UT8_GT0 0x80U
107
#define UT8_MAX 0xFFU
108
#define UT8_MIN 0x00U
109
#define ASCII_MIN 32
110
#define ASCII_MAX 127
111
112
#if SSIZE_MAX == ST32_MAX
113
#define SZT_MAX UT32_MAX
114
#define SZT_MIN UT32_MIN
115
#define SSZT_MAX ST32_MAX
116
#define SSZT_MIN ST32_MIN
117
#else
118
#define SZT_MAX UT64_MAX
119
#define SZT_MIN UT64_MIN
120
#define SSZT_MAX ST64_MAX
121
#define SSZT_MIN ST64_MIN
122
#endif
123
124
#define UT64_ALIGN(x) (x + (x - (x % sizeof(ut64))))
125
#define UT32_ALIGN(x) (x + (x - (x % sizeof(ut32))))
126
#define UT16_ALIGN(x) (x + (x - (x % sizeof(ut16))))
127
128
#define UT32_LO(x) ((ut32)((x)&UT32_MAX))
129
#define UT32_HI(x) ((ut32)(((ut64)(x)) >> 32) & UT32_MAX)
130
131
#define RZ_BETWEEN(x, y, z) (((y) >= (x)) && ((y) <= (z)))
132
#define RZ_ROUND(x, y) ((x) % (y)) ? (x) + ((y) - ((x) % (y))) : (x)
133
#define RZ_DIM(x, y, z) (((x) < (y)) ? (y) : ((x) > (z)) ? (z) \
134
: (x))
135
#ifndef RZ_MAX_DEFINED
136
#define RZ_MAX(x, y) (((x) > (y)) ? (x) : (y))
137
#define RZ_MAX_DEFINED
138
#endif
139
#ifndef RZ_MIN_DEFINED
140
#define RZ_MIN(x, y) (((x) > (y)) ? (y) : (x))
141
#define RZ_MIN_DEFINED
142
#endif
143
#define RZ_ABS(x) (((x) < 0) ? -(x) : (x))
144
#define RZ_BTW(x, y, z) (((x) >= (y)) && ((y) <= (z))) ? y : x
145
146
#include "
rz_types_overflow.h
"
147
148
/* copied from bithacks.h */
149
#define B_IS_SET(x, n) (((x) & (1ULL << (n))) ? 1 : 0)
150
#define B_SET(x, n) ((x) |= (1ULL << (n)))
151
#define B_EVEN(x) (((x)&1) == 0)
152
#define B_ODD(x) (!B_EVEN((x)))
153
#define B_UNSET(x, n) ((x) &= ~(1ULL << (n)))
154
#define B_TOGGLE(x, n) ((x) ^= (1ULL << (n)))
155
156
#define B11111 31
157
#define B11110 30
158
#define B11101 29
159
#define B11100 28
160
#define B11011 27
161
#define B11010 26
162
#define B11001 25
163
#define B11000 24
164
#define B10111 23
165
#define B10110 22
166
#define B10101 21
167
#define B10100 20
168
#define B10011 19
169
#define B10010 18
170
#define B10001 17
171
#define B10000 16
172
#define B1111 15
173
#define B1110 14
174
#define B1101 13
175
#define B1100 12
176
#define B1011 11
177
#define B1010 10
178
#define B1001 9
179
#define B1000 8
180
#define B0111 7
181
#define B0110 6
182
#define B0101 5
183
#define B0100 4
184
#define B0011 3
185
#define B0010 2
186
#define B0001 1
187
#define B0000 0
188
#undef B
189
#define B4(a, b, c, d) ((a << 12) | (b << 8) | (c << 4) | (d))
190
191
/* portable non-c99 inf/nan types */
192
#if !defined(INFINITY)
193
#define INFINITY (1.0f / 0.0f)
194
#endif
195
196
#if !defined(NAN)
197
#define NAN (0.0f / 0.0f)
198
#endif
199
200
/* A workaround against libc headers redefinition of __attribute__:
201
* Standard include has lines like
202
* #if (GCC_VERSION < 2007)
203
* # define __attribute__(x)
204
* #endif
205
* So we have do remove this define for TinyCC compiler
206
*/
207
#if defined(__TINYC__) && (GCC_VERSION < 2007)
208
#undef __attribute__
209
#endif
210
211
#ifdef _MSC_VER
212
#define RZ_PACKED(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
213
#undef INFINITY
214
#undef NAN
215
#elif defined(__GNUC__) || defined(__TINYC__)
216
#define RZ_PACKED(__Declaration__) __Declaration__ __attribute__((__packed__))
217
#endif
218
219
#if APPLE_SDK_IPHONESIMULATOR
220
#undef DEBUGGER
221
#define DEBUGGER 0
222
#endif
223
224
#define HEAPTYPE(x) \
225
static x *x##_new(x n) { \
226
x *m = malloc(sizeof(x)); \
227
return m ? *m = n, m : m; \
228
}
229
230
#endif
// RZ_TYPES_BASE_H
ut16
uint16_t ut16
Definition:
demangler_util.h:30
ut32
uint32_t ut32
Definition:
demangler_util.h:31
ut8
uint8_t ut8
Definition:
lh5801.h:11
RZ_ALIGNED
#define RZ_ALIGNED(x)
Definition:
rz_types_base.h:26
ut96
struct _ut96 ut96
st64
#define st64
Definition:
rz_types_base.h:10
utX
struct _utX utX
ut80
struct _ut80 ut80
ut128
struct _ut128 ut128
ut256
struct _ut256 ut256
st16
#define st16
Definition:
rz_types_base.h:14
st32
#define st32
Definition:
rz_types_base.h:12
ut64
#define ut64
Definition:
rz_types_base.h:9
rz_types_overflow.h
ssize_t
int ssize_t
Definition:
sftypes.h:39
intptr_t
_W64 signed int intptr_t
Definition:
stdint-msvc2008.h:118
_ut128
Definition:
rz_types_base.h:51
_ut128::High
st64 High
Definition:
rz_types_base.h:53
_ut128::Low
ut64 Low
Definition:
rz_types_base.h:52
_ut256
Definition:
rz_types_base.h:55
_ut256::Low
ut128 Low
Definition:
rz_types_base.h:56
_ut256::High
ut128 High
Definition:
rz_types_base.h:57
_ut80
Definition:
rz_types_base.h:43
_ut80::High
ut16 High
Definition:
rz_types_base.h:45
_ut80::Low
ut64 Low
Definition:
rz_types_base.h:44
_ut96
Definition:
rz_types_base.h:47
_ut96::Low
ut64 Low
Definition:
rz_types_base.h:48
_ut96::High
ut32 High
Definition:
rz_types_base.h:49
_utX
Definition:
rz_types_base.h:59
_utX::v256
ut256 v256
Definition:
rz_types_base.h:63
_utX::v80
ut80 v80
Definition:
rz_types_base.h:60
_utX::v128
ut128 v128
Definition:
rz_types_base.h:62
_utX::v96
ut96 v96
Definition:
rz_types_base.h:61
utAny
Definition:
rz_types_base.h:36
utAny::v16
ut16 v16
Definition:
rz_types_base.h:38
utAny::v64
ut64 v64
Definition:
rz_types_base.h:40
utAny::v8
ut8 v8
Definition:
rz_types_base.h:37
utAny::v32
ut32 v32
Definition:
rz_types_base.h:39
librz
include
rz_types_base.h
Generated by
1.9.1