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