Skip to content

Commit 9affd1c

Browse files
committed
Silence a legitimate vfptr sanitizer warning that is on by default in Android NDK 29
1 parent 23ce3b1 commit 9affd1c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

napi-inl.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#include <type_traits>
2222
#include <utility>
2323

24+
#if defined(__clang__) || defined(__GNUC__)
25+
#define NAPI_NO_SANITIZE_VPTR __attribute__((no_sanitize("vptr")))
26+
#else
27+
#define NAPI_NO_SANITIZE_VPTR
28+
#endif
29+
2430
namespace Napi {
2531

2632
#ifdef NAPI_CPP_CUSTOM_NAMESPACE
@@ -4717,7 +4723,8 @@ inline napi_value InstanceWrap<T>::WrappedMethod(
47174723
////////////////////////////////////////////////////////////////////////////////
47184724

47194725
template <typename T>
4720-
inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
4726+
inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::ObjectWrap(
4727+
const Napi::CallbackInfo& callbackInfo) {
47214728
napi_env env = callbackInfo.Env();
47224729
napi_value wrapper = callbackInfo.This();
47234730
napi_status status;
@@ -4731,7 +4738,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
47314738
}
47324739

47334740
template <typename T>
4734-
inline ObjectWrap<T>::~ObjectWrap() {
4741+
inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::~ObjectWrap() {
47354742
// If the JS object still exists at this point, remove the finalizer added
47364743
// through `napi_wrap()`.
47374744
if (!IsEmpty() && !_finalized) {
@@ -4744,8 +4751,12 @@ inline ObjectWrap<T>::~ObjectWrap() {
47444751
}
47454752
}
47464753

4754+
// with RTTI turned on, modern compilers check to see if virtual function
4755+
// pointers are stripped of RTTI by void casts. this is intrinsic to how Unwrap
4756+
// works, so we inject a compiler pragma to turn off that check just for the
4757+
// affected methods. this compiler check is on by default in Android NDK 29.
47474758
template <typename T>
4748-
inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
4759+
inline NAPI_NO_SANITIZE_VPTR T* ObjectWrap<T>::Unwrap(Object wrapper) {
47494760
void* unwrapped;
47504761
napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
47514762
NAPI_THROW_IF_FAILED(wrapper.Env(), status, nullptr);
@@ -7030,4 +7041,6 @@ inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
70307041

70317042
} // namespace Napi
70327043

7044+
#undef NAPI_NO_SANITIZE_VPTR
7045+
70337046
#endif // SRC_NAPI_INL_H_

0 commit comments

Comments
 (0)