This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA:] Take 2 (was: Re: RFC: --enable-checking=valgrind.)


On Mon, 18 Nov 2002, Richard Henderson wrote:
> Updated patch is ok.

Thanks for the review.

On request from Neil, I instead committed this for cppfiles.c,
as an obvious change to the patch.  Tested by inspecting
preprocessed output with and without --enable-checking=valgrind
and "manually" checking the expected whitespace change, plus the
expected extra ";" without --enable-checking, compared to the
previous, bootstrapped&checked patch.  Also bootstrapped&checked
without --enable-checking=valgrind.  New ChangeLog entry for
that file:

	* cppfiles.c [!ENABLE_VALGRIND_CHECKING] (VALGRIND_DISCARD):
	Define as empty.
	(read_include_file): When doing the mmap+1 trick,
	valgrind-annotate the byte after the mmap:ed area as readable.
	(purge_cache): Remove above annotation.

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.156
diff -p -c -r1.156 cppfiles.c
*** cppfiles.c	22 Sep 2002 02:03:16 -0000	1.156
--- cppfiles.c	20 Nov 2002 00:02:38 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 27,32 ****
--- 27,38 ----
  #include "intl.h"
  #include "mkdeps.h"
  #include "splay-tree.h"
+ #ifdef ENABLE_VALGRIND_CHECKING
+ #include <valgrind.h>
+ #else
+ /* Avoid #ifdef:s when we can help it.  */
+ #define VALGRIND_DISCARD(x)
+ #endif

  #ifdef HAVE_MMAP_FILE
  # include <sys/mman.h>
*************** read_include_file (pfile, inc)
*** 418,423 ****
--- 424,434 ----
  	  buf = (uchar *) mmap (0, size, PROT_READ, MAP_PRIVATE, inc->fd, 0);
  	  if (buf == (uchar *)-1)
  	    goto perror_fail;
+
+ 	  /* We must tell Valgrind that the byte at buf[size] is actually
+ 	     readable.  Discard the handle to avoid handle leak.  */
+ 	  VALGRIND_DISCARD (VALGRIND_MAKE_READABLE (buf + size, 1));
+
  	  inc->mapped = 1;
  	}
        else
*************** purge_cache (inc)
*** 498,504 ****
      {
  #if MMAP_THRESHOLD
        if (inc->mapped)
! 	munmap ((PTR) inc->buffer, inc->st.st_size);
        else
  #endif
  	free ((PTR) inc->buffer);
--- 509,522 ----
      {
  #if MMAP_THRESHOLD
        if (inc->mapped)
! 	{
! 	  /* Undo the previous annotation for the
! 	     known-zero-byte-after-mmap.  Discard the handle to avoid
! 	     handle leak.  */
! 	  VALGRIND_DISCARD (VALGRIND_MAKE_NOACCESS (inc->buffer
! 						    + inc->st.st_size, 1));
! 	  munmap ((PTR) inc->buffer, inc->st.st_size);
! 	}
        else
  #endif
  	free ((PTR) inc->buffer);

brgds, H-P




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]