sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 3 | /*--- The address space manager. pub_core_aspacemgr.h ---*/ |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
| 10 | Copyright (C) 2000-2005 Julian Seward |
| 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_CORE_ASPACEMGR_H |
| 32 | #define __PUB_CORE_ASPACEMGR_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module deals with management of the entire process |
| 36 | // address space. Almost everything depends upon it, including dynamic |
| 37 | // memory management. Hence this module is almost completely |
| 38 | // standalone; the only module it uses is m_debuglog. DO NOT CHANGE |
| 39 | // THIS. |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 40 | // [XXX: actually, this is far from true...] |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 41 | //-------------------------------------------------------------------- |
| 42 | |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 43 | #include "pub_tool_aspacemgr.h" |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 44 | #include "pub_core_debuginfo.h" |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 45 | |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 46 | // Address space globals |
| 47 | extern Addr VG_(client_base); // client address space limits |
| 48 | extern Addr VG_(client_end); |
| 49 | extern Addr VG_(client_mapbase); // base of mappings |
| 50 | extern Addr VG_(clstk_base); // client stack range |
| 51 | extern Addr VG_(clstk_end); |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 52 | extern UWord VG_(clstk_id); // client stack id |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 53 | extern Addr VG_(client_trampoline_code); |
| 54 | |
| 55 | extern Addr VG_(brk_base); // start of brk |
| 56 | extern Addr VG_(brk_limit); // current brk |
| 57 | extern Addr VG_(shadow_base); // tool's shadow memory |
| 58 | extern Addr VG_(shadow_end); |
| 59 | extern Addr VG_(valgrind_base); // valgrind's address range |
| 60 | extern Addr VG_(valgrind_last); // Nb: last byte, rather than one past the end |
| 61 | |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 62 | /* A Segment is mapped piece of client memory. This covers all kinds |
| 63 | of mapped memory (exe, brk, mmap, .so, shm, stack, etc) |
| 64 | |
| 65 | We try to encode everything we know about a particular segment here. |
| 66 | */ |
| 67 | #define SF_FIXED (1 << 0) // client asked for MAP_FIXED |
| 68 | #define SF_SHARED (1 << 1) // shared |
| 69 | #define SF_SHM (1 << 2) // SYSV SHM (also SF_SHARED) |
| 70 | #define SF_MMAP (1 << 3) // mmap memory |
| 71 | #define SF_FILE (1 << 4) // mapping is backed by a file |
| 72 | #define SF_STACK (1 << 5) // is a stack |
| 73 | #define SF_GROWDOWN (1 << 6) // segment grows down |
| 74 | #define SF_GROWUP (1 << 7) // segment grows up |
| 75 | #define SF_EXEC (1 << 8) // segment created by exec |
| 76 | #define SF_DYNLIB (1 << 9) // mapped from dynamic library |
| 77 | #define SF_NOSYMS (1 << 10) // don't load syms, even if present |
| 78 | #define SF_BRK (1 << 11) // brk segment |
| 79 | #define SF_CORE (1 << 12) // allocated by core on behalf of the client |
| 80 | #define SF_VALGRIND (1 << 13) // a valgrind-internal mapping - not in client |
| 81 | #define SF_CODE (1 << 14) // segment contains cached code |
| 82 | #define SF_DEVICE (1 << 15) // device mapping; avoid careless touching |
| 83 | |
| 84 | struct _Segment { |
| 85 | UInt prot; // VKI_PROT_* |
| 86 | UInt flags; // SF_* |
| 87 | |
| 88 | Addr addr; // mapped addr (page aligned) |
| 89 | SizeT len; // size of mapping (page aligned) |
| 90 | |
| 91 | // These are valid if (flags & SF_FILE) |
| 92 | OffT offset; // file offset |
| 93 | const Char* filename; // filename (NULL if unknown) |
| 94 | Int fnIdx; // filename table index (-1 if unknown) |
| 95 | UInt dev; // device |
| 96 | UInt ino; // inode |
| 97 | |
njn | 36ef6ba | 2005-05-14 18:42:26 +0000 | [diff] [blame] | 98 | SegInfo* seginfo; // symbol table, etc |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | /* segment mapped from a file descriptor */ |
| 102 | extern void VG_(map_fd_segment) (Addr addr, SizeT len, UInt prot, UInt flags, |
| 103 | Int fd, ULong off, const Char *filename); |
| 104 | |
| 105 | /* segment mapped from a file */ |
| 106 | extern void VG_(map_file_segment)(Addr addr, SizeT len, UInt prot, UInt flags, |
| 107 | UInt dev, UInt ino, ULong off, const Char *filename); |
| 108 | |
| 109 | /* simple segment */ |
| 110 | extern void VG_(map_segment) (Addr addr, SizeT len, UInt prot, UInt flags); |
| 111 | |
| 112 | extern void VG_(unmap_range) (Addr addr, SizeT len); |
| 113 | extern void VG_(mprotect_range)(Addr addr, SizeT len, UInt prot); |
| 114 | extern Addr VG_(find_map_space)(Addr base, SizeT len, Bool for_client); |
| 115 | |
| 116 | /* Find the segment containing a, or NULL if none. */ |
| 117 | extern Segment *VG_(find_segment)(Addr a); |
| 118 | |
| 119 | /* a is an unmapped address (is checked). Find the next segment |
| 120 | along in the address space, or NULL if none. */ |
| 121 | extern Segment *VG_(find_segment_above_unmapped)(Addr a); |
| 122 | |
| 123 | /* a is a mapped address (in a segment, is checked). Find the |
| 124 | next segment along. */ |
| 125 | extern Segment *VG_(find_segment_above_mapped)(Addr a); |
| 126 | |
| 127 | extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size); |
| 128 | extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size); |
| 129 | |
| 130 | extern Segment *VG_(split_segment)(Addr a); |
| 131 | |
| 132 | extern void VG_(pad_address_space) (Addr start); |
| 133 | extern void VG_(unpad_address_space)(Addr start); |
| 134 | |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 135 | extern UWord VG_(handle_stack_register)(Addr start, Addr end); |
| 136 | extern void VG_(handle_stack_deregister)(UWord id); |
| 137 | extern void VG_(handle_stack_change)(UWord id, Addr start, Addr end); |
| 138 | |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 139 | extern VGA_REGPARM(2) |
| 140 | void VG_(unknown_SP_update) ( Addr old_SP, Addr new_SP ); |
| 141 | |
| 142 | ///* Search /proc/self/maps for changes which aren't reflected in the |
| 143 | // segment list */ |
| 144 | //extern void VG_(sync_segments)(UInt flags); |
| 145 | |
| 146 | /* Return string for prot */ |
| 147 | extern const HChar *VG_(prot_str)(UInt prot); |
| 148 | |
| 149 | extern Addr VG_(get_memory_from_mmap_for_client) |
| 150 | (Addr base, SizeT len, UInt prot, UInt flags); |
| 151 | |
| 152 | //extern void VG_(print_shadow_stats)(); |
| 153 | |
| 154 | /* Parses /proc/self/maps, calling `record_mapping' for each entry. */ |
| 155 | extern |
| 156 | void VG_(parse_procselfmaps) ( |
| 157 | void (*record_mapping)( Addr addr, SizeT len, UInt prot, |
| 158 | UInt dev, UInt ino, ULong foff, |
| 159 | const UChar *filename ) ); |
| 160 | |
njn | e3f0635 | 2005-06-01 03:48:33 +0000 | [diff] [blame] | 161 | // Pointercheck |
| 162 | extern Bool VGA_(setup_pointercheck) ( Addr client_base, Addr client_end ); |
| 163 | |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 164 | #endif // __PUB_CORE_ASPACEMGR_H |
| 165 | |
| 166 | /*--------------------------------------------------------------------*/ |
| 167 | /*--- end pub_core_aspacemgr.h ---*/ |
| 168 | /*--------------------------------------------------------------------*/ |