Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:59:10

0001 
0002 /*--------------------------------------------------------------------*/
0003 /*--- The core/tool interface.                pub_tool_tooliface.h ---*/
0004 /*--------------------------------------------------------------------*/
0005 
0006 /*
0007    This file is part of Valgrind, a dynamic binary instrumentation
0008    framework.
0009 
0010    Copyright (C) 2000-2017 Julian Seward
0011       jseward@acm.org
0012 
0013    This program is free software; you can redistribute it and/or
0014    modify it under the terms of the GNU General Public License as
0015    published by the Free Software Foundation; either version 2 of the
0016    License, or (at your option) any later version.
0017 
0018    This program is distributed in the hope that it will be useful, but
0019    WITHOUT ANY WARRANTY; without even the implied warranty of
0020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0021    General Public License for more details.
0022 
0023    You should have received a copy of the GNU General Public License
0024    along with this program; if not, see <http://www.gnu.org/licenses/>.
0025 
0026    The GNU General Public License is contained in the file COPYING.
0027 */
0028 
0029 #ifndef __PUB_TOOL_TOOLIFACE_H
0030 #define __PUB_TOOL_TOOLIFACE_H
0031 
0032 #include "pub_tool_errormgr.h"   // for Error, Supp
0033 #include "libvex.h"              // for all Vex stuff
0034 
0035 /* ------------------------------------------------------------------ */
0036 /* The interface version */
0037 
0038 /* Initialise tool.   Must do the following:
0039    - initialise the `details' struct, via the VG_(details_*)() functions
0040    - register the basic tool functions, via VG_(basic_tool_funcs)().
0041    May do the following:
0042    - initialise the `needs' struct to indicate certain requirements, via
0043      the VG_(needs_*)() functions
0044    - any other tool-specific initialisation
0045 */
0046 extern void (*VG_(tl_pre_clo_init)) ( void );
0047 
0048 /* Every tool must include this macro somewhere, exactly once.  The
0049    interface version is no longer relevant, but we kept the same name
0050    to avoid requiring changes to tools.
0051 */
0052 #define VG_DETERMINE_INTERFACE_VERSION(pre_clo_init) \
0053    void (*VG_(tl_pre_clo_init)) ( void ) = pre_clo_init;
0054 
0055 /* ------------------------------------------------------------------ */
0056 /* Basic tool functions */
0057 
0058 /* The tool_instrument function is passed as a callback to
0059    LibVEX_Translate.  VgCallbackClosure carries additional info
0060    which the instrumenter might like to know, but which is opaque to
0061    Vex.
0062 */
0063 typedef 
0064    struct {
0065       Addr     nraddr; /* non-redirected guest address */
0066       Addr     readdr; /* redirected guest address */
0067       ThreadId tid;    /* tid requesting translation */
0068    }
0069    VgCallbackClosure;
0070 
0071 extern void VG_(basic_tool_funcs)(
0072    // Do any initialisation that can only be done after command line
0073    // processing.
0074    void  (*post_clo_init)(void),
0075 
0076    // Instrument a basic block.  Must be a true function, ie. the same
0077    // input always results in the same output, because basic blocks
0078    // can be retranslated, unless you're doing something really
0079    // strange.  Anyway, the arguments.  Mostly they are straightforward
0080    // except for the distinction between redirected and non-redirected
0081    // guest code addresses, which is important to understand.
0082    //
0083    // VgCallBackClosure* closure contains extra arguments passed
0084    // from Valgrind to the instrumenter, which Vex doesn't know about.
0085    // You are free to look inside this structure.
0086    //
0087    // * closure->tid is the ThreadId of the thread requesting the
0088    //   translation.  Not sure why this is here; perhaps callgrind
0089    //   uses it.
0090    //
0091    // * closure->nraddr is the non-redirected guest address of the
0092    //   start of the translation.  In other words, the translation is
0093    //   being constructed because the guest program jumped to 
0094    //   closure->nraddr but no translation of it was found.
0095    //
0096    // * closure->readdr is the redirected guest address, from which
0097    //   the translation was really made.
0098    //
0099    //   To clarify this, consider what happens when, in Memcheck, the
0100    //   first call to malloc() happens.  The guest program will be
0101    //   trying to jump to malloc() in libc; hence ->nraddr will contain
0102    //   that address.  However, Memcheck intercepts and replaces
0103    //   malloc, hence ->readdr will be the address of Memcheck's
0104    //   malloc replacement in
0105    //   coregrind/m_replacemalloc/vg_replacemalloc.c.  It follows
0106    //   that the first IMark in the translation will be labelled as
0107    //   from ->readdr rather than ->nraddr.
0108    //
0109    //   Since most functions are not redirected, the majority of the
0110    //   time ->nraddr will be the same as ->readdr.  However, you
0111    //   cannot assume this: if your tool has metadata associated
0112    //   with code addresses it will get into deep trouble if it does
0113    //   make this assumption.
0114    //
0115    // IRSB* sb_in is the incoming superblock to be instrumented,
0116    // in flat IR form.
0117    //
0118    // VexGuestLayout* layout contains limited info on the layout of
0119    // the guest state: where the stack pointer and program counter
0120    // are, and which fields should be regarded as 'always defined'.
0121    // Memcheck uses this.
0122    //
0123    // VexGuestExtents* vge points to a structure which states the
0124    // precise byte ranges of original code from which this translation
0125    // was made (there may be up to three different ranges involved).
0126    // Note again that these are the real addresses from which the code
0127    // came.  And so it should be the case that closure->readdr is the
0128    // same as vge->base[0]; indeed Cachegrind contains this assertion.
0129    //
0130    // Tools which associate shadow data with code addresses
0131    // (cachegrind, callgrind) need to be particularly clear about
0132    // whether they are making the association with redirected or
0133    // non-redirected code addresses.  Both approaches are viable
0134    // but you do need to understand what's going on.  See comments
0135    // below on discard_basic_block_info().
0136    //
0137    // IRType gWordTy and IRType hWordTy contain the types of native
0138    // words on the guest (simulated) and host (real) CPUs.  They will
0139    // by either Ity_I32 or Ity_I64.  So far we have never built a
0140    // cross-architecture Valgrind so they should always be the same.
0141    //
0142    /* --- Further comments about the IR that your --- */
0143    /* --- instrumentation function will receive. --- */
0144    /*
0145       In the incoming IRSB, the IR for each instruction begins with an
0146       IRStmt_IMark, which states the address and length of the
0147       instruction from which this IR came.  This makes it easy for
0148       profiling-style tools to know precisely which guest code
0149       addresses are being executed.
0150 
0151       However, before the first IRStmt_IMark, there may be other IR
0152       statements -- a preamble.  In most cases this preamble is empty,
0153       but when it isn't, what it contains is some supporting IR that
0154       the JIT uses to ensure control flow works correctly.  This
0155       preamble does not modify any architecturally defined guest state
0156       (registers or memory) and so does not contain anything that will
0157       be of interest to your tool.
0158 
0159       You should therefore 
0160 
0161       (1) copy any IR preceding the first IMark verbatim to the start
0162           of the output IRSB.
0163 
0164       (2) not try to instrument it or modify it in any way.
0165 
0166       For the record, stuff that may be in the preamble at
0167       present is:
0168 
0169       - A self-modifying-code check has been requested for this block.
0170         The preamble will contain instructions to checksum the block,
0171         compare against the expected value, and exit the dispatcher
0172         requesting a discard (hence forcing a retranslation) if they
0173         don't match.
0174 
0175       - This block is known to be the entry point of a wrapper of some
0176         function F.  In this case the preamble contains code to write
0177         the address of the original F (the fn being wrapped) into a
0178         'hidden' guest state register _NRADDR.  The wrapper can later
0179         read this register using a client request and make a
0180         non-redirected call to it using another client-request-like
0181         magic macro.
0182 
0183       - For platforms that use the AIX ABI (including ppc64-linux), it
0184         is necessary to have a preamble even for replacement functions
0185         (not just for wrappers), because it is necessary to switch the
0186         R2 register (constant-pool pointer) to a different value when
0187         swizzling the program counter.
0188 
0189         Hence the preamble pushes both R2 and LR (the return address)
0190         on a small 16-entry stack in the guest state and sets R2 to an
0191         appropriate value for the wrapper/replacement fn.  LR is then
0192         set so that the wrapper/replacement fn returns to a magic IR
0193         stub which restores R2 and LR and returns.
0194 
0195         It's all hugely ugly and fragile.  And it places a stringent
0196         requirement on m_debuginfo to find out the correct R2 (toc
0197         pointer) value for the wrapper/replacement function.  So much
0198         so that m_redir will refuse to honour a redirect-to-me request
0199         if it cannot find (by asking m_debuginfo) a plausible R2 value
0200         for 'me'.
0201 
0202         Because this mechanism maintains a shadow stack of (R2,LR)
0203         pairs in the guest state, it will fail if the
0204         wrapper/redirection function, or anything it calls, longjumps
0205         out past the wrapper, because then the magic return stub will
0206         not be run and so the shadow stack will not be popped.  So it
0207         will quickly fill up.  Fortunately none of this applies to
0208         {x86,amd64,ppc32}-linux; on those platforms, wrappers can
0209         longjump and recurse arbitrarily and everything should work
0210         fine.
0211 
0212       Note that copying the preamble verbatim may cause complications
0213       for your instrumenter if you shadow IR temporaries.  See big
0214       comment in MC_(instrument) in memcheck/mc_translate.c for
0215       details.
0216    */
0217    IRSB*(*instrument)(VgCallbackClosure* closure, 
0218                       IRSB*              sb_in, 
0219                       const VexGuestLayout*  layout, 
0220                       const VexGuestExtents* vge, 
0221                       const VexArchInfo*     archinfo_host,
0222                       IRType             gWordTy, 
0223                       IRType             hWordTy),
0224 
0225    // Finish up, print out any results, etc.  `exitcode' is program's exit
0226    // code.  The shadow can be found with VG_(get_exit_status_shadow)().
0227    void  (*fini)(Int)
0228 );
0229 
0230 /* ------------------------------------------------------------------ */
0231 /* Details */
0232 
0233 /* Default value for avg_translations_sizeB (in bytes), indicating typical
0234    code expansion of about 6:1. */
0235 #define VG_DEFAULT_TRANS_SIZEB   172
0236 
0237 /* Information used in the startup message.  `name' also determines the
0238    string used for identifying suppressions in a suppression file as
0239    belonging to this tool.  `version' can be NULL, in which case (not
0240    surprisingly) no version info is printed; this mechanism is designed for
0241    tools distributed with Valgrind that share a version number with
0242    Valgrind.  Other tools not distributed as part of Valgrind should
0243    probably have their own version number.  */
0244 extern void VG_(details_name)                  ( const HChar* name );
0245 extern void VG_(details_version)               ( const HChar* version );
0246 extern void VG_(details_description)           ( const HChar* description );
0247 extern void VG_(details_copyright_author)      ( const HChar* copyright_author );
0248 
0249 /* Average size of a translation, in bytes, so that the translation
0250    storage machinery can allocate memory appropriately.  Not critical,
0251    setting is optional. */
0252 extern void VG_(details_avg_translation_sizeB) ( UInt size );
0253 
0254 /* String printed if an `tl_assert' assertion fails or VG_(tool_panic)
0255    is called.  Should probably be an email address. */
0256 extern void VG_(details_bug_reports_to)   ( const HChar* bug_reports_to );
0257 
0258 /* ------------------------------------------------------------------ */
0259 /* Needs */
0260 
0261 /* Should __libc_freeres() be run?  Bugs in it can crash the tool. */
0262 extern void VG_(needs_libc_freeres) ( void );
0263 
0264 /* Should __gnu_cxx::__freeres() be run?  Bugs in it can crash the tool. */
0265 extern void VG_(needs_cxx_freeres) ( void );
0266 
0267 /* Want to have errors detected by Valgrind's core reported?  Includes:
0268    - pthread API errors (many;  eg. unlocking a non-locked mutex) 
0269      [currently disabled]
0270    - invalid file descriptors to syscalls like read() and write()
0271    - bad signal numbers passed to sigaction()
0272    - attempt to install signal handler for SIGKILL or SIGSTOP */
0273 extern void VG_(needs_core_errors) ( void );
0274 
0275 /* Booleans that indicate extra operations are defined;  if these are True,
0276    the corresponding template functions (given below) must be defined.  A
0277    lot like being a member of a type class. */
0278 
0279 /* Want to report errors from tool?  This implies use of suppressions, too. */
0280 extern void VG_(needs_tool_errors) (
0281    // Identify if two errors are equal, or close enough.  This function is
0282    // only called if e1 and e2 will have the same error kind.  `res' indicates
0283    // how close is "close enough".  `res' should be passed on as necessary,
0284    // eg. if the Error's `extra' part contains an ExeContext, `res' should be
0285    // passed to VG_(eq_ExeContext)() if the ExeContexts are considered.  Other
0286    // than that, probably don't worry about it unless you have lots of very
0287    // similar errors occurring.
0288    Bool (*eq_Error)(VgRes res, const Error* e1, const Error* e2),
0289 
0290    // We give tools a chance to have a look at errors
0291    // just before they are printed.  That is, before_pp_Error is 
0292    // called just before pp_Error itself.  This gives the tool a
0293    // chance to look at the just-about-to-be-printed error, so as to 
0294    // emit any arbitrary output if wants to, before the error itself
0295    // is printed.  This functionality was added to allow Helgrind to
0296    // print thread-announcement messages immediately before the 
0297    // errors that refer to them.
0298    void (*before_pp_Error)(const Error* err),
0299 
0300    // Print error context.
0301    void (*pp_Error)(const Error* err),
0302 
0303    // Should the core indicate which ThreadId each error comes from?
0304    Bool show_ThreadIDs_for_errors,
0305 
0306    // Should fill in any details that could be postponed until after the
0307    // decision whether to ignore the error (ie. details not affecting the
0308    // result of VG_(tdict).tool_eq_Error()).  This saves time when errors
0309    // are ignored.
0310    // Yuk.
0311    // Return value: must be the size of the `extra' part in bytes -- used by
0312    // the core to make a copy.
0313    UInt (*update_extra)(const Error* err),
0314 
0315    // Return value indicates recognition.  If recognised, must set skind using
0316    // VG_(set_supp_kind)().
0317    Bool (*recognised_suppression)(const HChar* name, Supp* su),
0318 
0319    // Read any extra info for this suppression kind.  Most likely for filling
0320    // in the `extra' and `string' parts (with VG_(set_supp_{extra, string})())
0321    // of a suppression if necessary.  Should return False if a syntax error
0322    // occurred, True otherwise.
0323    // fd, bufpp, nBufp and lineno are the same as for VG_(get_line).
0324    Bool (*read_extra_suppression_info)(Int fd, HChar** bufpp, SizeT* nBufp,
0325                                        Int* lineno, Supp* su),
0326 
0327    // This should just check the kinds match and maybe some stuff in the
0328    // `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
0329    // get the relevant suppression parts).
0330    Bool (*error_matches_suppression)(const Error* err, const Supp* su),
0331 
0332    // This should return the suppression name, for --gen-suppressions, or NULL
0333    // if that error type cannot be suppressed.  This is the inverse of
0334    // VG_(tdict).tool_recognised_suppression().
0335    const HChar* (*get_error_name)(const Error* err),
0336 
0337    // This should print into buf[0..nBuf-1] any extra info for the
0338    // error, for --gen-suppressions, but not including any leading
0339    // spaces nor a trailing newline.  The string needs to be null 
0340    // terminated. If the buffer is large enough to hold the string
0341    // including the terminating null character the function shall
0342    // return the value that strlen would return for the string.
0343    // If the buffer is too small the function shall return nBuf.
0344    SizeT (*print_extra_suppression_info)(const Error* err,
0345                                          /*OUT*/HChar* buf, Int nBuf),
0346 
0347    // This is similar to print_extra_suppression_info, but is used
0348    // to print information such as additional statistical counters
0349    // as part of the used suppression list produced by -v.
0350    SizeT (*print_extra_suppression_use)(const Supp* su,
0351                                         /*OUT*/HChar* buf, Int nBuf),
0352 
0353    // Called by error mgr once it has been established that err
0354    // is suppressed by su. update_extra_suppression_use typically
0355    // can be used to update suppression extra information such as
0356    // some statistical counters that will be printed by
0357    // print_extra_suppression_use.
0358    void (*update_extra_suppression_use)(const Error* err, const Supp* su)
0359 );
0360 
0361 /* Is information kept by the tool about specific instructions or
0362    translations?  (Eg. for cachegrind there are cost-centres for every
0363    instruction, stored in a per-translation fashion.)  If so, the info
0364    may have to be discarded when translations are unloaded (eg. due to
0365    .so unloading, or otherwise at the discretion of m_transtab, eg
0366    when the table becomes too full) to avoid stale information being
0367    reused for new translations. */
0368 extern void VG_(needs_superblock_discards) (
0369    // Discard any information that pertains to specific translations
0370    // or instructions within the address range given.  There are two
0371    // possible approaches.
0372    // - If info is being stored at a per-translation level, use orig_addr
0373    //   to identify which translation is being discarded.  Each translation
0374    //   will be discarded exactly once.
0375    //   This orig_addr will match the closure->nraddr which was passed to
0376    //   to instrument() (see extensive comments above) when this 
0377    //   translation was made.  Note that orig_addr won't necessarily be 
0378    //   the same as the first address in "extents".
0379    // - If info is being stored at a per-instruction level, you can get
0380    //   the address range(s) being discarded by stepping through "extents".
0381    //   Note that any single instruction may belong to more than one
0382    //   translation, and so could be covered by the "extents" of more than
0383    //   one call to this function.
0384    // Doing it the first way (as eg. Cachegrind does) is probably easier.
0385    void (*discard_superblock_info)(Addr orig_addr, VexGuestExtents extents)
0386 );
0387 
0388 /* Tool defines its own command line options? */
0389 extern void VG_(needs_command_line_options) (
0390    // Return True if option was recognised, False if it wasn't (but also see
0391    // below).  Presumably sets some state to record the option as well.  
0392    //
0393    // Nb: tools can assume that the argv will never disappear.  So they can,
0394    // for example, store a pointer to a string within an option, rather than
0395    // having to make a copy.
0396    //
0397    // Options (and combinations of options) should be checked in this function
0398    // if possible rather than in post_clo_init(), and if they are bad then
0399    // VG_(fmsg_bad_option)() should be called.  This ensures that the
0400    // messaging is consistent with command line option errors from the core.
0401    Bool (*process_cmd_line_option)(const HChar* argv),
0402 
0403    // Print out command line usage for options for normal tool operation.
0404    void (*print_usage)(void),
0405 
0406    // Print out command line usage for options for debugging the tool.
0407    void (*print_debug_usage)(void)
0408 );
0409 
0410 /* Tool defines its own client requests? */
0411 extern void VG_(needs_client_requests) (
0412    // If using client requests, the number of the first request should be equal
0413    // to VG_USERREQ_TOOL_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two
0414    // character identification for the string.  The second and subsequent
0415    // requests should follow.
0416    //
0417    // This function should use the VG_IS_TOOL_USERREQ macro (in
0418    // include/valgrind.h) to first check if it's a request for this tool.  Then
0419    // should handle it if it's recognised (and return True), or return False if
0420    // not recognised.  arg_block[0] holds the request number, any further args
0421    // from the request are in arg_block[1..].  'ret' is for the return value...
0422    // it should probably be filled, if only with 0.
0423    Bool (*handle_client_request)(ThreadId tid, UWord* arg_block, UWord* ret)
0424 );
0425 
0426 /* Tool does stuff before and/or after system calls? */
0427 // Nb: If either of the pre_ functions malloc() something to return, the
0428 // corresponding post_ function had better free() it!
0429 // Also, the args are the 'original args' -- that is, it may be
0430 // that the syscall pre-wrapper will modify the args before the
0431 // syscall happens.  So these args are the original, un-modified
0432 // args.  Finally, nArgs merely indicates the length of args[..],
0433 // it does not indicate how many of those values are actually
0434 // relevant to the syscall.  args[0 .. nArgs-1] is guaranteed
0435 // to be defined and to contain all the args for this syscall,
0436 // possibly including some trailing zeroes.
0437 extern void VG_(needs_syscall_wrapper) (
0438                void (* pre_syscall)(ThreadId tid, UInt syscallno,
0439                                     UWord* args, UInt nArgs),
0440                void (*post_syscall)(ThreadId tid, UInt syscallno,
0441                                     UWord* args, UInt nArgs, SysRes res)
0442 );
0443 
0444 /* Are tool-state sanity checks performed? */
0445 // Can be useful for ensuring a tool's correctness.  cheap_sanity_check()
0446 // is called very frequently;  expensive_sanity_check() is called less
0447 // frequently and can be more involved.
0448 extern void VG_(needs_sanity_checks) (
0449    Bool(*cheap_sanity_check)(void),
0450    Bool(*expensive_sanity_check)(void)
0451 );
0452 
0453 /* Can the tool produce stats during execution? */
0454 extern void VG_(needs_print_stats) (
0455    // Print out tool status. Note that the stats at end of execution
0456    // should be output by the VG_(basic_tool_funcs) "fini" function.
0457    void (*print_stats)(void)
0458 );
0459 
0460 /* Has the tool a tool specific function to retrieve and print location info
0461    of an address ? */
0462 extern void VG_(needs_info_location) (
0463    // Get and pp information about Addr
0464    void (*info_location)(DiEpoch, Addr)
0465 );
0466 
0467 /* Do we need to see variable type and location information? */
0468 extern void VG_(needs_var_info) ( void );
0469 
0470 /* Does the tool replace malloc() and friends with its own versions?
0471    This has to be combined with the use of a vgpreload_<tool>.so module
0472    or it won't work.  See massif/Makefile.am for how to build it. */
0473 // The 'p' prefix avoids GCC complaints about overshadowing global names.
0474 extern void VG_(needs_malloc_replacement)(
0475    void* (*pmalloc)               ( ThreadId tid, SizeT n ),
0476    void* (*p__builtin_new)        ( ThreadId tid, SizeT n ),
0477    void* (*p__builtin_new_aligned)( ThreadId tid, SizeT n, SizeT align ),
0478    void* (*p__builtin_vec_new)    ( ThreadId tid, SizeT n ),
0479    void* (*p__builtin_vec_new_aligned)( ThreadId tid, SizeT n, SizeT align ),
0480    void* (*pmemalign)             ( ThreadId tid, SizeT align, SizeT n ),
0481    void* (*pcalloc)               ( ThreadId tid, SizeT nmemb, SizeT size1 ),
0482    void  (*pfree)                 ( ThreadId tid, void* p ),
0483    void  (*p__builtin_delete)     ( ThreadId tid, void* p ),
0484    void  (*p__builtin_delete_aligned)     ( ThreadId tid, void* p, SizeT align ),
0485    void  (*p__builtin_vec_delete) ( ThreadId tid, void* p ),
0486    void  (*p__builtin_vec_delete_aligned) ( ThreadId tid, void* p, SizeT align ),
0487    void* (*prealloc)              ( ThreadId tid, void* p, SizeT new_size ),
0488    SizeT (*pmalloc_usable_size)   ( ThreadId tid, void* p), 
0489    SizeT client_malloc_redzone_szB
0490 );
0491 
0492 /* Can the tool do XML output?  This is a slight misnomer, because the tool
0493  * is not requesting the core to do anything, rather saying "I can handle
0494  * it". */
0495 extern void VG_(needs_xml_output) ( void );
0496 
0497 /* Does the tool want to have one final pass over the IR after tree
0498    building but before instruction selection?  If so specify the
0499    function here. */
0500 extern void VG_(needs_final_IR_tidy_pass) ( IRSB*(*final_tidy)(IRSB*) );
0501 
0502 
0503 /* ------------------------------------------------------------------ */
0504 /* Core events to track */
0505 
0506 /* Part of the core from which this call was made.  Useful for determining
0507    what kind of error message should be emitted. */
0508 typedef
0509    enum { Vg_CoreStartup=1, Vg_CoreSignal, Vg_CoreSysCall,
0510           // This is for platforms where syscall args are passed on the
0511           // stack; although pre_mem_read is the callback that will be
0512           // called, such an arg should be treated (with respect to
0513           // presenting information to the user) as if it was passed in a
0514           // register, ie. like pre_reg_read.
0515           Vg_CoreSysCallArgInMem,  
0516           Vg_CoreTranslate, Vg_CoreClientReq
0517    } CorePart;
0518 
0519 /* Events happening in core to track.  To be notified, pass a callback
0520    function to the appropriate function.  To ignore an event, don't do
0521    anything (the default is for events to be ignored).
0522 
0523    Note that most events aren't passed a ThreadId.  If the event is one called
0524    from generated code (eg. new_mem_stack_*), you can use
0525    VG_(get_running_tid)() to find it.  Otherwise, it has to be passed in,
0526    as in pre_mem_read, and so the event signature will require changing.
0527 
0528    Memory events (Nb: to track heap allocation/freeing, a tool must replace
0529    malloc() et al.  See above how to do this.)
0530 
0531    These ones occur at startup, upon some signals, and upon some syscalls.
0532 
0533    For new_mem_brk and new_mem_stack_signal, the supplied ThreadId
0534    indicates the thread for whom the new memory is being allocated.
0535 
0536    For new_mem_startup and new_mem_mmap, the di_handle argument is a
0537    handle which can be used to retrieve debug info associated with the
0538    mapping or allocation (because it is of a file that Valgrind has
0539    decided to read debug info from).  If the value is zero, there is
0540    no associated debug info.  If the value exceeds zero, it can be
0541    supplied as an argument to selected queries in m_debuginfo.
0542 */
0543 void VG_(track_new_mem_startup)     (void(*f)(Addr a, SizeT len,
0544                                               Bool rr, Bool ww, Bool xx,
0545                                               ULong di_handle));
0546 void VG_(track_new_mem_stack_signal)(void(*f)(Addr a, SizeT len, ThreadId tid));
0547 void VG_(track_new_mem_brk)         (void(*f)(Addr a, SizeT len, ThreadId tid));
0548 void VG_(track_new_mem_mmap)        (void(*f)(Addr a, SizeT len,
0549                                               Bool rr, Bool ww, Bool xx,
0550                                               ULong di_handle));
0551 
0552 void VG_(track_copy_mem_remap)      (void(*f)(Addr from, Addr to, SizeT len));
0553 void VG_(track_change_mem_mprotect) (void(*f)(Addr a, SizeT len,
0554                                               Bool rr, Bool ww, Bool xx));
0555 void VG_(track_die_mem_stack_signal)(void(*f)(Addr a, SizeT len));
0556 void VG_(track_die_mem_brk)         (void(*f)(Addr a, SizeT len));
0557 void VG_(track_die_mem_munmap)      (void(*f)(Addr a, SizeT len));
0558 
0559 /* These ones are called when SP changes.  A tool could track these itself
0560    (except for ban_mem_stack) but it's much easier to use the core's help.
0561 
0562    The specialised ones are called in preference to the general one, if they
0563    are defined.  These functions are called a lot if they are used, so
0564    specialising can optimise things significantly.  If any of the
0565    specialised cases are defined, the general case must be defined too.
0566 
0567    Nb: all the specialised ones must use the VG_REGPARM(n) attribute.
0568 
0569    For the _new functions, a tool may specify with with-ECU
0570    (ExeContext Unique) or without-ECU version for each size, but not
0571    both.  If the with-ECU version is supplied, then the core will
0572    arrange to pass, as the ecu argument, a 32-bit int which uniquely
0573    identifies the instruction moving the stack pointer down.  This
0574    32-bit value is as obtained from VG_(get_ECU_from_ExeContext).
0575    VG_(get_ExeContext_from_ECU) can then be used to retrieve the
0576    associated depth-1 ExeContext for the location.  All this
0577    complexity is provided to support origin tracking in Memcheck.
0578 */
0579 void VG_(track_new_mem_stack_4_w_ECU)  (VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0580 void VG_(track_new_mem_stack_8_w_ECU)  (VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0581 void VG_(track_new_mem_stack_12_w_ECU) (VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0582 void VG_(track_new_mem_stack_16_w_ECU) (VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0583 void VG_(track_new_mem_stack_32_w_ECU) (VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0584 void VG_(track_new_mem_stack_112_w_ECU)(VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0585 void VG_(track_new_mem_stack_128_w_ECU)(VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0586 void VG_(track_new_mem_stack_144_w_ECU)(VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0587 void VG_(track_new_mem_stack_160_w_ECU)(VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
0588 void VG_(track_new_mem_stack_w_ECU)                  (void(*f)(Addr a, SizeT len,
0589                                                                        UInt ecu));
0590 
0591 void VG_(track_new_mem_stack_4)  (VG_REGPARM(1) void(*f)(Addr new_ESP));
0592 void VG_(track_new_mem_stack_8)  (VG_REGPARM(1) void(*f)(Addr new_ESP));
0593 void VG_(track_new_mem_stack_12) (VG_REGPARM(1) void(*f)(Addr new_ESP));
0594 void VG_(track_new_mem_stack_16) (VG_REGPARM(1) void(*f)(Addr new_ESP));
0595 void VG_(track_new_mem_stack_32) (VG_REGPARM(1) void(*f)(Addr new_ESP));
0596 void VG_(track_new_mem_stack_112)(VG_REGPARM(1) void(*f)(Addr new_ESP));
0597 void VG_(track_new_mem_stack_128)(VG_REGPARM(1) void(*f)(Addr new_ESP));
0598 void VG_(track_new_mem_stack_144)(VG_REGPARM(1) void(*f)(Addr new_ESP));
0599 void VG_(track_new_mem_stack_160)(VG_REGPARM(1) void(*f)(Addr new_ESP));
0600 void VG_(track_new_mem_stack)                  (void(*f)(Addr a, SizeT len));
0601 
0602 void VG_(track_die_mem_stack_4)  (VG_REGPARM(1) void(*f)(Addr die_ESP));
0603 void VG_(track_die_mem_stack_8)  (VG_REGPARM(1) void(*f)(Addr die_ESP));
0604 void VG_(track_die_mem_stack_12) (VG_REGPARM(1) void(*f)(Addr die_ESP));
0605 void VG_(track_die_mem_stack_16) (VG_REGPARM(1) void(*f)(Addr die_ESP));
0606 void VG_(track_die_mem_stack_32) (VG_REGPARM(1) void(*f)(Addr die_ESP));
0607 void VG_(track_die_mem_stack_112)(VG_REGPARM(1) void(*f)(Addr die_ESP));
0608 void VG_(track_die_mem_stack_128)(VG_REGPARM(1) void(*f)(Addr die_ESP));
0609 void VG_(track_die_mem_stack_144)(VG_REGPARM(1) void(*f)(Addr die_ESP));
0610 void VG_(track_die_mem_stack_160)(VG_REGPARM(1) void(*f)(Addr die_ESP));
0611 void VG_(track_die_mem_stack)                  (void(*f)(Addr a, SizeT len));
0612 
0613 /* Used for redzone at end of thread stacks */
0614 void VG_(track_ban_mem_stack)      (void(*f)(Addr a, SizeT len));
0615 
0616 /* Used to report VG_USERREQ__STACK_REGISTER client requests */
0617 void VG_(track_register_stack)     (void(*f)(Addr start, Addr end));
0618 
0619 /* These ones occur around syscalls, signal handling, etc */
0620 void VG_(track_pre_mem_read)       (void(*f)(CorePart part, ThreadId tid,
0621                                              const HChar* s, Addr a, SizeT size));
0622 void VG_(track_pre_mem_read_asciiz)(void(*f)(CorePart part, ThreadId tid,
0623                                              const HChar* s, Addr a));
0624 void VG_(track_pre_mem_write)      (void(*f)(CorePart part, ThreadId tid,
0625                                              const HChar* s, Addr a, SizeT size));
0626 void VG_(track_post_mem_write)     (void(*f)(CorePart part, ThreadId tid,
0627                                              Addr a, SizeT size));
0628 
0629 /* Register events.  Use VG_(set_shadow_state_area)() to set the shadow regs
0630    for these events.  */
0631 void VG_(track_pre_reg_read)  (void(*f)(CorePart part, ThreadId tid,
0632                                         const HChar* s, PtrdiffT guest_state_offset,
0633                                         SizeT size));
0634 void VG_(track_post_reg_write)(void(*f)(CorePart part, ThreadId tid,
0635                                         PtrdiffT guest_state_offset,
0636                                         SizeT size));
0637 
0638 /* This one is called for malloc() et al if they are replaced by a tool. */
0639 void VG_(track_post_reg_write_clientcall_return)(
0640       void(*f)(ThreadId tid, PtrdiffT guest_state_offset, SizeT size, Addr f));
0641 
0642 /* Mem-to-reg or reg-to-mem copy functions, these ones occur around syscalls
0643    and signal handling when the VCPU state is saved to (or restored from) the
0644    client memory. */
0645 void VG_(track_copy_mem_to_reg)(void(*f)(CorePart part, ThreadId tid,
0646                                          Addr a, PtrdiffT guest_state_offset,
0647                                          SizeT size));
0648 void VG_(track_copy_reg_to_mem)(void(*f)(CorePart part, ThreadId tid,
0649                                          PtrdiffT guest_state_offset,
0650                                          Addr a, SizeT size));
0651 
0652 
0653 /* Scheduler events (not exhaustive) */
0654 
0655 /* Called when 'tid' starts or stops running client code blocks.
0656    Gives the total dispatched block count at that event.  Note, this
0657    is not the same as 'tid' holding the BigLock (the lock that ensures
0658    that only one thread runs at a time): a thread can hold the lock
0659    for other purposes (making translations, etc) yet not be running
0660    client blocks.  Obviously though, a thread must hold the lock in
0661    order to run client code blocks, so the times bracketed by
0662    'start_client_code'..'stop_client_code' are a subset of the times
0663    when thread 'tid' holds the cpu lock.
0664 */
0665 void VG_(track_start_client_code)(
0666         void(*f)(ThreadId tid, ULong blocks_dispatched)
0667      );
0668 void VG_(track_stop_client_code)(
0669         void(*f)(ThreadId tid, ULong blocks_dispatched)
0670      );
0671 
0672 
0673 /* Thread events (not exhaustive)
0674 
0675    ll_create: low level thread creation.  Called before the new thread
0676    has run any instructions (or touched any memory).  In fact, called
0677    immediately before the new thread has come into existence; the new
0678    thread can be assumed to exist when notified by this call.
0679 
0680    ll_exit: low level thread exit.  Called after the exiting thread
0681    has run its last instruction.
0682 
0683    The _ll_ part makes it clear these events are not to do with
0684    pthread_create or pthread_exit/pthread_join (etc), which are a
0685    higher level abstraction synthesised by libpthread.  What you can
0686    be sure of from _ll_create/_ll_exit is the absolute limits of each
0687    thread's lifetime, and hence be assured that all memory references
0688    made by the thread fall inside the _ll_create/_ll_exit pair.  This
0689    is important for tools that need a 100% accurate account of which
0690    thread is responsible for every memory reference in the process.
0691 
0692    pthread_create/join/exit do not give this property.  Calls/returns
0693    to/from them happen arbitrarily far away from the relevant
0694    low-level thread create/quit event.  In general a few hundred
0695    instructions; hence a few hundred(ish) memory references could get
0696    misclassified each time.
0697 
0698    pre_thread_first_insn: is called when the thread is all set up and
0699    ready to go (stack in place, etc) but has not executed its first
0700    instruction yet.  Gives threading tools a chance to ask questions
0701    about the thread (eg, what is its initial client stack pointer)
0702    that are not easily answered at pre_thread_ll_create time.
0703 
0704    For a given thread, the call sequence is:
0705       ll_create (in the parent's context)
0706       first_insn (in the child's context)
0707       ll_exit (in the child's context)
0708 */
0709 void VG_(track_pre_thread_ll_create) (void(*f)(ThreadId tid, ThreadId child));
0710 void VG_(track_pre_thread_first_insn)(void(*f)(ThreadId tid));
0711 void VG_(track_pre_thread_ll_exit)   (void(*f)(ThreadId tid));
0712 
0713 
0714 /* Signal events (not exhaustive)
0715 
0716    ... pre_send_signal, post_send_signal ...
0717 
0718    Called before a signal is delivered;  `alt_stack' indicates if it is
0719    delivered on an alternative stack.  */
0720 void VG_(track_pre_deliver_signal) (void(*f)(ThreadId tid, Int sigNo,
0721                                              Bool alt_stack));
0722 /* Called after a signal is delivered.  Nb: unfortunately, if the signal
0723    handler longjmps, this won't be called.  */
0724 void VG_(track_post_deliver_signal)(void(*f)(ThreadId tid, Int sigNo));
0725 
0726 #endif   // __PUB_TOOL_TOOLIFACE_H
0727 
0728 /*--------------------------------------------------------------------*/
0729 /*--- end                                                          ---*/
0730 /*--------------------------------------------------------------------*/