about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt-clock_gettime.patch
blob: f9323ed95c05cb573cbbec3c0151daf47c35e078 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
commit f00c7bccf7955b7dfbb4859fd9019e9eb3349f2d
Author: Tobias Mayer <tobim@fastmail.fm>
Date:   Wed Feb 13 12:44:17 2019 +0100

    Provide clock_gettime for xray on macos < 10.12

diff --git a/lib/xray/xray_basic_logging.cc b/lib/xray/xray_basic_logging.cc
index a46c151af..38aea6932 100644
--- a/lib/xray/xray_basic_logging.cc
+++ b/lib/xray/xray_basic_logging.cc
@@ -36,6 +36,29 @@
 #include "xray_tsc.h"
 #include "xray_utils.h"
 
+#if __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+enum clockid_t {
+    CLOCK_MONOTONIC = REALTIME_CLOCK,
+    CLOCK_REALTIME = REALTIME_CLOCK
+};
+
+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
+  if (ts != NULL) {
+      clock_serv_t cclock;
+      mach_timespec_t mts;
+      host_get_clock_service(mach_host_self(), clock_id, &cclock);
+      clock_get_time(cclock, &mts);
+      mach_port_deallocate(mach_task_self(), cclock);
+      ts->tv_sec = mts.tv_sec;
+      ts->tv_nsec = mts.tv_nsec;
+      return 0;
+  }
+  return -1;
+}
+#endif
+
 namespace __xray {
 
 SpinMutex LogMutex;
diff --git a/lib/xray/xray_fdr_logging.cc b/lib/xray/xray_fdr_logging.cc
index 4b308b27f..1d044c8fd 100644
--- a/lib/xray/xray_fdr_logging.cc
+++ b/lib/xray/xray_fdr_logging.cc
@@ -38,6 +38,29 @@
 #include "xray_tsc.h"
 #include "xray_utils.h"
 
+#if __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+enum clockid_t {
+    CLOCK_MONOTONIC = REALTIME_CLOCK,
+    CLOCK_REALTIME = REALTIME_CLOCK
+};
+
+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
+  if (ts != NULL) {
+      clock_serv_t cclock;
+      mach_timespec_t mts;
+      host_get_clock_service(mach_host_self(), clock_id, &cclock);
+      clock_get_time(cclock, &mts);
+      mach_port_deallocate(mach_task_self(), cclock);
+      ts->tv_sec = mts.tv_sec;
+      ts->tv_nsec = mts.tv_nsec;
+      return 0;
+  }
+  return -1;
+}
+#endif
+
 namespace __xray {
 
 atomic_sint32_t LoggingStatus = {XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};