Commit f3745430 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[msan] Add static type checks for non-msan builds

Currently, non-msan builds don't check the arguments for
MSAN_ALLOCATED_UNINITIALIZED_MEMORY and MSAN_MEMORY_IS_INITIALIZED
calls, so type errors will only be reported on the msan builder.
This CL adds static_asserts for non-msan builds.

Drive-by: Rename MEMORY_SANITIZER to V8_USE_MEMORY_SANITIZER and move
it to macros.h, where also other such macros (like
V8_USE_ADDRESS_SANITIZER) live.

R=ahaas@chromium.org

Bug: v8:7570
Change-Id: If6c3c6e0d1287b5f1e0c59828cd028d1beac933d
Reviewed-on: https://chromium-review.googlesource.com/1046655Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53071}
parent fd9addd7
......@@ -149,20 +149,27 @@ V8_INLINE Dest bit_cast(Source const& source) {
#define INLINE(declarator) V8_INLINE declarator
#define NO_INLINE(declarator) V8_NOINLINE declarator
// Define V8_USE_ADDRESS_SANITIZER macros.
// Define V8_USE_ADDRESS_SANITIZER macro.
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define V8_USE_ADDRESS_SANITIZER 1
#endif
#endif
// Define DISABLE_ASAN macros.
// Define DISABLE_ASAN macro.
#ifdef V8_USE_ADDRESS_SANITIZER
#define DISABLE_ASAN __attribute__((no_sanitize_address))
#else
#define DISABLE_ASAN
#endif
// Define V8_USE_MEMORY_SANITIZER macro.
#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
#define V8_USE_MEMORY_SANITIZER 1
#endif
#endif
// Helper macro to define no_sanitize attributes only with clang.
#if defined(__clang__) && defined(__has_attribute)
#if __has_attribute(no_sanitize)
......
......@@ -7,18 +7,12 @@
#ifndef V8_MSAN_H_
#define V8_MSAN_H_
#include "src/base/macros.h"
#include "src/globals.h"
#ifndef __has_feature
# define __has_feature(x) 0
#endif
#ifdef V8_USE_MEMORY_SANITIZER
#if __has_feature(memory_sanitizer) && !defined(MEMORY_SANITIZER)
# define MEMORY_SANITIZER
#endif
#if defined(MEMORY_SANITIZER)
# include <sanitizer/msan_interface.h> // NOLINT
#include <sanitizer/msan_interface.h>
// Marks a memory range as uninitialized, as if it was allocated here.
#define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(p, s) \
......@@ -26,9 +20,17 @@
// Marks a memory range as initialized.
#define MSAN_MEMORY_IS_INITIALIZED(p, s) \
__msan_unpoison(reinterpret_cast<const void*>(p), (s))
#else
# define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(p, s)
#define MSAN_MEMORY_IS_INITIALIZED(p, s)
#endif
#else // !V8_USE_MEMORY_SANITIZER
#define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(p, s) \
static_assert((std::is_pointer<decltype(p)>::value || \
std::is_same<v8::internal::Address, decltype(p)>::value) && \
std::is_convertible<decltype(s), size_t>::value, \
"static type violation")
#define MSAN_MEMORY_IS_INITIALIZED(p, s) \
MSAN_ALLOCATED_UNINITIALIZED_MEMORY(p, s)
#endif // V8_USE_MEMORY_SANITIZER
#endif // V8_MSAN_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment