Rizin
unix-like reverse engineering framework and cli tools
rz_types.h
Go to the documentation of this file.
1 #ifndef RZ_TYPES_H
2 #define RZ_TYPES_H
3 
4 #undef _FILE_OFFSET_BITS
5 #define _FILE_OFFSET_BITS 64
6 
7 // defines like IS_DIGIT, etc'
8 #include <rz_userconf.h>
9 #include <rz_util/rz_str_util.h>
10 #include <stddef.h>
11 #include <assert.h>
12 #include <errno.h>
13 #if HAVE_HEADER_INTTYPES_H
14 #include <inttypes.h>
15 #endif
16 
17 // TODO: fix this to make it crosscompile-friendly: RZ_SYS_OSTYPE ?
18 /* operating system */
19 #undef __BSD__
20 #undef __KFBSD__
21 #undef __UNIX__
22 #undef __WINDOWS__
23 
24 // TODO: these modes should be dropped when oldshell is removed in favour of RzOutputMode.
25 #define RZ_MODE_PRINT 0x000
26 #define RZ_MODE_RIZINCMD 0x001
27 #define RZ_MODE_SET 0x002
28 #define RZ_MODE_SIMPLE 0x004
29 #define RZ_MODE_JSON 0x008
30 #define RZ_MODE_ARRAY 0x010
31 #define RZ_MODE_SIMPLEST 0x020
32 #define RZ_MODE_CLASSDUMP 0x040
33 #define RZ_MODE_EQUAL 0x080
34 
38 typedef enum {
48 } RzOutputMode;
49 
50 #define RZ_IN /* do not use, implicit */
51 #define RZ_OUT /* parameter is written, not read */
52 #define RZ_INOUT /* parameter is read and written */
53 
54 #ifdef RZ_BINDINGS
55 #define RZ_OWN __attribute__((annotate("RZ_OWN")))
56 #define RZ_BORROW __attribute__((annotate("RZ_BORROW")))
57 
58 #define RZ_NONNULL __attribute__((annotate("RZ_NONNULL")))
59 #define RZ_NULLABLE __attribute__((annotate("RZ_NULLABLE")))
60 #define RZ_DEPRECATE __attribute__((annotate("RZ_DEPRECATE")))
61 #else
62 #define RZ_OWN /* pointer ownership is transferred */
63 #define RZ_BORROW /* pointer ownership is not transferred, it must not be freed by the receiver */
64 #define RZ_NONNULL /* pointer can not be null */
65 #define RZ_NULLABLE /* pointer can be null */
66 #define RZ_DEPRECATE /* should not be used in new code and should/will be removed in the future */
67 #endif
68 
69 #define RZ_IFNULL(x) /* default value for the pointer when null */
70 #ifdef __GNUC__
71 #define RZ_UNUSED __attribute__((__unused__))
72 #else
73 #define RZ_UNUSED /* unused */
74 #endif
75 
76 #ifdef RZ_NEW
77 #undef RZ_NEW
78 #endif
79 
80 #ifdef RZ_NEW0
81 #undef RZ_NEW0
82 #endif
83 
84 #ifdef RZ_FREE
85 #undef RZ_FREE
86 #endif
87 
88 #ifdef RZ_NEWCOPY
89 #undef RZ_NEWCOPY
90 #endif
91 
92 // used in debug, io, bin, analysis, ...
93 #define RZ_PERM_R 4
94 #define RZ_PERM_W 2
95 #define RZ_PERM_X 1
96 #define RZ_PERM_RW (RZ_PERM_R | RZ_PERM_W)
97 #define RZ_PERM_RX (RZ_PERM_R | RZ_PERM_X)
98 #define RZ_PERM_RWX (RZ_PERM_R | RZ_PERM_W | RZ_PERM_X)
99 #define RZ_PERM_WX (RZ_PERM_W | RZ_PERM_X)
100 #define RZ_PERM_SHAR 8
101 #define RZ_PERM_PRIV 16
102 #define RZ_PERM_ACCESS 32
103 #define RZ_PERM_CREAT 64
104 
105 #if defined(__powerpc) || defined(__powerpc__)
106 #undef __POWERPC__
107 #define __POWERPC__ 1
108 #endif
109 
110 #if defined(__OpenBSD__)
111 #include <sys/param.h>
112 #endif
113 
114 #ifdef __GNUC__
115 #define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
116 #else
117 #define UNUSED_FUNCTION(x) UNUSED_##x
118 #endif
119 
120 #ifdef __EMSCRIPTEN__
121 #define __UNIX__ 1
122 #endif
123 
124 #ifdef __HAIKU__
125 #define __UNIX__ 1
126 #endif
127 
128 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
129 #define __KFBSD__ 1
130 #else
131 #define __KFBSD__ 0
132 #endif
133 
134 #ifdef __MSYS__
135 #define __UNIX__ 1
136 #endif
137 
138 #ifdef _MSC_VER
139 #define restrict
140 #define strcasecmp stricmp
141 #define strncasecmp strnicmp
142 #define __WINDOWS__ 1
143 #endif
144 
145 #if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) || defined(__sun) || defined(__HAIKU__)
146 #define __BSD__ 0
147 #define __UNIX__ 1
148 #endif
149 #if __KFBSD__ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
150 #define __BSD__ 1
151 #define __UNIX__ 1
152 #endif
153 #if __WINDOWS__ || _WIN32
154 #define __WINDOWS__ 1
155 #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
156 #undef __UNIX__
157 #undef __BSD__
158 #endif
159 
160 #if defined(__APPLE__) && ((__arm__ || __arm64__ || __aarch64__) && IS_IOS)
161 #define TARGET_OS_IPHONE 1
162 #else
163 #define TARGET_OS_IPHONE 0
164 #endif
165 
166 #ifdef __GNUC__
167 #define FUNC_ATTR_MALLOC __attribute__((malloc))
168 #define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
169 #define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) __attribute__((alloc_size(x, y)))
170 #define FUNC_ATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x)))
171 #define FUNC_ATTR_PURE __attribute__((pure))
172 #define FUNC_ATTR_CONST __attribute__((const))
173 #define FUNC_ATTR_USED __attribute__((used))
174 #define FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
175 #define FUNC_ATTR_ALWAYS_INLINE __attribute__((always_inline))
176 #else
177 #define FUNC_ATTR_MALLOC
178 #define FUNC_ATTR_ALLOC_SIZE(x)
179 #define FUNC_ATTR_ALLOC_SIZE_PROD(x, y)
180 #define FUNC_ATTR_ALLOC_ALIGN(x)
181 #define FUNC_ATTR_PURE
182 #define FUNC_ATTR_CONST
183 #define FUNC_ATTR_USED
184 #define FUNC_ATTR_WARN_UNUSED_RESULT
185 #define FUNC_ATTR_ALWAYS_INLINE
186 #endif
187 
188 /* printf format check attributes */
189 #if defined(__clang__) || defined(__GNUC__)
190 #define RZ_PRINTF_CHECK(fmt, dots) __attribute__((format(printf, fmt, dots)))
191 #else
192 #define RZ_PRINTF_CHECK(fmt, dots)
193 #endif
194 
195 #include <rz_types_base.h>
196 #include <rz_constructor.h>
197 
198 #undef _GNU_SOURCE
199 #define _GNU_SOURCE
200 
201 #include <stdio.h>
202 #include <string.h>
203 #include <stdlib.h>
204 #include <stdarg.h>
205 #include <fcntl.h> /* for O_RDONLY */
206 #include <rz_endian.h> /* needs size_t */
207 
208 #ifdef __cplusplus
209 extern "C" {
210 #endif
211 
212 #if __WINDOWS__
213 #define RZ_SYS_DIR "\\"
214 #define RZ_SYS_ENVSEP ";"
215 #define RZ_SYS_HOME "USERPROFILE"
216 #define RZ_SYS_TMP "TEMP"
217 #else
218 #define RZ_SYS_DIR "/"
219 #define RZ_SYS_ENVSEP ":"
220 #define RZ_SYS_HOME "HOME"
221 #define RZ_SYS_TMP "TMPDIR"
222 #endif
223 
224 #define RZ_JOIN_2_PATHS(p1, p2) p1 RZ_SYS_DIR p2
225 #define RZ_JOIN_3_PATHS(p1, p2, p3) p1 RZ_SYS_DIR p2 RZ_SYS_DIR p3
226 #define RZ_JOIN_4_PATHS(p1, p2, p3, p4) p1 RZ_SYS_DIR p2 RZ_SYS_DIR p3 RZ_SYS_DIR p4
227 #define RZ_JOIN_5_PATHS(p1, p2, p3, p4, p5) p1 RZ_SYS_DIR p2 RZ_SYS_DIR p3 RZ_SYS_DIR p4 RZ_SYS_DIR p5
228 
229 #ifndef __packed
230 #define __packed __attribute__((__packed__))
231 #endif
232 
233 typedef int (*PrintfCallback)(const char *str, ...) RZ_PRINTF_CHECK(1, 2);
234 
235 /* compile-time introspection helpers */
236 #define CTO(y, z) ((size_t) & ((y *)0)->z)
237 #define CTA(x, y, z) (x + CTO(y, z))
238 #define CTI(x, y, z) (*((size_t *)(CTA(x, y, z))))
239 #define CTS(x, y, z, t, v) \
240  { \
241  t *_ = (t *)CTA(x, y, z); \
242  *_ = v; \
243  }
244 
245 #ifdef RZ_IPI
246 #undef RZ_IPI
247 #endif
248 
249 #define RZ_IPI
250 
251 #ifdef RZ_HEAP
252 #undef RZ_HEAP
253 #endif
254 #define RZ_HEAP
255 
256 #ifdef RZ_API
257 #undef RZ_API
258 #endif
259 #ifdef RZ_BINDINGS
260 #define RZ_API __attribute__((annotate("RZ_API")))
261 #elif RZ_INLINE
262 #define RZ_API inline
263 #else
264 #if defined(__GNUC__) && __GNUC__ >= 4
265 #define RZ_API __attribute__((visibility("default")))
266 #elif defined(_MSC_VER)
267 #define RZ_API __declspec(dllexport)
268 #else
269 #define RZ_API
270 #endif
271 #endif
272 
273 #define RZ_LIB_VERSION_HEADER(x) \
274  RZ_API const char *x##_version(void)
275 #define RZ_LIB_VERSION(x) \
276  RZ_API const char *x##_version(void) { \
277  return "" RZ_VERSION; \
278  }
279 
280 #define BITS2BYTES(x) (((x) / 8) + (((x) % 8) ? 1 : 0))
281 #define ZERO_FILL(x) memset(&x, 0, sizeof(x))
282 #define RZ_NEWS0(x, y) (x *)calloc(y, sizeof(x))
283 #define RZ_NEWS(x, y) (x *)malloc(sizeof(x) * (y))
284 #define RZ_NEW0(x) (x *)calloc(1, sizeof(x))
285 #define RZ_NEW(x) (x *)malloc(sizeof(x))
286 #define RZ_NEWCOPY(x, y) (x *)rz_new_copy(sizeof(x), y)
287 
288 static inline void *rz_new_copy(int size, void *data) {
289  void *a = malloc(size);
290  if (a) {
291  memcpy(a, data, size);
292  }
293  return a;
294 }
295 // TODO: Make RZ_NEW_COPY be 1 arg, not two
296 #define RZ_NEW_COPY(x, y) \
297  x = (void *)malloc(sizeof(y)); \
298  memcpy(x, y, sizeof(y))
299 #define RZ_MEM_ALIGN(x) ((void *)(size_t)(((ut64)(size_t)x) & 0xfffffffffffff000LL))
300 #define RZ_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
301 #define RZ_PTR_MOVE(d, s) \
302  d = s; \
303  s = NULL;
304 
305 #define RZ_PTR_ALIGN(v, t) \
306  ((char *)(((size_t)(v)) & ~(t - 1)))
307 #define RZ_PTR_ALIGN_NEXT(v, t) \
308  ((char *)(((size_t)(v) + (t - 1)) & ~(t - 1)))
309 
310 #define RZ_BIT_MASK32(x, y) ((1UL << (x)) - (1UL << (y)))
311 #define RZ_BIT_SET(x, y) (((ut8 *)x)[y >> 4] |= (1 << (y & 0xf)))
312 #define RZ_BIT_UNSET(x, y) (((ut8 *)x)[y >> 4] &= ~(1 << (y & 0xf)))
313 #define RZ_BIT_TOGGLE(x, y) (RZ_BIT_CHK(x, y) ? RZ_BIT_UNSET(x, y) : RZ_BIT_SET(x, y))
314 
315 //#define RZ_BIT_CHK(x,y) ((((const ut8*)x)[y>>4] & (1<<(y&0xf))))
316 #define RZ_BIT_CHK(x, y) (*(x) & (1 << (y)))
317 
318 /* try for C99, but provide backwards compatibility */
319 #if defined(_MSC_VER) && (_MSC_VER <= 1800)
320 #define __func__ __FUNCTION__
321 #endif
322 
323 #define PERROR_WITH_FILELINE 0
324 
325 #if PERROR_WITH_FILELINE
326 /* make error messages useful by prepending file, line, and function name */
327 #define _perror(str, file, line, func) \
328  { \
329  char buf[256]; \
330  snprintf(buf, sizeof(buf), "[%s:%d %s] %s", file, line, func, str); \
331  rz_sys_perror_str(buf); \
332  }
333 #define perror(x) _perror(x, __FILE__, __LINE__, __func__)
334 #define rz_sys_perror(x) _perror(x, __FILE__, __LINE__, __func__)
335 #else
336 #define rz_sys_perror(x) rz_sys_perror_str(x);
337 #endif
338 
339 #if __UNIX__
340 #include <sys/types.h>
341 #include <sys/stat.h>
342 #include <fcntl.h>
343 #include <dirent.h>
344 #include <unistd.h>
345 #include <sys/time.h>
346 #endif
347 
348 #ifndef HAVE_EPRINTF
349 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
350 #define HAVE_EPRINTF 1
351 #endif
352 
353 #ifndef typeof
354 #define typeof(arg) __typeof__(arg)
355 #endif
356 
357 // There is a bug of using "offsetof()" in the structure
358 // initialization in GCC < 5.0 versions
359 #if !(defined(__GNUC__) && __GNUC__ < 5) || defined(__clang__)
360 #define rz_offsetof(type, member) offsetof(type, member)
361 #else
362 #if __WINDOWS__
363 #define rz_offsetof(type, member) ((unsigned long)(ut64) & ((type *)0)->member)
364 #else
365 #define rz_offsetof(type, member) ((unsigned long)&((type *)0)->member)
366 #endif
367 #endif
368 
369 #define RZ_FREE(x) \
370  { \
371  free((void *)x); \
372  x = NULL; \
373  }
374 
375 #define RZ_FREE_CUSTOM(x, y) \
376  { \
377  y(x); \
378  x = NULL; \
379  }
380 
381 #if __WINDOWS__
382 #define PFMT64x "I64x"
383 #define PFMT64d "I64d"
384 #define PFMT64u "I64u"
385 #define PFMT64o "I64o"
386 #define PFMTSZx "Ix"
387 #define PFMTSZd "Id"
388 #define PFMTSZu "Iu"
389 #define PFMTSZo "Io"
390 #define LDBLFMT "f"
391 #define HHXFMT "x"
392 #else
393 #define PFMT64x "llx"
394 #define PFMT64d "lld"
395 #define PFMT64u "llu"
396 #define PFMT64o "llo"
397 #define PFMTSZx "zx"
398 #define PFMTSZd "zd"
399 #define PFMTSZu "zu"
400 #define PFMTSZo "zo"
401 #define LDBLFMT "Lf"
402 #define HHXFMT "hhx"
403 #endif
404 
405 #define PFMTDPTR "td"
406 
407 #define PFMT32x "x"
408 #define PFMT32d "d"
409 #define PFMT32u "u"
410 #define PFMT32o "o"
411 
412 #ifndef O_BINARY
413 #define O_BINARY 0
414 #endif
415 
416 #if __APPLE__
417 #if __i386__
418 #define RZ_SYS_BASE ((ut64)0x1000)
419 #elif __x86_64__
420 #define RZ_SYS_BASE ((ut64)0x100000000)
421 #else
422 #define RZ_SYS_BASE ((ut64)0x1000)
423 #endif
424 #elif __WINDOWS__
425 #define RZ_SYS_BASE ((ut64)0x01001000)
426 #else // linux, bsd, ...
427 #if __arm__ || __arm64__
428 #define RZ_SYS_BASE ((ut64)0x4000)
429 #else
430 #define RZ_SYS_BASE ((ut64)0x8048000)
431 #endif
432 #endif
433 
434 /* arch */
435 #if __i386__
436 #define RZ_SYS_ARCH "x86"
437 #define RZ_SYS_BITS RZ_SYS_BITS_32
438 #define RZ_SYS_ENDIAN 0
439 #elif __EMSCRIPTEN__
440 #define RZ_SYS_ARCH "wasm"
441 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
442 #define RZ_SYS_ENDIAN 0
443 #elif __x86_64__
444 #define RZ_SYS_ARCH "x86"
445 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
446 #define RZ_SYS_ENDIAN 0
447 #elif __POWERPC__
448 #define RZ_SYS_ARCH "ppc"
449 #ifdef __powerpc64__
450 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
451 #else
452 #define RZ_SYS_BITS RZ_SYS_BITS_32
453 #endif
454 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
455 #define RZ_SYS_ENDIAN 0
456 #else
457 #define RZ_SYS_ENDIAN 1
458 #endif
459 #elif __arm__
460 #define RZ_SYS_ARCH "arm"
461 #define RZ_SYS_BITS RZ_SYS_BITS_32
462 #define RZ_SYS_ENDIAN 0
463 #elif __arm64__ || __aarch64__
464 #define RZ_SYS_ARCH "arm"
465 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
466 #define RZ_SYS_ENDIAN 0
467 #elif __arc__
468 #define RZ_SYS_ARCH "arc"
469 #define RZ_SYS_BITS RZ_SYS_BITS_32
470 #define RZ_SYS_ENDIAN 0
471 #elif __s390x__
472 #define RZ_SYS_ARCH "sysz"
473 #define RZ_SYS_BITS RZ_SYS_BITS_64
474 #define RZ_SYS_ENDIAN 1
475 #elif __sparc__
476 #define RZ_SYS_ARCH "sparc"
477 #define RZ_SYS_BITS RZ_SYS_BITS_32
478 #define RZ_SYS_ENDIAN 1
479 #elif __mips__
480 #define RZ_SYS_ARCH "mips"
481 #define RZ_SYS_BITS RZ_SYS_BITS_32
482 #define RZ_SYS_ENDIAN 1
483 #elif __EMSCRIPTEN__
484 /* we should default to wasm when ready */
485 #define RZ_SYS_ARCH "x86"
486 #define RZ_SYS_BITS RZ_SYS_BITS_32
487 #elif __riscv__ || __riscv
488 #define RZ_SYS_ARCH "riscv"
489 #define RZ_SYS_ENDIAN 0
490 #if __riscv_xlen == 32
491 #define RZ_SYS_BITS RZ_SYS_BITS_32
492 #else
493 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
494 #endif
495 #else
496 #ifdef _MSC_VER
497 #if defined(_M_X64) || defined(_M_AMD64)
498 #define RZ_SYS_ARCH "x86"
499 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
500 #define RZ_SYS_ENDIAN 0
501 #define __x86_64__ 1
502 #elif defined(_M_IX86)
503 #define RZ_SYS_ARCH "x86"
504 #define RZ_SYS_BITS (RZ_SYS_BITS_32)
505 #define RZ_SYS_ENDIAN 0
506 #define __i386__ 1
507 #elif defined(_M_ARM64)
508 #define RZ_SYS_ARCH "arm"
509 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
510 #define RZ_SYS_ENDIAN 0
511 #define __arm64__ 1
512 #elif defined(_M_ARM)
513 #define RZ_SYS_ARCH "arm"
514 #define RZ_SYS_BITS RZ_SYS_BITS_32
515 #define RZ_SYS_ENDIAN 0
516 #define __arm__ 1
517 #endif
518 #else
519 #define RZ_SYS_ARCH "unknown"
520 #define RZ_SYS_BITS RZ_SYS_BITS_32
521 #define RZ_SYS_ENDIAN 0
522 #endif
523 #endif
524 
525 #define RZ_SYS_ENDIAN_NONE 0
526 #define RZ_SYS_ENDIAN_LITTLE 1
527 #define RZ_SYS_ENDIAN_BIG 2
528 #define RZ_SYS_ENDIAN_BI 3
529 
530 typedef enum {
566 
567 /* os */
568 #if defined(__QNX__)
569 #define RZ_SYS_OS "qnx"
570 //#elif TARGET_OS_IPHONE
571 //#define RZ_SYS_OS "ios"
572 #elif defined(__APPLE__)
573 #define RZ_SYS_OS "darwin"
574 #elif defined(__linux__)
575 #define RZ_SYS_OS "linux"
576 #elif defined(__WINDOWS__)
577 #define RZ_SYS_OS "windows"
578 #elif defined(__NetBSD__)
579 #define RZ_SYS_OS "netbsd"
580 #elif defined(__OpenBSD__)
581 #define RZ_SYS_OS "openbsd"
582 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
583 #define RZ_SYS_OS "freebsd"
584 #elif defined(__HAIKU__)
585 #define RZ_SYS_OS "haiku"
586 #else
587 #define RZ_SYS_OS "unknown"
588 #endif
589 
590 #ifdef __cplusplus
591 }
592 #endif
593 
594 static inline void rz_run_call1(void *fcn, void *arg1) {
595  ((void (*)(void *))(fcn))(arg1);
596 }
597 
598 static inline void rz_run_call2(void *fcn, void *arg1, void *arg2) {
599  ((void (*)(void *, void *))(fcn))(arg1, arg2);
600 }
601 
602 static inline void rz_run_call3(void *fcn, void *arg1, void *arg2, void *arg3) {
603  ((void (*)(void *, void *, void *))(fcn))(arg1, arg2, arg3);
604 }
605 
606 static inline void rz_run_call4(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4) {
607  ((void (*)(void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4);
608 }
609 
610 static inline void rz_run_call5(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5) {
611  ((void (*)(void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5);
612 }
613 
614 static inline void rz_run_call6(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5,
615  void *arg6) {
616  ((void (*)(void *, void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6);
617 }
618 
619 static inline void rz_run_call7(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5,
620  void *arg6, void *arg7) {
621  ((void (*)(void *, void *, void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
622 }
623 
624 static inline void rz_run_call8(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5,
625  void *arg6, void *arg7, void *arg8) {
626  ((void (*)(void *, void *, void *, void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
627 }
628 
629 static inline void rz_run_call9(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5,
630  void *arg6, void *arg7, void *arg8, void *arg9) {
631  ((void (*)(void *, void *, void *, void *, void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
632 }
633 
634 static inline void rz_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5,
635  void *arg6, void *arg7, void *arg8, void *arg9, void *arg10) {
636  ((void (*)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
637 }
638 
639 #define RZ_V_NOT(op, fail_ret) \
640  if ((op) == (fail_ret)) \
641  RZ_LOG_WARN(#op " at %s:%d failed: %s\n", __FILE__, __LINE__, strerror(errno))
642 #define rz_xwrite(fd, buf, count) RZ_V_NOT(write(fd, buf, count), -1)
643 #define rz_xread(fd, buf, count) RZ_V_NOT(read(fd, buf, count), -1)
644 #define rz_xfreopen(pathname, mode, stream) RZ_V_NOT(freopen(pathname, mode, stream), NULL)
645 
646 #ifndef container_of
647 #ifdef _MSC_VER
648 #define container_of(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
649 #else
650 #define container_of(ptr, type, member) ((type *)((char *)(__typeof__(((type *)0)->member) *){ ptr } - offsetof(type, member)))
651 #endif
652 #endif
653 
654 // reference counter
655 typedef int RzRef;
656 
657 #define RZ_REF_NAME refcount
658 #define rz_ref(x) x->RZ_REF_NAME++;
659 #define rz_ref_init(x) x->RZ_REF_NAME = 1
660 #define rz_unref(x, f) \
661  { \
662  assert(x->RZ_REF_NAME > 0); \
663  if (!--(x->RZ_REF_NAME)) { \
664  f(x); \
665  } \
666  }
667 
668 #define RZ_REF_TYPE RzRef RZ_REF_NAME
669 #define RZ_REF_FUNCTIONS(s, n) \
670  static inline void n##_ref(s *x) { \
671  x->RZ_REF_NAME++; \
672  } \
673  static inline void n##_unref(s *x) { \
674  rz_unref(x, n##_free); \
675  }
676 
677 #endif // RZ_TYPES_H
voidpf void uLong size
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123
static void rz_run_call8(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8)
Definition: rz_types.h:624
int RzRef
Definition: rz_types.h:655
RzSysArch
Definition: rz_types.h:530
@ RZ_SYS_ARCH_PPC
Definition: rz_types.h:534
@ RZ_SYS_ARCH_BF
Definition: rz_types.h:542
@ RZ_SYS_ARCH_XAP
Definition: rz_types.h:539
@ RZ_SYS_ARCH_MIPS
Definition: rz_types.h:537
@ RZ_SYS_ARCH_M68K
Definition: rz_types.h:535
@ RZ_SYS_ARCH_JAVA
Definition: rz_types.h:536
@ RZ_SYS_ARCH_XCORE
Definition: rz_types.h:557
@ RZ_SYS_ARCH_NONE
Definition: rz_types.h:531
@ RZ_SYS_ARCH_RISCV
Definition: rz_types.h:564
@ RZ_SYS_ARCH_ARC
Definition: rz_types.h:547
@ RZ_SYS_ARCH_Z80
Definition: rz_types.h:546
@ RZ_SYS_ARCH_DALVIK
Definition: rz_types.h:545
@ RZ_SYS_ARCH_SH
Definition: rz_types.h:543
@ RZ_SYS_ARCH_HPPA
Definition: rz_types.h:561
@ RZ_SYS_ARCH_MSIL
Definition: rz_types.h:540
@ RZ_SYS_ARCH_OBJD
Definition: rz_types.h:541
@ RZ_SYS_ARCH_MSP430
Definition: rz_types.h:559
@ RZ_SYS_ARCH_I8080
Definition: rz_types.h:548
@ RZ_SYS_ARCH_EBC
Definition: rz_types.h:552
@ RZ_SYS_ARCH_8051
Definition: rz_types.h:550
@ RZ_SYS_ARCH_AVR
Definition: rz_types.h:544
@ RZ_SYS_ARCH_TMS320
Definition: rz_types.h:551
@ RZ_SYS_ARCH_CR16
Definition: rz_types.h:554
@ RZ_SYS_ARCH_V850
Definition: rz_types.h:555
@ RZ_SYS_ARCH_SYSZ
Definition: rz_types.h:556
@ RZ_SYS_ARCH_SPARC
Definition: rz_types.h:538
@ RZ_SYS_ARCH_LM32
Definition: rz_types.h:563
@ RZ_SYS_ARCH_CRIS
Definition: rz_types.h:560
@ RZ_SYS_ARCH_X86
Definition: rz_types.h:532
@ RZ_SYS_ARCH_PROPELLER
Definition: rz_types.h:558
@ RZ_SYS_ARCH_V810
Definition: rz_types.h:562
@ RZ_SYS_ARCH_RAR
Definition: rz_types.h:549
@ RZ_SYS_ARCH_ARM
Definition: rz_types.h:533
@ RZ_SYS_ARCH_H8300
Definition: rz_types.h:553
static void rz_run_call9(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8, void *arg9)
Definition: rz_types.h:629
static void rz_run_call1(void *fcn, void *arg1)
Definition: rz_types.h:594
static void rz_run_call6(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6)
Definition: rz_types.h:614
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
#define RZ_PRINTF_CHECK(fmt, dots)
Definition: rz_types.h:192
static void rz_run_call3(void *fcn, void *arg1, void *arg2, void *arg3)
Definition: rz_types.h:602
static void rz_run_call4(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4)
Definition: rz_types.h:606
static void * rz_new_copy(int size, void *data)
Definition: rz_types.h:288
static void rz_run_call5(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5)
Definition: rz_types.h:610
static void rz_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8, void *arg9, void *arg10)
Definition: rz_types.h:634
static void rz_run_call7(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7)
Definition: rz_types.h:619
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_LONG_JSON
Definition: rz_types.h:45
@ RZ_OUTPUT_MODE_SDB
Definition: rz_types.h:43
@ RZ_OUTPUT_MODE_QUIETEST
Definition: rz_types.h:47
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
static void rz_run_call2(void *fcn, void *arg1, void *arg2)
Definition: rz_types.h:598
static int
Definition: sfsocketcall.h:114
#define a(i)
Definition: sha256.c:41