[PATCH] D40665: [sanitizer] Implement NanoTime() on Darwin

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 12:01:54 PST 2017


kubamracek created this revision.
kubamracek added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

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.


Repository:
  rCRT Compiler Runtime

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,7 +363,9 @@
 }
 
 u64 NanoTime() {
-  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() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40665.124985.patch
Type: text/x-patch
Size: 680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171130/24670503/attachment.bin>


More information about the llvm-commits mailing list