diff options
5 files changed, 26 insertions, 1 deletions
diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc index 520fa7bb428..0716460dcd2 100644 --- a/compiler-rt/lib/msan/tests/msan_test.cc +++ b/compiler-rt/lib/msan/tests/msan_test.cc @@ -2047,6 +2047,13 @@ TEST(MemorySanitizer, dlopenFailed) { #endif // MSAN_TEST_DISABLE_DLOPEN +TEST(MemorySanitizer, sched_getaffinity) { + cpu_set_t mask; + int res = sched_getaffinity(getpid(), sizeof(mask), &mask); + ASSERT_EQ(0, res); + ASSERT_TRUE(CPU_ISSET(0, &mask)); +} + TEST(MemorySanitizer, scanf) { const char *input = "42 hello"; int* d = new int; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 58dd044d309..5a7d77c3b51 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -1761,6 +1761,20 @@ INTERCEPTOR(SIZE_T, confstr, int name, char *buf, SIZE_T len) { #define INIT_CONFSTR #endif +#if SANITIZER_INTERCEPT_SCHED_GETAFFINITY +INTERCEPTOR(int, sched_getaffinity, int pid, SIZE_T cpusetsize, void *mask) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, sched_getaffinity, pid, cpusetsize, mask); + int res = REAL(sched_getaffinity)(pid, cpusetsize, mask); + if (mask && !res) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, mask, cpusetsize); + return res; +} +#define INIT_SCHED_GETAFFINITY INTERCEPT_FUNCTION(sched_getaffinity); +#else +#define INIT_SCHED_GETAFFINITY +#endif + #define SANITIZER_COMMON_INTERCEPTORS_INIT \ INIT_STRCMP; \ INIT_STRNCMP; \ @@ -1820,4 +1834,5 @@ INTERCEPTOR(SIZE_T, confstr, int name, char *buf, SIZE_T len) { INIT_TCGETATTR; \ INIT_REALPATH; \ INIT_CANONICALIZE_FILE_NAME; \ - INIT_CONFSTR; + INIT_CONFSTR; \ + INIT_SCHED_GETAFFINITY; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index a601c7f0054..e3aaf211f36 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -110,5 +110,6 @@ # define SANITIZER_INTERCEPT_REALPATH SI_NOT_WINDOWS # define SANITIZER_INTERCEPT_CANONICALIZE_FILE_NAME SI_LINUX_NOT_ANDROID # define SANITIZER_INTERCEPT_CONFSTR SI_MAC || SI_LINUX_NOT_ANDROID +# define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc index fe0c09cf1f9..dacc498d92d 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc @@ -353,6 +353,7 @@ void StatOutput(u64 *stat) { name[StatInt_realpath] = " realpath "; name[StatInt_canonicalize_file_name] = " canonicalize_file_name "; name[StatInt_confstr] = " confstr "; + name[StatInt_sched_getaffinity] = " sched_getaffinity "; name[StatAnnotation] = "Dynamic annotations "; name[StatAnnotateHappensBefore] = " HappensBefore "; diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h index 606ee66e759..b3a850a03f0 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.h +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h @@ -348,6 +348,7 @@ enum StatType { StatInt_realpath, StatInt_canonicalize_file_name, StatInt_confstr, + StatInt_sched_getaffinity, // Dynamic annotations. StatAnnotation, |

