[compiler-rt] r187788 - [sanitizer] Intercept sched_getaffinity.

David Blaikie dblaikie at gmail.com
Tue Aug 6 17:41:09 PDT 2013


On Tue, Aug 6, 2013 at 2:29 AM, Evgeniy Stepanov
<eugeni.stepanov at gmail.com> wrote:
> Author: eugenis
> Date: Tue Aug  6 04:29:01 2013
> New Revision: 187788
>
> URL: http://llvm.org/viewvc/llvm-project?rev=187788&view=rev
> Log:
> [sanitizer] Intercept sched_getaffinity.

I've reverted this in r187841 as the test case is unreliable (as tests
may be run in an environment where the test process does not have
affinity to cpu0). Possibly it should be written to use CPU_COUNT != 0
rather than CPU_ISSET 0.

> Modified:
>     compiler-rt/trunk/lib/msan/tests/msan_test.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
>     compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
>
> Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=187788&r1=187787&r2=187788&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
> +++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Tue Aug  6 04:29:01 2013
> @@ -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;
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=187788&r1=187787&r2=187788&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Aug  6 04:29:01 2013
> @@ -1761,6 +1761,20 @@ INTERCEPTOR(SIZE_T, confstr, int name, c
>  #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, c
>    INIT_TCGETATTR;                          \
>    INIT_REALPATH;                           \
>    INIT_CANONICALIZE_FILE_NAME;             \
> -  INIT_CONFSTR;
> +  INIT_CONFSTR;                            \
> +  INIT_SCHED_GETAFFINITY;
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=187788&r1=187787&r2=187788&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Aug  6 04:29:01 2013
> @@ -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
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=187788&r1=187787&r2=187788&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Tue Aug  6 04:29:01 2013
> @@ -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                   ";
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=187788&r1=187787&r2=187788&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Tue Aug  6 04:29:01 2013
> @@ -348,6 +348,7 @@ enum StatType {
>    StatInt_realpath,
>    StatInt_canonicalize_file_name,
>    StatInt_confstr,
> +  StatInt_sched_getaffinity,
>
>    // Dynamic annotations.
>    StatAnnotation,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list