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 | |
| 10 | ## These are the parameterised functions in the core. The default definitions |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 11 | ## are overridden by LD_PRELOADed 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 | |
| 20 | ## Do initialisation that can only be done after command line processing. |
| 21 | void, post_clo_init |
| 22 | |
| 23 | ## Instrument a basic block. Must be a true function, ie. the same input |
| 24 | ## always results in the same output, because basic blocks can be |
| 25 | ## retranslated. Unless you're doing something really strange... |
| 26 | ## 'orig_addr' is the address of the first instruction in the block. |
| 27 | UCodeBlock*, instrument, UCodeBlock* cb, Addr orig_addr |
| 28 | |
| 29 | ## Finish up, print out any results, etc. `exitcode' is program's exit |
| 30 | ## code. The shadow (if the `shadow_regs' need is set) can be found with |
nethercote | 15218bd | 2004-09-11 15:11:47 +0000 | [diff] [blame] | 31 | ## VG_(get_exit_status_shadow)(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 32 | void, fini, Int exitcode |
| 33 | |
| 34 | |
| 35 | ## ------------------------------------------------------------------ |
| 36 | ## VG_(needs).core_errors |
| 37 | |
| 38 | ## (none needed) |
| 39 | |
| 40 | ## ------------------------------------------------------------------ |
| 41 | ## VG_(needs).skin_errors |
| 42 | |
| 43 | ## Identify if two errors are equal, or equal enough. `res' indicates how |
| 44 | ## close is "close enough". `res' should be passed on as necessary, eg. if |
| 45 | ## the Error's `extra' part contains an ExeContext, `res' should be |
| 46 | ## passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other |
| 47 | ## than that, probably don't worry about it unless you have lots of very |
| 48 | ## similar errors occurring. |
| 49 | Bool, eq_SkinError, VgRes res, Error* e1, Error* e2 |
| 50 | |
| 51 | ## Print error context. |
| 52 | void, pp_SkinError, Error* err |
| 53 | |
| 54 | ## Should fill in any details that could be postponed until after the |
| 55 | ## decision whether to ignore the error (ie. details not affecting the |
| 56 | ## result of SK_(eq_SkinError)()). This saves time when errors are ignored. |
| 57 | ## Yuk. |
| 58 | |
| 59 | ## Return value: must be the size of the `extra' part in bytes -- used by |
| 60 | ## the core to make a copy. |
| 61 | UInt, update_extra, Error* err |
| 62 | |
| 63 | ## Return value indicates recognition. If recognised, must set skind using |
| 64 | ## VG_(set_supp_kind)(). |
| 65 | Bool, recognised_suppression, Char* name, Supp* su |
| 66 | |
| 67 | ## Read any extra info for this suppression kind. Most likely for filling |
| 68 | ## in the `extra' and `string' parts (with VG_(set_supp_{extra, string})()) |
| 69 | ## of a suppression if necessary. Should return False if a syntax error |
| 70 | ## occurred, True otherwise. |
| 71 | Bool, read_extra_suppression_info, Int fd, Char* buf, Int nBuf, Supp* su |
| 72 | |
| 73 | ## This should just check the kinds match and maybe some stuff in the |
| 74 | ## `string' and `extra' field if appropriate (using VG_(get_supp_*)() to |
| 75 | ## get the relevant suppression parts). |
| 76 | Bool, error_matches_suppression, Error* err, Supp* su |
| 77 | |
| 78 | ## This should return the suppression name, for --gen-suppressions, or NULL |
| 79 | ## if that error type cannot be suppressed. This is the inverse of |
| 80 | ## SK_(recognised_suppression)(). |
| 81 | Char*, get_error_name, Error* err |
| 82 | |
| 83 | ## This should print any extra info for the error, for --gen-suppressions, |
| 84 | ## including the newline. This is the inverse of |
| 85 | ## SK_(read_extra_suppression_info)(). |
| 86 | void, print_extra_suppression_info, Error* err |
| 87 | |
| 88 | |
| 89 | ## ------------------------------------------------------------------ |
| 90 | ## VG_(needs).basic_block_discards |
| 91 | |
| 92 | ## Should discard any information that pertains to specific basic blocks |
| 93 | ## or instructions within the address range given. |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame^] | 94 | void, discard_basic_block_info, Addr a, SizeT size |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | ## ------------------------------------------------------------------ |
| 98 | ## VG_(needs).shadow_regs |
| 99 | |
| 100 | ## No functions must be defined, but the post_reg[s]_write_* events should |
| 101 | ## be tracked. |
| 102 | |
| 103 | ## ------------------------------------------------------------------ |
| 104 | ## VG_(needs).command_line_options |
| 105 | |
| 106 | ## Return True if option was recognised. Presumably sets some state to |
| 107 | ## record the option as well. |
| 108 | Bool, process_cmd_line_option, Char* argv |
| 109 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 110 | ## Print out command line usage for options for normal tool operation. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 111 | void, print_usage |
| 112 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 113 | ## Print out command line usage for options for debugging the tool. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 114 | void, print_debug_usage |
| 115 | |
| 116 | ## ------------------------------------------------------------------ |
| 117 | ## VG_(needs).client_requests |
| 118 | |
| 119 | ## If using client requests, the number of the first request should be equal |
| 120 | ## to VG_USERREQ_SKIN_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two |
| 121 | ## character identification for the string. The second and subsequent |
| 122 | ## requests should follow. |
| 123 | |
| 124 | ## This function should use the VG_IS_SKIN_USERREQ macro (in |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 125 | ## 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] | 126 | ## should handle it if it's recognised (and return True), or return False if |
| 127 | ## not recognised. arg_block[0] holds the request number, any further args |
| 128 | ## from the request are in arg_block[1..]. 'ret' is for the return value... |
| 129 | ## it should probably be filled, if only with 0. |
| 130 | Bool, handle_client_request, ThreadId tid, UInt* arg_block, UInt* ret |
| 131 | |
| 132 | |
| 133 | ## ------------------------------------------------------------------ |
| 134 | ## VG_(needs).extends_UCode |
| 135 | |
| 136 | ## 'X' prefix indicates eXtended UCode. |
| 137 | Int, get_Xreg_usage, UInstr* u, Tag tag, Int* regs, Bool* isWrites |
| 138 | void, emit_XUInstr, UInstr* u, RRegSet regs_live_before |
| 139 | Bool, sane_XUInstr, Bool beforeRA, Bool beforeLiveness, UInstr* u |
| 140 | Char *, name_XUOpcode, Opcode opc |
| 141 | void, pp_XUInstr, UInstr* u |
| 142 | |
| 143 | |
| 144 | ## ------------------------------------------------------------------ |
| 145 | ## VG_(needs).syscall_wrapper |
| 146 | |
| 147 | ## If either of the pre_ functions malloc() something to return, the |
| 148 | ## corresponding post_ function had better free() it! |
| 149 | |
| 150 | void *, pre_syscall, ThreadId tid, UInt syscallno, Bool is_blocking |
| 151 | void, post_syscall, ThreadId tid, UInt syscallno, void* pre_result, Int res, Bool is_blocking |
| 152 | |
| 153 | |
| 154 | ## --------------------------------------------------------------------- |
| 155 | ## VG_(needs).sanity_checks |
| 156 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 157 | ## Can be useful for ensuring a tool's correctness. SK_(cheap_sanity_check) |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 158 | ## is called very frequently; SK_(expensive_sanity_check) is called less |
| 159 | ## frequently and can be more involved. |
| 160 | Bool, cheap_sanity_check |
| 161 | Bool, expensive_sanity_check |
| 162 | |
| 163 | |
| 164 | ## ================================================================================ |
| 165 | ## Event tracking functions |
| 166 | :track |
| 167 | |
| 168 | ## Events happening in core to track. To be notified, pass a callback |
| 169 | ## function to the appropriate function. To ignore an event, don't do |
| 170 | ## anything (default is for events to be ignored). |
| 171 | |
| 172 | ## Note that most events aren't passed a ThreadId. To find out the ThreadId |
| 173 | ## of the affected thread, use VG_(get_current_or_recent_tid)(). For the |
| 174 | ## ones passed a ThreadId, use that instead, since |
| 175 | ## VG_(get_current_or_recent_tid)() might not give the right ThreadId in |
| 176 | ## that case. |
| 177 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 178 | ## Memory events (Nb: to track heap allocation/freeing, a tool must replace |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 179 | ## malloc() et al. See above how to do this.) |
| 180 | |
| 181 | ## These ones occur at startup, upon some signals, and upon some syscalls |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 182 | void, new_mem_startup, Addr a, SizeT len, Bool rr, Bool ww, Bool xx |
| 183 | void, new_mem_stack_signal, Addr a, SizeT len |
| 184 | void, new_mem_brk, Addr a, SizeT len |
| 185 | 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] | 186 | |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 187 | void, copy_mem_remap, Addr from, Addr to, SizeT len |
| 188 | void, change_mem_mprotect, Addr a, SizeT len, Bool rr, Bool ww, Bool xx |
| 189 | void, die_mem_stack_signal, Addr a, SizeT len |
| 190 | void, die_mem_brk, Addr a, SizeT len |
| 191 | void, die_mem_munmap, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 192 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 193 | ## These ones are called when %esp changes. A tool could track these itself |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 194 | ## (except for ban_mem_stack) but it's much easier to use the core's help. |
| 195 | |
| 196 | ## The specialised ones are called in preference to the general one, if they |
| 197 | ## are defined. These functions are called a lot if they are used, so |
| 198 | ## specialising can optimise things significantly. If any of the |
| 199 | ## specialised cases are defined, the general case must be defined too. |
| 200 | |
nethercote | eec4630 | 2004-08-23 15:06:23 +0000 | [diff] [blame] | 201 | ## Nb: they must all use the REGPARM(n) attribute. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 202 | void, new_mem_stack_4, Addr new_ESP |
| 203 | void, new_mem_stack_8, Addr new_ESP |
| 204 | void, new_mem_stack_12, Addr new_ESP |
| 205 | void, new_mem_stack_16, Addr new_ESP |
| 206 | void, new_mem_stack_32, Addr new_ESP |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 207 | void, new_mem_stack, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 208 | |
| 209 | void, die_mem_stack_4, Addr die_ESP |
| 210 | void, die_mem_stack_8, Addr die_ESP |
| 211 | void, die_mem_stack_12, Addr die_ESP |
| 212 | void, die_mem_stack_16, Addr die_ESP |
| 213 | void, die_mem_stack_32, Addr die_ESP |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 214 | void, die_mem_stack, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 215 | |
| 216 | ## Used for redzone at end of thread stacks |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 217 | void, ban_mem_stack, Addr a, SizeT len |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 218 | |
| 219 | ## These ones occur around syscalls, signal handling, etc |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 220 | void, pre_mem_read, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 221 | void, pre_mem_read_asciiz, CorePart part, ThreadId tid, Char* s, Addr a |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 222 | void, pre_mem_write, CorePart part, ThreadId tid, Char* s, Addr a, SizeT size |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 223 | ## Not implemented yet -- have to add in lots of places, which is a |
| 224 | ## pain. Won't bother unless/until there's a need. |
nethercote | 451eae9 | 2004-11-02 13:06:32 +0000 | [diff] [blame] | 225 | ## void (*post_mem_read) ( ThreadState* tst, Char* s, Addr a, SizeT size ); |
| 226 | void, post_mem_write, Addr a, SizeT size |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 227 | |
| 228 | |
| 229 | ## Register events -- if `shadow_regs' need is set, all should probably be |
| 230 | ## used. Use VG_(set_thread_shadow_archreg)() to set the shadow of the |
| 231 | ## changed register. |
| 232 | |
| 233 | ## Use VG_(set_shadow_archreg)() to set the eight general purpose regs, |
| 234 | ## and use VG_(set_shadow_eflags)() to set eflags. |
| 235 | void, post_regs_write_init, void |
| 236 | |
| 237 | ## Use VG_(set_thread_shadow_archreg)() to set the shadow regs for these |
| 238 | ## events. |
| 239 | void, post_reg_write_syscall_return, ThreadId tid, UInt reg |
| 240 | void, post_reg_write_deliver_signal, ThreadId tid, UInt reg |
| 241 | void, post_reg_write_pthread_return, ThreadId tid, UInt reg |
| 242 | void, post_reg_write_clientreq_return, ThreadId tid, UInt reg |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 243 | ## This one is called for malloc() et al if they are replaced by a tool. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 244 | void, post_reg_write_clientcall_return, ThreadId tid, UInt reg, Addr f |
| 245 | |
| 246 | |
| 247 | ## Scheduler events (not exhaustive) |
| 248 | void, thread_run, ThreadId tid |
| 249 | |
| 250 | |
| 251 | ## Thread events (not exhaustive) |
| 252 | |
| 253 | ## Called during thread create, before the new thread has run any |
| 254 | ## instructions (or touched any memory). |
| 255 | void, post_thread_create, ThreadId tid, ThreadId child |
| 256 | void, post_thread_join, ThreadId joiner, ThreadId joinee |
| 257 | |
| 258 | |
| 259 | ## Mutex events (not exhaustive) |
| 260 | ## "void *mutex" is really a pthread_mutex * |
| 261 | |
| 262 | ## Called before a thread can block while waiting for a mutex (called |
| 263 | ## regardless of whether the thread will block or not). |
| 264 | void, pre_mutex_lock, ThreadId tid, void* mutex |
| 265 | ## Called once the thread actually holds the mutex (always paired with |
| 266 | ## pre_mutex_lock). |
| 267 | void, post_mutex_lock, ThreadId tid, void* mutex |
| 268 | ## Called after a thread has released a mutex (no need for a corresponding |
| 269 | ## pre_mutex_unlock, because unlocking can't block). |
| 270 | void, post_mutex_unlock, ThreadId tid, void* mutex |
| 271 | |
| 272 | ## Signal events (not exhaustive) |
| 273 | |
| 274 | ## ... pre_send_signal, post_send_signal ... |
| 275 | |
| 276 | ## Called before a signal is delivered; `alt_stack' indicates if it is |
| 277 | ## delivered on an alternative stack. |
| 278 | void, pre_deliver_signal, ThreadId tid, Int sigNo, Bool alt_stack |
| 279 | ## Called after a signal is delivered. Nb: unfortunately, if the signal |
| 280 | ## handler longjmps, this won't be called. |
| 281 | void, post_deliver_signal, ThreadId tid, Int sigNo |
| 282 | |
| 283 | |
| 284 | ## Others... condition variable... |
| 285 | ## ... |
| 286 | |
| 287 | ## Shadow memory management |
| 288 | void, init_shadow_page, Addr p |
| 289 | |
| 290 | ## ================================================================================ |
| 291 | ## malloc and friends |
| 292 | :malloc |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 293 | void*, malloc, SizeT n |
| 294 | void*, __builtin_new, SizeT n |
| 295 | void*, __builtin_vec_new, SizeT n |
| 296 | void*, memalign, SizeT align, SizeT n |
| 297 | void*, calloc, SizeT nmemb, SizeT n |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 298 | void, free, void* p |
| 299 | void, __builtin_delete, void* p |
| 300 | void, __builtin_vec_delete, void* p |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 301 | void*, realloc, void* p, SizeT size |