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, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 #ifndef __PRIV_ASPACEMGR_H
31 #define __PRIV_ASPACEMGR_H
33 /* One of the important design goals of the address space manager is
34 to minimise dependence on other modules. Hence the following
35 minimal set of imports. */
37 #include "pub_core_basics.h" // types
38 #include "pub_core_vkiscnums.h" // system call numbers
39 #include "pub_core_vki.h" // VKI_PAGE_SIZE, VKI_MREMAP_MAYMOVE,
40 // VKI_MREMAP_FIXED, vki_stat64
42 #include "pub_core_debuglog.h" // VG_(debugLog)
44 #include "pub_core_libcbase.h" // VG_(strlen), VG_(strcmp), VG_(strncpy)
46 // VG_PGROUNDDN, VG_PGROUNDUP
48 #include "pub_core_libcassert.h" // VG_(exit_now)
50 #include "pub_core_syscall.h" // VG_(do_syscallN)
51 // VG_(mk_SysRes_Error)
52 // VG_(mk_SysRes_Success)
54 #include "pub_core_options.h" // VG_(clo_sanity_level)
56 #if defined(VGO_freebsd)
57 #include "pub_core_libcproc.h" // VG_(sysctlbyname)
60 #include "pub_core_aspacemgr.h" // self
63 /* --------------- Implemented in aspacemgr-common.c ---------------*/
65 /* Simple assert-like, file I/O and syscall facilities, which avoid
66 dependence on m_libcassert, and hence on the entire module graph.
67 This is important since most of the system itself depends on
68 aspacem, so we have to do this to avoid a circular dependency. */
70 __attribute__ ((noreturn
))
71 extern void ML_(am_exit
) ( Int status
);
72 __attribute__ ((noreturn
))
73 extern void ML_(am_barf
) ( const HChar
* what
);
74 __attribute__ ((noreturn
))
75 extern void ML_(am_barf_toolow
) ( const HChar
* what
);
77 __attribute__ ((noreturn
))
78 extern void ML_(am_assert_fail
) ( const HChar
* expr
,
83 #define aspacem_assert(expr) \
84 ((void) (LIKELY(expr) ? (void)0 : \
85 (ML_(am_assert_fail)(#expr, \
87 __PRETTY_FUNCTION__))))
89 /* Dude, what's my process ID ? */
90 extern Int
ML_(am_getpid
)( void );
92 /* A simple, self-contained sprintf implementation. */
93 extern UInt
ML_(am_sprintf
) ( HChar
* buf
, const HChar
*format
, ... );
95 /* mmap et al wrappers */
96 /* wrapper for munmap */
97 extern SysRes
ML_(am_do_munmap_NO_NOTIFY
)(Addr start
, SizeT length
);
99 /* wrapper for the ghastly 'mremap' syscall */
100 extern SysRes
ML_(am_do_extend_mapping_NO_NOTIFY
)(
106 extern SysRes
ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY
)(
107 Addr old_addr
, Addr old_len
,
108 Addr new_addr
, Addr new_len
111 /* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared
114 extern SysRes
ML_(am_open
) ( const HChar
* pathname
, Int flags
, Int mode
);
115 extern void ML_(am_close
) ( Int fd
);
116 extern Int
ML_(am_read
) ( Int fd
, void* buf
, Int count
);
117 extern Int
ML_(am_readlink
) ( const HChar
* path
, HChar
* buf
, UInt bufsiz
);
118 extern Int
ML_(am_fcntl
) ( Int fd
, Int cmd
, Addr arg
);
120 /* Get the dev, inode and mode info for a file descriptor, if
121 possible. Returns True on success. */
123 Bool
ML_(am_get_fd_d_i_m
)( Int fd
,
125 /*OUT*/ULong
* ino
, /*OUT*/UInt
* mode
);
128 Bool
ML_(am_resolve_filename
) ( Int fd
, /*OUT*/HChar
* buf
, Int nbuf
);
130 /* ------ Implemented separately in aspacemgr-linux.c ------ */
132 /* Do a sanity check (/proc/self/maps sync check) */
133 extern void ML_(am_do_sanity_check
)( void );
136 /* ------ Implemented in aspacemgr-segnames.c ------ */
137 void ML_(am_segnames_init
)(void);
138 void ML_(am_show_segnames
)(Int logLevel
, const HChar
*prefix
);
140 /* Put NAME into the string table of segment names. Return index for
141 future reference. A return value of -1 indicates that the segment name
142 could not be stored. Basically an out-of-memory situation. */
143 Int
ML_(am_allocate_segname
)(const HChar
*name
);
145 /* Increment / decrement the reference counter for this segment name. */
146 void ML_(am_inc_refcount
)(Int
);
147 void ML_(am_dec_refcount
)(Int
);
149 /* Check whether the segname index is sane. */
150 Bool
ML_(am_sane_segname
)(Int fnIdx
);
152 /* Return the segment name for the given index. Maybe return NULL, if the
153 segment does not have a name. */
154 const HChar
*ML_(am_get_segname
)(Int fnIdx
);
156 /* Return the sequence number of the segment name */
157 Int
ML_(am_segname_get_seqnr
)(Int fnIdx
);
159 #endif // __PRIV_ASPACEMGR_H
161 /*--------------------------------------------------------------------*/
163 /*--------------------------------------------------------------------*/