sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 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 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 11 | Copyright (C) 2006-2017 OpenWorks LLP |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 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 | |
njn | dad944a | 2009-05-04 05:55:46 +0000 | [diff] [blame] | 46 | #include "pub_core_libcbase.h" // VG_(strlen), VG_(strcmp), VG_(strncpy) |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 47 | // VG_IS_PAGE_ALIGNED |
| 48 | // VG_PGROUNDDN, VG_PGROUNDUP |
| 49 | |
florian | 421c26e | 2014-07-24 12:46:28 +0000 | [diff] [blame] | 50 | #include "pub_core_libcassert.h" // VG_(exit_now) |
| 51 | |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 52 | #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 | |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 68 | __attribute__ ((noreturn)) |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 69 | extern void ML_(am_exit) ( Int status ); |
florian | 3c9f186 | 2015-01-23 16:53:06 +0000 | [diff] [blame] | 70 | __attribute__ ((noreturn)) |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 71 | extern void ML_(am_barf) ( const HChar* what ); |
florian | 3c9f186 | 2015-01-23 16:53:06 +0000 | [diff] [blame] | 72 | __attribute__ ((noreturn)) |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 73 | extern void ML_(am_barf_toolow) ( const HChar* what ); |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 74 | |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 75 | __attribute__ ((noreturn)) |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 76 | extern void ML_(am_assert_fail) ( const HChar* expr, |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 77 | const HChar* file, |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 78 | Int line, |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 79 | const HChar* fn ); |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 80 | |
| 81 | #define aspacem_assert(expr) \ |
florian | 8f9b0d2 | 2014-07-25 08:38:02 +0000 | [diff] [blame] | 82 | ((void) (LIKELY(expr) ? 0 : \ |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 83 | (ML_(am_assert_fail)(#expr, \ |
| 84 | __FILE__, __LINE__, \ |
| 85 | __PRETTY_FUNCTION__)))) |
| 86 | |
| 87 | /* Dude, what's my process ID ? */ |
| 88 | extern Int ML_(am_getpid)( void ); |
| 89 | |
| 90 | /* A simple, self-contained sprintf implementation. */ |
| 91 | extern UInt ML_(am_sprintf) ( HChar* buf, const HChar *format, ... ); |
| 92 | |
| 93 | /* mmap et al wrappers */ |
| 94 | /* wrapper for munmap */ |
| 95 | extern SysRes ML_(am_do_munmap_NO_NOTIFY)(Addr start, SizeT length); |
| 96 | |
| 97 | /* wrapper for the ghastly 'mremap' syscall */ |
| 98 | extern SysRes ML_(am_do_extend_mapping_NO_NOTIFY)( |
| 99 | Addr old_addr, |
| 100 | SizeT old_len, |
| 101 | SizeT new_len |
| 102 | ); |
| 103 | /* ditto */ |
| 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 |
| 107 | ); |
| 108 | |
| 109 | /* There is also VG_(do_mmap_NO_NOTIFY), but that's not declared |
| 110 | here (obviously). */ |
| 111 | |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 112 | extern SysRes ML_(am_open) ( const HChar* pathname, Int flags, Int mode ); |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 113 | extern void ML_(am_close) ( Int fd ); |
| 114 | extern Int ML_(am_read) ( Int fd, void* buf, Int count); |
florian | 3297124 | 2014-10-23 17:47:15 +0000 | [diff] [blame] | 115 | extern Int ML_(am_readlink) ( const HChar* path, HChar* buf, UInt bufsiz ); |
njn | dad944a | 2009-05-04 05:55:46 +0000 | [diff] [blame] | 116 | extern Int ML_(am_fcntl) ( Int fd, Int cmd, Addr arg ); |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 117 | |
| 118 | /* Get the dev, inode and mode info for a file descriptor, if |
| 119 | possible. Returns True on success. */ |
| 120 | extern |
| 121 | Bool ML_(am_get_fd_d_i_m)( Int fd, |
njn | dad944a | 2009-05-04 05:55:46 +0000 | [diff] [blame] | 122 | /*OUT*/ULong* dev, |
| 123 | /*OUT*/ULong* ino, /*OUT*/UInt* mode ); |
| 124 | |
| 125 | extern |
| 126 | Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf ); |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 127 | |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 128 | /* ------ Implemented separately in aspacemgr-linux.c ------ */ |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 129 | |
| 130 | /* Do a sanity check (/proc/self/maps sync check) */ |
| 131 | extern void ML_(am_do_sanity_check)( void ); |
| 132 | |
| 133 | |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 134 | /* ------ Implemented in aspacemgr-segnames.c ------ */ |
florian | 4ecd483 | 2015-04-30 17:34:04 +0000 | [diff] [blame] | 135 | void ML_(am_segnames_init)(void); |
| 136 | void ML_(am_show_segnames)(Int logLevel, const HChar *prefix); |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 137 | |
| 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. */ |
florian | 4ecd483 | 2015-04-30 17:34:04 +0000 | [diff] [blame] | 141 | Int ML_(am_allocate_segname)(const HChar *name); |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 142 | |
| 143 | /* Increment / decrement the reference counter for this segment name. */ |
florian | 4ecd483 | 2015-04-30 17:34:04 +0000 | [diff] [blame] | 144 | void ML_(am_inc_refcount)(Int); |
| 145 | void ML_(am_dec_refcount)(Int); |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 146 | |
| 147 | /* Check whether the segname index is sane. */ |
florian | 4ecd483 | 2015-04-30 17:34:04 +0000 | [diff] [blame] | 148 | Bool ML_(am_sane_segname)(Int fnIdx); |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 149 | |
| 150 | /* Return the segment name for the given index. Maybe return NULL, if the |
| 151 | segment does not have a name. */ |
florian | 4ecd483 | 2015-04-30 17:34:04 +0000 | [diff] [blame] | 152 | const HChar *ML_(am_get_segname)(Int fnIdx); |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 153 | |
| 154 | /* Return the sequence number of the segment name */ |
florian | 4ecd483 | 2015-04-30 17:34:04 +0000 | [diff] [blame] | 155 | Int ML_(am_segname_get_seqnr)(Int fnIdx); |
florian | 346ee2f | 2015-04-06 21:34:30 +0000 | [diff] [blame] | 156 | |
sewardj | 297f6b0 | 2006-10-14 22:25:30 +0000 | [diff] [blame] | 157 | #endif // __PRIV_ASPACEMGR_H |
| 158 | |
| 159 | /*--------------------------------------------------------------------*/ |
| 160 | /*--- end ---*/ |
| 161 | /*--------------------------------------------------------------------*/ |