njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 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 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 11 | Copyright (C) 2000-2017 Julian Seward |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 12 | jseward@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 | |
njn | 2e8f4ef | 2005-05-14 21:44:20 +0000 | [diff] [blame] | 40 | #include "pub_core_transtab_asm.h" |
florian | 5f1aeb6 | 2015-01-13 17:33:59 +0000 | [diff] [blame] | 41 | #include "pub_tool_transtab.h" |
florian | de6ffbd | 2014-10-06 16:41:14 +0000 | [diff] [blame] | 42 | #include "libvex.h" // VexGuestExtents |
njn | 2e8f4ef | 2005-05-14 21:44:20 +0000 | [diff] [blame] | 43 | |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 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. */ |
sewardj | 5f76de0 | 2007-02-11 05:08:06 +0000 | [diff] [blame] | 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 | |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 58 | |
philippe | 924c852 | 2015-03-15 12:24:19 +0000 | [diff] [blame] | 59 | /* Initialises the TC, using VG_(clo_num_transtab_sectors) |
| 60 | and VG_(clo_avg_transtab_entry_size). |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 61 | VG_(clo_num_transtab_sectors) must be >= MIN_N_SECTORS |
| 62 | and <= MAX_N_SECTORS. */ |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 63 | extern void VG_(init_tt_tc) ( void ); |
| 64 | |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 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 |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 69 | #define MAX_N_SECTORS 48 |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 70 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 71 | /* Default for the nr of sectors, if not overridden by command line. |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 72 | On Android, space is limited, so try to get by with fewer sectors. |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 73 | On other platforms we can go to town. 32 sectors gives theoretical |
| 74 | capacity of about 880MB of JITted code in 2.1 million translations |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 75 | (realistically, about 2/3 of that) for Memcheck. */ |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 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) |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 80 | # define N_SECTORS_DEFAULT 12 |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 81 | #else |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 82 | # define N_SECTORS_DEFAULT 32 |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 83 | #endif |
| 84 | |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 85 | extern |
florian | 518850b | 2014-10-22 22:25:30 +0000 | [diff] [blame] | 86 | void VG_(add_to_transtab)( const VexGuestExtents* vge, |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 87 | Addr entry, |
florian | 44bd446 | 2014-12-29 17:04:46 +0000 | [diff] [blame] | 88 | Addr code, |
sewardj | 26412bd | 2005-07-07 10:05:05 +0000 | [diff] [blame] | 89 | UInt code_len, |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 90 | Bool is_self_checking, |
| 91 | Int offs_profInc, |
sewardj | 5973142 | 2014-07-24 12:45:24 +0000 | [diff] [blame] | 92 | UInt n_guest_instrs ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 93 | |
philippe | 523b5b8 | 2015-03-23 21:49:32 +0000 | [diff] [blame] | 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 | |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 101 | extern |
| 102 | void VG_(tt_tc_do_chaining) ( void* from__patch_addr, |
philippe | 523b5b8 | 2015-03-23 21:49:32 +0000 | [diff] [blame] | 103 | SECno to_sNo, |
| 104 | TTEno to_tteNo, |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 105 | Bool to_fastEP ); |
| 106 | |
florian | 44bd446 | 2014-12-29 17:04:46 +0000 | [diff] [blame] | 107 | extern Bool VG_(search_transtab) ( /*OUT*/Addr* res_hcode, |
philippe | 523b5b8 | 2015-03-23 21:49:32 +0000 | [diff] [blame] | 108 | /*OUT*/SECno* res_sNo, |
| 109 | /*OUT*/TTEno* res_tteNo, |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 110 | Addr guest_addr, |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 111 | Bool upd_cache ); |
| 112 | |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 113 | extern void VG_(discard_translations) ( Addr start, ULong range, |
florian | 1636d33 | 2012-11-15 04:27:04 +0000 | [diff] [blame] | 114 | const HChar* who ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 115 | |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 116 | extern void VG_(print_tt_tc_stats) ( void ); |
| 117 | |
| 118 | extern UInt VG_(get_bbs_translated) ( void ); |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 119 | extern UInt VG_(get_bbs_discarded_or_dumped) ( void ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 120 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 121 | /* Add to / search the auxiliary, small, unredirected translation |
| 122 | table. */ |
| 123 | |
| 124 | extern |
florian | 518850b | 2014-10-22 22:25:30 +0000 | [diff] [blame] | 125 | void VG_(add_to_unredir_transtab)( const VexGuestExtents* vge, |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 126 | Addr entry, |
florian | 44bd446 | 2014-12-29 17:04:46 +0000 | [diff] [blame] | 127 | Addr code, |
njn | 1dcee09 | 2009-02-24 03:07:37 +0000 | [diff] [blame] | 128 | UInt code_len ); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 129 | extern |
florian | 44bd446 | 2014-12-29 17:04:46 +0000 | [diff] [blame] | 130 | Bool VG_(search_unredir_transtab) ( /*OUT*/Addr* result, |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 131 | Addr guest_addr ); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 132 | |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 133 | // SB profiling stuff |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 134 | |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 135 | typedef struct _SBProfEntry { |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 136 | Addr addr; |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 137 | ULong score; |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 138 | } SBProfEntry; |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 139 | |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 140 | extern ULong VG_(get_SB_profile) ( SBProfEntry tops[], UInt n_tops ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 141 | |
florian | 5f1aeb6 | 2015-01-13 17:33:59 +0000 | [diff] [blame] | 142 | // Exported variables |
| 143 | extern Bool VG_(ok_to_discard_translations); |
| 144 | |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 145 | #endif // __PUB_CORE_TRANSTAB_H |
| 146 | |
| 147 | /*--------------------------------------------------------------------*/ |
| 148 | /*--- end ---*/ |
| 149 | /*--------------------------------------------------------------------*/ |