[sysprof] build: various fixes for compiling on macOS
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] build: various fixes for compiling on macOS
- Date: Mon, 16 Nov 2020 22:13:44 +0000 (UTC)
commit f18fbe5ae867aceeb6d463d3a3f34d313d808162
Author: Christian Hergert <chergert redhat com>
Date: Mon Nov 16 14:01:02 2020 -0800
build: various fixes for compiling on macOS
src/libsysprof-capture/sysprof-capture-reader.c | 2 --
src/libsysprof-capture/sysprof-capture-types.h | 6 +++++-
src/libsysprof-capture/sysprof-capture-writer.c | 6 +++++-
src/libsysprof-capture/sysprof-clock.c | 6 +++++-
src/libsysprof-capture/sysprof-clock.h | 4 ++++
src/libsysprof-capture/sysprof-macros-internal.h | 18 ++++++++++++++++++
src/libsysprof/preload/sysprof-speedtrack-collector.c | 14 +++++++++++---
7 files changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c
index 41e6af3..b07ad2d 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/src/libsysprof-capture/sysprof-capture-reader.c
@@ -57,8 +57,6 @@
#include "config.h"
#include <assert.h>
-#include <byteswap.h>
-#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
diff --git a/src/libsysprof-capture/sysprof-capture-types.h b/src/libsysprof-capture/sysprof-capture-types.h
index eaba446..2f5b4b4 100644
--- a/src/libsysprof-capture/sysprof-capture-types.h
+++ b/src/libsysprof-capture/sysprof-capture-types.h
@@ -57,7 +57,11 @@
#pragma once
#include <assert.h>
-#include <endian.h>
+#ifdef __APPLE__
+# include <machine/endian.h>
+#else
+# include <endian.h>
+#endif
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index 14577aa..8fa89d2 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -57,7 +57,11 @@
#include "config.h"
#include <assert.h>
-#include <endian.h>
+#ifdef __APPLE__
+# include <machine/endian.h>
+#else
+# include <endian.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
diff --git a/src/libsysprof-capture/sysprof-clock.c b/src/libsysprof-capture/sysprof-clock.c
index cbaafa1..7ee8017 100644
--- a/src/libsysprof-capture/sysprof-clock.c
+++ b/src/libsysprof-capture/sysprof-clock.c
@@ -68,9 +68,13 @@ void
sysprof_clock_init (void)
{
static const int clock_ids[] = {
+#ifdef __APPLE__
+ _CLOCK_MONOTONIC,
+#else
CLOCK_MONOTONIC,
- CLOCK_MONOTONIC_RAW,
+#endif
#ifdef __linux__
+ CLOCK_MONOTONIC_RAW,
CLOCK_MONOTONIC_COARSE,
CLOCK_REALTIME_COARSE,
#endif
diff --git a/src/libsysprof-capture/sysprof-clock.h b/src/libsysprof-capture/sysprof-clock.h
index c127c09..2bd1544 100644
--- a/src/libsysprof-capture/sysprof-clock.h
+++ b/src/libsysprof-capture/sysprof-clock.h
@@ -80,7 +80,11 @@ sysprof_clock_get_current_time (void)
SysprofClock clock = sysprof_clock;
if SYSPROF_UNLIKELY (clock == -1)
+#ifdef __APPLE__
+ clock = _CLOCK_MONOTONIC;
+#else
clock = CLOCK_MONOTONIC;
+#endif
clock_gettime (clock, &ts);
return (ts.tv_sec * SYSPROF_NSEC_PER_SEC) + ts.tv_nsec;
diff --git a/src/libsysprof-capture/sysprof-macros-internal.h
b/src/libsysprof-capture/sysprof-macros-internal.h
index 7162d3d..92772e4 100644
--- a/src/libsysprof-capture/sysprof-macros-internal.h
+++ b/src/libsysprof-capture/sysprof-macros-internal.h
@@ -61,6 +61,14 @@
#include <string.h>
+#ifdef __APPLE__
+# include <libkern/OSByteOrder.h>
+# include <architecture/byte_order.h>
+#else
+# include <byteswap.h>
+# include <endian.h>
+#endif
+
#define sysprof_assert_not_reached() assert (false)
#define SYSPROF_N_ELEMENTS(a) (sizeof (a) / sizeof (*a))
@@ -77,3 +85,13 @@
} while (0)
#define sysprof_strdup(s) ((s) ? strdup(s) : NULL)
+
+#ifdef __APPLE__
+# define bswap_16 OSSwapInt16
+# define bswap_32 OSSwapInt32
+# define bswap_64 OSSwapInt64
+# define htole32 OSSwapHostToLittleInt32
+# define __BYTE_ORDER __DARWIN_BYTE_ORDER
+# define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+# define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+#endif
diff --git a/src/libsysprof/preload/sysprof-speedtrack-collector.c
b/src/libsysprof/preload/sysprof-speedtrack-collector.c
index 62f75a6..65e4f9d 100644
--- a/src/libsysprof/preload/sysprof-speedtrack-collector.c
+++ b/src/libsysprof/preload/sysprof-speedtrack-collector.c
@@ -67,7 +67,15 @@ is_capturing (void)
return FALSE;
if G_UNLIKELY (tid == 0)
- tid = syscall (__NR_gettid, 0);
+ {
+#if defined(__linux__)
+ tid = syscall (__NR_gettid, 0);
+#elif defined(__APPLE__)
+ uint64_t threadid;
+ pthread_threadid_np (NULL, &threadid);
+ tid = threadid;
+#endif
+ }
if G_UNLIKELY (pid == 0)
pid = getpid ();
@@ -102,7 +110,7 @@ open (const char *filename,
mode_t mode;
va_start (args, flags);
- mode = va_arg (args, mode_t);
+ mode = va_arg (args, int);
va_end (args);
if (is_capturing ())
@@ -139,7 +147,7 @@ hook_open (const char *filename, int flags, ...)
mode_t mode;
va_start (args, flags);
- mode = va_arg (args, mode_t);
+ mode = va_arg (args, int);
va_end (args);
hook_func ((void **)&real_open, "open");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]