1 2 /*--------------------------------------------------------------------*/ 3 /*--- The translation table and cache. ---*/ 4 /*--- pub_core_transtab.h ---*/ 5 /*--------------------------------------------------------------------*/ 6 7 /* 8 This file is part of Valgrind, a dynamic binary instrumentation 9 framework. 10 11 Copyright (C) 2000-2015 Julian Seward 12 jseward (at) acm.org 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 __PUB_CORE_TRANSTAB_H 33 #define __PUB_CORE_TRANSTAB_H 34 35 //-------------------------------------------------------------------- 36 // PURPOSE: This module is responsible for caching translations, and 37 // enabling fast look-ups of them. 38 //-------------------------------------------------------------------- 39 40 #include "pub_core_transtab_asm.h" 41 #include "pub_tool_transtab.h" 42 #include "libvex.h" // VexGuestExtents 43 44 /* The fast-cache for tt-lookup. Unused entries are denoted by .guest 45 == 1, which is assumed to be a bogus address for all guest code. */ 46 typedef 47 struct { 48 Addr guest; 49 Addr host; 50 } 51 FastCacheEntry; 52 53 extern __attribute__((aligned(16))) 54 FastCacheEntry VG_(tt_fast) [VG_TT_FAST_SIZE]; 55 56 #define TRANSTAB_BOGUS_GUEST_ADDR ((Addr)1) 57 58 59 /* Initialises the TC, using VG_(clo_num_transtab_sectors) 60 and VG_(clo_avg_transtab_entry_size). 61 VG_(clo_num_transtab_sectors) must be >= MIN_N_SECTORS 62 and <= MAX_N_SECTORS. */ 63 extern void VG_(init_tt_tc) ( void ); 64 65 66 /* Limits for number of sectors the TC is divided into. If you need a larger 67 overall translation cache, increase MAX_N_SECTORS. */ 68 #define MIN_N_SECTORS 2 69 #define MAX_N_SECTORS 24 70 71 /* Default for the nr of sectors, if not overriden by command line. 72 On Android, space is limited, so try to get by with fewer sectors. 73 On other platforms we can go to town. 16 sectors gives theoretical 74 capacity of about 440MB of JITted code in 1.05 million translations 75 (realistically, about 2/3 of that) for Memcheck. */ 76 #if defined(VGPV_arm_linux_android) \ 77 || defined(VGPV_x86_linux_android) \ 78 || defined(VGPV_mips32_linux_android) \ 79 || defined(VGPV_arm64_linux_android) 80 # define N_SECTORS_DEFAULT 6 81 #else 82 # define N_SECTORS_DEFAULT 16 83 #endif 84 85 extern 86 void VG_(add_to_transtab)( const VexGuestExtents* vge, 87 Addr entry, 88 Addr code, 89 UInt code_len, 90 Bool is_self_checking, 91 Int offs_profInc, 92 UInt n_guest_instrs ); 93 94 typedef UShort SECno; // SECno type identifies a sector 95 typedef UShort TTEno; // TTEno type identifies a TT entry in a sector. 96 97 // 2 constants that indicates Invalid entries. 98 #define INV_SNO ((SECno)0xFFFF) 99 #define INV_TTE ((TTEno)0xFFFF) 100 101 extern 102 void VG_(tt_tc_do_chaining) ( void* from__patch_addr, 103 SECno to_sNo, 104 TTEno to_tteNo, 105 Bool to_fastEP ); 106 107 extern Bool VG_(search_transtab) ( /*OUT*/Addr* res_hcode, 108 /*OUT*/SECno* res_sNo, 109 /*OUT*/TTEno* res_tteNo, 110 Addr guest_addr, 111 Bool upd_cache ); 112 113 extern void VG_(discard_translations) ( Addr start, ULong range, 114 const HChar* who ); 115 116 extern void VG_(print_tt_tc_stats) ( void ); 117 118 extern UInt VG_(get_bbs_translated) ( void ); 119 120 /* Add to / search the auxiliary, small, unredirected translation 121 table. */ 122 123 extern 124 void VG_(add_to_unredir_transtab)( const VexGuestExtents* vge, 125 Addr entry, 126 Addr code, 127 UInt code_len ); 128 extern 129 Bool VG_(search_unredir_transtab) ( /*OUT*/Addr* result, 130 Addr guest_addr ); 131 132 // SB profiling stuff 133 134 typedef struct _SBProfEntry { 135 Addr addr; 136 ULong score; 137 } SBProfEntry; 138 139 extern ULong VG_(get_SB_profile) ( SBProfEntry tops[], UInt n_tops ); 140 141 // Exported variables 142 extern Bool VG_(ok_to_discard_translations); 143 144 #endif // __PUB_CORE_TRANSTAB_H 145 146 /*--------------------------------------------------------------------*/ 147 /*--- end ---*/ 148 /*--------------------------------------------------------------------*/ 149