1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker * Copyright 2016 Google Inc.
3*c8dee2aaSAndroid Build Coastguard Worker *
4*c8dee2aaSAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker */
7*c8dee2aaSAndroid Build Coastguard Worker
8*c8dee2aaSAndroid Build Coastguard Worker #ifndef SkMSAN_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define SkMSAN_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkAssert.h"
12*c8dee2aaSAndroid Build Coastguard Worker
13*c8dee2aaSAndroid Build Coastguard Worker #include <cstddef>
14*c8dee2aaSAndroid Build Coastguard Worker #include <string.h>
15*c8dee2aaSAndroid Build Coastguard Worker
16*c8dee2aaSAndroid Build Coastguard Worker // Typically declared in LLVM's msan_interface.h. Easier for us to just re-declare.
17*c8dee2aaSAndroid Build Coastguard Worker extern "C" {
18*c8dee2aaSAndroid Build Coastguard Worker void __msan_check_mem_is_initialized(const volatile void*, size_t);
19*c8dee2aaSAndroid Build Coastguard Worker void __msan_unpoison (const volatile void*, size_t);
20*c8dee2aaSAndroid Build Coastguard Worker }
21*c8dee2aaSAndroid Build Coastguard Worker
22*c8dee2aaSAndroid Build Coastguard Worker // Code that requires initialized inputs can call this to make it clear that
23*c8dee2aaSAndroid Build Coastguard Worker // the blame for use of uninitialized data belongs further up the call stack.
sk_msan_assert_initialized(const void * begin,const void * end)24*c8dee2aaSAndroid Build Coastguard Worker static inline void sk_msan_assert_initialized(const void* begin, const void* end) {
25*c8dee2aaSAndroid Build Coastguard Worker #if defined(__has_feature)
26*c8dee2aaSAndroid Build Coastguard Worker #if __has_feature(memory_sanitizer)
27*c8dee2aaSAndroid Build Coastguard Worker __msan_check_mem_is_initialized(begin, (const char*)end - (const char*)begin);
28*c8dee2aaSAndroid Build Coastguard Worker #endif
29*c8dee2aaSAndroid Build Coastguard Worker #endif
30*c8dee2aaSAndroid Build Coastguard Worker }
31*c8dee2aaSAndroid Build Coastguard Worker
32*c8dee2aaSAndroid Build Coastguard Worker // Lie to MSAN that this range of memory is initialized.
33*c8dee2aaSAndroid Build Coastguard Worker // This can hide serious problems if overused. Every use of this should refer to a bug.
sk_msan_mark_initialized(const void * begin,const void * end,const char * skbug)34*c8dee2aaSAndroid Build Coastguard Worker static inline void sk_msan_mark_initialized(const void* begin, const void* end, const char* skbug) {
35*c8dee2aaSAndroid Build Coastguard Worker SkASSERT(skbug && 0 != strcmp(skbug, ""));
36*c8dee2aaSAndroid Build Coastguard Worker #if defined(__has_feature)
37*c8dee2aaSAndroid Build Coastguard Worker #if __has_feature(memory_sanitizer)
38*c8dee2aaSAndroid Build Coastguard Worker __msan_unpoison(begin, (const char*)end - (const char*)begin);
39*c8dee2aaSAndroid Build Coastguard Worker #endif
40*c8dee2aaSAndroid Build Coastguard Worker #endif
41*c8dee2aaSAndroid Build Coastguard Worker }
42*c8dee2aaSAndroid Build Coastguard Worker
43*c8dee2aaSAndroid Build Coastguard Worker #endif//SkMSAN_DEFINED
44