diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -1365,12 +1365,16 @@ 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 --- /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 +#include +#include +#include + +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; +}