diff options
author | Hans-Peter Nilsson <hp@bitrange.com> | 2002-11-20 19:49:53 +0000 |
---|---|---|
committer | Hans-Peter Nilsson <hp@gcc.gnu.org> | 2002-11-20 19:49:53 +0000 |
commit | 414d23ae18deaae675fe45cd997e71ede2f6af94 (patch) | |
tree | 9eafda11516ee784c63faf8b744d44153d2c5e6c /gcc/cppfiles.c | |
parent | 3ba2436a67f611be43fc02a1f400a69a95088695 (diff) | |
download | gcc-414d23ae18deaae675fe45cd997e71ede2f6af94.zip gcc-414d23ae18deaae675fe45cd997e71ede2f6af94.tar.gz gcc-414d23ae18deaae675fe45cd997e71ede2f6af94.tar.bz2 |
Makefile.in (RUN_GEN, [...]): New variables.
* Makefile.in (RUN_GEN, VALGRIND_DRIVER_DEFINES): New variables.
(DRIVER_DEFINES): Add $(VALGRIND_DRIVER_DEFINES).
(executing gencheck, genconfigs, genconditions, genflags,
gencodes, genconstants, genemit, genrecog, genopinit, genextract,
genpeep, genattr, genattrtab, genoutput, gengenrtl, genpreds,
gengtype, genprotos): Prepend $(RUN_GEN).
* configure.in: Move host compiler tests before --enable-checking
tests.
(--enable-checking=valgrind): New.
* config.in, configure: Regenerate.
* 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.
* gcc.c (execute) [ENABLE_VALGRIND_CHECKING]: Arrange to prepend
VALGRIND_PATH -q to each command.
From-SVN: r59309
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r-- | gcc/cppfiles.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c index e7281c5..2e11912 100644 --- a/gcc/cppfiles.c +++ b/gcc/cppfiles.c @@ -27,6 +27,12 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #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> @@ -417,6 +423,11 @@ read_include_file (pfile, inc) 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 @@ -497,7 +508,14 @@ purge_cache (inc) { #if MMAP_THRESHOLD if (inc->mapped) - munmap ((PTR) inc->buffer, inc->st.st_size); + { + /* 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); |