diff options
author | Alexander Potapenko <glider@google.com> | 2015-06-29 15:58:16 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2015-06-29 15:58:16 +0000 |
commit | e54cfa1004dd96f4c3d48ee79b8ff81b3273c36f (patch) | |
tree | ccd4fdcfad7b7ca477288a894cf472562c3af521 /compiler-rt | |
parent | 7180c84364235e70a41db78959cf91294645c73f (diff) |
[libsanitizer] Replace ReadBinaryName() with ReadBinaryNameCached(),
which caches the executable name upon the first invocation.
This is necessary because Google Chrome (and potentially other programs)
restrict the access to /proc/self/exe on linux.
This change should fix https://code.google.com/p/chromium/issues/detail?id=502974
Diffstat (limited to 'compiler-rt')
4 files changed, 16 insertions, 3 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 5bbd31ed6d1..d14e98824d9 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -353,11 +353,23 @@ const char *GetBinaryBasename() { // Call once to make sure that binary_name_cache_str is initialized void CacheBinaryName() { - CHECK_EQ('\0', binary_name_cache_str[0]); + if (binary_name_cache_str[0] != '\0') + return; ReadBinaryName(binary_name_cache_str, sizeof(binary_name_cache_str)); binary_basename_cache_str = StripModuleName(binary_name_cache_str); } +uptr ReadBinaryNameCached(/*out*/char *buf, uptr buf_len) { + CacheBinaryName(); + uptr name_len = internal_strlen(binary_name_cache_str); + name_len = (name_len < buf_len - 1) ? name_len : buf_len - 1; + if (buf_len == 0) + return 0; + internal_memcpy(buf, binary_name_cache_str, name_len); + buf[name_len] = '\0'; + return name_len; +} + } // namespace __sanitizer using namespace __sanitizer; // NOLINT diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 3cd04450396..e697eb5359c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -243,6 +243,7 @@ const char *StripModuleName(const char *module); // OS uptr ReadBinaryName(/*out*/char *buf, uptr buf_len); +uptr ReadBinaryNameCached(/*out*/char *buf, uptr buf_len); const char *GetBinaryBasename(); void CacheBinaryName(); void DisableCoreDumperIfNecessary(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index ba844be1b3b..04ecbb81e80 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -425,7 +425,7 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { if (data->first) { data->first = false; // First module is the binary itself. - ReadBinaryName(module_name.data(), module_name.size()); + ReadBinaryNameCached(module_name.data(), module_name.size()); } else if (info->dlpi_name) { module_name.append("%s", info->dlpi_name); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_suppressions.cc b/compiler-rt/lib/sanitizer_common/sanitizer_suppressions.cc index 8009b4d6aad..08cb497269b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_suppressions.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_suppressions.cc @@ -34,7 +34,7 @@ static bool GetPathAssumingFileIsRelativeToExec(const char *file_path, /*out*/char *new_file_path, uptr new_file_path_size) { InternalScopedString exec(kMaxPathLength); - if (ReadBinaryName(exec.data(), exec.size())) { + if (ReadBinaryNameCached(exec.data(), exec.size())) { const char *file_name_pos = StripModuleName(exec.data()); uptr path_to_exec_len = file_name_pos - exec.data(); internal_strncat(new_file_path, exec.data(), |