Skip to content

Commit 98a392c

Browse files
jckingtstuefe
authored andcommitted
8302102: Disable ASan for SafeFetch and os::print_hex_dump
Reviewed-by: dholmes, stuefe
1 parent 9ccf8ad commit 98a392c

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/hotspot/os/posix/safefetch_sigjmp.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "precompiled.hpp"
2727

2828
#include "runtime/safefetch.hpp"
29+
#include "sanitizers/address.hpp"
2930
#include "utilities/debug.hpp"
3031
#include "utilities/globalDefinitions.hpp"
3132

@@ -63,7 +64,7 @@ bool handle_safefetch(int sig, address ignored1, void* ignored2) {
6364
}
6465

6566
template <class T>
66-
static bool _SafeFetchXX_internal(const T *adr, T* result) {
67+
ATTRIBUTE_NO_ASAN static bool _SafeFetchXX_internal(const T *adr, T* result) {
6768

6869
T n = 0;
6970

src/hotspot/os/windows/safefetch_windows.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
#ifndef OS_WINDOWS_SAFEFETCH_WINDOWS_HPP
2727
#define OS_WINDOWS_SAFEFETCH_WINDOWS_HPP
2828

29+
#include "sanitizers/address.hpp"
2930
#include "utilities/globalDefinitions.hpp"
3031

3132
// On windows, we use structured exception handling to implement SafeFetch
3233

3334
template <class T>
34-
inline T SafeFetchXX(const T* adr, T errValue) {
35+
ATTRIBUTE_NO_ASAN inline T SafeFetchXX(const T* adr, T errValue) {
3536
T v = 0;
3637
__try {
3738
v = *adr;

src/hotspot/share/runtime/os.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "runtime/threadSMR.hpp"
6161
#include "runtime/vmOperations.hpp"
6262
#include "runtime/vm_version.hpp"
63+
#include "sanitizers/address.hpp"
6364
#include "services/attachListener.hpp"
6465
#include "services/mallocTracker.hpp"
6566
#include "services/mallocHeader.inline.hpp"
@@ -942,6 +943,16 @@ bool os::print_function_and_library_name(outputStream* st,
942943
return have_function_name || have_library_name;
943944
}
944945

946+
ATTRIBUTE_NO_ASAN static void print_hex_readable_pointer(outputStream* st, address p,
947+
int unitsize) {
948+
switch (unitsize) {
949+
case 1: st->print("%02x", *(u1*)p); break;
950+
case 2: st->print("%04x", *(u2*)p); break;
951+
case 4: st->print("%08x", *(u4*)p); break;
952+
case 8: st->print("%016" FORMAT64_MODIFIER "x", *(u8*)p); break;
953+
}
954+
}
955+
945956
void os::print_hex_dump(outputStream* st, address start, address end, int unitsize,
946957
int bytes_per_line, address logical_start) {
947958
assert(unitsize == 1 || unitsize == 2 || unitsize == 4 || unitsize == 8, "just checking");
@@ -960,12 +971,7 @@ void os::print_hex_dump(outputStream* st, address start, address end, int unitsi
960971
st->print(PTR_FORMAT ": ", p2i(logical_p));
961972
while (p < end) {
962973
if (is_readable_pointer(p)) {
963-
switch (unitsize) {
964-
case 1: st->print("%02x", *(u1*)p); break;
965-
case 2: st->print("%04x", *(u2*)p); break;
966-
case 4: st->print("%08x", *(u4*)p); break;
967-
case 8: st->print("%016" FORMAT64_MODIFIER "x", *(u8*)p); break;
968-
}
974+
print_hex_readable_pointer(st, p, unitsize);
969975
} else {
970976
st->print("%*.*s", 2*unitsize, 2*unitsize, "????????????????");
971977
}

src/hotspot/share/sanitizers/address.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@
2929
#include <sanitizer/asan_interface.h>
3030
#endif
3131

32+
// ATTRIBUTE_NO_ASAN
33+
//
34+
// Function attribute which informs the compiler to not instrument memory accesses in the function.
35+
// Useful if the function is known to do something dangerous, such as reading previous stack frames
36+
// or reading arbitrary regions of memory when dumping during a crash.
37+
#ifdef ADDRESS_SANITIZER
38+
#if defined(TARGET_COMPILER_gcc)
39+
// GCC-like, including Clang.
40+
#define ATTRIBUTE_NO_ASAN __attribute__((no_sanitize_address))
41+
#elif defined(TARGET_COMPILER_visCPP)
42+
// Microsoft Visual C++
43+
#define ATTRIBUTE_NO_ASAN __declspec(no_sanitize_address)
44+
#endif
45+
#endif
46+
47+
#ifndef ATTRIBUTE_NO_ASAN
48+
#define ATTRIBUTE_NO_ASAN
49+
#endif
50+
3251
// ASAN_POISON_MEMORY_REGION()/ASAN_UNPOISON_MEMORY_REGION()
3352
//
3453
// Poisons/unpoisons the specified memory region. When ASan is available this is the macro of the

0 commit comments

Comments
 (0)