njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- The core/tool interface. pub_core_tooliface.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 10 | Copyright (C) 2000-2017 Julian Seward |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_CORE_TOOLIFACE_H |
| 32 | #define __PUB_CORE_TOOLIFACE_H |
| 33 | |
| 34 | #include "pub_tool_tooliface.h" |
| 35 | |
| 36 | //-------------------------------------------------------------------- |
| 37 | // PURPOSE: This module encapsulates the key parts of the core/tool |
| 38 | // interface: 'details', 'needs' and 'trackable events'. |
| 39 | //-------------------------------------------------------------------- |
| 40 | |
| 41 | // Note the use of C's comma operator here -- it means that we execute both |
| 42 | // statements, and the rvalue of the whole thing is the rvalue of the last |
| 43 | // statement. This lets us say "x = VG_TDICT_CALL(...)" in the required |
| 44 | // places, while still checking the assertion. |
| 45 | #define VG_TDICT_CALL(fn, args...) \ |
florian | e2800c9 | 2014-09-15 20:57:45 +0000 | [diff] [blame] | 46 | ( vg_assert2(VG_(tdict).fn, \ |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 47 | "you forgot to set VgToolInterface function '" #fn "'"), \ |
| 48 | VG_(tdict).fn(args) ) |
| 49 | |
| 50 | #define VG_TRACK(fn, args...) \ |
| 51 | do { \ |
| 52 | if (VG_(tdict).track_##fn) \ |
| 53 | VG_(tdict).track_##fn(args); \ |
| 54 | } while(0) |
| 55 | |
| 56 | /* These structs are not exposed to tools to mitigate possibility of |
| 57 | binary-incompatibilities when the core/tool interface changes. Instead, |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 58 | set functions are provided (see include/pub_tool_tooliface.h). */ |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 59 | |
| 60 | /* --------------------------------------------------------------------- |
| 61 | 'Details' |
| 62 | ------------------------------------------------------------------ */ |
| 63 | |
| 64 | typedef |
| 65 | struct { |
florian | 2b8059a | 2012-10-14 16:45:23 +0000 | [diff] [blame] | 66 | const HChar* name; |
| 67 | const HChar* version; |
| 68 | const HChar* description; |
| 69 | const HChar* copyright_author; |
| 70 | const HChar* bug_reports_to; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 71 | UInt avg_translation_sizeB; |
| 72 | } |
| 73 | VgDetails; |
| 74 | |
| 75 | extern VgDetails VG_(details); |
| 76 | |
| 77 | /* --------------------------------------------------------------------- |
| 78 | 'Needs' |
| 79 | ------------------------------------------------------------------ */ |
| 80 | |
| 81 | typedef |
| 82 | struct { |
| 83 | Bool libc_freeres; |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame] | 84 | Bool cxx_freeres; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 85 | Bool core_errors; |
| 86 | Bool tool_errors; |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 87 | Bool superblock_discards; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 88 | Bool command_line_options; |
| 89 | Bool client_requests; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 90 | Bool syscall_wrapper; |
| 91 | Bool sanity_checks; |
philippe | 8587b54 | 2013-12-15 20:24:43 +0000 | [diff] [blame] | 92 | Bool print_stats; |
philippe | 07c0852 | 2014-05-14 20:39:27 +0000 | [diff] [blame] | 93 | Bool info_location; |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 94 | Bool var_info; |
njn | fc51f8d | 2005-06-21 03:20:17 +0000 | [diff] [blame] | 95 | Bool malloc_replacement; |
njn | ca54af3 | 2006-04-16 10:25:43 +0000 | [diff] [blame] | 96 | Bool xml_output; |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 97 | Bool final_IR_tidy_pass; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 98 | } |
| 99 | VgNeeds; |
| 100 | |
| 101 | extern VgNeeds VG_(needs); |
| 102 | |
| 103 | /* --------------------------------------------------------------------- |
| 104 | The dictionary of callable tool functions |
| 105 | ------------------------------------------------------------------ */ |
| 106 | |
| 107 | typedef struct { |
| 108 | // -- 'Needs'-related functions ---------------------------------- |
| 109 | // Basic functions |
| 110 | void (*tool_pre_clo_init) (void); |
| 111 | void (*tool_post_clo_init)(void); |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 112 | IRSB* (*tool_instrument) (VgCallbackClosure*, |
| 113 | IRSB*, |
florian | 3c0c947 | 2014-09-24 12:06:55 +0000 | [diff] [blame] | 114 | const VexGuestLayout*, const VexGuestExtents*, |
| 115 | const VexArchInfo*, IRType, IRType); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 116 | void (*tool_fini) (Int); |
| 117 | |
| 118 | // VG_(needs).core_errors |
| 119 | // (none) |
| 120 | |
| 121 | // VG_(needs).tool_errors |
florian | 8e3fbb5 | 2014-10-20 19:02:38 +0000 | [diff] [blame] | 122 | Bool (*tool_eq_Error) (VgRes, const Error*, const Error*); |
| 123 | void (*tool_before_pp_Error) (const Error*); |
| 124 | void (*tool_pp_Error) (const Error*); |
sewardj | adb102f | 2007-11-09 23:21:44 +0000 | [diff] [blame] | 125 | Bool tool_show_ThreadIDs_for_errors; |
florian | 8e3fbb5 | 2014-10-20 19:02:38 +0000 | [diff] [blame] | 126 | UInt (*tool_update_extra) (const Error*); |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 127 | Bool (*tool_recognised_suppression) (const HChar*, Supp*); |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 128 | Bool (*tool_read_extra_suppression_info) (Int, HChar**, SizeT*, Int*, |
| 129 | Supp*); |
florian | 8e3fbb5 | 2014-10-20 19:02:38 +0000 | [diff] [blame] | 130 | Bool (*tool_error_matches_suppression) (const Error*, const Supp*); |
| 131 | const HChar* (*tool_get_error_name) (const Error*); |
| 132 | SizeT (*tool_get_extra_suppression_info) (const Error*,/*OUT*/HChar*,Int); |
| 133 | SizeT (*tool_print_extra_suppression_use) (const Supp*,/*OUT*/HChar*,Int); |
| 134 | void (*tool_update_extra_suppression_use) (const Error*, const Supp*); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 135 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 136 | // VG_(needs).superblock_discards |
florian | ddd61ff | 2015-01-04 17:20:45 +0000 | [diff] [blame] | 137 | void (*tool_discard_superblock_info)(Addr, VexGuestExtents); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 138 | |
| 139 | // VG_(needs).command_line_options |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 140 | Bool (*tool_process_cmd_line_option)(const HChar*); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 141 | void (*tool_print_usage) (void); |
| 142 | void (*tool_print_debug_usage) (void); |
| 143 | |
| 144 | // VG_(needs).client_requests |
| 145 | Bool (*tool_handle_client_request)(ThreadId, UWord*, UWord*); |
| 146 | |
| 147 | // VG_(needs).syscall_wrapper |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 148 | void (*tool_pre_syscall) (ThreadId, UInt, UWord*, UInt); |
| 149 | void (*tool_post_syscall)(ThreadId, UInt, UWord*, UInt, SysRes); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 150 | |
| 151 | // VG_(needs).sanity_checks |
| 152 | Bool (*tool_cheap_sanity_check)(void); |
| 153 | Bool (*tool_expensive_sanity_check)(void); |
| 154 | |
philippe | 8587b54 | 2013-12-15 20:24:43 +0000 | [diff] [blame] | 155 | // VG_(needs).print_stats |
| 156 | void (*tool_print_stats)(void); |
| 157 | |
philippe | 07c0852 | 2014-05-14 20:39:27 +0000 | [diff] [blame] | 158 | // VG_(needs).info_location |
| 159 | void (*tool_info_location)(Addr a); |
| 160 | |
njn | fc51f8d | 2005-06-21 03:20:17 +0000 | [diff] [blame] | 161 | // VG_(needs).malloc_replacement |
| 162 | void* (*tool_malloc) (ThreadId, SizeT); |
| 163 | void* (*tool___builtin_new) (ThreadId, SizeT); |
| 164 | void* (*tool___builtin_vec_new) (ThreadId, SizeT); |
| 165 | void* (*tool_memalign) (ThreadId, SizeT, SizeT); |
| 166 | void* (*tool_calloc) (ThreadId, SizeT, SizeT); |
| 167 | void (*tool_free) (ThreadId, void*); |
| 168 | void (*tool___builtin_delete) (ThreadId, void*); |
| 169 | void (*tool___builtin_vec_delete)(ThreadId, void*); |
| 170 | void* (*tool_realloc) (ThreadId, void*, SizeT); |
njn | 8b140de | 2009-02-17 04:31:18 +0000 | [diff] [blame] | 171 | SizeT (*tool_malloc_usable_size) (ThreadId, void*); |
njn | fc51f8d | 2005-06-21 03:20:17 +0000 | [diff] [blame] | 172 | SizeT tool_client_redzone_szB; |
| 173 | |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 174 | // VG_(needs).final_IR_tidy_pass |
| 175 | IRSB* (*tool_final_IR_tidy_pass) (IRSB*); |
| 176 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 177 | // VG_(needs).xml_output |
| 178 | // (none) |
| 179 | |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 180 | // -- Event tracking functions ------------------------------------ |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 181 | void (*track_new_mem_startup) (Addr, SizeT, Bool, Bool, Bool, ULong); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 182 | void (*track_new_mem_stack_signal)(Addr, SizeT, ThreadId); |
| 183 | void (*track_new_mem_brk) (Addr, SizeT, ThreadId); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 184 | void (*track_new_mem_mmap) (Addr, SizeT, Bool, Bool, Bool, ULong); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 185 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 186 | void (*track_copy_mem_remap) (Addr src, Addr dst, SizeT); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 187 | void (*track_change_mem_mprotect) (Addr, SizeT, Bool, Bool, Bool); |
| 188 | void (*track_die_mem_stack_signal)(Addr, SizeT); |
| 189 | void (*track_die_mem_brk) (Addr, SizeT); |
| 190 | void (*track_die_mem_munmap) (Addr, SizeT); |
| 191 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 192 | void VG_REGPARM(2) (*track_new_mem_stack_4_w_ECU) (Addr,UInt); |
| 193 | void VG_REGPARM(2) (*track_new_mem_stack_8_w_ECU) (Addr,UInt); |
| 194 | void VG_REGPARM(2) (*track_new_mem_stack_12_w_ECU) (Addr,UInt); |
| 195 | void VG_REGPARM(2) (*track_new_mem_stack_16_w_ECU) (Addr,UInt); |
| 196 | void VG_REGPARM(2) (*track_new_mem_stack_32_w_ECU) (Addr,UInt); |
| 197 | void VG_REGPARM(2) (*track_new_mem_stack_112_w_ECU)(Addr,UInt); |
| 198 | void VG_REGPARM(2) (*track_new_mem_stack_128_w_ECU)(Addr,UInt); |
| 199 | void VG_REGPARM(2) (*track_new_mem_stack_144_w_ECU)(Addr,UInt); |
| 200 | void VG_REGPARM(2) (*track_new_mem_stack_160_w_ECU)(Addr,UInt); |
| 201 | void (*track_new_mem_stack_w_ECU)(Addr,SizeT,UInt); |
| 202 | |
sewardj | f5c8e37 | 2006-02-12 15:42:20 +0000 | [diff] [blame] | 203 | void VG_REGPARM(1) (*track_new_mem_stack_4) (Addr); |
| 204 | void VG_REGPARM(1) (*track_new_mem_stack_8) (Addr); |
| 205 | void VG_REGPARM(1) (*track_new_mem_stack_12) (Addr); |
| 206 | void VG_REGPARM(1) (*track_new_mem_stack_16) (Addr); |
| 207 | void VG_REGPARM(1) (*track_new_mem_stack_32) (Addr); |
| 208 | void VG_REGPARM(1) (*track_new_mem_stack_112)(Addr); |
| 209 | void VG_REGPARM(1) (*track_new_mem_stack_128)(Addr); |
| 210 | void VG_REGPARM(1) (*track_new_mem_stack_144)(Addr); |
| 211 | void VG_REGPARM(1) (*track_new_mem_stack_160)(Addr); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 212 | void (*track_new_mem_stack)(Addr,SizeT); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 213 | |
sewardj | f5c8e37 | 2006-02-12 15:42:20 +0000 | [diff] [blame] | 214 | void VG_REGPARM(1) (*track_die_mem_stack_4) (Addr); |
| 215 | void VG_REGPARM(1) (*track_die_mem_stack_8) (Addr); |
| 216 | void VG_REGPARM(1) (*track_die_mem_stack_12) (Addr); |
| 217 | void VG_REGPARM(1) (*track_die_mem_stack_16) (Addr); |
| 218 | void VG_REGPARM(1) (*track_die_mem_stack_32) (Addr); |
| 219 | void VG_REGPARM(1) (*track_die_mem_stack_112)(Addr); |
| 220 | void VG_REGPARM(1) (*track_die_mem_stack_128)(Addr); |
| 221 | void VG_REGPARM(1) (*track_die_mem_stack_144)(Addr); |
| 222 | void VG_REGPARM(1) (*track_die_mem_stack_160)(Addr); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 223 | void (*track_die_mem_stack)(Addr, SizeT); |
| 224 | |
| 225 | void (*track_ban_mem_stack)(Addr, SizeT); |
| 226 | |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 227 | void (*track_pre_mem_read) (CorePart, ThreadId, const HChar*, Addr, SizeT); |
| 228 | void (*track_pre_mem_read_asciiz)(CorePart, ThreadId, const HChar*, Addr); |
| 229 | void (*track_pre_mem_write) (CorePart, ThreadId, const HChar*, Addr, SizeT); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 230 | void (*track_post_mem_write) (CorePart, ThreadId, Addr, SizeT); |
| 231 | |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 232 | void (*track_pre_reg_read) (CorePart, ThreadId, const HChar*, PtrdiffT, SizeT); |
| 233 | void (*track_post_reg_write)(CorePart, ThreadId, PtrdiffT, SizeT); |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 234 | void (*track_post_reg_write_clientcall_return)(ThreadId, PtrdiffT, SizeT, |
| 235 | Addr); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 236 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 237 | void (*track_copy_mem_to_reg)(CorePart, ThreadId, Addr, PtrdiffT, SizeT); |
| 238 | void (*track_copy_reg_to_mem)(CorePart, ThreadId, PtrdiffT, Addr, SizeT); |
| 239 | |
njn | 3e32c87 | 2006-12-24 07:51:17 +0000 | [diff] [blame] | 240 | void (*track_start_client_code)(ThreadId, ULong); |
| 241 | void (*track_stop_client_code) (ThreadId, ULong); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 242 | |
sewardj | adb102f | 2007-11-09 23:21:44 +0000 | [diff] [blame] | 243 | void (*track_pre_thread_ll_create)(ThreadId, ThreadId); |
sewardj | 7a387ea | 2007-11-25 14:06:06 +0000 | [diff] [blame] | 244 | void (*track_pre_thread_first_insn)(ThreadId); |
sewardj | adb102f | 2007-11-09 23:21:44 +0000 | [diff] [blame] | 245 | void (*track_pre_thread_ll_exit) (ThreadId); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 246 | |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 247 | void (*track_pre_deliver_signal) (ThreadId, Int sigNo, Bool); |
| 248 | void (*track_post_deliver_signal)(ThreadId, Int sigNo); |
| 249 | |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 250 | } VgToolInterface; |
| 251 | |
| 252 | extern VgToolInterface VG_(tdict); |
| 253 | |
| 254 | /* --------------------------------------------------------------------- |
| 255 | Miscellaneous functions |
| 256 | ------------------------------------------------------------------ */ |
| 257 | |
florian | 2b8059a | 2012-10-14 16:45:23 +0000 | [diff] [blame] | 258 | Bool VG_(sanity_check_needs) ( const HChar** failmsg ); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 259 | |
| 260 | #endif // __PUB_CORE_TOOLIFACE_H |
| 261 | |
| 262 | /*--------------------------------------------------------------------*/ |
| 263 | /*--- end ---*/ |
| 264 | /*--------------------------------------------------------------------*/ |