priv_aspacemgr.h revision 4d474d086188fd1f29fa97dbd84d8ea2e589a9b8
1
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
11   Copyright (C) 2006-2008 OpenWorks LLP
12      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
46#include "pub_core_libcbase.h"   // VG_(strlen), VG_(strcmp)
47                                 // VG_IS_PAGE_ALIGNED
48                                 // VG_PGROUNDDN, VG_PGROUNDUP
49
50#include "pub_core_syscall.h"    // VG_(do_syscallN)
51                                 // VG_(mk_SysRes_Error)
52                                 // VG_(mk_SysRes_Success)
53
54#include "pub_core_options.h"    // VG_(clo_sanity_level)
55
56#include "pub_core_aspacemgr.h"  // self
57
58
59/* --------------- Implemented in aspacemgr-common.c ---------------*/
60
61/* Simple assert-like, file I/O and syscall facilities, which avoid
62   dependence on m_libcassert, and hence on the entire module graph.
63   This is important since most of the system itself depends on
64   aspacem, so we have to do this to avoid a circular dependency. */
65
66extern void   ML_(am_exit) ( Int status );
67extern void   ML_(am_barf) ( HChar* what );
68extern void   ML_(am_barf_toolow) ( HChar* what );
69
70extern void   ML_(am_assert_fail) ( const HChar* expr,
71                                    const Char* file,
72                                    Int line,
73                                    const Char* fn );
74
75#define aspacem_assert(expr)                              \
76  ((void) ((expr) ? 0 :                                   \
77           (ML_(am_assert_fail)(#expr,                    \
78                                __FILE__, __LINE__,       \
79                                __PRETTY_FUNCTION__))))
80
81/* Dude, what's my process ID ? */
82extern Int    ML_(am_getpid)( void );
83
84/* A simple, self-contained sprintf implementation. */
85extern UInt   ML_(am_sprintf) ( HChar* buf, const HChar *format, ... );
86
87/* mmap et al wrappers */
88/* wrapper for munmap */
89extern SysRes ML_(am_do_munmap_NO_NOTIFY)(Addr start, SizeT length);
90
91/* wrapper for the ghastly 'mremap' syscall */
92extern SysRes ML_(am_do_extend_mapping_NO_NOTIFY)(
93                 Addr  old_addr,
94                 SizeT old_len,
95                 SizeT new_len
96              );
97/* ditto */
98extern SysRes ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY)(
99                 Addr old_addr, Addr old_len,
100                 Addr new_addr, Addr new_len
101              );
102
103/* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared
104   here (obviously). */
105
106extern SysRes ML_(am_open)  ( const Char* pathname, Int flags, Int mode );
107extern void   ML_(am_close) ( Int fd );
108extern Int    ML_(am_read)  ( Int fd, void* buf, Int count);
109extern Int    ML_(am_readlink) ( HChar* path, HChar* buf, UInt bufsiz );
110
111/* Get the dev, inode and mode info for a file descriptor, if
112   possible.  Returns True on success. */
113extern
114Bool ML_(am_get_fd_d_i_m)( Int fd,
115                                /*OUT*/UWord* dev,
116                                /*OUT*/UWord* ino, /*OUT*/UInt* mode );
117
118/* ------ Implemented seperately in aspacemgr-{linux,aix5}.c ------ */
119
120/* Do a sanity check (/proc/self/maps sync check) */
121extern void ML_(am_do_sanity_check)( void );
122
123
124#endif   // __PRIV_ASPACEMGR_H
125
126/*--------------------------------------------------------------------*/
127/*--- end                                                          ---*/
128/*--------------------------------------------------------------------*/
129