[compiler-rt] r185416 - [sanitizer] Intercept setlocale.

Alexander Potapenko glider at google.com
Tue Jul 2 02:31:39 PDT 2013


Dima, is it possible to get rid of this manual padding in tsan_stat.cc?

On Tue, Jul 2, 2013 at 1:23 PM, Evgeniy Stepanov
<eugeni.stepanov at gmail.com> wrote:
> Author: eugenis
> Date: Tue Jul  2 04:23:45 2013
> New Revision: 185416
>
> URL: http://llvm.org/viewvc/llvm-project?rev=185416&view=rev
> Log:
> [sanitizer] Intercept setlocale.
>
> Added:
>     compiler-rt/trunk/lib/msan/lit_tests/setlocale.cc   (with props)
> Modified:
>     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
>
> Added: compiler-rt/trunk/lib/msan/lit_tests/setlocale.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/setlocale.cc?rev=185416&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/msan/lit_tests/setlocale.cc (added)
> +++ compiler-rt/trunk/lib/msan/lit_tests/setlocale.cc Tue Jul  2 04:23:45 2013
> @@ -0,0 +1,13 @@
> +// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t
> +
> +#include <assert.h>
> +#include <locale.h>
> +#include <stdlib.h>
> +
> +int main(void) {
> +  char *locale = setlocale (LC_ALL, "");
> +  assert(locale);
> +  if (locale[0])
> +    exit(0);
> +  return 0;
> +}
>
> Propchange: compiler-rt/trunk/lib/msan/lit_tests/setlocale.cc
> ------------------------------------------------------------------------------
>     svn:eol-style = LF
>
> 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=185416&r1=185415&r2=185416&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Jul  2 04:23:45 2013
> @@ -1399,6 +1399,24 @@ INTERCEPTOR(uptr, ptrace, int request, i
>  #define INIT_PTRACE
>  #endif
>
> +#if SANITIZER_INTERCEPT_SETLOCALE
> +INTERCEPTOR(char *, setlocale, int category, char *locale) {
> +  void *ctx;
> +  COMMON_INTERCEPTOR_ENTER(ctx, setlocale, category, locale);
> +  if (locale)
> +    COMMON_INTERCEPTOR_READ_RANGE(ctx, locale, REAL(strlen)(locale) + 1);
> +  char * res = REAL(setlocale)(category, locale);
> +  if (res)
> +    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, REAL(strlen)(res) + 1);
> +  return res;
> +}
> +
> +#define INIT_SETLOCALE           \
> +  INTERCEPT_FUNCTION(setlocale);
> +#else
> +#define INIT_SETLOCALE
> +#endif
> +
>
>  #define SANITIZER_COMMON_INTERCEPTORS_INIT \
>    INIT_STRCASECMP;                         \
> @@ -1445,4 +1463,5 @@ INTERCEPTOR(uptr, ptrace, int request, i
>    INIT_SYSINFO;                            \
>    INIT_READDIR;                            \
>    INIT_READDIR64;                          \
> -  INIT_PTRACE;
> +  INIT_PTRACE;                             \
> +  INIT_SETLOCALE;
>
> 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=185416&r1=185415&r2=185416&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Jul  2 04:23:45 2013
> @@ -96,5 +96,6 @@
>  # define SANITIZER_INTERCEPT_READDIR SI_NOT_WINDOWS
>  # define SANITIZER_INTERCEPT_READDIR64 SI_LINUX_NOT_ANDROID
>  # define SANITIZER_INTERCEPT_PTRACE SI_LINUX_NOT_ANDROID
> +# define SANITIZER_INTERCEPT_SETLOCALE SI_NOT_WINDOWS
>
>  #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=185416&r1=185415&r2=185416&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Tue Jul  2 04:23:45 2013
> @@ -337,6 +337,7 @@ void StatOutput(u64 *stat) {
>    name[StatInt_readdir_r]                = "  readdir_r                       ";
>    name[StatInt_readdir64_r]              = "  readdir64_r                     ";
>    name[StatInt_ptrace]                   = "  ptrace                          ";
> +  name[StatInt_setlocale]                = "  setlocale                       ";
>
>    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=185416&r1=185415&r2=185416&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Tue Jul  2 04:23:45 2013
> @@ -332,6 +332,7 @@ enum StatType {
>    StatInt_readdir_r,
>    StatInt_readdir64_r,
>    StatInt_ptrace,
> +  StatInt_setlocale,
>
>    // Dynamic annotations.
>    StatAnnotation,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



-- 
Alexander Potapenko
Software Engineer
Google Moscow



More information about the llvm-commits mailing list