Skip to content

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Jan 3, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jan 3, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: David CARLIER (devnexen)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/76851.diff

4 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc (+17)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h (+1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp (+2)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h (+7)
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
 

Copy link

github-actions bot commented Jan 3, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions h,inc,cpp -- compiler-rt/test/sanitizer_common/TestCases/FreeBSD/cpuset_getcomain.cpp compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index a35ff2306..920e63264 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10389,20 +10389,22 @@ INTERCEPTOR(int, getservbyport_r, int port, const char *proto,
 
 #if SANITIZER_INTERCEPT_CPUSET_GETDOMAIN
 INTERCEPTOR(int, cpuset_getdomain, int level, int which, __int64 id,
-            SIZE_T domainsetsize, __sanitizer_domainset_t *mask, int *policy) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, cpuset_getdomain, level, which, id, domainsetsize,
-                           mask, policy);
-  int res = REAL(cpuset_getdomain)(level, which, id, domainsetsize, mask, policy);
+            SIZE_T domainsetsize, __sanitizer_domainset_t* mask, int* policy) {
+  void* ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, cpuset_getdomain, level, which, id,
+                           domainsetsize, mask, policy);
+  int res =
+      REAL(cpuset_getdomain)(level, which, id, domainsetsize, mask, policy);
   if (mask && !res) {
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, mask, domainsetsize);
-    if (policy) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, policy, sizeof(*policy));
+    if (policy)
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, policy, sizeof(*policy));
   }
   return res;
 }
-#define INIT_CPUSET_GETDOMAIN COMMON_INTERCEPT_FUNCTION(cpuset_getdomain);
+#  define INIT_CPUSET_GETDOMAIN COMMON_INTERCEPT_FUNCTION(cpuset_getdomain);
 #else
-#define INIT_CPUSET_GETDOMAIN
+#  define INIT_CPUSET_GETDOMAIN
 #endif
 
 #include "sanitizer_common_interceptors_netbsd_compat.inc"
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 bbbf2c4ca..1183fc740 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -18,35 +18,35 @@
 #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>
-#include <sys/link_elf.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
-#include <sys/mqueue.h>
-#include <sys/msg.h>
-#include <sys/mtio.h>
-#include <sys/ptrace.h>
-#include <sys/resource.h>
-#include <sys/shm.h>
-#include <sys/signal.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/soundcard.h>
-#include <sys/stat.h>
-#include <sys/statvfs.h>
-#include <sys/time.h>
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-W#warnings"
-#include <sys/timeb.h>
-#pragma clang diagnostic pop
-#include <sys/times.h>
-#include <sys/timespec.h>
-#include <sys/types.h>
-#include <sys/ucontext.h>
-#include <sys/utsname.h>
+#  include <sys/domainset.h>
+#  include <sys/filio.h>
+#  include <sys/ipc.h>
+#  include <sys/kbio.h>
+#  include <sys/link_elf.h>
+#  include <sys/mman.h>
+#  include <sys/mount.h>
+#  include <sys/mqueue.h>
+#  include <sys/msg.h>
+#  include <sys/mtio.h>
+#  include <sys/ptrace.h>
+#  include <sys/resource.h>
+#  include <sys/shm.h>
+#  include <sys/signal.h>
+#  include <sys/socket.h>
+#  include <sys/sockio.h>
+#  include <sys/soundcard.h>
+#  include <sys/stat.h>
+#  include <sys/statvfs.h>
+#  include <sys/time.h>
+#  pragma clang diagnostic push
+#  pragma clang diagnostic ignored "-W#warnings"
+#  include <sys/timeb.h>
+#  pragma clang diagnostic pop
+#  include <sys/times.h>
+#  include <sys/timespec.h>
+#  include <sys/types.h>
+#  include <sys/ucontext.h>
+#  include <sys/utsname.h>
 //
 #include <arpa/inet.h>
 #include <net/ethernet.h>

@devnexen devnexen force-pushed the fbsd_cpudomain branch 2 times, most recently from 41f3f8c to 792b139 Compare January 3, 2024 19:40
@devnexen devnexen requested a review from vitalybuka January 3, 2024 19:49
Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some basic test would be nice

#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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> _

@vitalybuka
Copy link
Collaborator

Please rebase and re-request review if it's still relevant.

@devnexen devnexen force-pushed the fbsd_cpudomain branch 2 times, most recently from f7b6f1f to 6496bad Compare October 17, 2025 17:59
@devnexen devnexen requested a review from vitalybuka October 17, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants