Cheng Shao pushed to branch wip/terrorjack/asan at Glasgow Haskell Compiler / GHC
Commits:
-
4ae15738
by Cheng Shao at 2025-12-12T16:30:39+01:00
4 changed files:
Changes:
| ... | ... | @@ -335,6 +335,7 @@ external prototype return neither of these types to workaround #11395. |
| 335 | 335 | #include "stg/MachRegsForHost.h"
|
| 336 | 336 | #include "stg/Regs.h"
|
| 337 | 337 | #include "stg/Ticky.h"
|
| 338 | +#include "rts/ASANUtils.h"
|
|
| 338 | 339 | #include "rts/TSANUtils.h"
|
| 339 | 340 | |
| 340 | 341 | #if IN_STG_CODE
|
| 1 | +#pragma once
|
|
| 2 | + |
|
| 3 | +#if defined(__SANITIZE_ADDRESS__)
|
|
| 4 | +#define ASAN_ENABLED
|
|
| 5 | +#elif defined(__has_feature)
|
|
| 6 | +#if __has_feature(address_sanitizer)
|
|
| 7 | +#define ASAN_ENABLED
|
|
| 8 | +#endif
|
|
| 9 | +#endif
|
|
| 10 | + |
|
| 11 | +#if defined(ASAN_ENABLED)
|
|
| 12 | +#include <sanitizer/asan_interface.h>
|
|
| 13 | +#else
|
|
| 14 | +#include <stdlib.h>
|
|
| 15 | +#endif
|
|
| 16 | + |
|
| 17 | +static inline void __ghc_asan_poison_memory_region(void const volatile *addr, size_t size) {
|
|
| 18 | +#if defined(ASAN_ENABLED)
|
|
| 19 | + __asan_poison_memory_region(addr, size);
|
|
| 20 | +#endif
|
|
| 21 | +}
|
|
| 22 | + |
|
| 23 | +static inline void __ghc_asan_unpoison_memory_region(void const volatile *addr, size_t size) {
|
|
| 24 | +#if defined(ASAN_ENABLED)
|
|
| 25 | + __asan_unpoison_memory_region(addr, size);
|
|
| 26 | +#endif
|
|
| 27 | +} |
| ... | ... | @@ -289,6 +289,7 @@ library |
| 289 | 289 | -- ^ generated
|
| 290 | 290 | rts/ghc_ffi.h
|
| 291 | 291 | rts/Adjustor.h
|
| 292 | + rts/ASANUtils.h
|
|
| 292 | 293 | rts/ExecPage.h
|
| 293 | 294 | rts/BlockSignals.h
|
| 294 | 295 | rts/Bytecodes.h
|
| ... | ... | @@ -579,6 +579,8 @@ getMBlocks(uint32_t n) |
| 579 | 579 | |
| 580 | 580 | ret = getCommittedMBlocks(n);
|
| 581 | 581 | |
| 582 | + __ghc_asan_unpoison_memory_region(ret, (W_)n * MBLOCK_SIZE);
|
|
| 583 | + |
|
| 582 | 584 | debugTrace(DEBUG_gc, "allocated %d megablock(s) at %p",n,ret);
|
| 583 | 585 | |
| 584 | 586 | mblocks_allocated += n;
|
| ... | ... | @@ -611,6 +613,8 @@ freeMBlocks(void *addr, uint32_t n) |
| 611 | 613 | |
| 612 | 614 | mblocks_allocated -= n;
|
| 613 | 615 | |
| 616 | + __ghc_asan_poison_memory_region(addr, (W_)n * MBLOCK_SIZE);
|
|
| 617 | + |
|
| 614 | 618 | decommitMBlocks(addr, n);
|
| 615 | 619 | }
|
| 616 | 620 |