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-2012 Julian Seward 11 jseward (at) 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_TOOL_ASPACEMGR_H 32 #define __PUB_TOOL_ASPACEMGR_H 33 34 35 //-------------------------------------------------------------- 36 // Definition of address-space segments 37 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 46 SkShmC, // shared memory segment belonging to the client 47 SkResvn // reservation 48 } 49 SegKind; 50 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; 59 60 /* Describes a segment. Invariants: 61 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 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 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) 92 */ 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 ULong dev; 103 ULong ino; 104 Off64T offset; 105 UInt mode; 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 const * VG_(am_find_nsegment) ( Addr a ); 138 139 // See pub_core_aspacemgr.h for description. 140 extern HChar* VG_(am_get_filename)( NSegment const * ); 141 142 // See pub_core_aspacemgr.h for description. 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); 149 150 /* Unmap the given address range and update the segment array 151 accordingly. This fails if the range isn't valid for valgrind. */ 152 extern SysRes VG_(am_munmap_valgrind)( Addr start, SizeT length ); 153 154 #endif // __PUB_TOOL_ASPACEMGR_H 155 156 /*--------------------------------------------------------------------*/ 157 /*--- end ---*/ 158 /*--------------------------------------------------------------------*/ 159