2 /*--------------------------------------------------------------------*/
3 /*--- Address space manager. pub_tool_aspacemgr.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Julian Seward
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.
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.
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
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PUB_TOOL_ASPACEMGR_H
32 #define __PUB_TOOL_ASPACEMGR_H
34 #include "pub_tool_basics.h" // VG_ macro
36 //--------------------------------------------------------------
37 // Definition of address-space segments
39 /* Describes segment kinds. Enumerators are one-hot encoded so they
40 can be or'ed together. */
43 SkFree
= 0x01, // unmapped space
44 SkAnonC
= 0x02, // anonymous mapping belonging to the client
45 SkAnonV
= 0x04, // anonymous mapping belonging to valgrind
46 SkFileC
= 0x08, // file mapping belonging to the client
47 SkFileV
= 0x10, // file mapping belonging to valgrind
48 SkShmC
= 0x20, // shared memory segment belonging to the client
49 SkResvn
= 0x40 // reservation
53 /* Describes how a reservation segment can be resized. */
56 SmLower
, // lower end can move up
57 SmFixed
, // cannot be shrunk
58 SmUpper
// upper end can move down
62 /* Describes a segment. Invariants:
65 // the only meaningful fields are .start and .end
69 // there's no associated file:
70 dev==ino==foff = 0, fnidx == -1
71 // segment may have permissions
75 // there is an associated file
76 // segment may have permissions
80 // there's no associated file:
81 dev==ino==foff = 0, fnidx == -1
82 // segment may have permissions
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 == False
91 Also: hasT==True is only allowed in SkFileC, SkAnonC, and SkShmC
92 (viz, not allowed to make translations from non-client areas)
98 Addr start
; // lowest address in range
99 Addr end
; // highest address in range
100 /* Shrinkable? (SkResvn only) */
102 /* Associated file (SkFile{C,V} only) */
107 Int fnIdx
; // file name table index, if name is known
108 /* Permissions (SkAnon{C,V}, SkFile{C,V} only) */
112 Bool hasT
; // True --> translations have (or MAY have)
113 // been taken from this segment
114 Bool isCH
; // True --> is client heap (SkAnonC ONLY)
119 /* Collect up the start addresses of segments whose kind matches one of
120 the kinds specified in kind_mask.
121 The interface is a bit strange in order to avoid potential
122 segment-creation races caused by dynamic allocation of the result
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.
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
)( UInt kind_mask
, Addr
* starts
,
136 /* Finds the segment containing 'a'. Only returns file/anon/resvn
137 segments. This returns a 'NSegment const *' - a pointer to
139 extern NSegment
const * VG_(am_find_nsegment
) ( Addr a
);
141 /* Get the filename corresponding to this segment, if known and if it
142 has one. The function may return NULL if the file name is not known. */
143 extern const HChar
* VG_(am_get_filename
)( NSegment
const * );
145 /* Is the area [start .. start+len-1] validly accessible by the
146 client with at least the permissions 'prot' ? To find out
147 simply if said area merely belongs to the client, pass
148 VKI_PROT_NONE as 'prot'. Will return False if any part of the
149 area does not belong to the client or does not have at least
150 the stated permissions. */
151 extern Bool
VG_(am_is_valid_for_client
) ( Addr start
, SizeT len
,
154 /* Really just a wrapper around VG_(am_mmap_anon_float_valgrind). */
155 extern void* VG_(am_shadow_alloc
)(SizeT size
);
157 /* Unmap the given address range and update the segment array
158 accordingly. This fails if the range isn't valid for valgrind. */
159 extern SysRes
VG_(am_munmap_valgrind
)( Addr start
, SizeT length
);
161 #endif // __PUB_TOOL_ASPACEMGR_H
163 /*--------------------------------------------------------------------*/
165 /*--------------------------------------------------------------------*/