summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Athey <kda@google.com>2022-04-07 09:40:49 -0700
committerKevin Athey <kda@google.com>2022-04-07 16:49:25 -0700
commit0713053e4a3f08fc0a8408400ee5c4d20a188765 (patch)
tree5c0f1a09b4a5f38289ffc2509784a36c21ef856d
parente0cfe20ad2fb8c7aab3d6e82c42649eacf595d9f (diff)
downloadllvm-0713053e4a3f08fc0a8408400ee5c4d20a188765.tar.gz
[MSAN] extend prctl interceptor to support PR_SCHED_CORE
Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D122851
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc4
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp26
2 files changed, 30 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 18b023078441..9b98261b0d0f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1365,12 +1365,16 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, prctl, option, arg2, arg3, arg4, arg5);
static const int PR_SET_NAME = 15;
+ static const int PR_SCHED_CORE = 62;
+ static const int PR_SCHED_CORE_GET = 0;
int res = REAL(prctl(option, arg2, arg3, arg4, arg5));
if (option == PR_SET_NAME) {
char buff[16];
internal_strncpy(buff, (char *)arg2, 15);
buff[15] = 0;
COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, buff);
+ } else if (res != -1 && option == PR_SCHED_CORE && arg2 == PR_SCHED_CORE_GET) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64*)(arg5), sizeof(u64));
}
return res;
}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
new file mode 100644
index 000000000000..f1d19b3e7e6e
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp
@@ -0,0 +1,26 @@
+// RUN: %clangxx %s -o %t && %run %t %p
+
+#include <assert.h>
+#include <errno.h>
+#include <stdint.h>
+#include <sys/prctl.h>
+
+int main() {
+
+ int res;
+ res = prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, 0, 0);
+ if (res < 0) {
+ assert(errno == EINVAL);
+ return 0;
+ }
+
+ uint64_t cookie = 0;
+ res = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 0, 0, &cookie);
+ if (res < 0) {
+ assert(errno == EINVAL);
+ } else {
+ assert(cookie != 0);
+ }
+
+ return 0;
+}