[compiler-rt] r297923 - [msan] Intercept getloadavg.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 18:06:22 PDT 2017


Author: eugenis
Date: Wed Mar 15 20:06:22 2017
New Revision: 297923

URL: http://llvm.org/viewvc/llvm-project?rev=297923&view=rev
Log:
[msan] Intercept getloadavg.

Added:
    compiler-rt/trunk/test/msan/getloadavg.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

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=297923&r1=297922&r2=297923&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Mar 15 20:06:22 2017
@@ -6047,6 +6047,21 @@ INTERCEPTOR(void *, getutxline, void *ut
 #define INIT_UTMPX
 #endif
 
+#if SANITIZER_INTERCEPT_GETLOADAVG
+INTERCEPTOR(int, getloadavg, double *loadavg, int nelem) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, getloadavg, loadavg, nelem);
+  int res = REAL(getloadavg)(loadavg, nelem);
+  if (res > 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, loadavg, res * sizeof(*loadavg));
+  return res;
+}
+#define INIT_GETLOADAVG                      \
+  COMMON_INTERCEPT_FUNCTION(getloadavg);
+#else
+#define INIT_GETLOADAVG
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -6245,4 +6260,5 @@ static void InitializeCommonInterceptors
   // FIXME: add other *stat interceptors.
   INIT_UTMP;
   INIT_UTMPX;
+  INIT_GETLOADAVG;
 }

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=297923&r1=297922&r2=297923&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Mar 15 20:06:22 2017
@@ -326,6 +326,9 @@
 #define SANITIZER_INTERCEPT_UTMP SI_NOT_WINDOWS && !SI_MAC && !SI_FREEBSD
 #define SANITIZER_INTERCEPT_UTMPX SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
 
+#define SANITIZER_INTERCEPT_GETLOADAVG \
+  SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
+
 #define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (!SI_FREEBSD && !SI_MAC)
 #define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC)
 #define SANITIZER_INTERCEPT_PVALLOC (!SI_FREEBSD && !SI_MAC)

Added: compiler-rt/trunk/test/msan/getloadavg.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/getloadavg.cc?rev=297923&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/getloadavg.cc (added)
+++ compiler-rt/trunk/test/msan/getloadavg.cc Wed Mar 15 20:06:22 2017
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
+
+#define _BSD_SOURCE
+#include <assert.h>
+#include <stdlib.h>
+
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+  double x[4];
+  int ret = getloadavg(x, 3);
+  assert(ret > 0);
+  assert(ret <= 3);
+  assert(__msan_test_shadow(x, sizeof(double) * ret) == -1);
+  assert(__msan_test_shadow(&x[ret], sizeof(double)) == 0);
+}




More information about the llvm-commits mailing list