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

Johan Sjölen jsjolen at openjdk.org
Thu Oct 16 07:56:24 UTC 2025


On Wed, 15 Oct 2025 10:12:39 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

>> src/hotspot/share/nmt/mallocHeader.hpp line 96:
>> 
>>> 94:  public:
>>> 95:   AsanPoisoningHelper() = delete;
>>> 96:   AsanPoisoningHelper(U* addr) : _memory_region(addr) {
>> 
>> This is what I meant, then you don't need any casting when passing along the args.
>> 
>> ```c++
>> template<typename T>
>> class AsanPoisoningHelper {
>> 
>> public:
>>   AsanPoisoningHelper(T* addr) : _memory_region(addr) {
>>     #if INCLUDE_ASAN
>>       ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(_memory_region), sizeof(T));
>>     #endif
>>   }
>> };
>
> since we are using `const ...` types for `T`, we cannot use `reinterpret_cast`. 
> Casting is avoided everywhere by introducing second template parameter `U`.

`U` is `T` with `const`, right? Just make `_memory_region` `const T*` and remove `U`. If the `reinterpret_cast` isn't needed for the macro to work, then don't use it.

If you need some more advanced modifications of the types involved, then look at the `<type_traits>` header, example: https://en.cppreference.com/w/cpp/types/remove_cv.html

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

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


More information about the hotspot-runtime-dev mailing list