From 8c8691ea660bd1d89212effa131d1becd2fa17ab Mon Sep 17 00:00:00 2001 From: etkmao Date: Thu, 26 Sep 2024 17:45:11 +0800 Subject: [PATCH] fix(core): add safe static var for ios static crash --- modules/footstone/include/footstone/check.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/footstone/include/footstone/check.h b/modules/footstone/include/footstone/check.h index 0f9bb8b2457..234e747a83a 100644 --- a/modules/footstone/include/footstone/check.h +++ b/modules/footstone/include/footstone/check.h @@ -55,8 +55,9 @@ class SafeStaticVar { template static void InitSafeStaticVar(SafeStaticVar *var, std::shared_ptr &var_inner) { var->var_inner_ = var_inner; - uint64_t *p = (uint64_t *)&var_inner; + uint64_t *p = (uint64_t *)&var->var_inner_; uint64_t value = *p; + value ^= 0xf; var->sign_before_ = value; var->sign_after_ = value; } @@ -65,6 +66,10 @@ template static std::shared_ptr GetSafeStaticVar(SafeStaticVar *var) { uint64_t *p = (uint64_t *)&var->var_inner_; uint64_t value = *p; + if (value == 0) { + return nullptr; + } + value ^= 0xf; if (var->sign_before_ != value) { return nullptr; }