]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libsanitizer/asan/asan_poisoning.h
1 //===-- asan_poisoning.h ----------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
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"
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
24 void PoisonShadowPartialRightRedzone(uptr addr
,
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
,
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 bool poison_partial
= flags()->poison_partial
;
45 u8
*shadow
= (u8
*)MEM_TO_SHADOW(aligned_addr
);
46 for (uptr i
= 0; i
< redzone_size
; i
+= SHADOW_GRANULARITY
, shadow
++) {
47 if (i
+ SHADOW_GRANULARITY
<= size
) {
48 *shadow
= 0; // fully addressable
49 } else if (i
>= size
) {
50 *shadow
= (SHADOW_GRANULARITY
== 128) ? 0xff : value
; // unaddressable
52 // first size-i bytes are addressable
53 *shadow
= poison_partial
? static_cast<u8
>(size
- i
) : 0;