Disable GC on c++ catch block w/ASAN

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
Seonghyun Kim 2026-05-14 09:35:31 +09:00 committed by MuHong Byun
commit 166fa7c66b
2 changed files with 26 additions and 0 deletions

View file

@ -264,6 +264,16 @@ if (f.type == Type::B) { puts("failed in msvc."); }
#define HAVE_BUILTIN_ATOMIC_FUNCTIONS
#endif
#if defined(COMPILER_CLANG)
#if __has_feature(address_sanitizer)
#define ASAN_ENABLED
#endif
#elif defined(COMPILER_GCC)
#if defined(__SANITIZE_ADDRESS__)
#define ASAN_ENABLED
#endif
#endif
#if defined(COMPILER_MSVC)
#include <stddef.h>
#endif

View file

@ -111,6 +111,9 @@ SandBox::SandBoxResult SandBox::run(Value (*scriptRunner)(ExecutionState&, void*
result.result = scriptRunner(state, data);
} catch (const Value& err) {
processCatch(err, result);
#ifdef ASAN_ENABLED
GC_enable();
#endif
}
return result;
}
@ -123,6 +126,9 @@ SandBox::SandBoxResult SandBox::run(ExecutionState& parentState, Value (*runner)
result.result = runner(state, data);
} catch (const Value& err) {
processCatch(err, result);
#ifdef ASAN_ENABLED
GC_enable();
#endif
}
return result;
}
@ -310,6 +316,11 @@ void SandBox::throwException(ExecutionState& state, const Value& exception)
// We MUST save thrown exception Value.
// because bdwgc cannot track `thrown value`(may turned off by GC_DONT_REGISTER_MAIN_STATIC_DATA)
m_exception = exception;
// If ASAN is enabled, BDWGC cannot perform stack scanning properly in the catch block.
#ifdef ASAN_ENABLED
GC_disable();
#endif
throw exception;
}
@ -322,6 +333,11 @@ void SandBox::rethrowPreviouslyCaughtException(ExecutionState& state, Value exce
// We MUST save thrown exception Value.
// because bdwgc cannot track `thrown value`(may turned off by GC_DONT_REGISTER_MAIN_STATIC_DATA)
m_exception = exception;
// If ASAN is enabled, BDWGC cannot perform stack scanning properly in the catch block.
#ifdef ASAN_ENABLED
GC_disable();
#endif
throw exception;
}