summaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorhp <hp@138bc75d-0d04-0410-961f-82ee72b054a4>2002-11-20 19:49:53 +0000
committerhp <hp@138bc75d-0d04-0410-961f-82ee72b054a4>2002-11-20 19:49:53 +0000
commit0fa54ff10f530f6de61a405566b2b61c423ef0d8 (patch)
tree9eafda11516ee784c63faf8b744d44153d2c5e6c /gcc/cppfiles.c
parent13de7ba99d7d3ecb0e658e7b1294016dfc14a1ff (diff)
downloadgcc-0fa54ff10f530f6de61a405566b2b61c423ef0d8.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59309 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index e7281c5d7a6..2e11912934a 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);