[compiler-rt] [compiler-rt] sched_getaffinity mask definition for Linux. (PR #79903)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 13:33:59 PST 2024


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

None

>From 4365891cd134b0c7a771c81c944b8faaab64c419 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Mon, 29 Jan 2024 21:26:31 +0000
Subject: [PATCH] [compiler-rt] sched_getaffinity mask definition for Linux.

---
 .../sanitizer_common/sanitizer_common_interceptors.inc    | 2 +-
 .../sanitizer_platform_limits_freebsd.cpp                 | 1 +
 .../sanitizer_common/sanitizer_platform_limits_freebsd.h  | 2 ++
 .../sanitizer_common/sanitizer_platform_limits_posix.cpp  | 8 ++++++++
 .../sanitizer_common/sanitizer_platform_limits_posix.h    | 7 +++++++
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 3ecdb55cdbf72f5..9d556ff73d15b4e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -3870,7 +3870,7 @@ INTERCEPTOR(SIZE_T, confstr, int name, char *buf, SIZE_T len) {
 #endif
 
 #if SANITIZER_INTERCEPT_SCHED_GETAFFINITY
-INTERCEPTOR(int, sched_getaffinity, int pid, SIZE_T cpusetsize, void *mask) {
+INTERCEPTOR(int, sched_getaffinity, int pid, SIZE_T cpusetsize, __sanitizer_cpu_set_t *mask) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, sched_getaffinity, pid, cpusetsize, mask);
   // FIXME: under ASan the call below may write to freed memory and corrupt
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 38f968d533b147f..eedd642b34b7559 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -105,6 +105,7 @@ void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) {
 }
 
 unsigned struct_cpuset_sz = sizeof(cpuset_t);
+unsigned struct_cpu_set_sz = sizeof(cpu_set_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 43b8a38f39be182..e45d3efaa15ea6d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
@@ -725,7 +725,9 @@ struct __sanitizer_cpuset {
 };
 
 typedef struct __sanitizer_cpuset __sanitizer_cpuset_t;
+typedef struct __sanitizer_cpuset __sanitizer_cpu_set_t;
 extern unsigned struct_cpuset_sz;
+extern unsigned struct_cpu_set_sz;
 
 typedef unsigned long long __sanitizer_eventfd_t;
 }  // namespace __sanitizer
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index 6d61d276d77e35d..22449a0c316f3c1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -85,6 +85,9 @@
 #include <linux/utsname.h>
 #include <linux/posix_types.h>
 #include <net/if_arp.h>
+#if !SANITIZER_ANDROID
+#include <sched.h>
+#endif
 #endif
 
 #if SANITIZER_IOS
@@ -301,6 +304,7 @@ namespace __sanitizer {
   unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
   unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
   unsigned struct_statvfs_sz = sizeof(struct statvfs);
+  unsigned struct_cpu_set_sz = sizeof(cpu_set_t);
 #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
 
   const uptr sig_ign = (uptr)SIG_IGN;
@@ -1351,4 +1355,8 @@ CHECK_TYPE_SIZE(sem_t);
 COMPILER_CHECK(ARM_VFPREGS_SIZE == ARM_VFPREGS_SIZE_ASAN);
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+COMPILER_CHECK(sizeof(__sanitizer_cpu_set_t) == sizeof(cpu_set_t));
+#endif
+
 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_APPLE
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 34bfef1f7ef4569..db7d4bea30f5d16 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -209,6 +209,13 @@ struct __sanitizer_sem_t {
 extern unsigned struct_ustat_sz;
 extern unsigned struct_rlimit64_sz;
 extern unsigned struct_statvfs64_sz;
+extern unsigned struct_cpu_set_sz;
+
+struct __sanitizer_cpu_set {
+  unsigned long __bits[1024 / (8 * sizeof(unsigned long))];
+};
+
+typedef struct __sanitizer_cpu_set __sanitizer_cpu_set_t;
 
 struct __sanitizer_ipc_perm {
   int __key;



More information about the llvm-commits mailing list