njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Address space manager. pub_tool_aspacemgr.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2013 Julian Seward |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 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 | |
njn | 4a164d0 | 2005-06-18 18:49:40 +0000 | [diff] [blame] | 31 | #ifndef __PUB_TOOL_ASPACEMGR_H |
| 32 | #define __PUB_TOOL_ASPACEMGR_H |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 33 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 34 | #include "pub_tool_basics.h" // VG_ macro |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 35 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 36 | //-------------------------------------------------------------- |
| 37 | // Definition of address-space segments |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 38 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 39 | /* Describes segment kinds. */ |
| 40 | typedef |
| 41 | enum { |
| 42 | SkFree, // unmapped space |
| 43 | SkAnonC, // anonymous mapping belonging to the client |
| 44 | SkAnonV, // anonymous mapping belonging to valgrind |
| 45 | SkFileC, // file mapping belonging to the client |
| 46 | SkFileV, // file mapping belonging to valgrind |
tom | 1340c35 | 2005-10-04 15:59:54 +0000 | [diff] [blame] | 47 | SkShmC, // shared memory segment belonging to the client |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 48 | SkResvn // reservation |
| 49 | } |
| 50 | SegKind; |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 51 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 52 | /* Describes how a reservation segment can be resized. */ |
| 53 | typedef |
| 54 | enum { |
| 55 | SmLower, // lower end can move up |
| 56 | SmFixed, // cannot be shrunk |
| 57 | SmUpper // upper end can move down |
| 58 | } |
| 59 | ShrinkMode; |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 60 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 61 | /* Describes a segment. Invariants: |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 62 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 63 | kind == SkFree: |
| 64 | // the only meaningful fields are .start and .end |
| 65 | |
| 66 | kind == SkAnon{C,V}: |
| 67 | // smode==SmFixed |
| 68 | // there's no associated file: |
| 69 | dev==ino==foff = 0, fnidx == -1 |
| 70 | // segment may have permissions |
| 71 | |
| 72 | kind == SkFile{C,V}: |
| 73 | // smode==SmFixed |
| 74 | moveLo == moveHi == NotMovable, maxlen == 0 |
| 75 | // there is an associated file |
| 76 | // segment may have permissions |
| 77 | |
tom | 1340c35 | 2005-10-04 15:59:54 +0000 | [diff] [blame] | 78 | kind == SkShmC: |
| 79 | // smode==SmFixed |
| 80 | // there's no associated file: |
| 81 | dev==ino==foff = 0, fnidx == -1 |
| 82 | // segment may have permissions |
| 83 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 84 | kind == SkResvn |
| 85 | // the segment may be resized if required |
| 86 | // there's no associated file: |
| 87 | dev==ino==foff = 0, fnidx == -1 |
| 88 | // segment has no permissions |
| 89 | hasR==hasW==hasX==anyTranslated == False |
| 90 | |
| 91 | Also: anyTranslated==True is only allowed in SkFileV and SkAnonV |
| 92 | (viz, not allowed to make translations from non-client areas) |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 93 | */ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 94 | typedef |
| 95 | struct { |
| 96 | SegKind kind; |
| 97 | /* Extent (SkFree, SkAnon{C,V}, SkFile{C,V}, SkResvn) */ |
| 98 | Addr start; // lowest address in range |
| 99 | Addr end; // highest address in range |
| 100 | /* Shrinkable? (SkResvn only) */ |
| 101 | ShrinkMode smode; |
| 102 | /* Associated file (SkFile{C,V} only) */ |
sewardj | 4190600 | 2008-08-18 21:47:11 +0000 | [diff] [blame] | 103 | ULong dev; |
| 104 | ULong ino; |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 105 | Off64T offset; |
sewardj | 4190600 | 2008-08-18 21:47:11 +0000 | [diff] [blame] | 106 | UInt mode; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 107 | Int fnIdx; // file name table index, if name is known |
| 108 | /* Permissions (SkAnon{C,V}, SkFile{C,V} only) */ |
| 109 | Bool hasR; |
| 110 | Bool hasW; |
| 111 | Bool hasX; |
| 112 | Bool hasT; // True --> translations have (or MAY have) |
| 113 | // been taken from this segment |
| 114 | Bool isCH; // True --> is client heap (SkAnonC ONLY) |
| 115 | /* Admin */ |
| 116 | Bool mark; |
| 117 | } |
| 118 | NSegment; |
| 119 | |
| 120 | |
| 121 | /* Collect up the start addresses of all non-free, non-resvn segments. |
| 122 | The interface is a bit strange in order to avoid potential |
| 123 | segment-creation races caused by dynamic allocation of the result |
| 124 | buffer *starts. |
| 125 | |
| 126 | The function first computes how many entries in the result |
| 127 | buffer *starts will be needed. If this number <= nStarts, |
| 128 | they are placed in starts[0..], and the number is returned. |
| 129 | If nStarts is not large enough, nothing is written to |
| 130 | starts[0..], and the negation of the size is returned. |
| 131 | |
| 132 | Correct use of this function may mean calling it multiple times in |
| 133 | order to establish a suitably-sized buffer. */ |
| 134 | extern Int VG_(am_get_segment_starts)( Addr* starts, Int nStarts ); |
| 135 | |
| 136 | |
| 137 | // See pub_core_aspacemgr.h for description. |
sewardj | fa2a246 | 2006-10-17 01:30:07 +0000 | [diff] [blame] | 138 | extern NSegment const * VG_(am_find_nsegment) ( Addr a ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 139 | |
| 140 | // See pub_core_aspacemgr.h for description. |
tom | 858a0ef | 2008-01-08 16:48:30 +0000 | [diff] [blame] | 141 | extern HChar* VG_(am_get_filename)( NSegment const * ); |
tom | bcaf047 | 2005-11-16 00:11:14 +0000 | [diff] [blame] | 142 | |
| 143 | // See pub_core_aspacemgr.h for description. |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 144 | extern Bool VG_(am_is_valid_for_client) ( Addr start, SizeT len, |
| 145 | UInt prot ); |
| 146 | |
| 147 | // See pub_core_aspacemgr.h for description. |
| 148 | /* Really just a wrapper around VG_(am_mmap_anon_float_valgrind). */ |
| 149 | extern void* VG_(am_shadow_alloc)(SizeT size); |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 150 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 151 | /* Unmap the given address range and update the segment array |
| 152 | accordingly. This fails if the range isn't valid for valgrind. */ |
| 153 | extern SysRes VG_(am_munmap_valgrind)( Addr start, SizeT length ); |
| 154 | |
njn | 4a164d0 | 2005-06-18 18:49:40 +0000 | [diff] [blame] | 155 | #endif // __PUB_TOOL_ASPACEMGR_H |
njn | 4802b38 | 2005-06-11 04:58:29 +0000 | [diff] [blame] | 156 | |
| 157 | /*--------------------------------------------------------------------*/ |
| 158 | /*--- end ---*/ |
| 159 | /*--------------------------------------------------------------------*/ |