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 | |
| 10 | Copyright (C) 2000-2005 Julian Seward |
| 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...) \ |
| 46 | ( tl_assert2(VG_(tdict).fn, \ |
| 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 { |
| 66 | Char* name; |
| 67 | Char* version; |
| 68 | Char* description; |
| 69 | Char* copyright_author; |
| 70 | Char* bug_reports_to; |
| 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; |
| 84 | Bool core_errors; |
| 85 | Bool tool_errors; |
| 86 | Bool basic_block_discards; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 87 | Bool command_line_options; |
| 88 | Bool client_requests; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 89 | Bool syscall_wrapper; |
| 90 | Bool sanity_checks; |
| 91 | Bool data_syms; |
| 92 | Bool shadow_memory; |
njn | fc51f8d | 2005-06-21 03:20:17 +0000 | [diff] [blame] | 93 | Bool malloc_replacement; |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 94 | } |
| 95 | VgNeeds; |
| 96 | |
| 97 | extern VgNeeds VG_(needs); |
| 98 | |
| 99 | /* --------------------------------------------------------------------- |
| 100 | The dictionary of callable tool functions |
| 101 | ------------------------------------------------------------------ */ |
| 102 | |
| 103 | typedef struct { |
| 104 | // -- 'Needs'-related functions ---------------------------------- |
| 105 | // Basic functions |
| 106 | void (*tool_pre_clo_init) (void); |
| 107 | void (*tool_post_clo_init)(void); |
| 108 | IRBB* (*tool_instrument) (IRBB*, VexGuestLayout*, IRType, IRType); |
| 109 | void (*tool_fini) (Int); |
| 110 | |
| 111 | // VG_(needs).core_errors |
| 112 | // (none) |
| 113 | |
| 114 | // VG_(needs).tool_errors |
| 115 | Bool (*tool_eq_Error) (VgRes, Error*, Error*); |
| 116 | void (*tool_pp_Error) (Error*); |
| 117 | UInt (*tool_update_extra) (Error*); |
| 118 | Bool (*tool_recognised_suppression) (Char*, Supp*); |
| 119 | Bool (*tool_read_extra_suppression_info) (Int, Char*, Int, Supp*); |
| 120 | Bool (*tool_error_matches_suppression) (Error*, Supp*); |
| 121 | Char* (*tool_get_error_name) (Error*); |
| 122 | void (*tool_print_extra_suppression_info)(Error*); |
| 123 | |
| 124 | // VG_(needs).basic_block_discards |
| 125 | void (*tool_discard_basic_block_info)(Addr, SizeT); |
| 126 | |
| 127 | // VG_(needs).command_line_options |
| 128 | Bool (*tool_process_cmd_line_option)(Char*); |
| 129 | void (*tool_print_usage) (void); |
| 130 | void (*tool_print_debug_usage) (void); |
| 131 | |
| 132 | // VG_(needs).client_requests |
| 133 | Bool (*tool_handle_client_request)(ThreadId, UWord*, UWord*); |
| 134 | |
| 135 | // VG_(needs).syscall_wrapper |
| 136 | void (*tool_pre_syscall) (ThreadId, UInt); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 137 | void (*tool_post_syscall)(ThreadId, UInt, SysRes); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 138 | |
| 139 | // VG_(needs).sanity_checks |
| 140 | Bool (*tool_cheap_sanity_check)(void); |
| 141 | Bool (*tool_expensive_sanity_check)(void); |
| 142 | |
njn | fc51f8d | 2005-06-21 03:20:17 +0000 | [diff] [blame] | 143 | // VG_(needs).malloc_replacement |
| 144 | void* (*tool_malloc) (ThreadId, SizeT); |
| 145 | void* (*tool___builtin_new) (ThreadId, SizeT); |
| 146 | void* (*tool___builtin_vec_new) (ThreadId, SizeT); |
| 147 | void* (*tool_memalign) (ThreadId, SizeT, SizeT); |
| 148 | void* (*tool_calloc) (ThreadId, SizeT, SizeT); |
| 149 | void (*tool_free) (ThreadId, void*); |
| 150 | void (*tool___builtin_delete) (ThreadId, void*); |
| 151 | void (*tool___builtin_vec_delete)(ThreadId, void*); |
| 152 | void* (*tool_realloc) (ThreadId, void*, SizeT); |
| 153 | SizeT tool_client_redzone_szB; |
| 154 | |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 155 | // -- Event tracking functions ------------------------------------ |
| 156 | void (*track_new_mem_startup) (Addr, SizeT, Bool, Bool, Bool); |
| 157 | void (*track_new_mem_stack_signal)(Addr, SizeT); |
| 158 | void (*track_new_mem_brk) (Addr, SizeT); |
| 159 | void (*track_new_mem_mmap) (Addr, SizeT, Bool, Bool, Bool); |
| 160 | |
| 161 | void (*track_copy_mem_remap) (Addr, Addr, SizeT); |
| 162 | void (*track_change_mem_mprotect) (Addr, SizeT, Bool, Bool, Bool); |
| 163 | void (*track_die_mem_stack_signal)(Addr, SizeT); |
| 164 | void (*track_die_mem_brk) (Addr, SizeT); |
| 165 | void (*track_die_mem_munmap) (Addr, SizeT); |
| 166 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 167 | void VG_REGPARM(1) (*track_new_mem_stack_4) (Addr); |
| 168 | void VG_REGPARM(1) (*track_new_mem_stack_8) (Addr); |
| 169 | void VG_REGPARM(1) (*track_new_mem_stack_12)(Addr); |
| 170 | void VG_REGPARM(1) (*track_new_mem_stack_16)(Addr); |
| 171 | void VG_REGPARM(1) (*track_new_mem_stack_32)(Addr); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 172 | void (*track_new_mem_stack)(Addr, SizeT); |
| 173 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 174 | void VG_REGPARM(1) (*track_die_mem_stack_4) (Addr); |
| 175 | void VG_REGPARM(1) (*track_die_mem_stack_8) (Addr); |
| 176 | void VG_REGPARM(1) (*track_die_mem_stack_12)(Addr); |
| 177 | void VG_REGPARM(1) (*track_die_mem_stack_16)(Addr); |
| 178 | void VG_REGPARM(1) (*track_die_mem_stack_32)(Addr); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 179 | void (*track_die_mem_stack)(Addr, SizeT); |
| 180 | |
| 181 | void (*track_ban_mem_stack)(Addr, SizeT); |
| 182 | |
| 183 | void (*track_pre_mem_read) (CorePart, ThreadId, Char*, Addr, SizeT); |
| 184 | void (*track_pre_mem_read_asciiz)(CorePart, ThreadId, Char*, Addr); |
| 185 | void (*track_pre_mem_write) (CorePart, ThreadId, Char*, Addr, SizeT); |
| 186 | void (*track_post_mem_write) (CorePart, ThreadId, Addr, SizeT); |
| 187 | |
| 188 | void (*track_pre_reg_read) (CorePart, ThreadId, Char*, OffT, SizeT); |
| 189 | void (*track_post_reg_write)(CorePart, ThreadId, OffT, SizeT); |
| 190 | void (*track_post_reg_write_clientcall_return)(ThreadId, OffT, SizeT, Addr); |
| 191 | |
| 192 | void (*track_thread_run)(ThreadId); |
| 193 | |
| 194 | void (*track_post_thread_create)(ThreadId, ThreadId); |
| 195 | void (*track_post_thread_join) (ThreadId, ThreadId); |
| 196 | |
| 197 | void (*track_pre_mutex_lock) (ThreadId, void*); |
| 198 | void (*track_post_mutex_lock) (ThreadId, void*); |
| 199 | void (*track_post_mutex_unlock)(ThreadId, void*); |
| 200 | |
| 201 | void (*track_pre_deliver_signal) (ThreadId, Int sigNo, Bool); |
| 202 | void (*track_post_deliver_signal)(ThreadId, Int sigNo); |
| 203 | |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 204 | } VgToolInterface; |
| 205 | |
| 206 | extern VgToolInterface VG_(tdict); |
| 207 | |
| 208 | /* --------------------------------------------------------------------- |
| 209 | Miscellaneous functions |
| 210 | ------------------------------------------------------------------ */ |
| 211 | |
njn | 64c8324 | 2005-06-21 01:54:38 +0000 | [diff] [blame] | 212 | Bool VG_(sanity_check_needs) ( Bool non_zero_shadow_memory, Char** failmsg ); |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 213 | |
| 214 | #endif // __PUB_CORE_TOOLIFACE_H |
| 215 | |
| 216 | /*--------------------------------------------------------------------*/ |
| 217 | /*--- end ---*/ |
| 218 | /*--------------------------------------------------------------------*/ |