• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // MemorySanitizer support.
6 
7 #ifndef V8_BASE_SANITIZER_MSAN_H_
8 #define V8_BASE_SANITIZER_MSAN_H_
9 
10 #include "src/base/macros.h"
11 #include "src/base/memory.h"
12 
13 #ifdef V8_USE_MEMORY_SANITIZER
14 
15 #include <sanitizer/msan_interface.h>
16 
17 // Marks a memory range as uninitialized, as if it was allocated here.
18 #define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(start, size) \
19   __msan_allocated_memory(reinterpret_cast<const void*>(start), (size))
20 
21 // Marks a memory range as initialized.
22 #define MSAN_MEMORY_IS_INITIALIZED(start, size) \
23   __msan_unpoison(reinterpret_cast<const void*>(start), (size))
24 
25 #else  // !V8_USE_MEMORY_SANITIZER
26 
27 #define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(start, size)                   \
28   static_assert((std::is_pointer<decltype(start)>::value ||                \
29                  std::is_same<v8::base::Address, decltype(start)>::value), \
30                 "static type violation");                                  \
31   static_assert(std::is_convertible<decltype(size), size_t>::value,        \
32                 "static type violation");                                  \
33   USE(start, size)
34 
35 #define MSAN_MEMORY_IS_INITIALIZED(start, size) \
36   MSAN_ALLOCATED_UNINITIALIZED_MEMORY(start, size)
37 
38 #endif  // V8_USE_MEMORY_SANITIZER
39 
40 #endif  // V8_BASE_SANITIZER_MSAN_H_
41