blob: 1c01eceb599d2e2b04d551359d277115df6ca0b9 [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.
40//--------------------------------------------------------------------
41
42/* #include "pub_tool_aspacemgr.h" */
43
44/* A Segment is mapped piece of client memory. This covers all kinds
45 of mapped memory (exe, brk, mmap, .so, shm, stack, etc)
46
47 We try to encode everything we know about a particular segment here.
48*/
49#define SF_FIXED (1 << 0) // client asked for MAP_FIXED
50#define SF_SHARED (1 << 1) // shared
51#define SF_SHM (1 << 2) // SYSV SHM (also SF_SHARED)
52#define SF_MMAP (1 << 3) // mmap memory
53#define SF_FILE (1 << 4) // mapping is backed by a file
54#define SF_STACK (1 << 5) // is a stack
55#define SF_GROWDOWN (1 << 6) // segment grows down
56#define SF_GROWUP (1 << 7) // segment grows up
57#define SF_EXEC (1 << 8) // segment created by exec
58#define SF_DYNLIB (1 << 9) // mapped from dynamic library
59#define SF_NOSYMS (1 << 10) // don't load syms, even if present
60#define SF_BRK (1 << 11) // brk segment
61#define SF_CORE (1 << 12) // allocated by core on behalf of the client
62#define SF_VALGRIND (1 << 13) // a valgrind-internal mapping - not in client
63#define SF_CODE (1 << 14) // segment contains cached code
64#define SF_DEVICE (1 << 15) // device mapping; avoid careless touching
65
66struct _Segment {
67 UInt prot; // VKI_PROT_*
68 UInt flags; // SF_*
69
70 Addr addr; // mapped addr (page aligned)
71 SizeT len; // size of mapping (page aligned)
72
73 // These are valid if (flags & SF_FILE)
74 OffT offset; // file offset
75 const Char* filename; // filename (NULL if unknown)
76 Int fnIdx; // filename table index (-1 if unknown)
77 UInt dev; // device
78 UInt ino; // inode
79
80 SegInfo* symtab; // symbol table
81};
82
83/* segment mapped from a file descriptor */
84extern void VG_(map_fd_segment) (Addr addr, SizeT len, UInt prot, UInt flags,
85 Int fd, ULong off, const Char *filename);
86
87/* segment mapped from a file */
88extern void VG_(map_file_segment)(Addr addr, SizeT len, UInt prot, UInt flags,
89 UInt dev, UInt ino, ULong off, const Char *filename);
90
91/* simple segment */
92extern void VG_(map_segment) (Addr addr, SizeT len, UInt prot, UInt flags);
93
94extern void VG_(unmap_range) (Addr addr, SizeT len);
95extern void VG_(mprotect_range)(Addr addr, SizeT len, UInt prot);
96extern Addr VG_(find_map_space)(Addr base, SizeT len, Bool for_client);
97
98/* Find the segment containing a, or NULL if none. */
99extern Segment *VG_(find_segment)(Addr a);
100
101/* a is an unmapped address (is checked). Find the next segment
102 along in the address space, or NULL if none. */
103extern Segment *VG_(find_segment_above_unmapped)(Addr a);
104
105/* a is a mapped address (in a segment, is checked). Find the
106 next segment along. */
107extern Segment *VG_(find_segment_above_mapped)(Addr a);
108
109extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size);
110extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size);
111
112extern Segment *VG_(split_segment)(Addr a);
113
114extern void VG_(pad_address_space) (Addr start);
115extern void VG_(unpad_address_space)(Addr start);
116
117extern VGA_REGPARM(2)
118 void VG_(unknown_SP_update) ( Addr old_SP, Addr new_SP );
119
120///* Search /proc/self/maps for changes which aren't reflected in the
121// segment list */
122//extern void VG_(sync_segments)(UInt flags);
123
124/* Return string for prot */
125extern const HChar *VG_(prot_str)(UInt prot);
126
127extern Addr VG_(get_memory_from_mmap_for_client)
128 (Addr base, SizeT len, UInt prot, UInt flags);
129
130//extern void VG_(print_shadow_stats)();
131
132/* Parses /proc/self/maps, calling `record_mapping' for each entry. */
133extern
134void VG_(parse_procselfmaps) (
135 void (*record_mapping)( Addr addr, SizeT len, UInt prot,
136 UInt dev, UInt ino, ULong foff,
137 const UChar *filename ) );
138
139#endif // __PUB_CORE_ASPACEMGR_H
140
141/*--------------------------------------------------------------------*/
142/*--- end pub_core_aspacemgr.h ---*/
143/*--------------------------------------------------------------------*/