[PATCH] D40665: [sanitizer] Implement NanoTime() on Darwin
Kuba (Brecka) Mracek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 15:58:35 PST 2017
kubamracek updated this revision to Diff 126861.
https://reviews.llvm.org/D40665
Files:
lib/sanitizer_common/sanitizer_mac.cc
Index: lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -59,6 +59,7 @@
#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>
@@ -362,11 +363,17 @@
}
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() {
@@ -673,6 +680,9 @@
}
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40665.126861.patch
Type: text/x-patch
Size: 1192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171213/6ca1022b/attachment.bin>
More information about the llvm-commits
mailing list