From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17409 invoked by alias); 20 Nov 2002 19:57:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 17402 invoked from network); 20 Nov 2002 19:57:27 -0000 Received: from unknown (HELO dair.pair.com) (209.68.1.49) by sources.redhat.com with SMTP; 20 Nov 2002 19:57:27 -0000 Received: (qmail 93786 invoked by uid 20157); 20 Nov 2002 19:57:26 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 Nov 2002 19:57:26 -0000 Date: Wed, 20 Nov 2002 11:57:00 -0000 From: Hans-Peter Nilsson X-X-Sender: hp@dair.pair.com To: gcc-patches@gcc.gnu.org Subject: Re: [RFA:] Take 2 (was: Re: RFC: --enable-checking=valgrind.) In-Reply-To: <20021118203717.A3046@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-11/txt/msg01253.txt.bz2 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 + #else + /* Avoid #ifdef:s when we can help it. */ + #define VALGRIND_DISCARD(x) + #endif #ifdef HAVE_MMAP_FILE # include *************** 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