brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 84268a1 Raw
50 lines · c
1//===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H10#define LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H11 12#include "src/__support/macros/config.h" //LIBC_HAS_FEATURE13 14//-----------------------------------------------------------------------------15// Functions to unpoison memory16//-----------------------------------------------------------------------------17 18#if LIBC_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__)19#define LIBC_HAS_ADDRESS_SANITIZER20#endif21 22#if LIBC_HAS_FEATURE(memory_sanitizer)23#define LIBC_HAS_MEMORY_SANITIZER24#endif25 26#ifdef LIBC_HAS_MEMORY_SANITIZER27// Only perform MSAN unpoison in non-constexpr context.28#include <sanitizer/msan_interface.h>29#define MSAN_UNPOISON(addr, size)                                              \30  do {                                                                         \31    if (!__builtin_is_constant_evaluated())                                    \32      __msan_unpoison(addr, size);                                             \33  } while (0)34#else35#define MSAN_UNPOISON(ptr, size)36#endif37 38#ifdef LIBC_HAS_ADDRESS_SANITIZER39#include <sanitizer/asan_interface.h>40#define ASAN_POISON_MEMORY_REGION(addr, size)                                  \41  __asan_poison_memory_region((addr), (size))42#define ASAN_UNPOISON_MEMORY_REGION(addr, size)                                \43  __asan_unpoison_memory_region((addr), (size))44#else45#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))46#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))47#endif48 49#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H50