blob: 4c39c29857efd1c18c3898cea7b9d963c0a19929 [file] [log] [blame]
sewardj55f9d1a2005-04-25 11:11:44 +00001
2/*--------------------------------------------------------------------*/
njn43b9a8a2005-05-10 04:37:01 +00003/*--- The address space manager. pub_core_aspacemgr.h ---*/
sewardj55f9d1a2005-04-25 11:11:44 +00004/*--------------------------------------------------------------------*/
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
31#ifndef __PUB_CORE_ASPACEMGR_H
32#define __PUB_CORE_ASPACEMGR_H
33
34//--------------------------------------------------------------------
35// PURPOSE: This module deals with management of the entire process
36// address space. Almost everything depends upon it, including dynamic
37// memory management. Hence this module is almost completely
38// standalone; the only module it uses is m_debuglog. DO NOT CHANGE
39// THIS.
njnea27e462005-05-31 02:38:09 +000040// [XXX: actually, this is far from true...]
sewardj55f9d1a2005-04-25 11:11:44 +000041//--------------------------------------------------------------------
42
njn4802b382005-06-11 04:58:29 +000043#include "pub_tool_aspacemgr.h"
njnea27e462005-05-31 02:38:09 +000044#include "pub_core_debuginfo.h"
sewardj55f9d1a2005-04-25 11:11:44 +000045
njn04e16982005-05-31 00:23:43 +000046// Address space globals
47extern Addr VG_(client_base); // client address space limits
48extern Addr VG_(client_end);
49extern Addr VG_(client_mapbase); // base of mappings
50extern Addr VG_(clstk_base); // client stack range
51extern Addr VG_(clstk_end);
rjwalsh0140af52005-06-04 20:42:33 +000052extern UWord VG_(clstk_id); // client stack id
njn04e16982005-05-31 00:23:43 +000053extern Addr VG_(client_trampoline_code);
54
55extern Addr VG_(brk_base); // start of brk
56extern Addr VG_(brk_limit); // current brk
57extern Addr VG_(shadow_base); // tool's shadow memory
58extern Addr VG_(shadow_end);
59extern Addr VG_(valgrind_base); // valgrind's address range
60extern Addr VG_(valgrind_last); // Nb: last byte, rather than one past the end
61
sewardj55f9d1a2005-04-25 11:11:44 +000062/* A Segment is mapped piece of client memory. This covers all kinds
63 of mapped memory (exe, brk, mmap, .so, shm, stack, etc)
64
65 We try to encode everything we know about a particular segment here.
66*/
67#define SF_FIXED (1 << 0) // client asked for MAP_FIXED
68#define SF_SHARED (1 << 1) // shared
69#define SF_SHM (1 << 2) // SYSV SHM (also SF_SHARED)
70#define SF_MMAP (1 << 3) // mmap memory
71#define SF_FILE (1 << 4) // mapping is backed by a file
72#define SF_STACK (1 << 5) // is a stack
73#define SF_GROWDOWN (1 << 6) // segment grows down
74#define SF_GROWUP (1 << 7) // segment grows up
75#define SF_EXEC (1 << 8) // segment created by exec
76#define SF_DYNLIB (1 << 9) // mapped from dynamic library
77#define SF_NOSYMS (1 << 10) // don't load syms, even if present
78#define SF_BRK (1 << 11) // brk segment
79#define SF_CORE (1 << 12) // allocated by core on behalf of the client
80#define SF_VALGRIND (1 << 13) // a valgrind-internal mapping - not in client
81#define SF_CODE (1 << 14) // segment contains cached code
82#define SF_DEVICE (1 << 15) // device mapping; avoid careless touching
83
84struct _Segment {
85 UInt prot; // VKI_PROT_*
86 UInt flags; // SF_*
87
88 Addr addr; // mapped addr (page aligned)
89 SizeT len; // size of mapping (page aligned)
90
91 // These are valid if (flags & SF_FILE)
92 OffT offset; // file offset
93 const Char* filename; // filename (NULL if unknown)
94 Int fnIdx; // filename table index (-1 if unknown)
95 UInt dev; // device
96 UInt ino; // inode
97
njn36ef6ba2005-05-14 18:42:26 +000098 SegInfo* seginfo; // symbol table, etc
sewardj55f9d1a2005-04-25 11:11:44 +000099};
100
101/* segment mapped from a file descriptor */
102extern void VG_(map_fd_segment) (Addr addr, SizeT len, UInt prot, UInt flags,
103 Int fd, ULong off, const Char *filename);
104
105/* segment mapped from a file */
106extern void VG_(map_file_segment)(Addr addr, SizeT len, UInt prot, UInt flags,
107 UInt dev, UInt ino, ULong off, const Char *filename);
108
109/* simple segment */
110extern void VG_(map_segment) (Addr addr, SizeT len, UInt prot, UInt flags);
111
112extern void VG_(unmap_range) (Addr addr, SizeT len);
113extern void VG_(mprotect_range)(Addr addr, SizeT len, UInt prot);
114extern Addr VG_(find_map_space)(Addr base, SizeT len, Bool for_client);
115
116/* Find the segment containing a, or NULL if none. */
117extern Segment *VG_(find_segment)(Addr a);
118
119/* a is an unmapped address (is checked). Find the next segment
120 along in the address space, or NULL if none. */
121extern Segment *VG_(find_segment_above_unmapped)(Addr a);
122
123/* a is a mapped address (in a segment, is checked). Find the
124 next segment along. */
125extern Segment *VG_(find_segment_above_mapped)(Addr a);
126
127extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size);
128extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size);
129
130extern Segment *VG_(split_segment)(Addr a);
131
132extern void VG_(pad_address_space) (Addr start);
133extern void VG_(unpad_address_space)(Addr start);
134
rjwalsh0140af52005-06-04 20:42:33 +0000135extern UWord VG_(handle_stack_register)(Addr start, Addr end);
136extern void VG_(handle_stack_deregister)(UWord id);
137extern void VG_(handle_stack_change)(UWord id, Addr start, Addr end);
138
sewardj55f9d1a2005-04-25 11:11:44 +0000139extern VGA_REGPARM(2)
140 void VG_(unknown_SP_update) ( Addr old_SP, Addr new_SP );
141
142///* Search /proc/self/maps for changes which aren't reflected in the
143// segment list */
144//extern void VG_(sync_segments)(UInt flags);
145
146/* Return string for prot */
147extern const HChar *VG_(prot_str)(UInt prot);
148
149extern Addr VG_(get_memory_from_mmap_for_client)
150 (Addr base, SizeT len, UInt prot, UInt flags);
151
152//extern void VG_(print_shadow_stats)();
153
154/* Parses /proc/self/maps, calling `record_mapping' for each entry. */
155extern
156void VG_(parse_procselfmaps) (
157 void (*record_mapping)( Addr addr, SizeT len, UInt prot,
158 UInt dev, UInt ino, ULong foff,
159 const UChar *filename ) );
160
njne3f06352005-06-01 03:48:33 +0000161// Pointercheck
162extern Bool VGA_(setup_pointercheck) ( Addr client_base, Addr client_end );
163
sewardj55f9d1a2005-04-25 11:11:44 +0000164#endif // __PUB_CORE_ASPACEMGR_H
165
166/*--------------------------------------------------------------------*/
167/*--- end pub_core_aspacemgr.h ---*/
168/*--------------------------------------------------------------------*/