drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / coregrind / m_aspacemgr / priv_aspacemgr.h
blobfbc46aca7b9dfafd3856e8bd949f8633af5f97c4
2 /*--------------------------------------------------------------------*/
3 /*--- Module-local header file for m_aspacemgr. ---*/
4 /*--- priv_aspacemgr.h ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2006-2017 OpenWorks LLP
12 info@open-works.co.uk
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)
45 // VG_IS_PAGE_ALIGNED
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 #include "pub_core_aspacemgr.h" // self
59 /* --------------- Implemented in aspacemgr-common.c ---------------*/
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. */
66 __attribute__ ((noreturn))
67 extern void ML_(am_exit) ( Int status );
68 __attribute__ ((noreturn))
69 extern void ML_(am_barf) ( const HChar* what );
70 __attribute__ ((noreturn))
71 extern void ML_(am_barf_toolow) ( const HChar* what );
73 __attribute__ ((noreturn))
74 extern void ML_(am_assert_fail) ( const HChar* expr,
75 const HChar* file,
76 Int line,
77 const HChar* fn );
79 #define aspacem_assert(expr) \
80 ((void) (LIKELY(expr) ? 0 : \
81 (ML_(am_assert_fail)(#expr, \
82 __FILE__, __LINE__, \
83 __PRETTY_FUNCTION__))))
85 /* Dude, what's my process ID ? */
86 extern Int ML_(am_getpid)( void );
88 /* A simple, self-contained sprintf implementation. */
89 extern UInt ML_(am_sprintf) ( HChar* buf, const HChar *format, ... );
91 /* mmap et al wrappers */
92 /* wrapper for munmap */
93 extern SysRes ML_(am_do_munmap_NO_NOTIFY)(Addr start, SizeT length);
95 /* wrapper for the ghastly 'mremap' syscall */
96 extern SysRes ML_(am_do_extend_mapping_NO_NOTIFY)(
97 Addr old_addr,
98 SizeT old_len,
99 SizeT new_len
101 /* ditto */
102 extern SysRes ML_(am_do_relocate_nooverlap_mapping_NO_NOTIFY)(
103 Addr old_addr, Addr old_len,
104 Addr new_addr, Addr new_len
107 /* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared
108 here (obviously). */
110 extern SysRes ML_(am_open) ( const HChar* pathname, Int flags, Int mode );
111 extern void ML_(am_close) ( Int fd );
112 extern Int ML_(am_read) ( Int fd, void* buf, Int count);
113 extern Int ML_(am_readlink) ( const HChar* path, HChar* buf, UInt bufsiz );
114 extern Int ML_(am_fcntl) ( Int fd, Int cmd, Addr arg );
116 /* Get the dev, inode and mode info for a file descriptor, if
117 possible. Returns True on success. */
118 extern
119 Bool ML_(am_get_fd_d_i_m)( Int fd,
120 /*OUT*/ULong* dev,
121 /*OUT*/ULong* ino, /*OUT*/UInt* mode );
123 extern
124 Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf );
126 /* ------ Implemented separately in aspacemgr-linux.c ------ */
128 /* Do a sanity check (/proc/self/maps sync check) */
129 extern void ML_(am_do_sanity_check)( void );
132 /* ------ Implemented in aspacemgr-segnames.c ------ */
133 void ML_(am_segnames_init)(void);
134 void ML_(am_show_segnames)(Int logLevel, const HChar *prefix);
136 /* Put NAME into the string table of segment names. Return index for
137 future reference. A return value of -1 indicates that the segment name
138 could not be stored. Basically an out-of-memory situation. */
139 Int ML_(am_allocate_segname)(const HChar *name);
141 /* Increment / decrement the reference counter for this segment name. */
142 void ML_(am_inc_refcount)(Int);
143 void ML_(am_dec_refcount)(Int);
145 /* Check whether the segname index is sane. */
146 Bool ML_(am_sane_segname)(Int fnIdx);
148 /* Return the segment name for the given index. Maybe return NULL, if the
149 segment does not have a name. */
150 const HChar *ML_(am_get_segname)(Int fnIdx);
152 /* Return the sequence number of the segment name */
153 Int ML_(am_segname_get_seqnr)(Int fnIdx);
155 #endif // __PRIV_ASPACEMGR_H
157 /*--------------------------------------------------------------------*/
158 /*--- end ---*/
159 /*--------------------------------------------------------------------*/