From: Nicholas Nethercote Date: Tue, 22 Jul 2003 09:12:33 +0000 (+0000) Subject: Added overlap checking to Addrcheck, mostly just moving things around. In X-Git-Tag: svn/VALGRIND_2_0_0~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ca84f991d30bf8af78513c48955a2e313d8aff5e;p=thirdparty%2Fvalgrind.git Added overlap checking to Addrcheck, mostly just moving things around. In particular, renamed mc_replace_strmem.c as mac_replace_strmem.c; the 'mac' prefix indicates it's shared between Memcheck and Addrcheck. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1774 --- diff --git a/addrcheck/Makefile.am b/addrcheck/Makefile.am index 1a4f5060e4..a3731e7300 100644 --- a/addrcheck/Makefile.am +++ b/addrcheck/Makefile.am @@ -17,5 +17,6 @@ vgskin_addrcheck_so_LDADD = \ ../memcheck/mac_leakcheck.o \ ../memcheck/mac_malloc_wrappers.o \ ../memcheck/mac_needs.o \ + ../memcheck/mac_replace_strmem.o \ ../coregrind/vg_replace_malloc.o diff --git a/memcheck/Makefile.am b/memcheck/Makefile.am index e938507312..3463d2cf3a 100644 --- a/memcheck/Makefile.am +++ b/memcheck/Makefile.am @@ -16,11 +16,11 @@ vgskin_memcheck_so_SOURCES = \ mac_leakcheck.c \ mac_malloc_wrappers.c \ mac_needs.c \ + mac_replace_strmem.c \ mc_main.c \ mc_clientreqs.c \ mc_errcontext.c \ mc_from_ucode.c \ - mc_replace_strmem.c \ mc_translate.c \ mc_helpers.S vgskin_memcheck_so_LDFLAGS = -shared @@ -36,5 +36,5 @@ noinst_HEADERS = \ mc_constants.h \ mc_include.h -mc_replace_strmem.o: CFLAGS += -fno-omit-frame-pointer +mac_replace_strmem.o: CFLAGS += -fno-omit-frame-pointer diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c index daec938493..e90151e00d 100644 --- a/memcheck/mac_needs.c +++ b/memcheck/mac_needs.c @@ -287,6 +287,13 @@ void MAC_(pp_shared_SkinError) ( Error* err ) MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); break; + case OverlapErr: + VG_(message)(Vg_UserMsg, + "Source and destination overlap in %s", + VG_(get_error_string)(err)); + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + break; + case LeakErr: { /* Totally abusing the types of these spare fields... oh well. */ UInt n_this_record = (UInt)VG_(get_error_address)(err); @@ -464,6 +471,16 @@ void MAC_(record_freemismatch_error) ( ThreadState* tst, Addr a ) VG_(maybe_record_error)( tst, FreeMismatchErr, a, /*s*/NULL, &err_extra ); } + +void MAC_(record_overlap_error) ( ThreadState* tst, Char* function ) +{ + MAC_Error err_extra; + + MAC_(clear_MAC_Error)( &err_extra ); + VG_(maybe_record_error)( tst, OverlapErr, /*addr*/0, function, &err_extra ); +} + + /* Updates the copy with address info if necessary (but not for LeakErrs). */ UInt SK_(update_extra)( Error* err ) { diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mac_replace_strmem.c similarity index 96% rename from memcheck/mc_replace_strmem.c rename to memcheck/mac_replace_strmem.c index 0f1ce0778d..f40128fae9 100644 --- a/memcheck/mc_replace_strmem.c +++ b/memcheck/mac_replace_strmem.c @@ -2,7 +2,7 @@ /*--------------------------------------------------------------------*/ /*--- Replacements for strcpy(), memcpy() et al, which run on the ---*/ /*--- simulated CPU. ---*/ -/*--- mc_replace_strmem.c ---*/ +/*--- mac_replace_strmem.c ---*/ /*--------------------------------------------------------------------*/ /* @@ -84,7 +84,7 @@ void complain2 ( Char* s, char* dst, const char* src ) { Char buf[256]; snprintf(buf, 100, "%s(%p, %p)", s, dst, src ); - VALGRIND_NON_SIMD_tstCALL1( MC_(record_overlap_error), buf ); + VALGRIND_NON_SIMD_tstCALL1( MAC_(record_overlap_error), buf ); } static __inline__ @@ -92,7 +92,7 @@ void complain3 ( Char* s, void* dst, const void* src, int n ) { Char buf[256]; snprintf(buf, 100, "%s(%p, %p, %d)", s, dst, src, n ); - VALGRIND_NON_SIMD_tstCALL1( MC_(record_overlap_error), buf ); + VALGRIND_NON_SIMD_tstCALL1( MAC_(record_overlap_error), buf ); } char* strrchr ( const char* s, int c ) @@ -281,5 +281,5 @@ void* memcpy( void *dst, const void *src, unsigned int len ) /*--------------------------------------------------------------------*/ -/*--- end mc_replace_strmem.c ---*/ +/*--- end mac_replace_strmem.c ---*/ /*--------------------------------------------------------------------*/ diff --git a/memcheck/mac_shared.h b/memcheck/mac_shared.h index 5cb989316c..ffdf83b60f 100644 --- a/memcheck/mac_shared.h +++ b/memcheck/mac_shared.h @@ -304,6 +304,7 @@ extern void MAC_(record_param_error) ( ThreadState* tst, Addr a, extern void MAC_(record_jump_error) ( ThreadState* tst, Addr a ); extern void MAC_(record_free_error) ( ThreadState* tst, Addr a ); extern void MAC_(record_freemismatch_error)( ThreadState* tst, Addr a ); +extern void MAC_(record_overlap_error) ( ThreadState* tst, Char* function ); extern void MAC_(pp_shared_SkinError) ( Error* err); diff --git a/memcheck/mc_errcontext.c b/memcheck/mc_errcontext.c index 9eb0ae8b31..5539b220ee 100644 --- a/memcheck/mc_errcontext.c +++ b/memcheck/mc_errcontext.c @@ -114,13 +114,6 @@ void SK_(pp_SkinError) ( Error* err ) MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); break; - case OverlapErr: - VG_(message)(Vg_UserMsg, - "Source and destination overlap in %s", - VG_(get_error_string)(err)); - VG_(pp_ExeContext)( VG_(get_error_where)(err) ); - break; - default: MAC_(pp_shared_SkinError)(err); break; @@ -143,7 +136,7 @@ void MC_(record_value_error) ( ThreadState* tst, Int size ) VG_(maybe_record_error)( tst, ValueErr, /*addr*/0, /*s*/NULL, &err_extra ); } -/* These two called from non-generated code */ +/* This called from non-generated code */ void MC_(record_user_error) ( ThreadState* tst, Addr a, Bool isWrite ) { @@ -157,14 +150,6 @@ void MC_(record_user_error) ( ThreadState* tst, Addr a, Bool isWrite ) VG_(maybe_record_error)( tst, UserErr, a, /*s*/NULL, &err_extra ); } -void MC_(record_overlap_error) ( ThreadState* tst, Char* function ) -{ - MAC_Error err_extra; - - MAC_(clear_MAC_Error)( &err_extra ); - VG_(maybe_record_error)( tst, OverlapErr, /*addr*/0, function, &err_extra ); -} - /*------------------------------------------------------------*/ /*--- Suppressions ---*/ /*------------------------------------------------------------*/ diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index 63aee187b8..40458dcc90 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -113,14 +113,14 @@ extern Bool MC_(clo_avoid_strlen_errors); /*--- Functions ---*/ /*------------------------------------------------------------*/ -/* Functions defined in vg_memcheck_helpers.S */ +/* Functions defined in mc_helpers.S */ extern void MC_(helper_value_check4_fail) ( void ); extern void MC_(helper_value_check2_fail) ( void ); extern void MC_(helper_value_check1_fail) ( void ); extern void MC_(helper_value_check0_fail) ( void ); -/* Functions defined in vg_memcheck.c */ +/* Functions defined in mc_main.c */ extern void MC_(helperc_STOREV4) ( Addr, UInt ); extern void MC_(helperc_STOREV2) ( Addr, UInt ); extern void MC_(helperc_STOREV1) ( Addr, UInt ); @@ -151,15 +151,14 @@ extern Int MC_(get_or_set_vbits_for_client) ( Bool setting /* True <=> set vbits, False <=> get vbits */ ); -/* Functions defined in vg_memcheck_clientreqs.c */ +/* Functions defined in mc_clientreqs.c */ extern Bool MC_(client_perm_maybe_describe)( Addr a, AddrInfo* ai ); extern void MC_(show_client_block_stats) ( void ); -/* Functions defined in vg_memcheck_errcontext.c */ +/* Functions defined in mc_errcontext.c */ extern void MC_(record_value_error) ( ThreadState* tst, Int size ); extern void MC_(record_user_error) ( ThreadState* tst, Addr a, Bool isWrite ); -extern void MC_(record_overlap_error)( ThreadState* tst, Char* function ); #endif diff --git a/memcheck/tests/filter_stderr b/memcheck/tests/filter_stderr index 1c0a29564c..4d7aaf8b1a 100755 --- a/memcheck/tests/filter_stderr +++ b/memcheck/tests/filter_stderr @@ -7,8 +7,8 @@ $dir/../../tests/filter_stderr_basic | # Anonymise addresses $dir/../../tests/filter_addresses | -# Anonymise line numbers in mc_replace_strmem.c -sed "s/mc_replace_strmem.c:[0-9]\+/mc_replace_strmem.c:.../" | +# Anonymise line numbers in mac_replace_strmem.c +sed "s/mac_replace_strmem.c:[0-9]\+/mac_replace_strmem.c:.../" | $dir/../../tests/filter_test_paths | diff --git a/memcheck/tests/overlap.stderr.exp b/memcheck/tests/overlap.stderr.exp index 02180eb020..6468d486db 100644 --- a/memcheck/tests/overlap.stderr.exp +++ b/memcheck/tests/overlap.stderr.exp @@ -1,41 +1,41 @@ Source and destination overlap in memcpy(0x........, 0x........, 21) - at 0x........: memcpy (mc_replace_strmem.c:...) + at 0x........: memcpy (mac_replace_strmem.c:...) by 0x........: main (overlap.c:40) by 0x........: __libc_start_main (...libc...) by 0x........: ... Source and destination overlap in memcpy(0x........, 0x........, 21) - at 0x........: memcpy (mc_replace_strmem.c:...) + at 0x........: memcpy (mac_replace_strmem.c:...) by 0x........: main (overlap.c:42) by 0x........: __libc_start_main (...libc...) by 0x........: ... Source and destination overlap in strncpy(0x........, 0x........, 21) - at 0x........: strncpy (mc_replace_strmem.c:...) + at 0x........: strncpy (mac_replace_strmem.c:...) by 0x........: main (overlap.c:45) by 0x........: __libc_start_main (...libc...) by 0x........: ... Source and destination overlap in strncpy(0x........, 0x........, 21) - at 0x........: strncpy (mc_replace_strmem.c:...) + at 0x........: strncpy (mac_replace_strmem.c:...) by 0x........: main (overlap.c:47) by 0x........: __libc_start_main (...libc...) by 0x........: ... Source and destination overlap in strcpy(0x........, 0x........) - at 0x........: strcpy (mc_replace_strmem.c:...) + at 0x........: strcpy (mac_replace_strmem.c:...) by 0x........: main (overlap.c:54) by 0x........: __libc_start_main (...libc...) by 0x........: ... Source and destination overlap in strncat(0x........, 0x........, 21) - at 0x........: strncat (mc_replace_strmem.c:...) + at 0x........: strncat (mac_replace_strmem.c:...) by 0x........: main (overlap.c:112) by 0x........: __libc_start_main (...libc...) by 0x........: ... Source and destination overlap in strncat(0x........, 0x........, 21) - at 0x........: strncat (mc_replace_strmem.c:...) + at 0x........: strncat (mac_replace_strmem.c:...) by 0x........: main (overlap.c:113) by 0x........: __libc_start_main (...libc...) by 0x........: ...