From 8ad7b6149fa1e834733437292425091bc99de988 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 4 Jun 2022 01:19:17 +0300 Subject: [PATCH] OOM fuzz testing base --- src/builtins/md2.c | 2 +- src/core/stuff.h | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/builtins/md2.c b/src/builtins/md2.c index 0158e864..426eb431 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -10,7 +10,7 @@ B md2BI_ucw(Md2* t, B o, B f, B g, B w, B x) { return ((BMd2*)t)->ucw(t, o, f, g B val_c1(Md2D* d, B x) { return c1(d->f, x); } B val_c2(Md2D* d, B w, B x) { return c2(d->g, w,x); } -#if CATCH_ERRORS +#if CATCH_ERRORS && !BI_CATCH_DISABLED extern B lastErrMsg; // sysfn.c B fillBy_c1(Md2D* d, B x) { diff --git a/src/core/stuff.h b/src/core/stuff.h index deaa913d..adbbb96f 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -254,7 +254,16 @@ static BBB2B c2fn(B f) { extern u32** actrs; #endif #endif -static inline void onAlloc(usz sz, u8 type) { + +#ifdef OOM_TEST + extern i64 oomTestLeft; + NOINLINE NORETURN void thrOOMTest(void); +#endif + +FORCE_INLINE void onAlloc(usz sz, u8 type) { + #ifdef OOM_TEST + if (--oomTestLeft==0) thrOOMTest(); + #endif #ifdef ALLOC_STAT if (!ctr_a) { #ifdef ALLOC_SIZES @@ -272,7 +281,7 @@ static inline void onAlloc(usz sz, u8 type) { talloc+= sz; #endif } -static inline void onFree(Value* x) { +FORCE_INLINE void onFree(Value* x) { #ifdef ALLOC_STAT ctr_f[x->type]++; #endif