[compiler-rt] 0713053 - [MSAN] extend prctl interceptor to support PR_SCHED_CORE

Kevin Athey via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 16:49:32 PDT 2022


Author: Kevin Athey
Date: 2022-04-07T16:49:25-07:00
New Revision: 0713053e4a3f08fc0a8408400ee5c4d20a188765

URL: https://github.com/llvm/llvm-project/commit/0713053e4a3f08fc0a8408400ee5c4d20a188765
DIFF: https://github.com/llvm/llvm-project/commit/0713053e4a3f08fc0a8408400ee5c4d20a188765.diff

LOG: [MSAN] extend prctl interceptor to support PR_SCHED_CORE

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D122851

Added: 
    compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 18b023078441b..9b98261b0d0f5 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 0000000000000..f1d19b3e7e6e0
--- /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;
+}


        


More information about the llvm-commits mailing list