diff --git a/clients/drcachesim/tests/burst_maps.cpp b/clients/drcachesim/tests/burst_maps.cpp index e83d5329fc8..4fc26797105 100644 --- a/clients/drcachesim/tests/burst_maps.cpp +++ b/clients/drcachesim/tests/burst_maps.cpp @@ -1,5 +1,5 @@ /* ********************************************************** - * Copyright (c) 2017 Google, Inc. All rights reserved. + * Copyright (c) 2017-2019 Google, Inc. All rights reserved. * **********************************************************/ /* @@ -57,6 +57,8 @@ #define MAPS_LINE_MAX8 73 /* sum of 16 1 16 1 4 1 16 1 5 1 10 1 */ #define MAPS_LINE_MAX MAPS_LINE_MAX8 +char exe_path[MAPS_LINE_LENGTH]; + void * find_exe_base() { @@ -82,6 +84,8 @@ find_exe_base() if (len < 4) comment_buffer[0] = '\0'; if (strstr(comment_buffer, "burst_maps") != 0) { + strncpy(exe_path, comment_buffer, BUFFER_SIZE_ELEMENTS(exe_path)); + NULL_TERMINATE_BUFFER(exe_path); fclose(maps); return vm_start; } @@ -137,6 +141,17 @@ clobber_mapping() copy_and_remap(exe, 8 * clobber_size, clobber_size); } +DR_EXPORT void +dr_client_main(client_id_t id, int argc, const char *argv[]) +{ + /* Test the full_path used by DR when the maps file comments can't be used. */ + module_data_t *exe = dr_get_main_module(); + assert(exe != nullptr); + assert(exe->full_path != nullptr); + assert(strcmp(exe->full_path, exe_path) == 0); + dr_free_module_data(exe); +} + int main(int argc, const char *argv[]) { diff --git a/core/unix/os.c b/core/unix/os.c index fc96f48f2e0..8319263a012 100644 --- a/core/unix/os.c +++ b/core/unix/os.c @@ -9118,6 +9118,7 @@ os_walk_address_space(memquery_iter_t *iter, bool add_modules) iter->vm_start, iter->vm_start + image_size, iter->inode, iter->comment); if (add_modules) { + const char *modpath = iter->comment; /* look for executable */ # ifdef LINUX exec_match = get_application_name(); @@ -9125,8 +9126,17 @@ os_walk_address_space(memquery_iter_t *iter, bool add_modules) found_exec = (strcmp(iter->comment, exec_match) == 0); /* Handle an anon region for the header (i#2566) */ if (!found_exec && executable_start != NULL && - executable_start == iter->vm_start) + executable_start == iter->vm_start) { found_exec = true; + /* The maps file's first entry may not have the path, in the + * presence of mremapping for hugepages (i#2566; i#3387) (this + * could happen for libraries too, but we don't have alternatives + * there). Or, it may have an incorrect path. Prefer the path + * we recorded in early injection or obtained from + * /proc/self/exe. + */ + modpath = get_application_name(); + } # else /* We don't have a nice normalized name: it can have ./ or ../ inside * it. But, we can distinguish an exe from a lib here, even for PIE, @@ -9156,8 +9166,8 @@ os_walk_address_space(memquery_iter_t *iter, bool add_modules) /* We don't yet know whether contiguous so we have to settle for the * first segment's size. We'll update it in module_list_add(). */ - module_list_add(iter->vm_start, mod_first_end - mod_base, false, - iter->comment, iter->inode); + module_list_add(iter->vm_start, mod_first_end - mod_base, false, modpath, + iter->inode); # ifdef MACOS /* look for dyld */