njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame^] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Code redirections. pub_core_redir.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_REDIR_H |
| 32 | #define __PUB_CORE_REDIR_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module deals with: |
| 36 | // - code redirection: intercepting calls to client functions, and |
| 37 | // pointing them to a different piece of code. |
| 38 | // - function wrapping: add calls to code before and after client |
| 39 | // functions execute, for inspection and/or modification. |
| 40 | // |
| 41 | // Nb: It's possible that this should be two modules. |
| 42 | //-------------------------------------------------------------------- |
| 43 | |
| 44 | /* Redirection machinery */ |
| 45 | extern Addr VG_(code_redirect) ( Addr orig ); |
| 46 | |
| 47 | /* Set up some default redirects */ |
| 48 | extern void VG_(setup_code_redirect_table) ( void ); |
| 49 | |
| 50 | extern void VG_(add_redirect_sym_to_addr)(const Char *from_lib, |
| 51 | const Char *from_sym, |
| 52 | Addr to_addr); |
| 53 | extern void VG_(add_redirect_addr_to_addr)(Addr from_addr, Addr to_addr); |
| 54 | extern void VG_(resolve_seg_redirs)(SegInfo *si); |
| 55 | |
| 56 | /* Wrapping machinery */ |
| 57 | enum return_type { |
| 58 | RT_RETURN, |
| 59 | RT_LONGJMP, |
| 60 | RT_EXIT, |
| 61 | }; |
| 62 | |
| 63 | typedef struct _FuncWrapper FuncWrapper; |
| 64 | struct _FuncWrapper { |
| 65 | void *(*before)(va_list args); |
| 66 | void (*after) (void *nonce, enum return_type, Word retval); |
| 67 | }; |
| 68 | |
| 69 | extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper); |
| 70 | extern const FuncWrapper *VG_(is_wrapped)(Addr eip); |
| 71 | extern Bool VG_(is_wrapper_return)(Addr eip); |
| 72 | |
| 73 | /* Primary interface for adding wrappers for client-side functions. */ |
| 74 | extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym, |
| 75 | const FuncWrapper *wrapper); |
| 76 | |
| 77 | extern Bool VG_(is_resolved)(const CodeRedirect *redir); |
| 78 | |
| 79 | #endif // __PUB_CORE_REDIR_H |
| 80 | |
| 81 | /*--------------------------------------------------------------------*/ |
| 82 | /*--- end ---*/ |
| 83 | /*--------------------------------------------------------------------*/ |