]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Create a new module: ASpaceMgr, the address space manager. This
authorJulian Seward <jseward@acm.org>
Mon, 25 Apr 2005 11:11:44 +0000 (11:11 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 25 Apr 2005 11:11:44 +0000 (11:11 +0000)
contains what was previously vg_memory.c and also vg_procselfmaps.c,
which is really just a helper for the address space manager.

This just moves code around and modularises it a bit.  It doesn't yet
resolve the circular dependencies between ASpaceMgr and various other
chunks of functionality (vg_malloc2, vg_symtab2).

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3564

18 files changed:
configure.in
coregrind/Makefile.am
coregrind/core.h
coregrind/linux/syscalls.c
coregrind/m_aspacemgr/Makefile.am [new file with mode: 0644]
coregrind/m_aspacemgr/aspacemgr.c [moved from coregrind/vg_memory.c with 99% similarity]
coregrind/m_aspacemgr/read_procselfmaps.c [moved from coregrind/vg_procselfmaps.c with 97% similarity]
coregrind/m_sigframe/sigframe-x86-linux.c
coregrind/pub_core_aspacemgr.h [new file with mode: 0644]
coregrind/vg_main.c
coregrind/vg_malloc2.c
coregrind/vg_mylibc.c
coregrind/vg_redir.c
coregrind/vg_signals.c
coregrind/vg_symtab2.c
coregrind/vg_syscalls.c
coregrind/vg_translate.c
coregrind/x86-linux/syscalls.c

index 7075f77ed8ea9fb07186017221e550a126a4d162..575c554e3a2d9d51c95eb1ce40e5a20df48a943c 100644 (file)
@@ -395,6 +395,7 @@ AC_OUTPUT(
    coregrind/Makefile 
    coregrind/demangle/Makefile 
    coregrind/m_sigframe/Makefile 
+   coregrind/m_aspacemgr/Makefile 
    coregrind/amd64/Makefile
    coregrind/arm/Makefile
    coregrind/x86/Makefile
index aab971b70a94eafdb93d38f10d9029d8e30ec9ad..07839aa8239a78227e3d6c40c7323b05f703b890 100644 (file)
@@ -6,11 +6,11 @@ include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
 ## That's what DIST_SUBDIRS specifies.
 SUBDIRS = \
        $(VG_ARCH)     $(VG_OS)     $(VG_PLATFORM)     \
-       m_sigframe demangle .
+       m_sigframe m_aspacemgr demangle .
 
 DIST_SUBDIRS = \
        $(VG_ARCH_ALL) $(VG_OS_ALL) $(VG_PLATFORM_ALL) \
-       m_sigframe demangle .
+       m_sigframe m_aspacemgr demangle .
 
 AM_CPPFLAGS += -DVG_LIBDIR="\"$(valdir)"\" -I$(srcdir)/demangle \
                -DKICKSTART_BASE=@KICKSTART_BASE@ \
@@ -37,6 +37,7 @@ noinst_HEADERS = \
        pub_core_stacktrace.h   \
        pub_core_sigframe.h     \
        pub_core_debuglog.h     \
+       pub_core_aspacemgr.h    \
        ume.h                   \
        vg_symtab2.h            \
        vg_symtypes.h           \
@@ -73,11 +74,9 @@ stage2_SOURCES = \
        vg_replace_malloc.c \
        vg_main.c \
        vg_malloc2.c \
-       vg_memory.c \
        vg_messages.c \
        vg_mylibc.c \
        vg_needs.c \
-       vg_procselfmaps.c \
        vg_dummy_profile.c \
        vg_signals.c \
        vg_symtab2.c \
@@ -97,6 +96,7 @@ stage2_SOURCES = \
 stage2_extra= \
        demangle/libdemangle.a \
        m_sigframe/libsigframe.a \
+       m_aspacemgr/libaspacemgr.a \
        ${VG_PLATFORM}/libplatform.a \
        ${VG_ARCH}/libarch.a \
        ${VG_OS}/libos.a \
index 9b825f664f21a00a9dd30a21e939a537bf1caa15..84ee3cb56b98318bbc03ba2f2390e9fc2f6ed139 100644 (file)
@@ -861,18 +861,6 @@ Bool VG_(translate) ( ThreadId tid,
                       Bool     debugging_translation,
                       Int      debugging_verbosity );
 
-/* ---------------------------------------------------------------------
-   Exports of vg_procselfmaps.c
-   ------------------------------------------------------------------ */
-
-/* Parses /proc/self/maps, calling `record_mapping' for each entry. */
-extern 
-void VG_(parse_procselfmaps) (
-   void (*record_mapping)( Addr addr, SizeT len, UInt prot,
-                          UInt dev, UInt ino, ULong foff,
-                           const UChar *filename ) );
-
-
 /* ---------------------------------------------------------------------
    Exports of vg_symtab2.c
    ------------------------------------------------------------------ */
@@ -994,98 +982,6 @@ extern VexSubArch VG_(vex_subarch);
 extern ULong VG_(bbs_done);
 
 
-/* ---------------------------------------------------------------------
-   Exports of vg_memory.c
-   ------------------------------------------------------------------ */
-
-/* A Segment is mapped piece of client memory.  This covers all kinds
-   of mapped memory (exe, brk, mmap, .so, shm, stack, etc)
-
-   We try to encode everything we know about a particular segment here.
-*/
-#define SF_FIXED    (1 <<  0) // client asked for MAP_FIXED
-#define SF_SHARED   (1 <<  1) // shared
-#define SF_SHM      (1 <<  2) // SYSV SHM (also SF_SHARED)
-#define SF_MMAP     (1 <<  3) // mmap memory
-#define SF_FILE     (1 <<  4) // mapping is backed by a file
-#define SF_STACK    (1 <<  5) // is a stack
-#define SF_GROWDOWN (1 <<  6) // segment grows down
-#define SF_GROWUP   (1 <<  7) // segment grows up
-#define SF_EXEC     (1 <<  8) // segment created by exec
-#define SF_DYNLIB   (1 <<  9) // mapped from dynamic library
-#define SF_NOSYMS   (1 << 10) // don't load syms, even if present
-#define SF_BRK      (1 << 11) // brk segment
-#define SF_CORE     (1 << 12) // allocated by core on behalf of the client
-#define SF_VALGRIND (1 << 13) // a valgrind-internal mapping - not in client
-#define SF_CODE     (1 << 14) // segment contains cached code
-#define SF_DEVICE   (1 << 15) // device mapping; avoid careless touching
-
-struct _Segment {
-   UInt         prot;         // VKI_PROT_*
-   UInt         flags;        // SF_*
-
-   Addr         addr;         // mapped addr (page aligned)
-   SizeT        len;          // size of mapping (page aligned)
-
-   // These are valid if (flags & SF_FILE)
-   OffT        offset;        // file offset
-   const Char* filename;      // filename (NULL if unknown)
-   Int         fnIdx;         // filename table index (-1 if unknown)
-   UInt        dev;           // device
-   UInt        ino;           // inode
-
-   SegInfo*    symtab;        // symbol table
-};
-
-/* segment mapped from a file descriptor */
-extern void VG_(map_fd_segment)  (Addr addr, SizeT len, UInt prot, UInt flags, 
-                                 Int fd, ULong off, const Char *filename);
-
-/* segment mapped from a file */
-extern void VG_(map_file_segment)(Addr addr, SizeT len, UInt prot, UInt flags, 
-                                 UInt dev, UInt ino, ULong off, const Char *filename);
-
-/* simple segment */
-extern void VG_(map_segment)     (Addr addr, SizeT len, UInt prot, UInt flags);
-
-extern void VG_(unmap_range)   (Addr addr, SizeT len);
-extern void VG_(mprotect_range)(Addr addr, SizeT len, UInt prot);
-extern Addr VG_(find_map_space)(Addr base, SizeT len, Bool for_client);
-
-/* Find the segment containing a, or NULL if none. */
-extern Segment *VG_(find_segment)(Addr a);
-
-/* a is an unmapped address (is checked).  Find the next segment 
-   along in the address space, or NULL if none. */
-extern Segment *VG_(find_segment_above_unmapped)(Addr a);
-
-/* a is a mapped address (in a segment, is checked).  Find the
-   next segment along. */
-extern Segment *VG_(find_segment_above_mapped)(Addr a);
-
-extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size);
-extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size);
-
-extern Segment *VG_(split_segment)(Addr a);
-
-extern void VG_(pad_address_space)  (Addr start);
-extern void VG_(unpad_address_space)(Addr start);
-
-extern VGA_REGPARM(2)
-       void VG_(unknown_SP_update) ( Addr old_SP, Addr new_SP );
-
-///* Search /proc/self/maps for changes which aren't reflected in the
-//   segment list */
-//extern void VG_(sync_segments)(UInt flags);
-
-/* Return string for prot */
-extern const HChar *VG_(prot_str)(UInt prot);
-
-extern Addr VG_(get_memory_from_mmap_for_client)
-               (Addr base, SizeT len, UInt prot, UInt flags);
-
-//extern void VG_(print_shadow_stats)();
-
 /* ---------------------------------------------------------------------
    Exports of vg_syscalls.c
    ------------------------------------------------------------------ */
index 98f63a063253aa704185c2ef4f6bc8ca220a07b6..0490967f8e3dc9aaad302e45f97a9f6fa0a21664 100644 (file)
@@ -29,6 +29,7 @@
 */
 
 #include "core.h"
+#include "pub_core_aspacemgr.h"
 
 /* ---------------------------------------------------------------------
    PRE/POST wrappers for arch-generic, Linux-specific syscalls
diff --git a/coregrind/m_aspacemgr/Makefile.am b/coregrind/m_aspacemgr/Makefile.am
new file mode 100644 (file)
index 0000000..d8a6626
--- /dev/null
@@ -0,0 +1,19 @@
+include $(top_srcdir)/Makefile.all.am
+include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
+
+AM_CFLAGS = $(WERROR) -Wmissing-prototypes -Winline -Wall -Wshadow -O -g
+
+EXTRA_DIST = \
+       README_ASPACEMGR.txt
+
+noinst_LIBRARIES = libaspacemgr.a
+
+libaspacemgr_a_SOURCES = \
+       read_procselfmaps.c \
+       aspacemgr.c
+
+if USE_PIE
+libaspacemgr_a_CFLAGS = $(AM_CFLAGS) -fpie
+else
+libaspacemgr_a_CFLAGS = $(AM_CFLAGS)
+endif
similarity index 99%
rename from coregrind/vg_memory.c
rename to coregrind/m_aspacemgr/aspacemgr.c
index eaaffb00094dd0f7bf46127ca74c7022d7880ca6..347fa770af5a08feb296cce4ab868757d3c7d9d6 100644 (file)
@@ -1,8 +1,8 @@
 
 /*--------------------------------------------------------------------*/
-/*--- Memory-related stuff: segment initialisation and tracking,   ---*/
-/*--- stack operations                                             ---*/
-/*---                                                  vg_memory.c ---*/
+/*--- The address space manager: segment initialisation and        ---*/
+/*--- tracking, stack operations                                   ---*/
+/*---                                                  aspacemgr.c ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -31,6 +31,8 @@
 */
 
 #include "core.h"
+#include "pub_core_aspacemgr.h"
+
 
 /* Define to debug the memory-leak-detector. */
 /* #define VG_DEBUG_LEAKCHECK */
@@ -1300,5 +1302,5 @@ void *VG_(shadow_alloc)(UInt size)
 }
 
 /*--------------------------------------------------------------------*/
-/*--- end                                              vg_memory.c ---*/
+/*--- end                                              aspacemgr.c ---*/
 /*--------------------------------------------------------------------*/
similarity index 97%
rename from coregrind/vg_procselfmaps.c
rename to coregrind/m_aspacemgr/read_procselfmaps.c
index e3ec68eedb18af3091b08da2f1df6d1471dbd4fa..4ab8421996f4505194334a9c5dba2a112938711e 100644 (file)
@@ -1,7 +1,7 @@
 
 /*--------------------------------------------------------------------*/
-/*--- A simple parser for /proc/self/maps on Linux 2.4.X           ---*/
-/*---                                            vg_procselfmaps.c ---*/
+/*--- A simple parser for /proc/self/maps on Linux 2.4.X/2.6.X     ---*/
+/*---                                          read_procselfmaps.c ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -31,6 +31,8 @@
 
 
 #include "core.h"
+#include "pub_core_aspacemgr.h"
+
 
 /* Size of a smallish table used to read /proc/self/map entries. */
 #define M_PROCMAP_BUF 50000
@@ -261,5 +263,5 @@ void VG_(parse_procselfmaps) (
 }
 
 /*--------------------------------------------------------------------*/
-/*--- end                                        vg_procselfmaps.c ---*/
+/*--- end                                      read_procselfmaps.c ---*/
 /*--------------------------------------------------------------------*/
index 07e00913b37e3f9d16d9e15df0eefe0fa3621044..b0c60a9a338091d1ae570b60d5da4c5bd3219c20 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "core.h"
 #include "pub_core_sigframe.h"
+#include "pub_core_aspacemgr.h" /* find_segment */
+
 
 #include "libvex_guest_x86.h"
 
diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h
new file mode 100644 (file)
index 0000000..0debc0d
--- /dev/null
@@ -0,0 +1,144 @@
+
+/*--------------------------------------------------------------------*/
+/*--- The address space manager.                                   ---*/
+/*---                                         pub_core_aspacemgr.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   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_ASPACEMGR_H
+#define __PUB_CORE_ASPACEMGR_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module deals with management of the entire process
+// address space.  Almost everything depends upon it, including dynamic
+// memory management.  Hence this module is almost completely
+// standalone; the only module it uses is m_debuglog.  DO NOT CHANGE
+// THIS.
+//--------------------------------------------------------------------
+
+/* #include "pub_tool_aspacemgr.h" */
+
+/* A Segment is mapped piece of client memory.  This covers all kinds
+   of mapped memory (exe, brk, mmap, .so, shm, stack, etc)
+
+   We try to encode everything we know about a particular segment here.
+*/
+#define SF_FIXED    (1 <<  0) // client asked for MAP_FIXED
+#define SF_SHARED   (1 <<  1) // shared
+#define SF_SHM      (1 <<  2) // SYSV SHM (also SF_SHARED)
+#define SF_MMAP     (1 <<  3) // mmap memory
+#define SF_FILE     (1 <<  4) // mapping is backed by a file
+#define SF_STACK    (1 <<  5) // is a stack
+#define SF_GROWDOWN (1 <<  6) // segment grows down
+#define SF_GROWUP   (1 <<  7) // segment grows up
+#define SF_EXEC     (1 <<  8) // segment created by exec
+#define SF_DYNLIB   (1 <<  9) // mapped from dynamic library
+#define SF_NOSYMS   (1 << 10) // don't load syms, even if present
+#define SF_BRK      (1 << 11) // brk segment
+#define SF_CORE     (1 << 12) // allocated by core on behalf of the client
+#define SF_VALGRIND (1 << 13) // a valgrind-internal mapping - not in client
+#define SF_CODE     (1 << 14) // segment contains cached code
+#define SF_DEVICE   (1 << 15) // device mapping; avoid careless touching
+
+struct _Segment {
+   UInt         prot;         // VKI_PROT_*
+   UInt         flags;        // SF_*
+
+   Addr         addr;         // mapped addr (page aligned)
+   SizeT        len;          // size of mapping (page aligned)
+
+   // These are valid if (flags & SF_FILE)
+   OffT        offset;        // file offset
+   const Char* filename;      // filename (NULL if unknown)
+   Int         fnIdx;         // filename table index (-1 if unknown)
+   UInt        dev;           // device
+   UInt        ino;           // inode
+
+   SegInfo*    symtab;        // symbol table
+};
+
+/* segment mapped from a file descriptor */
+extern void VG_(map_fd_segment)  (Addr addr, SizeT len, UInt prot, UInt flags, 
+                                 Int fd, ULong off, const Char *filename);
+
+/* segment mapped from a file */
+extern void VG_(map_file_segment)(Addr addr, SizeT len, UInt prot, UInt flags, 
+                                 UInt dev, UInt ino, ULong off, const Char *filename);
+
+/* simple segment */
+extern void VG_(map_segment)     (Addr addr, SizeT len, UInt prot, UInt flags);
+
+extern void VG_(unmap_range)   (Addr addr, SizeT len);
+extern void VG_(mprotect_range)(Addr addr, SizeT len, UInt prot);
+extern Addr VG_(find_map_space)(Addr base, SizeT len, Bool for_client);
+
+/* Find the segment containing a, or NULL if none. */
+extern Segment *VG_(find_segment)(Addr a);
+
+/* a is an unmapped address (is checked).  Find the next segment 
+   along in the address space, or NULL if none. */
+extern Segment *VG_(find_segment_above_unmapped)(Addr a);
+
+/* a is a mapped address (in a segment, is checked).  Find the
+   next segment along. */
+extern Segment *VG_(find_segment_above_mapped)(Addr a);
+
+extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size);
+extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size);
+
+extern Segment *VG_(split_segment)(Addr a);
+
+extern void VG_(pad_address_space)  (Addr start);
+extern void VG_(unpad_address_space)(Addr start);
+
+extern VGA_REGPARM(2)
+       void VG_(unknown_SP_update) ( Addr old_SP, Addr new_SP );
+
+///* Search /proc/self/maps for changes which aren't reflected in the
+//   segment list */
+//extern void VG_(sync_segments)(UInt flags);
+
+/* Return string for prot */
+extern const HChar *VG_(prot_str)(UInt prot);
+
+extern Addr VG_(get_memory_from_mmap_for_client)
+               (Addr base, SizeT len, UInt prot, UInt flags);
+
+//extern void VG_(print_shadow_stats)();
+
+/* Parses /proc/self/maps, calling `record_mapping' for each entry. */
+extern 
+void VG_(parse_procselfmaps) (
+   void (*record_mapping)( Addr addr, SizeT len, UInt prot,
+                          UInt dev, UInt ino, ULong foff,
+                           const UChar *filename ) );
+
+#endif   // __PUB_CORE_ASPACEMGR_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                     pub_core_aspacemgr.h ---*/
+/*--------------------------------------------------------------------*/
index 9a2e2ed8aab9d5ad691c6efbea0f9c6b6bf125ab..eaa5f69bf5b5de15bfbf212c7219cbdecfa51cd4 100644 (file)
@@ -35,6 +35,7 @@
 #include "pub_core_execontext.h"
 #include "pub_core_errormgr.h"
 #include "pub_core_debuglog.h"
+#include "pub_core_aspacemgr.h"
 
 #include <dirent.h>
 #include <dlfcn.h>
index 1af123de8447e61f37bb48fb5c169c011666e707..00e0ee421d0e840e4fcc4f5088ea34ffee91dea3 100644 (file)
@@ -31,6 +31,8 @@
 
 
 #include "core.h"
+#include "pub_core_aspacemgr.h"
+
 //zz#include "memcheck/memcheck.h"
 
 //#define DEBUG_MALLOC      // turn on heavyweight debugging machinery
index 4465f6d259815b34da64765911d5a094231adf6b..c5bfc7b450901a5cc895546913eadae7d753fb35 100644 (file)
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_stacktrace.h"
 #include "pub_core_debuglog.h"    /* VG_(debugLog_vprintf) */
+#include "pub_core_aspacemgr.h"
 
 
 /* ---------------------------------------------------------------------
index 0e7f1b3859ac8425c3b5dd6681f82e95948c0bb1..b1487d9e0606c6c3074446901fe1901dd641ab0b 100644 (file)
@@ -32,6 +32,8 @@
 #include "core.h"
 #include "vg_symtab2.h"
 
+#include "pub_core_aspacemgr.h"
+
 /*------------------------------------------------------------*/
 /*--- General purpose redirection.                         ---*/
 /*------------------------------------------------------------*/
index 1f0c64045e9315e52bd7a3f1d34e170c7deea342..8650b1f8f4c345a24ddb2040db2dff4f987056e8 100644 (file)
@@ -83,6 +83,7 @@
 
 #include "pub_core_errormgr.h"
 #include "pub_core_sigframe.h"
+#include "pub_core_aspacemgr.h"
 
 
 /* Define to give more sanity checking for signals. */
index 391688e207c5a2b37472bcb76c8f17686ab036b9..d6aa3281c8cbe09c2ec0d0de68ca86cfcade0ef6 100644 (file)
@@ -33,6 +33,8 @@
 #include "vg_symtypes.h"
 #include "vg_symtab2.h"
 
+#include "pub_core_aspacemgr.h"
+
 #include <elf.h>          /* ELF defns                      */
 
 static SegInfo* segInfo = NULL;
index 344ee6d61b9b532c2ac3c52e834252f00a2f5f37..de05e10bc86591b39403bbca46fb7a3400897530 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "core.h"
 #include "pub_core_stacktrace.h"
+#include "pub_core_aspacemgr.h"
+
 
 /* All system calls are channelled through here, doing two things:
 
index c236c30285efe195d5c3e523ca5b63bcb7c520de..b6c31ac7e4656f495b4f9cea7c2fc2d23a2442d5 100644 (file)
@@ -30,6 +30,7 @@
 */
 
 #include "core.h"
+#include "pub_core_aspacemgr.h"
 
 
 /*------------------------------------------------------------*/
index b2ee4aa827afcce41c842448a0f74bdff739910b..093a45ba893bd4f3c92fec6e84f3c40496a1d53a 100644 (file)
@@ -36,6 +36,8 @@
 #include "core.h"
 #include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_sigframe.h"
+#include "pub_core_aspacemgr.h"
+
 
 /* ---------------------------------------------------------------------
    Stacks, thread wrappers, clone