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 |
| 11 | ## are overridden by LD_PRELOADed skin version. At the very least, a skin |
| 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 |
| 31 | ## VG_(get_shadow_archreg)(R_EBX), since %ebx holds the argument to the |
| 32 | ## exit() syscall. |
| 33 | void, fini, Int exitcode |
| 34 | |
| 35 | |
| 36 | ## ------------------------------------------------------------------ |
| 37 | ## VG_(needs).core_errors |
| 38 | |
| 39 | ## (none needed) |
| 40 | |
| 41 | ## ------------------------------------------------------------------ |
| 42 | ## VG_(needs).skin_errors |
| 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. |
| 50 | Bool, eq_SkinError, VgRes res, Error* e1, Error* e2 |
| 51 | |
| 52 | ## Print error context. |
| 53 | void, pp_SkinError, Error* err |
| 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 |
| 57 | ## result of SK_(eq_SkinError)()). This saves time when errors are ignored. |
| 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 |
| 81 | ## SK_(recognised_suppression)(). |
| 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 |
| 86 | ## SK_(read_extra_suppression_info)(). |
| 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. |
| 95 | void, discard_basic_block_info, Addr a, UInt size |
| 96 | |
| 97 | |
| 98 | ## ------------------------------------------------------------------ |
| 99 | ## VG_(needs).shadow_regs |
| 100 | |
| 101 | ## No functions must be defined, but the post_reg[s]_write_* events should |
| 102 | ## be tracked. |
| 103 | |
| 104 | ## ------------------------------------------------------------------ |
| 105 | ## VG_(needs).command_line_options |
| 106 | |
| 107 | ## Return True if option was recognised. Presumably sets some state to |
| 108 | ## record the option as well. |
| 109 | Bool, process_cmd_line_option, Char* argv |
| 110 | |
| 111 | ## Print out command line usage for options for normal skin operation. |
| 112 | void, print_usage |
| 113 | |
| 114 | ## Print out command line usage for options for debugging the skin. |
| 115 | void, print_debug_usage |
| 116 | |
| 117 | ## ------------------------------------------------------------------ |
| 118 | ## VG_(needs).client_requests |
| 119 | |
| 120 | ## If using client requests, the number of the first request should be equal |
| 121 | ## to VG_USERREQ_SKIN_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two |
| 122 | ## character identification for the string. The second and subsequent |
| 123 | ## requests should follow. |
| 124 | |
| 125 | ## This function should use the VG_IS_SKIN_USERREQ macro (in |
| 126 | ## include/valgrind.h) to first check if it's a request for this skin. Then |
| 127 | ## should handle it if it's recognised (and return True), or return False if |
| 128 | ## not recognised. arg_block[0] holds the request number, any further args |
| 129 | ## from the request are in arg_block[1..]. 'ret' is for the return value... |
| 130 | ## it should probably be filled, if only with 0. |
| 131 | Bool, handle_client_request, ThreadId tid, UInt* arg_block, UInt* ret |
| 132 | |
| 133 | |
| 134 | ## ------------------------------------------------------------------ |
| 135 | ## VG_(needs).extends_UCode |
| 136 | |
| 137 | ## 'X' prefix indicates eXtended UCode. |
| 138 | Int, get_Xreg_usage, UInstr* u, Tag tag, Int* regs, Bool* isWrites |
| 139 | void, emit_XUInstr, UInstr* u, RRegSet regs_live_before |
| 140 | Bool, sane_XUInstr, Bool beforeRA, Bool beforeLiveness, UInstr* u |
| 141 | Char *, name_XUOpcode, Opcode opc |
| 142 | void, pp_XUInstr, UInstr* u |
| 143 | |
| 144 | |
| 145 | ## ------------------------------------------------------------------ |
| 146 | ## VG_(needs).syscall_wrapper |
| 147 | |
| 148 | ## If either of the pre_ functions malloc() something to return, the |
| 149 | ## corresponding post_ function had better free() it! |
| 150 | |
| 151 | void *, pre_syscall, ThreadId tid, UInt syscallno, Bool is_blocking |
| 152 | void, post_syscall, ThreadId tid, UInt syscallno, void* pre_result, Int res, Bool is_blocking |
| 153 | |
| 154 | |
| 155 | ## --------------------------------------------------------------------- |
| 156 | ## VG_(needs).sanity_checks |
| 157 | |
| 158 | ## Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check) |
| 159 | ## is called very frequently; SK_(expensive_sanity_check) is called less |
| 160 | ## frequently and can be more involved. |
| 161 | Bool, cheap_sanity_check |
| 162 | Bool, expensive_sanity_check |
| 163 | |
| 164 | |
| 165 | ## ================================================================================ |
| 166 | ## Event tracking functions |
| 167 | :track |
| 168 | |
| 169 | ## Events happening in core to track. To be notified, pass a callback |
| 170 | ## function to the appropriate function. To ignore an event, don't do |
| 171 | ## anything (default is for events to be ignored). |
| 172 | |
| 173 | ## Note that most events aren't passed a ThreadId. To find out the ThreadId |
| 174 | ## of the affected thread, use VG_(get_current_or_recent_tid)(). For the |
| 175 | ## ones passed a ThreadId, use that instead, since |
| 176 | ## VG_(get_current_or_recent_tid)() might not give the right ThreadId in |
| 177 | ## that case. |
| 178 | |
| 179 | ## Memory events (Nb: to track heap allocation/freeing, a skin must replace |
| 180 | ## malloc() et al. See above how to do this.) |
| 181 | |
| 182 | ## These ones occur at startup, upon some signals, and upon some syscalls |
| 183 | void, new_mem_startup, Addr a, UInt len, Bool rr, Bool ww, Bool xx |
| 184 | void, new_mem_stack_signal, Addr a, UInt len |
| 185 | void, new_mem_brk, Addr a, UInt len |
| 186 | void, new_mem_mmap, Addr a, UInt len, Bool rr, Bool ww, Bool xx |
| 187 | |
| 188 | void, copy_mem_remap, Addr from, Addr to, UInt len |
| 189 | void, change_mem_mprotect, Addr a, UInt len, Bool rr, Bool ww, Bool xx |
| 190 | void, die_mem_stack_signal, Addr a, UInt len |
| 191 | void, die_mem_brk, Addr a, UInt len |
| 192 | void, die_mem_munmap, Addr a, UInt len |
| 193 | |
| 194 | ## These ones are called when %esp changes. A skin could track these itself |
| 195 | ## (except for ban_mem_stack) but it's much easier to use the core's help. |
| 196 | |
| 197 | ## The specialised ones are called in preference to the general one, if they |
| 198 | ## are defined. These functions are called a lot if they are used, so |
| 199 | ## specialising can optimise things significantly. If any of the |
| 200 | ## specialised cases are defined, the general case must be defined too. |
| 201 | |
| 202 | ## Nb: they must all use the __attribute__((regparm(n))) attribute. |
| 203 | void, new_mem_stack_4, Addr new_ESP |
| 204 | void, new_mem_stack_8, Addr new_ESP |
| 205 | void, new_mem_stack_12, Addr new_ESP |
| 206 | void, new_mem_stack_16, Addr new_ESP |
| 207 | void, new_mem_stack_32, Addr new_ESP |
| 208 | void, new_mem_stack, Addr a, UInt len |
| 209 | |
| 210 | void, die_mem_stack_4, Addr die_ESP |
| 211 | void, die_mem_stack_8, Addr die_ESP |
| 212 | void, die_mem_stack_12, Addr die_ESP |
| 213 | void, die_mem_stack_16, Addr die_ESP |
| 214 | void, die_mem_stack_32, Addr die_ESP |
| 215 | void, die_mem_stack, Addr a, UInt len |
| 216 | |
| 217 | ## Used for redzone at end of thread stacks |
| 218 | void, ban_mem_stack, Addr a, UInt len |
| 219 | |
| 220 | ## These ones occur around syscalls, signal handling, etc |
| 221 | void, pre_mem_read, CorePart part, ThreadId tid, Char* s, Addr a, UInt size |
| 222 | void, pre_mem_read_asciiz, CorePart part, ThreadId tid, Char* s, Addr a |
| 223 | void, pre_mem_write, CorePart part, ThreadId tid, Char* s, Addr a, UInt size |
| 224 | ## Not implemented yet -- have to add in lots of places, which is a |
| 225 | ## pain. Won't bother unless/until there's a need. |
| 226 | ## void (*post_mem_read) ( ThreadState* tst, Char* s, Addr a, UInt size ); |
| 227 | void, post_mem_write, Addr a, UInt size |
| 228 | |
| 229 | |
| 230 | ## Register events -- if `shadow_regs' need is set, all should probably be |
| 231 | ## used. Use VG_(set_thread_shadow_archreg)() to set the shadow of the |
| 232 | ## changed register. |
| 233 | |
| 234 | ## Use VG_(set_shadow_archreg)() to set the eight general purpose regs, |
| 235 | ## and use VG_(set_shadow_eflags)() to set eflags. |
| 236 | void, post_regs_write_init, void |
| 237 | |
| 238 | ## Use VG_(set_thread_shadow_archreg)() to set the shadow regs for these |
| 239 | ## events. |
| 240 | void, post_reg_write_syscall_return, ThreadId tid, UInt reg |
| 241 | void, post_reg_write_deliver_signal, ThreadId tid, UInt reg |
| 242 | void, post_reg_write_pthread_return, ThreadId tid, UInt reg |
| 243 | void, post_reg_write_clientreq_return, ThreadId tid, UInt reg |
| 244 | ## This one is called for malloc() et al if they are replaced by a skin. |
| 245 | void, post_reg_write_clientcall_return, ThreadId tid, UInt reg, Addr f |
| 246 | |
| 247 | |
| 248 | ## Scheduler events (not exhaustive) |
| 249 | void, thread_run, ThreadId tid |
| 250 | |
| 251 | |
| 252 | ## Thread events (not exhaustive) |
| 253 | |
| 254 | ## Called during thread create, before the new thread has run any |
| 255 | ## instructions (or touched any memory). |
| 256 | void, post_thread_create, ThreadId tid, ThreadId child |
| 257 | void, post_thread_join, ThreadId joiner, ThreadId joinee |
| 258 | |
| 259 | |
| 260 | ## Mutex events (not exhaustive) |
| 261 | ## "void *mutex" is really a pthread_mutex * |
| 262 | |
| 263 | ## Called before a thread can block while waiting for a mutex (called |
| 264 | ## regardless of whether the thread will block or not). |
| 265 | void, pre_mutex_lock, ThreadId tid, void* mutex |
| 266 | ## Called once the thread actually holds the mutex (always paired with |
| 267 | ## pre_mutex_lock). |
| 268 | void, post_mutex_lock, ThreadId tid, void* mutex |
| 269 | ## Called after a thread has released a mutex (no need for a corresponding |
| 270 | ## pre_mutex_unlock, because unlocking can't block). |
| 271 | void, post_mutex_unlock, ThreadId tid, void* mutex |
| 272 | |
| 273 | ## Signal events (not exhaustive) |
| 274 | |
| 275 | ## ... pre_send_signal, post_send_signal ... |
| 276 | |
| 277 | ## Called before a signal is delivered; `alt_stack' indicates if it is |
| 278 | ## delivered on an alternative stack. |
| 279 | void, pre_deliver_signal, ThreadId tid, Int sigNo, Bool alt_stack |
| 280 | ## Called after a signal is delivered. Nb: unfortunately, if the signal |
| 281 | ## handler longjmps, this won't be called. |
| 282 | void, post_deliver_signal, ThreadId tid, Int sigNo |
| 283 | |
| 284 | |
| 285 | ## Others... condition variable... |
| 286 | ## ... |
| 287 | |
| 288 | ## Shadow memory management |
| 289 | void, init_shadow_page, Addr p |
| 290 | |
| 291 | ## ================================================================================ |
| 292 | ## malloc and friends |
| 293 | :malloc |
| 294 | void*, malloc, Int n |
| 295 | void*, __builtin_new, Int n |
| 296 | void*, __builtin_vec_new, Int n |
| 297 | void*, memalign, Int align, Int n |
| 298 | void*, calloc, Int nmemb, Int n |
| 299 | void, free, void* p |
| 300 | void, __builtin_delete, void* p |
| 301 | void, __builtin_vec_delete, void* p |
| 302 | void*, realloc, void* p, Int size |