[Sanitizers] Call NanoTime() conditionally.
authorAlex Shlyapnikov <alekseys@google.com>
Fri, 3 Nov 2017 23:31:00 +0000 (23:31 +0000)
committerAlex Shlyapnikov <alekseys@google.com>
Fri, 3 Nov 2017 23:31:00 +0000 (23:31 +0000)
Summary:
Call NanoTime() in primary 64 bit allocator only when necessary,
otherwise the unwarranted syscall causes problems in sandbox environments.
ReleaseToOSIntervalMs() conditional allows them to turn the feature off
with allocator_release_to_os_interval_ms=-1 flag.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D39624

llvm-svn: 317386

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

index b22f3ab..630ae35 100644 (file)
@@ -677,7 +677,10 @@ class SizeClassAllocator64 {
         // preventing just allocated memory from being released sooner than
         // necessary and also preventing extraneous ReleaseMemoryPagesToOS calls
         // for short lived processes.
-        region->rtoi.last_release_at_ns = NanoTime();
+        // Do it only when the feature is turned on, to avoid a potentially
+        // extraneous syscall.
+        if (ReleaseToOSIntervalMs() >= 0)
+          region->rtoi.last_release_at_ns = NanoTime();
       }
       // Do the mmap for the user memory.
       uptr map_size = kUserMapSize;