-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[compiler-rt] intercept freebsd's cpuset_getdomain api. #76851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/76851.diff 4 Files Affected:
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
|
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
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>
|
41f3f8c
to
792b139
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> _
331a1ca
to
f6c6db6
Compare
Please rebase and re-request review if it's still relevant. |
f7b6f1f
to
6496bad
Compare
No description provided.