From a835185da216ac9e78a883ccf4add0b124cf5310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Ho=CC=88ner?= Date: Sun, 26 Nov 2017 04:00:55 +0100 Subject: [PATCH] Clang and GCC support in no-libc mode --- include/Zydis/CommonTypes.h | 66 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/include/Zydis/CommonTypes.h b/include/Zydis/CommonTypes.h index 9381cc3..8b0fd39 100644 --- a/include/Zydis/CommonTypes.h +++ b/include/Zydis/CommonTypes.h @@ -39,42 +39,48 @@ /* ============================================================================================== */ #if !defined(ZYDIS_NO_LIBC) - // LibC present, use stdint types. + // If is LibC present, we use stdint types. # include - typedef uint8_t ZydisU8; - typedef uint16_t ZydisU16; - typedef uint32_t ZydisU32; - typedef uint64_t ZydisU64; - typedef int8_t ZydisI8; - typedef int16_t ZydisI16; - typedef int32_t ZydisI32; - typedef int64_t ZydisI64; +# include + typedef uint8_t ZydisU8; + typedef uint16_t ZydisU16; + typedef uint32_t ZydisU32; + typedef uint64_t ZydisU64; + typedef int8_t ZydisI8; + typedef int16_t ZydisI16; + typedef int32_t ZydisI32; + typedef int64_t ZydisI64; + typedef size_t ZydisUSize; + typedef ptrdiff_t ZydisISize; #else - // No LibC, roll our own int sizes ... + // No LibC, use compiler built-in types / macros. # if defined(ZYDIS_MSVC) - typedef unsigned __int8 ZydisU8; - typedef unsigned __int16 ZydisU16; - typedef unsigned __int32 ZydisU32; - typedef unsigned __int64 ZydisU64; - typedef __int8 ZydisI8; - typedef __int16 ZydisI16; - typedef __int32 ZydisI32; - typedef __int64 ZydisI64; + typedef unsigned __int8 ZydisU8; + typedef unsigned __int16 ZydisU16; + typedef unsigned __int32 ZydisU32; + typedef unsigned __int64 ZydisU64; + typedef __int8 ZydisI8; + typedef __int16 ZydisI16; + typedef __int32 ZydisI32; + typedef __int64 ZydisI64; + typedef ZydisU64 ZydisUSize; + typedef ZydisI64 ZydisISize; +# elif defined(ZYDIS_GNUC) + typedef __UINT8_TYPE__ ZydisU8; + typedef __UINT16_TYPE__ ZydisU16; + typedef __UINT32_TYPE__ ZydisU32; + typedef __UINT64_TYPE__ ZydisU64; + typedef __INT8_TYPE__ ZydisI8; + typedef __INT16_TYPE__ ZydisI16; + typedef __INT32_TYPE__ ZydisI32; + typedef __INT64_TYPE__ ZydisI64; + typedef __SIZE_TYPE__ ZydisUSize; + typedef __PTRDIFF_TYPE__ ZydisISize; # else -# error "Unsupported compiler for NO_LIBC mode." +# error "Unsupported compiler for no-libc mode." # endif #endif -#if ZYDIS_WORD_SIZE == 32 - typedef ZydisU32 ZydisUSize; - typedef ZydisI32 ZydisISize; -#elif ZYDIS_WORD_SIZE == 64 - typedef ZydisU64 ZydisUSize; - typedef ZydisI64 ZydisISize; -#else -# error "Unsupported word size." -#endif - /* ============================================================================================== */ /* NULL */ /* ============================================================================================== */ @@ -91,7 +97,7 @@ /** * @briefs Defines the @c ZydisBool datatype. */ -typedef uint8_t ZydisBool; +typedef ZydisU8 ZydisBool; /* ============================================================================================== */