diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2014-05-28 21:23:53 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-05-28 21:23:53 +0000 |
commit | 8c724231e37df176473710b1e28a05bdbe221bbe (patch) | |
tree | 032d2c8d83b588bb094da38f9d685f139eaa2c1f | |
parent | dfa76add3b85e887862554431c993f3735158476 (diff) |
[Sanitizer] Always prefer cached contents of /proc/self/exe if it's available
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209773 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux.cc | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/sanitizer_common/sanitizer_linux.cc b/lib/sanitizer_common/sanitizer_linux.cc index f27f22e47..fea6241ed 100644 --- a/lib/sanitizer_common/sanitizer_linux.cc +++ b/lib/sanitizer_common/sanitizer_linux.cc @@ -667,24 +667,23 @@ static char proc_self_exe_cache_str[kMaxPathLength]; static uptr proc_self_exe_cache_len = 0; uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { + if (proc_self_exe_cache_len > 0) { + // If available, use the cached module name. + uptr module_name_len = + internal_snprintf(buf, buf_len, "%s", proc_self_exe_cache_str); + CHECK_LT(module_name_len, buf_len); + return module_name_len; + } uptr module_name_len = internal_readlink( "/proc/self/exe", buf, buf_len); int readlink_error; if (internal_iserror(module_name_len, &readlink_error)) { - if (proc_self_exe_cache_len) { - // If available, use the cached module name. - CHECK_LE(proc_self_exe_cache_len, buf_len); - internal_strncpy(buf, proc_self_exe_cache_str, buf_len); - module_name_len = internal_strlen(proc_self_exe_cache_str); - } else { - // We can't read /proc/self/exe for some reason, assume the name of the - // binary is unknown. - Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, " - "some stack frames may not be symbolized\n", readlink_error); - module_name_len = internal_snprintf(buf, buf_len, "/proc/self/exe"); - } + // We can't read /proc/self/exe for some reason, assume the name of the + // binary is unknown. + Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, " + "some stack frames may not be symbolized\n", readlink_error); + module_name_len = internal_snprintf(buf, buf_len, "/proc/self/exe"); CHECK_LT(module_name_len, buf_len); - buf[module_name_len] = '\0'; } return module_name_len; } |