De-convolute somewhat the client request usage for reporting overlap errors.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3407 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c
index 8612a72..705e271 100644
--- a/memcheck/mac_needs.c
+++ b/memcheck/mac_needs.c
@@ -904,9 +904,12 @@
return True;
}
- case _VG_USERREQ__MEMCHECK_GET_RECORD_OVERLAP:
- *ret = (Addr)MAC_(record_overlap_error);
+ case _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR: {
+ Char* s = (Char*) arg[1];
+ OverlapExtra* extra = (OverlapExtra*)arg[2];
+ MAC_(record_overlap_error)(tid, s, extra);
return True;
+ }
case VG_USERREQ__CREATE_MEMPOOL: {
Addr pool = (Addr)arg[1];
diff --git a/memcheck/mac_replace_strmem.c b/memcheck/mac_replace_strmem.c
index 0e4012f..53b8f28 100644
--- a/memcheck/mac_replace_strmem.c
+++ b/memcheck/mac_replace_strmem.c
@@ -34,27 +34,14 @@
#include "memcheck.h"
#include "valgrind.h"
-static Addr record_overlap_error;
-
-static int init_done;
-
-/* Startup hook - called as init section */
-static void init(void) __attribute__((constructor));
-static void init(void)
-{
- if (init_done)
- return;
-
- VALGRIND_MAGIC_SEQUENCE(record_overlap_error, 0,
- _VG_USERREQ__MEMCHECK_GET_RECORD_OVERLAP,
- 0, 0, 0, 0);
- init_done = 1;
-}
-
/* ---------------------------------------------------------------------
- The normal versions of these functions are hyper-optimised, which fools
- Memcheck and cause spurious value warnings. So we replace them with
- simpler versions. THEY RUN ON SIMD CPU!
+ We have our own versions of these functions for two reasons:
+ (a) it allows us to do overlap checking
+ (b) some of the normal versions are hyper-optimised, which fools
+ Memcheck and cause spurious value warnings. Our versions are
+ simpler.
+
+ THEY RUN ON THE SIMD CPU!
------------------------------------------------------------------ */
/* Figure out if [dst .. dst+dstlen-1] overlaps with
@@ -91,6 +78,15 @@
}
}
+// This is a macro rather than a function because we don't want to have an
+// extra function in the stack trace.
+#define RECORD_OVERLAP_ERROR(s, p_extra) \
+{ \
+ Word unused_res; \
+ VALGRIND_MAGIC_SEQUENCE(unused_res, 0, \
+ _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR, \
+ s, p_extra, 0, 0); \
+}
static __inline__
void complain2 ( Char* s, char* dst, const char* src )
@@ -98,8 +94,7 @@
OverlapExtra extra = {
.src = (Addr)src, .dst = (Addr)dst, .len = -1,
};
- init();
- VALGRIND_NON_SIMD_CALL2( record_overlap_error, s, &extra );
+ RECORD_OVERLAP_ERROR( s, &extra );
}
static __inline__
@@ -109,8 +104,7 @@
OverlapExtra extra = {
.src = (Addr)src, .dst = (Addr)dst, .len = n,
};
- init();
- VALGRIND_NON_SIMD_CALL2( record_overlap_error, s, &extra );
+ RECORD_OVERLAP_ERROR( s, &extra );
}
char* strrchr ( const char* s, int c )
diff --git a/memcheck/memcheck.h b/memcheck/memcheck.h
index 5b0639f..faff792 100644
--- a/memcheck/memcheck.h
+++ b/memcheck/memcheck.h
@@ -94,7 +94,8 @@
VG_USERREQ__CREATE_BLOCK,
/* This is just for memcheck's internal use - don't use it */
- _VG_USERREQ__MEMCHECK_GET_RECORD_OVERLAP = VG_USERREQ_TOOL_BASE('M','C')+256
+ _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR
+ = VG_USERREQ_TOOL_BASE('M','C') + 256
} Vg_MemCheckClientRequest;