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