SkMSAN.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #ifndef SkMSAN_DEFINED
  8. #define SkMSAN_DEFINED
  9. #include "include/core/SkTypes.h"
  10. #include <string.h>
  11. // Typically declared in LLVM's msan_interface.h. Easier for us to just re-declare.
  12. extern "C" {
  13. void __msan_check_mem_is_initialized(const volatile void*, size_t);
  14. void __msan_unpoison (const volatile void*, size_t);
  15. }
  16. // Code that requires initialized inputs can call this to make it clear that
  17. // the blame for use of uninitialized data belongs further up the call stack.
  18. static inline void sk_msan_assert_initialized(const void* begin, const void* end) {
  19. #if defined(__has_feature)
  20. #if __has_feature(memory_sanitizer)
  21. __msan_check_mem_is_initialized(begin, (const char*)end - (const char*)begin);
  22. #endif
  23. #endif
  24. }
  25. // Lie to MSAN that this range of memory is initialized.
  26. // This can hide serious problems if overused. Every use of this should refer to a bug.
  27. static inline void sk_msan_mark_initialized(const void* begin, const void* end, const char* skbug) {
  28. SkASSERT(skbug && 0 != strcmp(skbug, ""));
  29. #if defined(__has_feature)
  30. #if __has_feature(memory_sanitizer)
  31. __msan_unpoison(begin, (const char*)end - (const char*)begin);
  32. #endif
  33. #endif
  34. }
  35. #endif//SkMSAN_DEFINED