From 420e884e26429a73ee3228a2ce9648ab4a05af1c Mon Sep 17 00:00:00 2001 From: Vova Date: Fri, 28 May 2021 21:54:47 +0300 Subject: [PATCH] Fix #232 --- source/m3_api_uvwasi.c | 4 ++++ source/m3_compile.c | 2 ++ source/m3_config.h | 2 +- source/m3_config_platforms.h | 8 +++++++- source/m3_exec_defs.h | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/source/m3_api_uvwasi.c b/source/m3_api_uvwasi.c index e924bd3..a06aa3a 100644 --- a/source/m3_api_uvwasi.c +++ b/source/m3_api_uvwasi.c @@ -19,6 +19,10 @@ #include "uvwasi.h" +#ifndef d_m3EnableWasiTracing +# define d_m3EnableWasiTracing 0 +#endif + #ifdef __APPLE__ # include # define environ (*_NSGetEnviron()) diff --git a/source/m3_compile.c b/source/m3_compile.c index 8765769..c14e0e0 100644 --- a/source/m3_compile.c +++ b/source/m3_compile.c @@ -641,6 +641,8 @@ _ (PushAllocatedSlotAndEmit (o, i_type)); { u16 constTableIndex = slot - o->slotFirstConstIndex; + d_m3Assert(constTableIndex < d_m3MaxConstantTableSize); + if (is64BitType) { u64 * constant = (u64 *) & o->constants [constTableIndex]; diff --git a/source/m3_config.h b/source/m3_config.h index 6a204a3..8194572 100644 --- a/source/m3_config.h +++ b/source/m3_config.h @@ -33,7 +33,7 @@ # endif # ifndef d_m3MaxConstantTableSize -# define d_m3MaxConstantTableSize 120 +# define d_m3MaxConstantTableSize 1024 # endif # ifndef d_m3MaxDuplicateFunctionImpl diff --git a/source/m3_config_platforms.h b/source/m3_config_platforms.h index 887846a..57b24d2 100644 --- a/source/m3_config_platforms.h +++ b/source/m3_config_platforms.h @@ -65,10 +65,13 @@ # if defined(M3_COMPILER_MSVC) # define M3_WEAK //__declspec(selectany) +# define M3_NO_UBSAN # elif defined(__MINGW32__) # define M3_WEAK //__attribute__((selectany)) +# define M3_NO_UBSAN # else -# define M3_WEAK __attribute__((weak)) +# define M3_WEAK __attribute__((weak)) +# define M3_NO_UBSAN __attribute__((no_sanitize("undefined"))) # endif # ifndef M3_MIN @@ -163,6 +166,9 @@ typedef int8_t i8; # ifndef d_m3VerboseErrorMessages # define d_m3VerboseErrorMessages 0 # endif +# ifndef d_m3MaxConstantTableSize +# define d_m3MaxConstantTableSize 64 +# endif # ifndef d_m3MaxFunctionStackHeight # define d_m3MaxFunctionStackHeight 64 # endif diff --git a/source/m3_exec_defs.h b/source/m3_exec_defs.h index 98fa77d..991ce59 100644 --- a/source/m3_exec_defs.h +++ b/source/m3_exec_defs.h @@ -45,7 +45,7 @@ d_m3BeginExternC typedef m3ret_t (vectorcall * IM3Operation) (d_m3OpSig); #define d_m3RetSig static inline m3ret_t vectorcall -#define d_m3Op(NAME) op_section d_m3RetSig op_##NAME (d_m3OpSig) +#define d_m3Op(NAME) M3_NO_UBSAN op_section d_m3RetSig op_##NAME (d_m3OpSig) #define nextOpImpl() ((IM3Operation)(* _pc))(_pc + 1, d_m3OpArgs) #define jumpOpImpl(PC) ((IM3Operation)(* PC))( PC + 1, d_m3OpArgs)