blob: 174678b4f1f27e56d1429b49bc8ad63ecd0f257c [file] [log] [blame]
sewardj297f6b02006-10-14 22:25:30 +00001
2/*--------------------------------------------------------------------*/
3/*--- Module-local header file for m_aspacemgr. ---*/
4/*--- priv_aspacemgr.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
10
Elliott Hughesed398002017-06-21 14:41:24 -070011 Copyright (C) 2006-2017 OpenWorks LLP
sewardj297f6b02006-10-14 22:25:30 +000012 info@open-works.co.uk
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
32#ifndef __PRIV_ASPACEMGR_H
33#define __PRIV_ASPACEMGR_H
34
35/* One of the important design goals of the address space manager is
36 to minimise dependence on other modules. Hence the following
37 minimal set of imports. */
38
39#include "pub_core_basics.h" // types
40#include "pub_core_vkiscnums.h" // system call numbers
41#include "pub_core_vki.h" // VKI_PAGE_SIZE, VKI_MREMAP_MAYMOVE,
42 // VKI_MREMAP_FIXED, vki_stat64
43
44#include "pub_core_debuglog.h" // VG_(debugLog)
45
njndad944a2009-05-04 05:55:46 +000046#include "pub_core_libcbase.h" // VG_(strlen), VG_(strcmp), VG_(strncpy)
sewardj297f6b02006-10-14 22:25:30 +000047 // VG_IS_PAGE_ALIGNED
48 // VG_PGROUNDDN, VG_PGROUNDUP
49
florian421c26e2014-07-24 12:46:28 +000050#include "pub_core_libcassert.h" // VG_(exit_now)
51
sewardj297f6b02006-10-14 22:25:30 +000052#include "pub_core_syscall.h" // VG_(do_syscallN)
53 // VG_(mk_SysRes_Error)
54 // VG_(mk_SysRes_Success)
55
56#include "pub_core_options.h" // VG_(clo_sanity_level)
57
58#include "pub_core_aspacemgr.h" // self
59
60
61/* --------------- Implemented in aspacemgr-common.c ---------------*/
62
63/* Simple assert-like, file I/O and syscall facilities, which avoid
64 dependence on m_libcassert, and hence on the entire module graph.
65 This is important since most of the system itself depends on
66 aspacem, so we have to do this to avoid a circular dependency. */
67
njn4c245e52009-03-15 23:25:38 +000068__attribute__ ((noreturn))
sewardj297f6b02006-10-14 22:25:30 +000069extern void ML_(am_exit) ( Int status );
florian3c9f1862015-01-23 16:53:06 +000070__attribute__ ((noreturn))
floriandbb35842012-10-27 18:39:11 +000071extern void ML_(am_barf) ( const HChar* what );
florian3c9f1862015-01-23 16:53:06 +000072__attribute__ ((noreturn))
floriandbb35842012-10-27 18:39:11 +000073extern void ML_(am_barf_toolow) ( const HChar* what );
sewardj297f6b02006-10-14 22:25:30 +000074
njn4c245e52009-03-15 23:25:38 +000075__attribute__ ((noreturn))
sewardj297f6b02006-10-14 22:25:30 +000076extern void ML_(am_assert_fail) ( const HChar* expr,
floriandbb35842012-10-27 18:39:11 +000077 const HChar* file,
sewardj297f6b02006-10-14 22:25:30 +000078 Int line,
floriandbb35842012-10-27 18:39:11 +000079 const HChar* fn );
sewardj297f6b02006-10-14 22:25:30 +000080
81#define aspacem_assert(expr) \
florian8f9b0d22014-07-25 08:38:02 +000082 ((void) (LIKELY(expr) ? 0 : \
sewardj297f6b02006-10-14 22:25:30 +000083 (ML_(am_assert_fail)(#expr, \
84 __FILE__, __LINE__, \
85 __PRETTY_FUNCTION__))))
86
87/* Dude, what's my process ID ? */
88extern Int ML_(am_getpid)( void );
89
90/* A simple, self-contained sprintf implementation. */
91extern UInt ML_(am_sprintf) ( HChar* buf, const HChar *format, ... );
92
93/* mmap et al wrappers */
94/* wrapper for munmap */
95extern SysRes ML_(am_do_munmap_NO_NOTIFY)(Addr start, SizeT length);
96
97/* wrapper for the ghastly 'mremap' syscall */
98extern SysRes ML_(am_do_extend_mapping_NO_NOTIFY)(
99 Addr old_addr,
100 SizeT old_len,
101 SizeT new_len
102 );
103/* ditto */
104extern SysRes ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY)(
105 Addr old_addr, Addr old_len,
106 Addr new_addr, Addr new_len
107 );
108
109/* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared
110 here (obviously). */
111
floriandbb35842012-10-27 18:39:11 +0000112extern SysRes ML_(am_open) ( const HChar* pathname, Int flags, Int mode );
sewardj297f6b02006-10-14 22:25:30 +0000113extern void ML_(am_close) ( Int fd );
114extern Int ML_(am_read) ( Int fd, void* buf, Int count);
florian32971242014-10-23 17:47:15 +0000115extern Int ML_(am_readlink) ( const HChar* path, HChar* buf, UInt bufsiz );
njndad944a2009-05-04 05:55:46 +0000116extern Int ML_(am_fcntl) ( Int fd, Int cmd, Addr arg );
sewardj297f6b02006-10-14 22:25:30 +0000117
118/* Get the dev, inode and mode info for a file descriptor, if
119 possible. Returns True on success. */
120extern
121Bool ML_(am_get_fd_d_i_m)( Int fd,
njndad944a2009-05-04 05:55:46 +0000122 /*OUT*/ULong* dev,
123 /*OUT*/ULong* ino, /*OUT*/UInt* mode );
124
125extern
126Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf );
sewardj297f6b02006-10-14 22:25:30 +0000127
sewardj6e9de462011-06-28 07:25:29 +0000128/* ------ Implemented separately in aspacemgr-linux.c ------ */
sewardj297f6b02006-10-14 22:25:30 +0000129
130/* Do a sanity check (/proc/self/maps sync check) */
131extern void ML_(am_do_sanity_check)( void );
132
133
florian346ee2f2015-04-06 21:34:30 +0000134/* ------ Implemented in aspacemgr-segnames.c ------ */
florian4ecd4832015-04-30 17:34:04 +0000135void ML_(am_segnames_init)(void);
136void ML_(am_show_segnames)(Int logLevel, const HChar *prefix);
florian346ee2f2015-04-06 21:34:30 +0000137
138/* Put NAME into the string table of segment names. Return index for
139 future reference. A return value of -1 indicates that the segment name
140 could not be stored. Basically an out-of-memory situation. */
florian4ecd4832015-04-30 17:34:04 +0000141Int ML_(am_allocate_segname)(const HChar *name);
florian346ee2f2015-04-06 21:34:30 +0000142
143/* Increment / decrement the reference counter for this segment name. */
florian4ecd4832015-04-30 17:34:04 +0000144void ML_(am_inc_refcount)(Int);
145void ML_(am_dec_refcount)(Int);
florian346ee2f2015-04-06 21:34:30 +0000146
147/* Check whether the segname index is sane. */
florian4ecd4832015-04-30 17:34:04 +0000148Bool ML_(am_sane_segname)(Int fnIdx);
florian346ee2f2015-04-06 21:34:30 +0000149
150/* Return the segment name for the given index. Maybe return NULL, if the
151 segment does not have a name. */
florian4ecd4832015-04-30 17:34:04 +0000152const HChar *ML_(am_get_segname)(Int fnIdx);
florian346ee2f2015-04-06 21:34:30 +0000153
154/* Return the sequence number of the segment name */
florian4ecd4832015-04-30 17:34:04 +0000155Int ML_(am_segname_get_seqnr)(Int fnIdx);
florian346ee2f2015-04-06 21:34:30 +0000156
sewardj297f6b02006-10-14 22:25:30 +0000157#endif // __PRIV_ASPACEMGR_H
158
159/*--------------------------------------------------------------------*/
160/*--- end ---*/
161/*--------------------------------------------------------------------*/