diff --git a/src/hotspot/os/posix/safefetch_sigjmp.cpp b/src/hotspot/os/posix/safefetch_sigjmp.cpp index f1e674111c6..e141b8fb573 100644 --- a/src/hotspot/os/posix/safefetch_sigjmp.cpp +++ b/src/hotspot/os/posix/safefetch_sigjmp.cpp @@ -26,6 +26,7 @@ #include "precompiled.hpp" #include "runtime/safefetch.hpp" +#include "sanitizers/address.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" @@ -63,7 +64,7 @@ bool handle_safefetch(int sig, address ignored1, void* ignored2) { } template -static bool _SafeFetchXX_internal(const T *adr, T* result) { +ATTRIBUTE_NO_ASAN static bool _SafeFetchXX_internal(const T *adr, T* result) { T n = 0; diff --git a/src/hotspot/os/windows/safefetch_windows.hpp b/src/hotspot/os/windows/safefetch_windows.hpp index 01904ffa9b2..c745b832abe 100644 --- a/src/hotspot/os/windows/safefetch_windows.hpp +++ b/src/hotspot/os/windows/safefetch_windows.hpp @@ -26,12 +26,13 @@ #ifndef OS_WINDOWS_SAFEFETCH_WINDOWS_HPP #define OS_WINDOWS_SAFEFETCH_WINDOWS_HPP +#include "sanitizers/address.hpp" #include "utilities/globalDefinitions.hpp" // On windows, we use structured exception handling to implement SafeFetch template -inline T SafeFetchXX(const T* adr, T errValue) { +ATTRIBUTE_NO_ASAN inline T SafeFetchXX(const T* adr, T errValue) { T v = 0; __try { v = *adr; diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 35dd898ff7d..eb43fde5d71 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -60,6 +60,7 @@ #include "runtime/threadSMR.hpp" #include "runtime/vmOperations.hpp" #include "runtime/vm_version.hpp" +#include "sanitizers/address.hpp" #include "services/attachListener.hpp" #include "services/mallocTracker.hpp" #include "services/mallocHeader.inline.hpp" @@ -942,6 +943,16 @@ bool os::print_function_and_library_name(outputStream* st, return have_function_name || have_library_name; } +ATTRIBUTE_NO_ASAN static void print_hex_readable_pointer(outputStream* st, address p, + int unitsize) { + switch (unitsize) { + case 1: st->print("%02x", *(u1*)p); break; + case 2: st->print("%04x", *(u2*)p); break; + case 4: st->print("%08x", *(u4*)p); break; + case 8: st->print("%016" FORMAT64_MODIFIER "x", *(u8*)p); break; + } +} + void os::print_hex_dump(outputStream* st, address start, address end, int unitsize, int bytes_per_line, address logical_start) { 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 st->print(PTR_FORMAT ": ", p2i(logical_p)); while (p < end) { if (is_readable_pointer(p)) { - switch (unitsize) { - case 1: st->print("%02x", *(u1*)p); break; - case 2: st->print("%04x", *(u2*)p); break; - case 4: st->print("%08x", *(u4*)p); break; - case 8: st->print("%016" FORMAT64_MODIFIER "x", *(u8*)p); break; - } + print_hex_readable_pointer(st, p, unitsize); } else { st->print("%*.*s", 2*unitsize, 2*unitsize, "????????????????"); } diff --git a/src/hotspot/share/sanitizers/address.hpp b/src/hotspot/share/sanitizers/address.hpp index 8519de1a849..5186053f1c9 100644 --- a/src/hotspot/share/sanitizers/address.hpp +++ b/src/hotspot/share/sanitizers/address.hpp @@ -29,6 +29,25 @@ #include #endif +// ATTRIBUTE_NO_ASAN +// +// Function attribute which informs the compiler to not instrument memory accesses in the function. +// Useful if the function is known to do something dangerous, such as reading previous stack frames +// or reading arbitrary regions of memory when dumping during a crash. +#ifdef ADDRESS_SANITIZER +#if defined(TARGET_COMPILER_gcc) +// GCC-like, including Clang. +#define ATTRIBUTE_NO_ASAN __attribute__((no_sanitize_address)) +#elif defined(TARGET_COMPILER_visCPP) +// Microsoft Visual C++ +#define ATTRIBUTE_NO_ASAN __declspec(no_sanitize_address) +#endif +#endif + +#ifndef ATTRIBUTE_NO_ASAN +#define ATTRIBUTE_NO_ASAN +#endif + // ASAN_POISON_MEMORY_REGION()/ASAN_UNPOISON_MEMORY_REGION() // // Poisons/unpoisons the specified memory region. When ASan is available this is the macro of the