This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge amd-stg-open into amd-mainline-open
Change-Id: I946330c7455ee86a77183cfef8ed64479568963a
- Loading branch information
Showing
16 changed files
with
452 additions
and
309 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*===-------------------------------------------------------------------------- | ||
* ROCm Device Libraries | ||
* | ||
* This file is distributed under the University of Illinois Open Source | ||
* License. See LICENSE.TXT for details. | ||
*===------------------------------------------------------------------------*/ | ||
|
||
#pragma once | ||
#include "ockl.h" | ||
|
||
typedef ulong uptr; | ||
typedef unsigned char u8; | ||
typedef signed char s8; | ||
typedef unsigned short u16; | ||
typedef short s16; | ||
typedef unsigned long u64; | ||
|
||
#define ASAN_SHADOW 3 | ||
|
||
#define SHADOW_GRANULARITY (1ULL << ASAN_SHADOW) | ||
|
||
#define GET_CALLER_PC() (uptr) __builtin_return_address(0) | ||
|
||
#define WORKGROUP_ID(dim) __builtin_amdgcn_workgroup_id_##dim() | ||
|
||
#define OPT_NONE __attribute__((optnone)) | ||
|
||
#define NO_SANITIZE_ADDR __attribute__((no_sanitize("address"))) | ||
|
||
#define REPORT_IMPL(caller_pc, addr, is_write, size, no_abort) \ | ||
uptr read = is_write; \ | ||
if (no_abort) \ | ||
read |= 0xFFFFFFFF00000000; \ | ||
\ | ||
__ockl_sanitizer_report(addr, caller_pc, WORKGROUP_ID(x), WORKGROUP_ID(y), \ | ||
WORKGROUP_ID(z), __ockl_get_local_linear_id(), \ | ||
read, size); | ||
|
||
NO_SANITIZE_ADDR | ||
static bool | ||
is_aligned_by_granularity(uptr addr) | ||
{ | ||
return (addr & (SHADOW_GRANULARITY - 1)) == 0; | ||
} | ||
|
||
// round up size to the nearest multiple of boundary. | ||
NO_SANITIZE_ADDR | ||
static uptr | ||
round_upto(uptr size, uptr boundary) | ||
{ | ||
return (size + boundary - 1) & ~(boundary - 1); | ||
} | ||
|
||
// round down size to the nearest multiple of boundary. | ||
NO_SANITIZE_ADDR | ||
static uptr | ||
round_downto(uptr size, uptr boundary) | ||
{ | ||
return size & ~(boundary - 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*===-------------------------------------------------------------------------- | ||
* ROCm Device Libraries | ||
* | ||
* This file is distributed under the University of Illinois Open Source | ||
* License. See LICENSE.TXT for details. | ||
*===------------------------------------------------------------------------*/ | ||
|
||
#include "asan_util.h" | ||
#include "shadow_mapping.h" | ||
|
||
OPT_NONE | ||
NO_SANITIZE_ADDR | ||
static void | ||
check_memory_range_accessible(void* dest, const void* src, | ||
uptr size, uptr pc) { | ||
if (size == 0) | ||
return; | ||
uptr invalid_addr = 0; | ||
uptr src_addr = (uptr)src; | ||
invalid_addr = __asan_region_is_poisoned(src_addr, size); | ||
if (invalid_addr) { | ||
REPORT_IMPL(pc, invalid_addr, false, size, false) | ||
} | ||
uptr dest_addr = (uptr)dest; | ||
invalid_addr = __asan_region_is_poisoned(dest_addr, size); | ||
if (invalid_addr) { | ||
REPORT_IMPL(pc, invalid_addr, true, size, false) | ||
} | ||
} | ||
|
||
OPT_NONE | ||
NO_SANITIZE_ADDR | ||
void* | ||
__asan_memcpy(void* to, const void* from, uptr size) { | ||
uptr pc = GET_CALLER_PC(); | ||
check_memory_range_accessible(to, from, size, pc); | ||
return __builtin_memcpy(to, from, size); | ||
} | ||
|
||
OPT_NONE | ||
NO_SANITIZE_ADDR | ||
void* | ||
__asan_memmove(void* to, const void* from, uptr size) { | ||
uptr pc = GET_CALLER_PC(); | ||
check_memory_range_accessible(to, from, size, pc); | ||
return __builtin_memmove(to, from, size); | ||
} | ||
|
||
OPT_NONE | ||
NO_SANITIZE_ADDR | ||
void* | ||
__asan_memset(void* s, int c, uptr n) { | ||
uptr pc = GET_CALLER_PC(); | ||
uptr src_addr = (uptr)s; | ||
uptr invalid_addr = 0; | ||
invalid_addr = __asan_region_is_poisoned(src_addr, n); | ||
if (invalid_addr) { | ||
REPORT_IMPL(pc, invalid_addr, true, n, false) | ||
} | ||
return __builtin_memset(s, c, n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*===-------------------------------------------------------------------------- | ||
* ROCm Device Libraries | ||
* | ||
* This file is distributed under the University of Illinois Open Source | ||
* License. See LICENSE.TXT for details. | ||
*===------------------------------------------------------------------------*/ | ||
|
||
#include "shadow_mapping.h" | ||
|
||
NO_SANITIZE_ADDR | ||
static uptr | ||
range_check(uptr beg, uptr end) { | ||
uptr aligned_beg = round_downto(beg, SHADOW_GRANULARITY); | ||
uptr aligned_end = round_downto(end, SHADOW_GRANULARITY); | ||
uptr shadow_beg = MEM_TO_SHADOW(aligned_beg); | ||
uptr shadow_end = MEM_TO_SHADOW(aligned_end); | ||
uptr nbytes = (shadow_end - shadow_beg)+1; | ||
uptr shadow_byte_count = 0; | ||
while (shadow_beg <= shadow_end) { | ||
s8 shadow_value = *(__global s8 *)shadow_beg; | ||
if (shadow_value) | ||
break; | ||
shadow_byte_count++; | ||
shadow_beg++; | ||
} | ||
if (shadow_byte_count == nbytes) | ||
return 0; | ||
uptr start_addr = round_downto(beg + (shadow_byte_count*SHADOW_GRANULARITY), SHADOW_GRANULARITY); | ||
return start_addr; | ||
} | ||
|
||
//check all application bytes in [beg,beg+size) range are accessible | ||
NO_SANITIZE_ADDR | ||
uptr | ||
__asan_region_is_poisoned(uptr beg, uptr size) | ||
{ | ||
uptr end = beg + size - 1; | ||
uptr start_addr = range_check(beg, end); | ||
if (start_addr != 0) { | ||
// loop through the range to find accessible address. | ||
for (uptr addr = start_addr; addr <= end; ++addr) { | ||
if (is_address_poisoned(addr)) | ||
return addr; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.