Skip to content

Commit

Permalink
i#2566 anon text: Use the app path instead of maps comments
Browse files Browse the repository at this point in the history
For the application module, we use the application path obtained from
early injection or /proc/self/exe on Linux, rather than
/proc/self/maps comments.  The maps comments can be unreliable in the
face of anonymous or deleted-file mremaps used for hugepage backing
and other features.

Adds a test case to the existing "burst_maps" test.

Having the right module full_path helps many cases, including the
forthcoming restartable sequences ("rseq") support for #2350.

Issue: #2566, #2350
  • Loading branch information
derekbruening committed Jul 16, 2019
1 parent f76f144 commit c44e0f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 16 additions & 1 deletion clients/drcachesim/tests/burst_maps.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2017 Google, Inc. All rights reserved.
* Copyright (c) 2017-2019 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -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()
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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[])
{
Expand Down
16 changes: 13 additions & 3 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -9118,15 +9118,25 @@ 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();
if (exec_match != NULL && exec_match[0] != '\0')
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,
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit c44e0f9

Please sign in to comment.