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-2017 OpenWorks LLP 12 info (at) 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), VG_(strncpy) 47 // VG_IS_PAGE_ALIGNED 48 // VG_PGROUNDDN, VG_PGROUNDUP 49 50 #include "pub_core_libcassert.h" // VG_(exit_now) 51 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 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 ); 74 75 __attribute__ ((noreturn)) 76 extern void ML_(am_assert_fail) ( const HChar* expr, 77 const HChar* file, 78 Int line, 79 const HChar* fn ); 80 81 #define aspacem_assert(expr) \ 82 ((void) (LIKELY(expr) ? 0 : \ 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 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 ); 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, 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 ); 127 128 /* ------ Implemented separately in aspacemgr-linux.c ------ */ 129 130 /* Do a sanity check (/proc/self/maps sync check) */ 131 extern void ML_(am_do_sanity_check)( void ); 132 133 134 /* ------ Implemented in aspacemgr-segnames.c ------ */ 135 void ML_(am_segnames_init)(void); 136 void ML_(am_show_segnames)(Int logLevel, const HChar *prefix); 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. */ 141 Int ML_(am_allocate_segname)(const HChar *name); 142 143 /* Increment / decrement the reference counter for this segment name. */ 144 void ML_(am_inc_refcount)(Int); 145 void ML_(am_dec_refcount)(Int); 146 147 /* Check whether the segname index is sane. */ 148 Bool ML_(am_sane_segname)(Int fnIdx); 149 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); 153 154 /* Return the sequence number of the segment name */ 155 Int ML_(am_segname_get_seqnr)(Int fnIdx); 156 157 #endif // __PRIV_ASPACEMGR_H 158 159 /*--------------------------------------------------------------------*/ 160 /*--- end ---*/ 161 /*--------------------------------------------------------------------*/ 162