Various minor no-libc fixes

This commit is contained in:
Joel Höner 2017-11-27 00:06:09 +01:00
parent 486add62ed
commit a2cc8615ba
6 changed files with 51 additions and 44 deletions

View File

@ -59,10 +59,10 @@
typedef unsigned __int16 ZydisU16; typedef unsigned __int16 ZydisU16;
typedef unsigned __int32 ZydisU32; typedef unsigned __int32 ZydisU32;
typedef unsigned __int64 ZydisU64; typedef unsigned __int64 ZydisU64;
typedef __int8 ZydisI8; typedef signed __int8 ZydisI8;
typedef __int16 ZydisI16; typedef signed __int16 ZydisI16;
typedef __int32 ZydisI32; typedef signed __int32 ZydisI32;
typedef __int64 ZydisI64; typedef signed __int64 ZydisI64;
# if _WIN64 # if _WIN64
typedef ZydisU64 ZydisUSize; typedef ZydisU64 ZydisUSize;
typedef ZydisI64 ZydisISize; typedef ZydisI64 ZydisISize;
@ -86,16 +86,23 @@
# endif # endif
#endif #endif
// Verify assumptions. // Verify size assumptions.
ZYDIS_STATIC_ASSERT(sizeof(ZydisU8) == 1); ZYDIS_STATIC_ASSERT(sizeof(ZydisU8 ) == 1 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisU16) == 2); ZYDIS_STATIC_ASSERT(sizeof(ZydisU16 ) == 2 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisU32) == 4); ZYDIS_STATIC_ASSERT(sizeof(ZydisU32 ) == 4 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisU64) == 8); ZYDIS_STATIC_ASSERT(sizeof(ZydisU64 ) == 8 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisI8) == 1); ZYDIS_STATIC_ASSERT(sizeof(ZydisI8 ) == 1 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisI16) == 2); ZYDIS_STATIC_ASSERT(sizeof(ZydisI16 ) == 2 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisI32) == 4); ZYDIS_STATIC_ASSERT(sizeof(ZydisI32 ) == 4 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisI64) == 8); ZYDIS_STATIC_ASSERT(sizeof(ZydisI64 ) == 8 );
ZYDIS_STATIC_ASSERT(sizeof(ZydisUSize) == sizeof(ZydisISize)); ZYDIS_STATIC_ASSERT(sizeof(ZydisUSize) == sizeof(void*));
ZYDIS_STATIC_ASSERT(sizeof(ZydisISize) == sizeof(void*));
// Verify signedness assumptions (relies on size checks above).
ZYDIS_STATIC_ASSERT((ZydisI8 )-1 >> 1 < (ZydisI8 )((ZydisU8 )-1 >> 1));
ZYDIS_STATIC_ASSERT((ZydisI16)-1 >> 1 < (ZydisI16)((ZydisU16)-1 >> 1));
ZYDIS_STATIC_ASSERT((ZydisI32)-1 >> 1 < (ZydisI32)((ZydisU32)-1 >> 1));
ZYDIS_STATIC_ASSERT((ZydisI64)-1 >> 1 < (ZydisI64)((ZydisU64)-1 >> 1));
/* ============================================================================================== */ /* ============================================================================================== */
/* NULL */ /* NULL */

View File

@ -137,7 +137,7 @@
# if __has_builtin(__builtin_unreachable) # if __has_builtin(__builtin_unreachable)
# define ZYDIS_UNREACHABLE __builtin_unreachable() # define ZYDIS_UNREACHABLE __builtin_unreachable()
# else # else
# define ZYDIS_UNREACHABLE # define ZYDIS_UNREACHABLE for(;;)
# endif # endif
# elif defined(ZYDIS_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4) # elif defined(ZYDIS_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
# define ZYDIS_UNREACHABLE __builtin_unreachable() # define ZYDIS_UNREACHABLE __builtin_unreachable()
@ -151,10 +151,10 @@
# elif defined(ZYDIS_MSVC) # elif defined(ZYDIS_MSVC)
# define ZYDIS_UNREACHABLE __assume(0) # define ZYDIS_UNREACHABLE __assume(0)
# else # else
# define ZYDIS_UNREACHABLE # define ZYDIS_UNREACHABLE for(;;)
# endif # endif
#elif defined(ZYDIS_NO_LIBC) #elif defined(ZYDIS_NO_LIBC)
# define ZYDIS_UNREACHABLE # define ZYDIS_UNREACHABLE for(;;)
#else #else
# include <stdlib.h> # include <stdlib.h>
# define ZYDIS_UNREACHABLE { assert(0); abort(); } # define ZYDIS_UNREACHABLE { assert(0); abort(); }

View File

@ -125,7 +125,7 @@ enum ZydisFeatures
* Use the macros provided in this file to extract the major, minor, patch and build part from the * Use the macros provided in this file to extract the major, minor, patch and build part from the
* returned version value. * returned version value.
*/ */
ZYDIS_EXPORT ZydisU64 ZydisGetVersion(); ZYDIS_EXPORT ZydisU64 ZydisGetVersion(void);
/** /**
* @brief Checks, if the specified feature is enabled in the current zydis library instance. * @brief Checks, if the specified feature is enabled in the current zydis library instance.

View File

@ -272,9 +272,9 @@ extern const ZydisDecoderTreeNode filtersMVEXE[][2];
/* Decoder tree */ /* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------- */
const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode() const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void)
{ {
static const ZydisDecoderTreeNode root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x00000000 }; static const ZydisDecoderTreeNode root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x0000 };
return &root; return &root;
} }

View File

@ -280,7 +280,7 @@ typedef struct ZydisInstructionEncodingInfo_
* *
* @return The root node of the instruction tree. * @return The root node of the instruction tree.
*/ */
ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(); ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void);
/** /**
* @brief Returns the child node of @c parent specified by @c index. * @brief Returns the child node of @c parent specified by @c index.

View File

@ -30,7 +30,7 @@
/* Exported functions */ /* Exported functions */
/* ============================================================================================== */ /* ============================================================================================== */
ZydisU64 ZydisGetVersion() ZydisU64 ZydisGetVersion(void)
{ {
return ZYDIS_VERSION; return ZYDIS_VERSION;
} }