|
From: Nicholas N. <nj...@ca...> - 2003-12-02 14:57:43
|
CVS commit by nethercote:
Tools using shadow memory can't handle the first 64KB being mapped, because
they rely on this area being unmapped for their quick sanity check. This
commit make Valgrind refuse to mmap() this area. Added a regtest for it.
A memcheck/tests/zeropage.c 1.1 [POSSIBLY UNSAFE: printf] [no copyright]
A memcheck/tests/zeropage.stderr.exp 1.1
A memcheck/tests/zeropage.vgtest 1.1
M +12 -0 coregrind/vg_syscalls.c 1.62
M +4 -2 memcheck/tests/Makefile.am 1.30
--- valgrind/coregrind/vg_syscalls.c #1.61:1.62
@@ -3205,4 +3205,12 @@ PRE(mkdir)
}
+void check_mmap_start(ThreadState* tst, Addr start, Int flags)
+{
+ /* Refuse to mmap the first 64KB of memory, so that the cheap sanity test
+ for tools using shadow memory works. */
+ if (start < 65536 && (flags & VKI_MAP_FIXED))
+ tst->m_eax = -VKI_EINVAL;
+}
+
PRE(mmap2)
{
@@ -3215,4 +3223,6 @@ PRE(mmap2)
MAYBE_PRINTF("mmap2 ( %p, %d, %d, %d, %d, %d )\n",
arg1, arg2, arg3, arg4, arg5, arg6 );
+
+ check_mmap_start(tst, arg1, arg4);
}
@@ -3241,4 +3251,6 @@ PRE(mmap)
MAYBE_PRINTF("mmap ( %p, %d, %d, %d, %d, %d )\n",
a1, a2, a3, a4, a5, a6 );
+
+ check_mmap_start(tst, a1, a4);
}
--- valgrind/memcheck/tests/Makefile.am #1.29:1.30
@@ -63,5 +63,6 @@
threadederrno.stderr.exp threadederrno.stdout.exp \
threadederrno.vgtest \
- writev.stderr.exp writev.vgtest
+ writev.stderr.exp writev.vgtest \
+ zeropage.stderr.exp zeropage.vgtest
check_PROGRAMS = \
@@ -74,5 +75,5 @@
realloc1 realloc2 realloc3 sigaltstack signal2 supp1 supp2 suppfree \
trivialleak tronical weirdioctl \
- mismatches new_override metadata threadederrno writev
+ mismatches new_override metadata threadederrno writev zeropage
AM_CPPFLAGS = -I$(top_srcdir)/include
@@ -126,4 +127,5 @@
threadederrno_LDADD = -lpthread
writev_SOURCES = writev.c
+zeropage_SOURCES = zeropage.c
# C++ ones
|