* config/sh/sh.c (barrier_align): Return 0 when barrier_or_label
[official-gcc.git] / libsanitizer / asan / asan_poisoning.h
blob866c0a57c7ef7ea39f604a6619c1ee31092d4798
1 //===-- asan_poisoning.h ----------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // Shadow memory poisoning by ASan RTL and by user application.
11 //===----------------------------------------------------------------------===//
13 #include "asan_interceptors.h"
14 #include "asan_internal.h"
15 #include "asan_mapping.h"
17 namespace __asan {
19 // Poisons the shadow memory for "size" bytes starting from "addr".
20 void PoisonShadow(uptr addr, uptr size, u8 value);
22 // Poisons the shadow memory for "redzone_size" bytes starting from
23 // "addr + size".
24 void PoisonShadowPartialRightRedzone(uptr addr,
25 uptr size,
26 uptr redzone_size,
27 u8 value);
29 // Fast versions of PoisonShadow and PoisonShadowPartialRightRedzone that
30 // assume that memory addresses are properly aligned. Use in
31 // performance-critical code with care.
32 ALWAYS_INLINE void FastPoisonShadow(uptr aligned_beg, uptr aligned_size,
33 u8 value) {
34 DCHECK(flags()->poison_heap);
35 uptr shadow_beg = MEM_TO_SHADOW(aligned_beg);
36 uptr shadow_end = MEM_TO_SHADOW(
37 aligned_beg + aligned_size - SHADOW_GRANULARITY) + 1;
38 REAL(memset)((void*)shadow_beg, value, shadow_end - shadow_beg);
41 ALWAYS_INLINE void FastPoisonShadowPartialRightRedzone(
42 uptr aligned_addr, uptr size, uptr redzone_size, u8 value) {
43 DCHECK(flags()->poison_heap);
44 u8 *shadow = (u8*)MEM_TO_SHADOW(aligned_addr);
45 for (uptr i = 0; i < redzone_size; i += SHADOW_GRANULARITY, shadow++) {
46 if (i + SHADOW_GRANULARITY <= size) {
47 *shadow = 0; // fully addressable
48 } else if (i >= size) {
49 *shadow = (SHADOW_GRANULARITY == 128) ? 0xff : value; // unaddressable
50 } else {
51 // first size-i bytes are addressable
52 *shadow = static_cast<u8>(size - i);
57 } // namespace __asan