[compiler-rt] [compiler-rt] intercept freebsd's cpuset_getdomain api. (PR #76851)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 11:27:48 PST 2024


https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/76851

None

>From ea957915d413439ccc02a163dcd5b9bddc340109 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Wed, 3 Jan 2024 19:26:31 +0000
Subject: [PATCH] [compiler-rt] intercept freebsd's cpuset_getdomain api.

---
 .../sanitizer_common_interceptors.inc           | 17 +++++++++++++++++
 .../sanitizer_platform_interceptors.h           |  1 +
 .../sanitizer_platform_limits_freebsd.cpp       |  2 ++
 .../sanitizer_platform_limits_freebsd.h         |  7 +++++++
 4 files changed, 27 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 77fa1b4965a7a4..33d72869f7a04a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10258,6 +10258,22 @@ INTERCEPTOR(int, cpuset_getaffinity, int level, int which, __int64_t id, SIZE_T
 #define INIT_CPUSET_GETAFFINITY
 #endif
 
+#if SANITIZER_INTERCEPT_CPUSET_GETDOMAIN
+INTERCEPTOR(int, cpuset_getdomain, int level, int which, __int64 id, SIZE_T cpusetsize, __sanitizer_domainset_t *mask, int *policy) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, cpuset_getdomain, level, which, id, cpusetsize, mask, policy);
+  int res = REAL(cpuset_getdomain)(level, which, id, cpusetsize, mask, policy);
+  if (mask && !res) {
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, mask, cpusetsize);
+      if (policy) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, policy, sizeof(*policy));
+  }
+  return res;
+}
+#define INIT_CPUSET_GETDOMAIN COMMON_INTERCEPT_FUNCTION(cpuset_getdomain);
+#else
+#define INIT_CPUSET_GETDOMAIN
+#endif
+
 #include "sanitizer_common_interceptors_netbsd_compat.inc"
 
 namespace __sanitizer {
@@ -10578,6 +10594,7 @@ static void InitializeCommonInterceptors() {
   INIT_HEXDUMP;
   INIT_ARGP_PARSE;
   INIT_CPUSET_GETAFFINITY;
+  INIT_CPUSET_GETDOMAIN;
 
   INIT___PRINTF_CHK;
 }
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 0ce4e9351bc1da..02d4fbd970ef45 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -599,6 +599,7 @@
 #define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
 #define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
 #define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
+#define SANITIZER_INTERCEPT CPUSET_GETDOMAIN SI_FREEBSD
 
 // This macro gives a way for downstream users to override the above
 // interceptor macros irrespective of the platform they are on. They have
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
index 38f968d533b147..27c53c3ec82322 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -18,6 +18,7 @@
 #include <sys/capsicum.h>
 #include <sys/consio.h>
 #include <sys/cpuset.h>
+#include <sys/domainset.h>
 #include <sys/filio.h>
 #include <sys/ipc.h>
 #include <sys/kbio.h>
@@ -105,6 +106,7 @@ void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) {
 }
 
 unsigned struct_cpuset_sz = sizeof(cpuset_t);
+unsigned struct_domainset_sz = sizeof(domainset_t);
 unsigned struct_cap_rights_sz = sizeof(cap_rights_t);
 unsigned struct_utsname_sz = sizeof(struct utsname);
 unsigned struct_stat_sz = sizeof(struct stat);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
index 43b8a38f39be18..6a5fa5e422fe42 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
@@ -724,9 +724,16 @@ struct __sanitizer_cpuset {
 #endif
 };
 
+struct __sanitizer_domainset {
+  long __bits[(256 + (sizeof(long) * 8) - 1) / (sizeof(long) * 8)];
+};
+
 typedef struct __sanitizer_cpuset __sanitizer_cpuset_t;
 extern unsigned struct_cpuset_sz;
 
+typedef struct __sanitizer_domainset __sanitizer_domainset_t;
+extern unsigned struct_domainset_sz;
+
 typedef unsigned long long __sanitizer_eventfd_t;
 }  // namespace __sanitizer
 



More information about the llvm-commits mailing list