diff options
| author | Kostya Kortchinsky <kostyak@google.com> | 2018-04-19 18:38:15 +0000 |
|---|---|---|
| committer | Kostya Kortchinsky <kostyak@google.com> | 2018-04-19 18:38:15 +0000 |
| commit | 46eab8d9fee52444915e336ce73374ba4c9e53d4 (patch) | |
| tree | 26dfa950b088d8ec68a6e4008b485b8387f62c5c /compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc | |
| parent | 4ee16bfff7f0b7700c2c712d954d37c17200eab0 (diff) | |
| download | bcm5719-llvm-46eab8d9fee52444915e336ce73374ba4c9e53d4.tar.gz bcm5719-llvm-46eab8d9fee52444915e336ce73374ba4c9e53d4.zip | |
[sanitizer] Minor refactor of some ReservedAddressRange functions
Summary:
Some of the functions had spurious conditional statements and checks, and some
intermediary variables that I feel made the code more complicated than it needs
to be. Also, when unmapping the whole range, the range size would be 0, but
the base was set to the address of the end of the range, which sounds prone to
error. I think nulling out the base in this scenario is a better way to go.
Reviewers: alekseyshl, flowerhack
Reviewed By: alekseyshl
Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D45775
llvm-svn: 330355
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc')
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc index e7576000cbc..a81ea8b7b5d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -346,11 +346,7 @@ uptr ReservedAddressRange::Init(uptr size, const char *name, uptr fixed_addr) { // `open` (e.g. TSAN, ESAN), then you'll get a failure during initialization. // TODO(flowerhack): Fix the implementation of GetNamedMappingFd to solve // this problem. - if (fixed_addr) { - base_ = MmapFixedNoAccess(fixed_addr, size); - } else { - base_ = MmapNoAccess(size); - } + base_ = fixed_addr ? MmapFixedNoAccess(fixed_addr, size) : MmapNoAccess(size); size_ = size; name_ = name; (void)os_handle_; // unsupported @@ -368,16 +364,14 @@ uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr size) { } void ReservedAddressRange::Unmap(uptr addr, uptr size) { - void* addr_as_void = reinterpret_cast<void*>(addr); - uptr base_as_uptr = reinterpret_cast<uptr>(base_); - // Only unmap at the beginning or end of the range. - CHECK((addr_as_void == base_) || (addr + size == base_as_uptr + size_)); CHECK_LE(size, size_); + if (addr == reinterpret_cast<uptr>(base_)) + // If we unmap the whole range, just null out the base. + base_ = (size == size_) ? nullptr : reinterpret_cast<void*>(addr + size); + else + CHECK_EQ(addr + size, reinterpret_cast<uptr>(base_) + size_); + size_ -= size; UnmapOrDie(reinterpret_cast<void*>(addr), size); - if (addr_as_void == base_) { - base_ = reinterpret_cast<void*>(addr + size); - } - size_ = size_ - size; } void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name) { |

