RFR: 8369393: NMT: poison the canaries of malloc header under ASAN build [v7]

Afshin Zafari azafari at openjdk.org
Tue Oct 14 16:11:07 UTC 2025


On Tue, 14 Oct 2025 11:45:06 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:

>> Afshin Zafari has updated the pull request incrementally with three additional commits since the last revision:
>> 
>>  - better style
>>  - a step back
>>  - alternative impl
>
> src/hotspot/share/sanitizers/address.hpp line 29:
> 
>> 27: 
>> 28: #ifdef ADDRESS_SANITIZER
>> 29: #define __SANITIZE_ADDRESS__
> 
> Why not just check for `ADDRESS_SANITIZER` in the test, and skip this definition?

In `.../clang/15.0.0/include/sanitizer/asan_interface.h`, the ASAN_(UN)POISON_MEMORY_REGION  macros would be empty as  
```C++
// Macros provided for convenience.
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
/// Marks a memory region as unaddressable.
///
/// \note Macro provided for convenience; defined as a no-op if ASan is not
/// enabled.
///
/// \param addr Start of memory region.
/// \param size Size of memory region.
#define ASAN_POISON_MEMORY_REGION(addr, size) \
  __asan_poison_memory_region((addr), (size))

/// Marks a memory region as addressable.
///
/// \note Macro provided for convenience; defined as a no-op if ASan is not
/// enabled.
///
/// \param addr Start of memory region.
/// \param size Size of memory region.
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
  __asan_unpoison_memory_region((addr), (size))
#else
#define ASAN_POISON_MEMORY_REGION(addr, size) \
  ((void)(addr), (void)(size))
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
  ((void)(addr), (void)(size))
#endif


I couldn't find yet why is that. So a fast/certain solution was to define the `__SANITIZE_ADDRESS__` explicitly.
Should be found before integrating this PR.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27685#discussion_r2429725296


More information about the hotspot-runtime-dev mailing list