blob: 3968d76bbeb03048fe8a7ed5a9e6f0a8801074f7 [file] [log] [blame]
njn4802b382005-06-11 04:58:29 +00001
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
njn4a164d02005-06-18 18:49:40 +000031#ifndef __PUB_TOOL_ASPACEMGR_H
32#define __PUB_TOOL_ASPACEMGR_H
njn4802b382005-06-11 04:58:29 +000033
njn4802b382005-06-11 04:58:29 +000034
sewardj45f4e7c2005-09-27 19:20:21 +000035//--------------------------------------------------------------
36// Definition of address-space segments
njn4802b382005-06-11 04:58:29 +000037
sewardj45f4e7c2005-09-27 19:20:21 +000038/* Describes segment kinds. */
39typedef
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
tom1340c352005-10-04 15:59:54 +000046 SkShmC, // shared memory segment belonging to the client
sewardj45f4e7c2005-09-27 19:20:21 +000047 SkResvn // reservation
48 }
49 SegKind;
njn4802b382005-06-11 04:58:29 +000050
sewardj45f4e7c2005-09-27 19:20:21 +000051/* Describes how a reservation segment can be resized. */
52typedef
53 enum {
54 SmLower, // lower end can move up
55 SmFixed, // cannot be shrunk
56 SmUpper // upper end can move down
57 }
58 ShrinkMode;
njn4802b382005-06-11 04:58:29 +000059
sewardj45f4e7c2005-09-27 19:20:21 +000060/* Describes a segment. Invariants:
njn4802b382005-06-11 04:58:29 +000061
sewardj45f4e7c2005-09-27 19:20:21 +000062 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
tom1340c352005-10-04 15:59:54 +000077 kind == SkShmC:
78 // smode==SmFixed
79 // there's no associated file:
80 dev==ino==foff = 0, fnidx == -1
81 // segment may have permissions
82
sewardj45f4e7c2005-09-27 19:20:21 +000083 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)
njn6ace3ea2005-06-17 03:06:27 +000092*/
sewardj45f4e7c2005-09-27 19:20:21 +000093typedef
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;
tomf4c23102005-10-31 17:05:21 +0000104 UInt mode;
sewardj45f4e7c2005-09-27 19:20:21 +0000105 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. */
133extern Int VG_(am_get_segment_starts)( Addr* starts, Int nStarts );
134
135
136// See pub_core_aspacemgr.h for description.
137extern NSegment* VG_(am_find_nsegment) ( Addr a );
138
139// See pub_core_aspacemgr.h for description.
tombcaf0472005-11-16 00:11:14 +0000140extern HChar* VG_(am_get_filename)( NSegment* );
141
142// See pub_core_aspacemgr.h for description.
sewardj45f4e7c2005-09-27 19:20:21 +0000143extern 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). */
148extern void* VG_(am_shadow_alloc)(SizeT size);
njn4802b382005-06-11 04:58:29 +0000149
njn4a164d02005-06-18 18:49:40 +0000150#endif // __PUB_TOOL_ASPACEMGR_H
njn4802b382005-06-11 04:58:29 +0000151
152/*--------------------------------------------------------------------*/
153/*--- end ---*/
154/*--------------------------------------------------------------------*/