diff options
author | Kuba Mracek <mracek@apple.com> | 2018-02-11 19:25:34 +0000 |
---|---|---|
committer | Kuba Mracek <mracek@apple.com> | 2018-02-11 19:25:34 +0000 |
commit | d755bfd983c068cd1273d09355923810b62eca40 (patch) | |
tree | f293b34e281e0ecde64d9014dd113fe7d8432da2 /lib/sanitizer_common/sanitizer_mac.cc | |
parent | 2ad995068aa4473e6a870a53bfbeb33e19e5ca80 (diff) |
[sanitizer] Implement NanoTime() on Darwin
Currently NanoTime() on Darwin is unimplemented and always returns 0. Looks like there's quite a few things broken because of that (TSan periodic memory flush, ASan allocator releasing pages back to the OS). Let's fix that.
Differential Revision: https://reviews.llvm.org/D40665
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@324847 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_mac.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_mac.cc | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc index 4b88498e6..1f011d970 100644 --- a/lib/sanitizer_common/sanitizer_mac.cc +++ b/lib/sanitizer_common/sanitizer_mac.cc @@ -59,6 +59,7 @@ extern "C" { #include <libkern/OSAtomic.h> #include <mach-o/dyld.h> #include <mach/mach.h> +#include <mach/mach_time.h> #include <mach/vm_statistics.h> #include <pthread.h> #include <sched.h> @@ -399,11 +400,17 @@ void BlockingMutex::CheckLocked() { } u64 NanoTime() { - return 0; + timeval tv; + internal_memset(&tv, 0, sizeof(tv)); + gettimeofday(&tv, 0); + return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000; } +// This needs to be called during initialization to avoid being racy. u64 MonotonicNanoTime() { - return 0; + static mach_timebase_info_data_t timebase_info; + if (timebase_info.denom == 0) mach_timebase_info(&timebase_info); + return (mach_absolute_time() * timebase_info.numer) / timebase_info.denom; } uptr GetTlsSize() { @@ -710,6 +717,9 @@ bool DyldNeedsEnvVariable() { } void MaybeReexec() { + // FIXME: This should really live in some "InitializePlatform" method. + MonotonicNanoTime(); + if (ReexecDisabled()) return; // Make sure the dynamic runtime library is preloaded so that the |