[compiler-rt] r208196 - [sanitizer] Intercept obstack.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed May 7 04:50:57 PDT 2014
Author: eugenis
Date: Wed May 7 06:50:56 2014
New Revision: 208196
URL: http://llvm.org/viewvc/llvm-project?rev=208196&view=rev
Log:
[sanitizer] Intercept obstack.
Added:
compiler-rt/trunk/test/msan/obstack.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/sanitizer_common/sanitizer_platform_limits_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.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=208196&r1=208195&r2=208196&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed May 7 06:50:56 2014
@@ -3894,6 +3894,49 @@ INTERCEPTOR(__sanitizer_FILE *, fmemopen
#define INIT_OPEN_MEMSTREAM
#endif
+#if SANITIZER_INTERCEPT_OBSTACK
+static void initialize_obstack(__sanitizer_obstack *obstack) {
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(obstack, sizeof(*obstack));
+ if (obstack->chunk)
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(obstack->chunk,
+ sizeof(*obstack->chunk));
+}
+
+INTERCEPTOR(int, _obstack_begin_1, __sanitizer_obstack *obstack, int sz,
+ int align, void *(*alloc_fn)(uptr arg, uptr sz),
+ void (*free_fn)(uptr arg, void *p)) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, _obstack_begin_1, obstack, sz, align, alloc_fn,
+ free_fn);
+ int res = REAL(_obstack_begin_1)(obstack, sz, align, alloc_fn, free_fn);
+ if (res) initialize_obstack(obstack);
+ return res;
+}
+INTERCEPTOR(int, _obstack_begin, __sanitizer_obstack *obstack, int sz,
+ int align, void *(*alloc_fn)(uptr sz), void (*free_fn)(void *p)) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, _obstack_begin, obstack, sz, align, alloc_fn,
+ free_fn);
+ int res = REAL(_obstack_begin)(obstack, sz, align, alloc_fn, free_fn);
+ if (res) initialize_obstack(obstack);
+ return res;
+}
+INTERCEPTOR(void, _obstack_newchunk, __sanitizer_obstack *obstack, int length) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, _obstack_newchunk, obstack, length);
+ REAL(_obstack_newchunk)(obstack, length);
+ if (obstack->chunk)
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(
+ obstack->chunk, obstack->next_free - (char *)obstack->chunk);
+}
+#define INIT_OBSTACK \
+ COMMON_INTERCEPT_FUNCTION(_obstack_begin_1); \
+ COMMON_INTERCEPT_FUNCTION(_obstack_begin); \
+ COMMON_INTERCEPT_FUNCTION(_obstack_newchunk);
+#else
+#define INIT_OBSTACK
+#endif
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_TEXTDOMAIN; \
INIT_STRCMP; \
@@ -4027,5 +4070,6 @@ INTERCEPTOR(__sanitizer_FILE *, fmemopen
INIT_TSEARCH; \
INIT_LIBIO_INTERNALS; \
INIT_FOPEN; \
- INIT_OPEN_MEMSTREAM;
+ INIT_OPEN_MEMSTREAM; \
+ INIT_OBSTACK;
/**/
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=208196&r1=208195&r2=208196&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed May 7 06:50:56 2014
@@ -199,5 +199,6 @@
#define SANITIZER_INTERCEPT_LIBIO_INTERNALS SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_FOPEN SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_OPEN_MEMSTREAM SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_OBSTACK SI_LINUX_NOT_ANDROID
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=208196&r1=208195&r2=208196&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Wed May 7 06:50:56 2014
@@ -115,6 +115,7 @@
#if SANITIZER_LINUX && !SANITIZER_ANDROID
#include <glob.h>
+#include <obstack.h>
#include <mqueue.h>
#include <net/if_ppp.h>
#include <netax25/ax25.h>
@@ -1150,4 +1151,15 @@ CHECK_SIZE_AND_OFFSET(FILE, _chain);
CHECK_SIZE_AND_OFFSET(FILE, _fileno);
#endif
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk));
+CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit);
+CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev);
+CHECK_TYPE_SIZE(obstack);
+CHECK_SIZE_AND_OFFSET(obstack, chunk_size);
+CHECK_SIZE_AND_OFFSET(obstack, chunk);
+CHECK_SIZE_AND_OFFSET(obstack, object_base);
+CHECK_SIZE_AND_OFFSET(obstack, next_free);
+#endif
+
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_MAC
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=208196&r1=208195&r2=208196&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Wed May 7 06:50:56 2014
@@ -694,6 +694,21 @@ namespace __sanitizer {
};
#endif
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+struct __sanitizer__obstack_chunk {
+ char *limit;
+ struct __sanitizer__obstack_chunk *prev;
+};
+
+struct __sanitizer_obstack {
+ long chunk_size;
+ struct __sanitizer__obstack_chunk *chunk;
+ char *object_base;
+ char *next_free;
+ uptr more_fields[7];
+};
+#endif
+
#define IOC_NRBITS 8
#define IOC_TYPEBITS 8
#if defined(__powerpc__) || defined(__powerpc64__)
Added: compiler-rt/trunk/test/msan/obstack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/obstack.cc?rev=208196&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/obstack.cc (added)
+++ compiler-rt/trunk/test/msan/obstack.cc Wed May 7 06:50:56 2014
@@ -0,0 +1,37 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t
+// RUN: %clangxx_msan -m64 -O0 -g -DPOSITIVE %s -o %t && not %run %t |& FileCheck %s
+
+#include <obstack.h>
+#include <sanitizer/msan_interface.h>
+#include <stdlib.h>
+
+static void *obstack_chunk_alloc(size_t sz) {
+ return malloc(sz);
+}
+
+static void obstack_chunk_free(void *p) {
+ free(p);
+}
+
+int main(void) {
+ obstack obs;
+ obstack_init(&obs);
+ for (size_t sz = 16; sz < 0xFFFF; sz *= 2) {
+ void *p = obstack_alloc(&obs, sz);
+ int data[10] = {0};
+ obstack_grow(&obs, &data, sizeof(data));
+ obstack_blank(&obs, sz);
+ obstack_grow(&obs, &data, sizeof(data));
+ obstack_int_grow(&obs, 13);
+ p = obstack_finish(&obs);
+#ifdef POSITIVE
+ if (sz == 4096) {
+ __msan_check_mem_is_initialized(p, sizeof(data));
+ __msan_check_mem_is_initialized(p, sizeof(data) + 1);
+ }
+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: #0 0x{{.*}} in main{{.*}}obstack.cc:[[@LINE-30]]
+#endif
+ }
+ obstack_free(&obs, 0);
+}
Propchange: compiler-rt/trunk/test/msan/obstack.cc
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the llvm-commits
mailing list