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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 13:34:29 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: David CARLIER (devnexen)

<details>
<summary>Changes</summary>



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


5 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc (+1-1) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp (+1) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h (+2) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp (+8) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h (+7) 


``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 3ecdb55cdbf72f..9d556ff73d15b4 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 38f968d533b147..eedd642b34b755 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 43b8a38f39be18..e45d3efaa15ea6 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 6d61d276d77e35..22449a0c316f3c 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 34bfef1f7ef456..db7d4bea30f5d1 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;

``````````

</details>


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


More information about the llvm-commits mailing list