2 /*--------------------------------------------------------------------*/
3 /*--- Module-local header file for m_aspacemgr. ---*/
4 /*--- priv_aspacemgr.h ---*/
5 /*--------------------------------------------------------------------*/
8 This file is part of Valgrind, a dynamic binary instrumentation
11 Copyright (C) 2006-2017 OpenWorks LLP
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.
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.
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
29 The GNU General Public License is contained in the file COPYING.
32 #ifndef __PRIV_ASPACEMGR_H
33 #define __PRIV_ASPACEMGR_H
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. */
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
44 #include "pub_core_debuglog.h" // VG_(debugLog)
46 #include "pub_core_libcbase.h" // VG_(strlen), VG_(strcmp), VG_(strncpy)
48 // VG_PGROUNDDN, VG_PGROUNDUP
50 #include "pub_core_libcassert.h" // VG_(exit_now)
52 #include "pub_core_syscall.h" // VG_(do_syscallN)
53 // VG_(mk_SysRes_Error)
54 // VG_(mk_SysRes_Success)
56 #include "pub_core_options.h" // VG_(clo_sanity_level)
58 #include "pub_core_aspacemgr.h" // self
61 /* --------------- Implemented in aspacemgr-common.c ---------------*/
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. */
68 __attribute__ ((noreturn
))
69 extern void ML_(am_exit
) ( Int status
);
70 __attribute__ ((noreturn
))
71 extern void ML_(am_barf
) ( const HChar
* what
);
72 __attribute__ ((noreturn
))
73 extern void ML_(am_barf_toolow
) ( const HChar
* what
);
75 __attribute__ ((noreturn
))
76 extern void ML_(am_assert_fail
) ( const HChar
* expr
,
81 #define aspacem_assert(expr) \
82 ((void) (LIKELY(expr) ? 0 : \
83 (ML_(am_assert_fail)(#expr, \
85 __PRETTY_FUNCTION__))))
87 /* Dude, what's my process ID ? */
88 extern Int
ML_(am_getpid
)( void );
90 /* A simple, self-contained sprintf implementation. */
91 extern UInt
ML_(am_sprintf
) ( HChar
* buf
, const HChar
*format
, ... );
93 /* mmap et al wrappers */
94 /* wrapper for munmap */
95 extern SysRes
ML_(am_do_munmap_NO_NOTIFY
)(Addr start
, SizeT length
);
97 /* wrapper for the ghastly 'mremap' syscall */
98 extern SysRes
ML_(am_do_extend_mapping_NO_NOTIFY
)(
104 extern SysRes
ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY
)(
105 Addr old_addr
, Addr old_len
,
106 Addr new_addr
, Addr new_len
109 /* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared
112 extern SysRes
ML_(am_open
) ( const HChar
* pathname
, Int flags
, Int mode
);
113 extern void ML_(am_close
) ( Int fd
);
114 extern Int
ML_(am_read
) ( Int fd
, void* buf
, Int count
);
115 extern Int
ML_(am_readlink
) ( const HChar
* path
, HChar
* buf
, UInt bufsiz
);
116 extern Int
ML_(am_fcntl
) ( Int fd
, Int cmd
, Addr arg
);
118 /* Get the dev, inode and mode info for a file descriptor, if
119 possible. Returns True on success. */
121 Bool
ML_(am_get_fd_d_i_m
)( Int fd
,
123 /*OUT*/ULong
* ino
, /*OUT*/UInt
* mode
);
126 Bool
ML_(am_resolve_filename
) ( Int fd
, /*OUT*/HChar
* buf
, Int nbuf
);
128 /* ------ Implemented separately in aspacemgr-linux.c ------ */
130 /* Do a sanity check (/proc/self/maps sync check) */
131 extern void ML_(am_do_sanity_check
)( void );
134 /* ------ Implemented in aspacemgr-segnames.c ------ */
135 void ML_(am_segnames_init
)(void);
136 void ML_(am_show_segnames
)(Int logLevel
, const HChar
*prefix
);
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. */
141 Int
ML_(am_allocate_segname
)(const HChar
*name
);
143 /* Increment / decrement the reference counter for this segment name. */
144 void ML_(am_inc_refcount
)(Int
);
145 void ML_(am_dec_refcount
)(Int
);
147 /* Check whether the segname index is sane. */
148 Bool
ML_(am_sane_segname
)(Int fnIdx
);
150 /* Return the segment name for the given index. Maybe return NULL, if the
151 segment does not have a name. */
152 const HChar
*ML_(am_get_segname
)(Int fnIdx
);
154 /* Return the sequence number of the segment name */
155 Int
ML_(am_segname_get_seqnr
)(Int fnIdx
);
157 #endif // __PRIV_ASPACEMGR_H
159 /*--------------------------------------------------------------------*/
161 /*--------------------------------------------------------------------*/