diff --git a/source/m3_config.h b/source/m3_config.h index 0dd2537..4d1ed47 100644 --- a/source/m3_config.h +++ b/source/m3_config.h @@ -43,7 +43,7 @@ # define d_m3EnableOptimizations 0 # endif -// logging --------------------------------------------------------------------------- +// logging -------------------------------------------------------------------- # define d_m3EnableOpProfiling 0 # define d_m3RuntimeStackDumps 0 @@ -51,7 +51,7 @@ # define d_m3TraceExec (1 && d_m3RuntimeStackDumps && DEBUG) -// m3log (...) -------------------------------------------------------------------- +// m3log (...) ---------------------------------------------------------------- # define d_m3LogParse 0 # define d_m3LogCompile 0 @@ -64,5 +64,9 @@ # define d_m3LogStackTrace 0 # define d_m3LogNativeStack 0 +// other ---------------------------------------------------------------------- + +//#define d_m3SkipStackCheck +//#define d_m3SkipMemoryBoundsCheck #endif /* m3_config_h */ diff --git a/source/m3_exception.h b/source/m3_exception.h index c1d0d66..ad858f8 100644 --- a/source/m3_exception.h +++ b/source/m3_exception.h @@ -9,13 +9,13 @@ #ifndef m3_exception_h #define m3_exception_h +#include "m3_config.h" + // some macros to emulate try/catch -#define EXC_STR(X) #X -#define EXC_TOSTR(x) EXC_STR(x) -#define EXC_PRINT //puts("Exc: " __FILE__ ":" EXC_TOSTR(__LINE__) "\n"); +#define EXCEPTION_PRINT //puts("Exc: " __FILE__ ":" M3_STR(__LINE__) "\n"); #define _try -#define _(TRY) { result = TRY; if (result) { EXC_PRINT; goto _catch; } } -#define _throw(ERROR) { result = ERROR; EXC_PRINT; goto _catch; } +#define _(TRY) { result = TRY; if (result) { EXCEPTION_PRINT; goto _catch; } } +#define _throw(ERROR) { result = ERROR; EXCEPTION_PRINT; goto _catch; } #endif /* m3_exception_h */ diff --git a/source/m3_exec.h b/source/m3_exec.h index 834eb3a..84e20f0 100644 --- a/source/m3_exec.h +++ b/source/m3_exec.h @@ -689,6 +689,12 @@ d_m3SetRegisterSetSlot (f32, _fp0) d_m3SetRegisterSetSlot (f64, _fp0) +#if defined(d_m3SkipMemoryBoundsCheck) +# define m3MemCheck(x) true +#else +# define m3MemCheck(x) (x) +#endif + #ifdef DEBUG #define d_outOfBounds return ErrorRuntime (c_m3Err_trapOutOfBoundsMemoryAccess, \ _mem->runtime, "memory size: %zu; access offset: %zu", \ @@ -707,7 +713,9 @@ d_m3Op(DEST_TYPE##_Load_##SRC_TYPE##_r) \ u64 operand = (u32) _r0; \ operand += offset; \ \ - if (operand + sizeof (SRC_TYPE) <= _mem->length) { \ + if (m3MemCheck( \ + operand + sizeof (SRC_TYPE) <= _mem->length \ + )) { \ u8* src8 = m3MemData(_mem) + operand; \ SRC_TYPE value; \ memcpy(&value, src8, sizeof(value)); \ @@ -721,7 +729,9 @@ d_m3Op(DEST_TYPE##_Load_##SRC_TYPE##_s) \ u32 offset = immediate (u32); \ operand += offset; \ \ - if (operand + sizeof (SRC_TYPE) <= _mem->length) { \ + if (m3MemCheck( \ + operand + sizeof (SRC_TYPE) <= _mem->length \ + )) { \ u8* src8 = m3MemData(_mem) + operand; \ SRC_TYPE value; \ memcpy(&value, src8, sizeof(value)); \ @@ -760,7 +770,9 @@ d_m3Op (SRC_TYPE##_Store_##DEST_TYPE##_sr) \ u32 offset = immediate (u32); \ operand += offset; \ \ - if (operand + sizeof (DEST_TYPE) <= _mem->length) { \ + if (m3MemCheck( \ + operand + sizeof (DEST_TYPE) <= _mem->length \ + )) { \ u8* mem8 = m3MemData(_mem) + operand; \ DEST_TYPE val = (DEST_TYPE) REG; \ memcpy(mem8, &val, sizeof(val)); \ @@ -774,7 +786,9 @@ d_m3Op (SRC_TYPE##_Store_##DEST_TYPE##_rs) \ u32 offset = immediate (u32); \ operand += offset; \ \ - if (operand + sizeof (DEST_TYPE) <= _mem->length) { \ + if (m3MemCheck( \ + operand + sizeof (DEST_TYPE) <= _mem->length \ + )) { \ u8* mem8 = m3MemData(_mem) + operand; \ DEST_TYPE val = (DEST_TYPE) value; \ memcpy(mem8, &val, sizeof(val)); \ @@ -788,7 +802,9 @@ d_m3Op (SRC_TYPE##_Store_##DEST_TYPE##_ss) \ u32 offset = immediate (u32); \ operand += offset; \ \ - if (operand + sizeof (DEST_TYPE) <= _mem->length) { \ + if (m3MemCheck( \ + operand + sizeof (DEST_TYPE) <= _mem->length \ + )) { \ u8* mem8 = m3MemData(_mem) + operand; \ DEST_TYPE val = (DEST_TYPE) value; \ memcpy(mem8, &val, sizeof(val)); \ @@ -804,7 +820,9 @@ d_m3Op (TYPE##_Store_##TYPE##_rr) \ u32 offset = immediate (u32); \ operand += offset; \ \ - if (operand + sizeof (TYPE) <= _mem->length) { \ + if (m3MemCheck( \ + operand + sizeof (TYPE) <= _mem->length \ + )) { \ u8* mem8 = m3MemData(_mem) + operand; \ TYPE val = (TYPE) REG; \ memcpy(mem8, &val, sizeof(val)); \ @@ -828,6 +846,8 @@ d_m3Store_i (i64, i16) d_m3Store_i (i64, i32) d_m3Store_i (i64, i64) +#undef m3MemCheck + //--------------------------------------------------------------------------------------------------------------------- # if d_m3EnableOptimizations //---------------------------------------------------------------------------------------------------------------------