Skip to content

Commit 57eb233

Browse files
committed
[SWDEV-409372] [Asan] Add __asan_poison_region to device-libs.
Change-Id: I0e0019af87f3b00ac0225d348c624f1937ece673
1 parent 1ad9ba1 commit 57eb233

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

amd/device-libs/asanrtl/src/shadow_mapping.cl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "shadow_mapping.h"
99

10+
static const __constant u8 kAsanHeapLeftRedzoneMagic = (u8)0xfa;
11+
1012
NO_SANITIZE_ADDR
1113
static uptr
1214
range_check(uptr beg, uptr end) {
@@ -45,3 +47,25 @@ __asan_region_is_poisoned(uptr beg, uptr size)
4547
}
4648
return 0;
4749
}
50+
51+
USED NO_INLINE NO_SANITIZE_ADDR
52+
void
53+
__asan_poison_region(ulong beg, ulong size)
54+
{
55+
// Handle intial bytes if not aligned.
56+
if (!is_aligned_by_granularity(beg)) {
57+
ulong beg_round_downto = round_downto(beg, SHADOW_GRANULARITY);
58+
__global s8 *shadow_ptr = (__global s8 *)MEM_TO_SHADOW(beg_round_downto);
59+
s8 shadow_value = (s8) (beg - beg_round_downto);
60+
*shadow_ptr = shadow_value;
61+
}
62+
63+
// Handle aligned bytes.
64+
ulong end = round_downto(beg + size, SHADOW_GRANULARITY);
65+
ulong beg_round_upto = round_upto(beg, SHADOW_GRANULARITY);
66+
if (end > beg_round_upto) {
67+
u64 shadow_size = (end - beg_round_upto) / SHADOW_GRANULARITY;
68+
__global s8 *shadow_ptr = (__global s8 *)MEM_TO_SHADOW(beg_round_upto);
69+
__builtin_memset(shadow_ptr, kAsanHeapLeftRedzoneMagic, shadow_size);
70+
}
71+
}

0 commit comments

Comments
 (0)