[Git][ghc/ghc][ghc-9.14] 2 commits: rts: fix eager black holes: record mutated closure and fix assertion
Zubin pushed to branch ghc-9.14 at Glasgow Haskell Compiler / GHC Commits: bcc68c56 by Luite Stegeman at 2025-11-25T18:23:46+05:30 rts: fix eager black holes: record mutated closure and fix assertion This fixes two problems with handling eager black holes, introduced by a1de535f762bc23d4cf23a5b1853591dda12cdc9. - the closure mutation must be recorded even for eager black holes, since the mutator has mutated it before calling threadPaused - The assertion that an unmarked eager black hole must be owned by the TSO calling threadPaused is incorrect, since multiple threads can race to claim the black hole. fixes #26495 (cherry picked from commit 3ba3d9f9db784c903ebe8fd617447ce62d30b7d3) - - - - - 85e8147d by Zubin Duggal at 2025-11-28T14:00:24+05:30 rts/linker/PEi386: Copy strings before they are inserted into LoadedDllCache. The original strings are temporary and might be freed at an arbitrary point. Fixes #26613 (cherry picked from commit 5072da477b8ec883aea4b9ea27763fcc1971af1a) - - - - - 2 changed files: - rts/ThreadPaused.c - rts/linker/PEi386.c Changes: ===================================== rts/ThreadPaused.c ===================================== @@ -321,11 +321,12 @@ threadPaused(Capability *cap, StgTSO *tso) if(frame_info == &stg_bh_upd_frame_info) { // eager black hole: we do nothing - // it should be a black hole that we own + // it should be a black hole (but we may not own it, as another + // thread could have raced us to claim it) ASSERT(bh_info == &stg_BLACKHOLE_info || bh_info == &__stg_EAGER_BLACKHOLE_info || bh_info == &stg_CAF_BLACKHOLE_info); - ASSERT(blackHoleOwner(bh) == tso || blackHoleOwner(bh) == NULL); + } else { // lazy black hole @@ -368,13 +369,15 @@ threadPaused(Capability *cap, StgTSO *tso) // The payload of the BLACKHOLE points to the TSO RELEASE_STORE(&((StgInd *)bh)->indirectee, (StgClosure *)tso); SET_INFO_RELEASE(bh,&stg_BLACKHOLE_info); + } - // .. and we need a write barrier, since we just mutated the closure: - recordClosureMutated(cap,bh); + // We need a write barrier, since the closure was mutated (by + // threadPaused for lazy black holes, or the mutator for eager + // black holes). + recordClosureMutated(cap,bh); - // We pretend that bh has just been created. - LDV_RECORD_CREATE(bh); - } + // We pretend that bh has just been created. + LDV_RECORD_CREATE(bh); frame = (StgClosure *) ((StgUpdateFrame *)frame + 1); if (prev_was_update_frame) { ===================================== rts/linker/PEi386.c ===================================== @@ -552,7 +552,12 @@ static int compare_path(StgWord key1, StgWord key2) static void addLoadedDll(LoadedDllCache *cache, const pathchar *dll_name, HINSTANCE instance) { - insertHashTable_(cache->hash, (StgWord) dll_name, instance, hash_path); + // dll_name might be deallocated, we need to copy it to have a stable reference to the contents + // See #26613 + size_t size = wcslen(dll_name) + 1; + pathchar* dll_name_copy = stgMallocBytes(size * sizeof(pathchar), "addLoadedDll"); + wcsncpy(dll_name_copy, dll_name, size); + insertHashTable_(cache->hash, (StgWord) dll_name_copy, instance, hash_path); } static HINSTANCE isDllLoaded(const LoadedDllCache *cache, const pathchar *dll_name) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0e08b9aee6ce58fe7099f14ac1d7dea... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0e08b9aee6ce58fe7099f14ac1d7dea... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Zubin (@wz1000)