diff --git a/README.md b/README.md index f194eecdb..47ed1f9e1 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,6 @@ This repository contains a version of Valgrind including a few patches to improv Note that every version from macOS 10.12 onwards currently has the following issues: - using threads and signals together is undefined (crashes, hanging, etc), note: a few tests were disabled because of that -- drd crashes on 10.15 (probably onwards) -- dhat crashes (seen macOS 14 arm64) ## Usage diff --git a/coregrind/m_mach/dyld_cache.c b/coregrind/m_mach/dyld_cache.c index 5d8158473..db76d6770 100644 --- a/coregrind/m_mach/dyld_cache.c +++ b/coregrind/m_mach/dyld_cache.c @@ -62,11 +62,13 @@ static void output_debug_info(const dyld_cache_header* dyld_cache); typedef struct { const dyld_cache_header* header; Addr slide; + Bool tried; } DYLDCache; static DYLDCache dyld_cache = { .header = NULL, .slide = 0, + .tried = False, }; static Addr calculate_relative(const dyld_cache_header * header, Addr offset) { @@ -208,13 +210,23 @@ Addr VG_(dyld_cache_get_slide)(void) { return dyld_cache.slide; } -void VG_(dyld_cache_init)(void) { +int ensure_init(void) { + if (dyld_cache.header != NULL) { + return 1; + } + + // FIXME: unlikely race condition? + if (dyld_cache.tried) { + return 0; + } + dyld_cache.tried = True; + if (!try_to_init()) { VG_(dmsg)( "WARNING: could not read from dyld shared cache (DSC)\n" "Some reports (especially memory leaks) might be missing or incorrect (false-positives)\n" ); - return; + return 0; } #if defined(VGP_arm64_darwin) // We currently detect if dyld is loading/using a library by checking if stat64 fails. @@ -225,11 +237,22 @@ void VG_(dyld_cache_init)(void) { VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_pthread.dylib"); VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_platform.dylib"); #endif + + return 1; +} + +void VG_(dyld_cache_init)(const HChar* tool) { + // drd crashes if you map memory segments in m_main + if (VG_(strcmp)(tool, "drd") == 0) { + return; + } + + ensure_init(); } int VG_(dyld_cache_might_be_in)(const HChar* path) { // If not init'd, there is no point - if (dyld_cache.header == NULL) { + if (!ensure_init()) { return 0; } @@ -269,7 +292,7 @@ int VG_(dyld_cache_load_library)(const HChar* path) { SizeT len = 0; // If not init'd, there is no point trying - if (dyld_cache.header == NULL) { + if (!ensure_init()) { return 0; } diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 432e264e4..099119db7 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -1949,9 +1949,10 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp ) // Initialize the dyld cache, which is required with macOS 11 (Big Sur) and onwards // as some system libraries aren't provided on the disk anymore // p: none + // Note: some tools don't like to start mapping memory right way, so we do it lazily in those cases. //-------------------------------------------------------------- # if defined(VGO_darwin) && DARWIN_VERS >= DARWIN_11_00 - VG_(dyld_cache_init)(); + VG_(dyld_cache_init)(VG_(clo_toolname)); # endif //-------------------------------------------------------------- diff --git a/coregrind/pub_core_mach.h b/coregrind/pub_core_mach.h index 19cfff90a..08193a4a6 100644 --- a/coregrind/pub_core_mach.h +++ b/coregrind/pub_core_mach.h @@ -72,7 +72,7 @@ extern void VG_(mach_record_system_memory)(void); #if DARWIN_VERS >= DARWIN_11_00 // Dyld shared cache (DSC) parsing, which is required as system libraries are not provided on disk // starting with macOS 11.0 (Big Sur) -extern void VG_(dyld_cache_init)(void); +extern void VG_(dyld_cache_init)(const HChar*); extern int VG_(dyld_cache_might_be_in)(const HChar*); extern int VG_(dyld_cache_load_library)(const HChar*); extern Addr VG_(dyld_cache_get_slide)(void); diff --git a/dhat/dh_main.c b/dhat/dh_main.c index 9e6ec1c06..4098323d6 100644 --- a/dhat/dh_main.c +++ b/dhat/dh_main.c @@ -916,6 +916,10 @@ void dh_handle_noninsn_read_asciiz(CorePart part, ThreadId tid, const HChar* s, tl_assert(clo_mode == Heap); tl_assert(part == Vg_CoreSysCall); + + if (str == 0) + return; + dh_handle_noninsn_read(part, tid, s, str, VG_(strlen)((const HChar*)str+1)); }