|
From: <sv...@va...> - 2005-06-11 15:52:01
|
Author: njn
Date: 2005-06-11 16:51:30 +0100 (Sat, 11 Jun 2005)
New Revision: 3891
Log:
Modularised the libc low-level memory management stuff (mmap, etc).
Added:
trunk/coregrind/m_libcmman.c
trunk/coregrind/pub_core_libcmman.h
trunk/include/pub_tool_libcmman.h
Modified:
trunk/coregrind/Makefile.am
trunk/coregrind/core.h
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_debuginfo/symtab.c
trunk/coregrind/m_debuginfo/symtypes.c
trunk/coregrind/m_main.c
trunk/coregrind/m_mallocfree.c
trunk/coregrind/m_signals.c
trunk/coregrind/m_syscalls/syscalls-amd64-linux.c
trunk/coregrind/m_syscalls/syscalls-generic.c
trunk/coregrind/m_syscalls/syscalls-x86-linux.c
trunk/coregrind/m_transtab.c
trunk/coregrind/vg_mylibc.c
trunk/include/Makefile.am
trunk/include/tool.h
trunk/massif/ms_main.c
Modified: trunk/coregrind/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/Makefile.am 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/Makefile.am 2005-06-11 15:51:30 UTC (rev 3891)
@@ -49,6 +49,7 @@
pub_core_libcbase.h \
pub_core_libcassert.h \
pub_core_libcfile.h \
+ pub_core_libcmman.h \
pub_core_libcprint.h \
pub_core_libcsignal.h \
pub_core_main.h \
@@ -97,6 +98,7 @@
m_libcbase.c \
m_libcassert.c \
m_libcfile.c \
+ m_libcmman.c \
m_libcprint.c \
m_libcsignal.c \
m_main.c \
Modified: trunk/coregrind/core.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/core.h 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/core.h 2005-06-11 15:51:30 UTC (rev 3891)
@@ -126,16 +126,6 @@
extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout);
=20
-/* system/mman.h */
-extern void* VG_(mmap) ( void* start, SizeT length, UInt prot, UIn=
t flags,
- UInt sf_flags, UInt fd, OffT offset );
-extern SysRes VG_(mmap_native)( void* start, SizeT length, UInt prot, UI=
nt flags,
- UInt fd, OffT offset );
-extern Int VG_(munmap) ( void* start, SizeT length );
-extern Int VG_(mprotect) ( void *start, SizeT length, UInt prot );
-extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot );
-
-
/* Environment manipulations */
extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname,
const Char *val );
Modified: trunk/coregrind/m_aspacemgr/aspacemgr.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-11 10:47:27 UTC (rev =
3890)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-11 15:51:30 UTC (rev =
3891)
@@ -35,6 +35,7 @@
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h" // For VG_(fstat)()
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
@@ -1471,7 +1472,7 @@
{
static Addr shadow_alloc =3D 0;
Addr try_here;
- Int r;
+ SysRes r;
=20
if (0) show_segments("shadow_alloc(before)");
=20
@@ -1509,7 +1510,7 @@
r =3D VG_(mprotect_native)( (void*)try_here,=20
size, VKI_PROT_READ|VKI_PROT_WRITE );
=20
- if (r !=3D 0)
+ if (r.isError)
goto failed;
=20
shadow_alloc +=3D size;
Modified: trunk/coregrind/m_debuginfo/symtab.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_debuginfo/symtab.c 2005-06-11 10:47:27 UTC (rev 389=
0)
+++ trunk/coregrind/m_debuginfo/symtab.c 2005-06-11 15:51:30 UTC (rev 389=
1)
@@ -35,6 +35,7 @@
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
Modified: trunk/coregrind/m_debuginfo/symtypes.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_debuginfo/symtypes.c 2005-06-11 10:47:27 UTC (rev 3=
890)
+++ trunk/coregrind/m_debuginfo/symtypes.c 2005-06-11 15:51:30 UTC (rev 3=
891)
@@ -33,6 +33,7 @@
#include "pub_core_debuglog.h" /* VG_(debugLog_vprintf) */
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_mallocfree.h"
Added: trunk/coregrind/m_libcmman.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcmman.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/m_libcmman.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -0,0 +1,170 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Memory management libc stuff. m_libcmman.c ---*/
+/*--------------------------------------------------------------------*/
+=20
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward=20
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "core.h"
+#include "pub_core_aspacemgr.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
+#include "pub_core_libcprint.h"
+#include "vki_unistd.h"
+
+SysRes VG_(mmap_native)(void *start, SizeT length, UInt prot, UInt flags=
,
+ UInt fd, OffT offset)
+{
+ SysRes res;
+# if defined(VGP_x86_linux)
+ {=20
+ UWord args[6];
+ args[0] =3D (UWord)start;
+ args[1] =3D length;
+ args[2] =3D prot;
+ args[3] =3D flags;
+ args[4] =3D fd;
+ args[5] =3D offset;
+ res =3D VG_(do_syscall1)(__NR_mmap, (UWord)args );
+ }
+# elif defined(VGP_amd64_linux)
+ res =3D VG_(do_syscall6)(__NR_mmap, (UWord)start, length,=20
+ prot, flags, fd, offset);
+# else
+# error Unknown platform
+# endif
+ return res;
+}
+
+/* Returns -1 on failure. */
+void* VG_(mmap)( void* start, SizeT length,
+ UInt prot, UInt flags, UInt sf_flags, UInt fd, OffT off=
set)
+{
+ SysRes res;
+
+ if (!(flags & VKI_MAP_FIXED)) {
+ start =3D (void *)VG_(find_map_space)((Addr)start, length, !!(flag=
s & VKI_MAP_CLIENT));
+
+ flags |=3D VKI_MAP_FIXED;
+ }
+ if (start =3D=3D 0)
+ return (void *)-1;
+
+ res =3D VG_(mmap_native)(start, length, prot,=20
+ flags & ~(VKI_MAP_NOSYMS | VKI_MAP_CLIENT),
+ fd, offset);
+
+ // Check it ended up in the right place.
+ if (!res.isError) {
+ if (flags & VKI_MAP_CLIENT) {
+ vg_assert(VG_(client_base) <=3D res.val=20
+ && res.val+length <=3D VG_(client_end));
+ } else {
+ vg_assert(VG_(valgrind_base) <=3D res.val=20
+ && res.val+length-1 <=3D VG_(valgrind_last));
+ }
+
+ sf_flags |=3D SF_MMAP;
+ if ( flags & VKI_MAP_FIXED) sf_flags |=3D SF_FIXED;
+ if ( flags & VKI_MAP_SHARED) sf_flags |=3D SF_SHARED;
+ if (!(flags & VKI_MAP_ANONYMOUS)) sf_flags |=3D SF_FILE;
+ if (!(flags & VKI_MAP_CLIENT)) sf_flags |=3D SF_VALGRIND;
+ if ( flags & VKI_MAP_NOSYMS) sf_flags |=3D SF_NOSYMS;
+
+ VG_(map_fd_segment)(res.val, length, prot, sf_flags, fd, offset, N=
ULL);
+ }
+
+ return res.isError ? (void*)-1 : (void*)res.val;
+}
+
+static SysRes munmap_native(void *start, SizeT length)
+{
+ return VG_(do_syscall2)(__NR_munmap, (UWord)start, length );
+}
+
+/* Returns -1 on failure. */
+Int VG_(munmap)( void* start, SizeT length )
+{
+ SysRes res =3D munmap_native(start, length);
+ if (!res.isError) {
+ VG_(unmap_range)((Addr)start, length);
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+SysRes VG_(mprotect_native)( void *start, SizeT length, UInt prot )
+{
+ return VG_(do_syscall3)(__NR_mprotect, (UWord)start, length, prot );
+}
+
+Int VG_(mprotect)( void *start, SizeT length, UInt prot )
+{
+ SysRes res =3D VG_(mprotect_native)(start, length, prot);
+ if (!res.isError) {
+ VG_(mprotect_range)((Addr)start, length, prot);
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who )
+{
+ static SizeT tot_alloc =3D 0;
+ void* p;
+ p =3D VG_(mmap)(0, nBytes,
+ VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC,
+ VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS, 0, -1, 0);
+
+ if (p !=3D ((void*)(-1))) {
+ vg_assert((void*)VG_(valgrind_base) <=3D p && p <=3D (void*)VG_(va=
lgrind_last));
+ tot_alloc +=3D nBytes;
+ if (0)
+ VG_(printf)(
+ "get_memory_from_mmap: %llu tot, %llu req =3D %p .. %p, call=
er %s\n",
+ (ULong)tot_alloc, (ULong)nBytes, p, ((char*)p) + nBytes - 1,=
who );
+ return p;
+ }
+
+ VG_(printf)("\n");
+ VG_(printf)("VG_(get_memory_from_mmap): %s's request for %llu bytes f=
ailed.\n",
+ who, (ULong)nBytes);
+ VG_(printf)("VG_(get_memory_from_mmap): %llu bytes already allocated.=
\n",=20
+ (ULong)tot_alloc);
+ VG_(printf)("\n");
+ VG_(printf)("Sorry. You could try using a tool that uses less memory=
;\n");
+ VG_(printf)("eg. addrcheck instead of memcheck.\n");
+ VG_(printf)("\n");
+ VG_(exit)(1);
+}
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
Modified: trunk/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_main.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/m_main.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -39,6 +39,7 @@
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_main.h"
Modified: trunk/coregrind/m_mallocfree.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_mallocfree.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/m_mallocfree.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -34,6 +34,7 @@
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
Modified: trunk/coregrind/m_signals.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_signals.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/m_signals.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -85,6 +85,7 @@
#include "pub_core_errormgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_main.h"
Modified: trunk/coregrind/m_syscalls/syscalls-amd64-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-amd64-linux.c 2005-06-11 10:47:27=
UTC (rev 3890)
+++ trunk/coregrind/m_syscalls/syscalls-amd64-linux.c 2005-06-11 15:51:30=
UTC (rev 3891)
@@ -35,6 +35,7 @@
#include "pub_core_options.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_sigframe.h"
Modified: trunk/coregrind/m_syscalls/syscalls-generic.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-generic.c 2005-06-11 10:47:27 UTC=
(rev 3890)
+++ trunk/coregrind/m_syscalls/syscalls-generic.c 2005-06-11 15:51:30 UTC=
(rev 3891)
@@ -34,6 +34,7 @@
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_main.h"
Modified: trunk/coregrind/m_syscalls/syscalls-x86-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-x86-linux.c 2005-06-11 10:47:27 U=
TC (rev 3890)
+++ trunk/coregrind/m_syscalls/syscalls-x86-linux.c 2005-06-11 15:51:30 U=
TC (rev 3891)
@@ -40,6 +40,7 @@
#include "pub_core_options.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcsignal.h"
#include "pub_core_mallocfree.h"
Modified: trunk/coregrind/m_transtab.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_transtab.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/m_transtab.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -33,6 +33,7 @@
#include "pub_core_debuginfo.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_options.h"
#include "pub_core_tooliface.h"
Added: trunk/coregrind/pub_core_libcmman.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_libcmman.h 2005-06-11 10:47:27 UTC (rev 3890=
)
+++ trunk/coregrind/pub_core_libcmman.h 2005-06-11 15:51:30 UTC (rev 3891=
)
@@ -0,0 +1,54 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Memory management libc stuff. pub_core_libcmman.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_LIBCMMAN_H
+#define __PUB_CORE_LIBCMMAN_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains libc code related to low-level
+// memory management, ie. mmap and friends.
+//--------------------------------------------------------------------
+
+#include "pub_tool_libcmman.h"
+
+extern void* VG_(mmap) ( void* start, SizeT length, UInt prot, UInt fl=
ags,
+ UInt sf_flags, UInt fd, OffT offset );
+extern Int VG_(munmap) ( void* start, SizeT length );
+extern Int VG_(mprotect) ( void *start, SizeT length, UInt prot );
+
+extern SysRes VG_(mmap_native) ( void* start, SizeT length, UInt pro=
t,
+ UInt flags, UInt fd, OffT offset );
+extern SysRes VG_(mprotect_native) ( void *start, SizeT length, UInt pro=
t );
+
+#endif // __PUB_CORE_LIBCMMAN_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/vg_mylibc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_mylibc.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/coregrind/vg_mylibc.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -86,103 +86,9 @@
=20
=20
/* ---------------------------------------------------------------------
- mmap/munmap, exit, fcntl
+ exit, fcntl
------------------------------------------------------------------ */
=20
-SysRes VG_(mmap_native)(void *start, SizeT length, UInt prot, UInt flags=
,
- UInt fd, OffT offset)
-{
- SysRes res;
-# if defined(VGP_x86_linux)
- {=20
- UWord args[6];
- args[0] =3D (UWord)start;
- args[1] =3D length;
- args[2] =3D prot;
- args[3] =3D flags;
- args[4] =3D fd;
- args[5] =3D offset;
- res =3D VG_(do_syscall1)(__NR_mmap, (UWord)args );
- }
-# elif defined(VGP_amd64_linux)
- res =3D VG_(do_syscall6)(__NR_mmap, (UWord)start, length,=20
- prot, flags, fd, offset);
-# else
-# error Unknown platform
-# endif
- return res;
-}
-
-/* Returns -1 on failure. */
-void* VG_(mmap)( void* start, SizeT length,
- UInt prot, UInt flags, UInt sf_flags, UInt fd, OffT off=
set)
-{
- SysRes res;
-
- if (!(flags & VKI_MAP_FIXED)) {
- start =3D (void *)VG_(find_map_space)((Addr)start, length, !!(flag=
s & VKI_MAP_CLIENT));
-
- flags |=3D VKI_MAP_FIXED;
- }
- if (start =3D=3D 0)
- return (void *)-1;
-
- res =3D VG_(mmap_native)(start, length, prot,=20
- flags & ~(VKI_MAP_NOSYMS | VKI_MAP_CLIENT),
- fd, offset);
-
- // Check it ended up in the right place.
- if (!res.isError) {
- if (flags & VKI_MAP_CLIENT) {
- vg_assert(VG_(client_base) <=3D res.val=20
- && res.val+length <=3D VG_(client_end));
- } else {
- vg_assert(VG_(valgrind_base) <=3D res.val=20
- && res.val+length-1 <=3D VG_(valgrind_last));
- }
-
- sf_flags |=3D SF_MMAP;
- if ( flags & VKI_MAP_FIXED) sf_flags |=3D SF_FIXED;
- if ( flags & VKI_MAP_SHARED) sf_flags |=3D SF_SHARED;
- if (!(flags & VKI_MAP_ANONYMOUS)) sf_flags |=3D SF_FILE;
- if (!(flags & VKI_MAP_CLIENT)) sf_flags |=3D SF_VALGRIND;
- if ( flags & VKI_MAP_NOSYMS) sf_flags |=3D SF_NOSYMS;
-
- VG_(map_fd_segment)(res.val, length, prot, sf_flags, fd, offset, N=
ULL);
- }
-
- return res.isError ? (void*)-1 : (void*)res.val;
-}
-
-static Int munmap_native(void *start, SizeT length)
-{
- SysRes res =3D VG_(do_syscall2)(__NR_munmap, (UWord)start, length );
- return res.isError ? -1 : 0;
-}
-
-/* Returns -1 on failure. */
-Int VG_(munmap)( void* start, SizeT length )
-{
- Int res =3D munmap_native(start, length);
- if (0 =3D=3D res)
- VG_(unmap_range)((Addr)start, length);
- return res;
-}
-
-Int VG_(mprotect_native)( void *start, SizeT length, UInt prot )
-{
- SysRes res =3D VG_(do_syscall3)(__NR_mprotect, (UWord)start, length, =
prot );
- return res.isError ? -1 : 0;
-}
-
-Int VG_(mprotect)( void *start, SizeT length, UInt prot )
-{
- Int res =3D VG_(mprotect_native)(start, length, prot);
- if (0 =3D=3D res)
- VG_(mprotect_range)((Addr)start, length, prot);
- return res;
-}
-
/* Pull down the entire world */
void VG_(exit)( Int status )
{
@@ -524,40 +430,6 @@
}
=20
/* ---------------------------------------------------------------------
- Primitive support for bagging memory via mmap.
- ------------------------------------------------------------------ */
-
-void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who )
-{
- static SizeT tot_alloc =3D 0;
- void* p;
- p =3D VG_(mmap)(0, nBytes,
- VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC,
- VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS, 0, -1, 0);
-
- if (p !=3D ((void*)(-1))) {
- vg_assert((void*)VG_(valgrind_base) <=3D p && p <=3D (void*)VG_(va=
lgrind_last));
- tot_alloc +=3D nBytes;
- if (0)
- VG_(printf)(
- "get_memory_from_mmap: %llu tot, %llu req =3D %p .. %p, call=
er %s\n",
- (ULong)tot_alloc, (ULong)nBytes, p, ((char*)p) + nBytes - 1,=
who );
- return p;
- }
-
- VG_(printf)("\n");
- VG_(printf)("VG_(get_memory_from_mmap): %s's request for %llu bytes f=
ailed.\n",
- who, (ULong)nBytes);
- VG_(printf)("VG_(get_memory_from_mmap): %llu bytes already allocated.=
\n",=20
- (ULong)tot_alloc);
- VG_(printf)("\n");
- VG_(printf)("Sorry. You could try using a tool that uses less memory=
;\n");
- VG_(printf)("eg. addrcheck instead of memcheck.\n");
- VG_(printf)("\n");
- VG_(exit)(1);
-}
-
-/* ---------------------------------------------------------------------
Misc stuff looking for a proper home
------------------------------------------------------------------ */
=20
Modified: trunk/include/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/Makefile.am 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/include/Makefile.am 2005-06-11 15:51:30 UTC (rev 3891)
@@ -12,6 +12,7 @@
pub_tool_libcbase.h \
pub_tool_libcassert.h \
pub_tool_libcfile.h \
+ pub_tool_libcmman.h \
pub_tool_libcprint.h \
pub_tool_libcsignal.h \
pub_tool_mallocfree.h \
Added: trunk/include/pub_tool_libcmman.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/pub_tool_libcmman.h 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/include/pub_tool_libcmman.h 2005-06-11 15:51:30 UTC (rev 3891)
@@ -0,0 +1,41 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Memory management libc stuff. pub_tool_libcmman.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_LIBCMMAN_H
+#define __PUB_TOOL_LIBCMMAN_H
+
+/* Get memory by anonymous mmap. */
+extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
+
+#endif // __PUB_TOOL_LIBCMMAN_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
Modified: trunk/include/tool.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/tool.h 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/include/tool.h 2005-06-11 15:51:30 UTC (rev 3891)
@@ -137,9 +137,6 @@
extern Int VG_(setpgid) ( Int pid, Int pgrp );
=20
/* ------------------------------------------------------------------ */
-/* Get memory by anonymous mmap. */
-extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
-
/* Register an interest in apparently internal faults; used code which
wanders around dangerous memory (ie, leakcheck). The catcher is
not expected to return. */
Modified: trunk/massif/ms_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/massif/ms_main.c 2005-06-11 10:47:27 UTC (rev 3890)
+++ trunk/massif/ms_main.c 2005-06-11 15:51:30 UTC (rev 3891)
@@ -40,6 +40,7 @@
#include "pub_tool_libcbase.h"
#include "pub_tool_libcassert.h"
#include "pub_tool_libcfile.h"
+#include "pub_tool_libcmman.h"
#include "pub_tool_libcprint.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
|