fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 1 | # Tool interface functions |
| 2 | # The format for an interface function definition is: |
| 3 | # return_type, func_name, type arg, type arg |
| 4 | # If the function has no arguments, specify no arguments (rather than void) |
| 5 | # |
| 6 | # Comments starting with "##" are turned into C comments in the output |
| 7 | # |
| 8 | # Lines starting with : set the prefix |
| 9 | |
njn | 8b8cecd | 2004-11-22 20:25:56 +0000 | [diff] [blame] | 10 | ## These are the parameterised functions in the core. Some/all default |
| 11 | ## definitions are overridden by the tool version. At the very least, a tool |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 12 | ## must define the fundamental template functions. Depending on what needs |
| 13 | ## are set, extra template functions will be used too. Functions are |
| 14 | ## grouped under the needs that govern their use. |
| 15 | |
| 16 | :tool |
| 17 | ## ------------------------------------------------------------------ |
| 18 | ## Fundamental template functions |
| 19 | |
njn | ae13f10 | 2005-03-12 06:23:46 +0000 | [diff] [blame] | 20 | ## Do initialisation that can be done before command line processing. |
| 21 | void, pre_clo_init |
| 22 | |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 23 | ## Do initialisation that can only be done after command line processing. |
| 24 | void, post_clo_init |
| 25 | |
| 26 | ## Instrument a basic block. Must be a true function, ie. the same input |
| 27 | ## always results in the same output, because basic blocks can be |
| 28 | ## retranslated. Unless you're doing something really strange... |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 29 | IRBB*, instrument, IRBB* bb, VexGuestLayout* layout, IRType gWordTy, IRType hWordTy |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 30 | |
| 31 | ## Finish up, print out any results, etc. `exitcode' is program's exit |
njn | abb14ad | 2004-11-24 16:57:16 +0000 | [diff] [blame] | 32 | ## code. The shadow can be found with VG_(get_exit_status_shadow)(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 33 | void, fini, Int exitcode |
| 34 | |
| 35 | |
| 36 | ## ------------------------------------------------------------------ |
| 37 | ## VG_(needs).core_errors |
| 38 | |
| 39 | ## (none needed) |
| 40 | |
| 41 | ## ------------------------------------------------------------------ |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 42 | ## VG_(needs).tool_errors |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 43 | |
| 44 | ## Identify if two errors are equal, or equal enough. `res' indicates how |
| 45 | ## close is "close enough". `res' should be passed on as necessary, eg. if |
| 46 | ## the Error's `extra' part contains an ExeContext, `res' should be |
| 47 | ## passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other |
| 48 | ## than that, probably don't worry about it unless you have lots of very |
| 49 | ## similar errors occurring. |
njn | b126f73 | 2004-11-22 17:57:07 +0000 | [diff] [blame] | 50 | Bool, eq_Error, VgRes res, Error* e1, Error* e2 |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 51 | |
| 52 | ## Print error context. |
njn | b126f73 | 2004-11-22 17:57:07 +0000 | [diff] [blame] | 53 | void, pp_Error, Error* err |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 54 | |
| 55 | ## Should fill in any details that could be postponed until after the |
| 56 | ## decision whether to ignore the error (ie. details not affecting the |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 57 | ## result of TL_(eq_Error)()). This saves time when errors are ignored. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 58 | ## Yuk. |
| 59 | |
| 60 | ## Return value: must be the size of the `extra' part in bytes -- used by |
| 61 | ## the core to make a copy. |
| 62 | UInt, update_extra, Error* err |
| 63 | |
| 64 | ## Return value indicates recognition. If recognised, must set skind using |
| 65 | ## VG_(set_supp_kind)(). |
| 66 | Bool, recognised_suppression, Char* name, Supp* su |
| 67 | |
| 68 | ## Read any extra info for this suppression kind. Most likely for filling |
| 69 | ## in the `extra' and `string' parts (with VG_(set_supp_{extra, string})()) |
| 70 | ## of a suppression if necessary. Should return False if a syntax error |
| 71 | ## occurred, True otherwise. |
| 72 | Bool, read_extra_suppression_info, Int fd, Char* buf, Int nBuf, Supp* su |
| 73 | |
| 74 | ## This should just check the kinds match and maybe some stuff in the |
| 75 | ## `string' and `extra' field if appropriate (using VG_(get_supp_*)() to |
| 76 | ## get the relevant suppression parts). |
| 77 | Bool, error_matches_suppression, Error* err, Supp* su |
| 78 | |
| 79 | ## This should return the suppression name, for --gen-suppressions, or NULL |
| 80 | ## if that error type cannot be suppressed. This is the inverse of |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 81 | ## TL_(recognised_suppression)(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 82 | Char*, get_error_name, Error* err |
| 83 | |
| 84 | ## This should print any extra info for the error, for --gen-suppressions, |
| 85 | ## including the newline. This is the inverse of |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 86 | ## TL_(read_extra_suppression_info)(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 87 | void, print_extra_suppression_info, Error* err |
| 88 | |
| 89 | |
| 90 | ## ------------------------------------------------------------------ |
| 91 | ## VG_(needs).basic_block_discards |
| 92 | |
| 93 | ## Should discard any information that pertains to specific basic blocks |
| 94 | ## or instructions within the address range given. |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 95 | void, discard_basic_block_info, Addr a, SizeT size |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | ## ------------------------------------------------------------------ |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 99 | ## VG_(needs).command_line_options |
| 100 | |
| 101 | ## Return True if option was recognised. Presumably sets some state to |
| 102 | ## record the option as well. |
| 103 | Bool, process_cmd_line_option, Char* argv |
| 104 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 105 | ## Print out command line usage for options for normal tool operation. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 106 | void, print_usage |
| 107 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 108 | ## Print out command line usage for options for debugging the tool. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 109 | void, print_debug_usage |
| 110 | |
| 111 | ## ------------------------------------------------------------------ |
| 112 | ## VG_(needs).client_requests |
| 113 | |
| 114 | ## If using client requests, the number of the first request should be equal |
njn | fc26ff9 | 2004-11-22 19:12:49 +0000 | [diff] [blame] | 115 | ## to VG_USERREQ_TOOL_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 116 | ## character identification for the string. The second and subsequent |
| 117 | ## requests should follow. |
| 118 | |
njn | fc26ff9 | 2004-11-22 19:12:49 +0000 | [diff] [blame] | 119 | ## This function should use the VG_IS_TOOL_USERREQ macro (in |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 120 | ## include/valgrind.h) to first check if it's a request for this tool. Then |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 121 | ## should handle it if it's recognised (and return True), or return False if |
| 122 | ## not recognised. arg_block[0] holds the request number, any further args |
| 123 | ## from the request are in arg_block[1..]. 'ret' is for the return value... |
| 124 | ## it should probably be filled, if only with 0. |
nethercote | d1b64b2 | 2004-11-04 18:22:28 +0000 | [diff] [blame] | 125 | Bool, handle_client_request, ThreadId tid, UWord* arg_block, UWord* ret |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 126 | |
| 127 | |
| 128 | ## ------------------------------------------------------------------ |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 129 | ## VG_(needs).syscall_wrapper |
| 130 | |
| 131 | ## If either of the pre_ functions malloc() something to return, the |
| 132 | ## corresponding post_ function had better free() it! |
| 133 | |
njn | 31ebc3f | 2004-11-22 19:57:39 +0000 | [diff] [blame] | 134 | void, pre_syscall, ThreadId tid, UInt syscallno |
| 135 | void, post_syscall, ThreadId tid, UInt syscallno, Int res |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 136 | |
| 137 | |
| 138 | ## --------------------------------------------------------------------- |
| 139 | ## VG_(needs).sanity_checks |
| 140 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 141 | ## Can be useful for ensuring a tool's correctness. TL_(cheap_sanity_check) |
| 142 | ## is called very frequently; TL_(expensive_sanity_check) is called less |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 143 | ## frequently and can be more involved. |
| 144 | Bool, cheap_sanity_check |
| 145 | Bool, expensive_sanity_check |
| 146 | |
| 147 | |
| 148 | ## ================================================================================ |
| 149 | ## Event tracking functions |
| 150 | :track |
| 151 | |
| 152 | ## Events happening in core to track. To be notified, pass a callback |
| 153 | ## function to the appropriate function. To ignore an event, don't do |
njn | d4795be | 2004-11-24 11:57:51 +0000 | [diff] [blame] | 154 | ## anything (the default is for events to be ignored). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 155 | |
njn | d4795be | 2004-11-24 11:57:51 +0000 | [diff] [blame] | 156 | ## Note that most events aren't passed a ThreadId. If the event is one called |
| 157 | ## from generated code (eg. new_mem_stack_*), you can use |
njn | 7400cfa | 2005-03-20 18:23:11 +0000 | [diff] [blame] | 158 | ## VG_(get_running_tid)() to find it. Otherwise, it has to be passed in, |
njn | d4795be | 2004-11-24 11:57:51 +0000 | [diff] [blame] | 159 | ## as in pre_mem_read, and so the event signature will require changing. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 160 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 161 | ## Memory events (Nb: to track heap allocation/freeing, a tool must replace |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 162 | ## malloc() et al. See above how to do this.) |
| 163 | |
| 164 | ## These ones occur at startup, upon some signals, and upon some syscalls |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 165 | void, new_mem_startup, Addr a, SizeT len, Bool rr, Bool ww, Bool xx |
| 166 | void, new_mem_stack_signal, Addr a, SizeT len |
| 167 | void, new_mem_brk, Addr a, SizeT len |
| 168 | void, new_mem_mmap, Addr a, SizeT len, Bool rr, Bool ww, Bool xx |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 169 | |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 170 | void, copy_mem_remap, Addr from, Addr to, SizeT len |
| 171 | void, change_mem_mprotect, Addr a, SizeT len, Bool rr, Bool ww, Bool xx |
| 172 | void, die_mem_stack_signal, Addr a, SizeT len |
| 173 | void, die_mem_brk, Addr a, SizeT len |
| 174 | void, die_mem_munmap, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 175 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 176 | ## These ones are called when %esp changes. A tool could track these itself |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 177 | ## (except for ban_mem_stack) but it's much easier to use the core's help. |
| 178 | |
| 179 | ## The specialised ones are called in preference to the general one, if they |
| 180 | ## are defined. These functions are called a lot if they are used, so |
| 181 | ## specialising can optimise things significantly. If any of the |
| 182 | ## specialised cases are defined, the general case must be defined too. |
| 183 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 184 | ## Nb: they must all use the VGA_REGPARM(n) attribute. |
| 185 | VGA_REGPARM(1) void, new_mem_stack_4, Addr new_ESP |
| 186 | VGA_REGPARM(1) void, new_mem_stack_8, Addr new_ESP |
| 187 | VGA_REGPARM(1) void, new_mem_stack_12, Addr new_ESP |
| 188 | VGA_REGPARM(1) void, new_mem_stack_16, Addr new_ESP |
| 189 | VGA_REGPARM(1) void, new_mem_stack_32, Addr new_ESP |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 190 | void, new_mem_stack, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 191 | |
njn | 9fb73db | 2005-03-27 01:55:21 +0000 | [diff] [blame] | 192 | VGA_REGPARM(1) void, die_mem_stack_4, Addr die_ESP |
| 193 | VGA_REGPARM(1) void, die_mem_stack_8, Addr die_ESP |
| 194 | VGA_REGPARM(1) void, die_mem_stack_12, Addr die_ESP |
| 195 | VGA_REGPARM(1) void, die_mem_stack_16, Addr die_ESP |
| 196 | VGA_REGPARM(1) void, die_mem_stack_32, Addr die_ESP |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 197 | void, die_mem_stack, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 198 | |
| 199 | ## Used for redzone at end of thread stacks |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 200 | void, ban_mem_stack, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 201 | |
| 202 | ## These ones occur around syscalls, signal handling, etc |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 203 | void, pre_mem_read, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size |
| 204 | void, pre_mem_read_asciiz,CorePart part, ThreadId tid, Char* s, Addr a |
| 205 | void, pre_mem_write, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size |
| 206 | void, post_mem_write, CorePart part, ThreadId tid, Addr a, SizeT size |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 207 | |
| 208 | |
njn | abb14ad | 2004-11-24 16:57:16 +0000 | [diff] [blame] | 209 | ## Register events. Use VG_(set_shadow_state_area)() to set the shadow regs |
| 210 | ## for these events. |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 211 | |
| 212 | void, pre_reg_read, CorePart part, ThreadId tid, Char* s, OffT guest_state_offset, SizeT size |
| 213 | void, post_reg_write, CorePart part, ThreadId tid, OffT guest_state_offset, SizeT size |
| 214 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 215 | ## This one is called for malloc() et al if they are replaced by a tool. |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 216 | void, post_reg_write_clientcall_return, ThreadId tid, OffT guest_state_offset, SizeT size, Addr f |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 217 | |
| 218 | |
| 219 | ## Scheduler events (not exhaustive) |
| 220 | void, thread_run, ThreadId tid |
| 221 | |
| 222 | |
| 223 | ## Thread events (not exhaustive) |
| 224 | |
| 225 | ## Called during thread create, before the new thread has run any |
| 226 | ## instructions (or touched any memory). |
| 227 | void, post_thread_create, ThreadId tid, ThreadId child |
| 228 | void, post_thread_join, ThreadId joiner, ThreadId joinee |
| 229 | |
| 230 | |
| 231 | ## Mutex events (not exhaustive) |
| 232 | ## "void *mutex" is really a pthread_mutex * |
| 233 | |
| 234 | ## Called before a thread can block while waiting for a mutex (called |
| 235 | ## regardless of whether the thread will block or not). |
| 236 | void, pre_mutex_lock, ThreadId tid, void* mutex |
| 237 | ## Called once the thread actually holds the mutex (always paired with |
| 238 | ## pre_mutex_lock). |
| 239 | void, post_mutex_lock, ThreadId tid, void* mutex |
| 240 | ## Called after a thread has released a mutex (no need for a corresponding |
| 241 | ## pre_mutex_unlock, because unlocking can't block). |
| 242 | void, post_mutex_unlock, ThreadId tid, void* mutex |
| 243 | |
| 244 | ## Signal events (not exhaustive) |
| 245 | |
| 246 | ## ... pre_send_signal, post_send_signal ... |
| 247 | |
| 248 | ## Called before a signal is delivered; `alt_stack' indicates if it is |
| 249 | ## delivered on an alternative stack. |
| 250 | void, pre_deliver_signal, ThreadId tid, Int sigNo, Bool alt_stack |
| 251 | ## Called after a signal is delivered. Nb: unfortunately, if the signal |
| 252 | ## handler longjmps, this won't be called. |
| 253 | void, post_deliver_signal, ThreadId tid, Int sigNo |
| 254 | |
| 255 | |
| 256 | ## Others... condition variable... |
| 257 | ## ... |
| 258 | |
| 259 | ## Shadow memory management |
| 260 | void, init_shadow_page, Addr p |
| 261 | |
| 262 | ## ================================================================================ |
| 263 | ## malloc and friends |
| 264 | :malloc |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 265 | void*, malloc, ThreadId tid, SizeT n |
| 266 | void*, __builtin_new, ThreadId tid, SizeT n |
| 267 | void*, __builtin_vec_new, ThreadId tid, SizeT n |
| 268 | void*, memalign, ThreadId tid, SizeT align, SizeT n |
| 269 | void*, calloc, ThreadId tid, SizeT nmemb, SizeT n |
| 270 | void, free, ThreadId tid, void* p |
| 271 | void, __builtin_delete, ThreadId tid, void* p |
| 272 | void, __builtin_vec_delete, ThreadId tid, void* p |
| 273 | void*, realloc, ThreadId tid, void* p, SizeT size |