Skip to content

fix: dhat/drd run again #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 27 additions & 4 deletions coregrind/m_mach/dyld_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion coregrind/m_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

//--------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion coregrind/pub_core_mach.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions dhat/dh_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Loading