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: |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame^] | 36 | // - code replacement: intercepting calls to client functions, and |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 37 | // pointing them to a different piece of code. |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame^] | 38 | // - loading notification: telling the core where certain client-space |
| 39 | // functions are when they get loaded. |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 40 | // - function wrapping: add calls to code before and after client |
| 41 | // functions execute, for inspection and/or modification. |
| 42 | // |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame^] | 43 | // It's possible that this should be two or three modules. |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 44 | //-------------------------------------------------------------------- |
| 45 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame^] | 46 | #include "pub_tool_redir.h" |
| 47 | |
| 48 | //-------------------------------------------------------------------- |
| 49 | // General |
| 50 | //-------------------------------------------------------------------- |
| 51 | |
| 52 | // This module needs be told about all the symbols that get loaded, so |
| 53 | // it can check if it needs to do anything special. This is the function |
| 54 | // that does that checking. It modifies 'symbol' in-place by Z-decoding |
| 55 | // it if necessary. |
| 56 | void VG_(maybe_redir_or_notify) ( Char* symbol, Addr addr ); |
| 57 | |
| 58 | //-------------------------------------------------------------------- |
| 59 | // Code replacement |
| 60 | //-------------------------------------------------------------------- |
| 61 | |
| 62 | // See include/pub_tool_redir.h for details on how to do code replacement. |
| 63 | |
| 64 | // This is the crucial redirection function. It answers the question: |
| 65 | // should this code address be redirected somewhere else? It's used just |
| 66 | // before translating a basic block. |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 67 | extern Addr VG_(code_redirect) ( Addr orig ); |
| 68 | |
| 69 | /* Set up some default redirects */ |
| 70 | extern void VG_(setup_code_redirect_table) ( void ); |
| 71 | |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 72 | extern void VG_(resolve_seg_redirs)(SegInfo *si); |
| 73 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame^] | 74 | |
| 75 | //-------------------------------------------------------------------- |
| 76 | // Loading notification |
| 77 | //-------------------------------------------------------------------- |
| 78 | |
| 79 | /* Functions named with this macro have the property that the core will |
| 80 | be told what their address is when they are loaded. This can be useful |
| 81 | if the core wants to call them at some point, and so needs to know their |
| 82 | address. This is a weaker but more general mechanism than code |
| 83 | replacement. |
| 84 | |
| 85 | Functions named with this macro should be in client space, ie. in |
| 86 | vg_preload_<tool>.h or vg_preload_core.h. */ |
| 87 | |
| 88 | #define VG_NOTIFY_ON_LOAD(name) _vgw_##name |
| 89 | #define VG_NOTIFY_ON_LOAD_PREFIX "_vgw_" |
| 90 | #define VG_NOTIFY_ON_LOAD_PREFIX_LEN 5 |
| 91 | |
| 92 | |
| 93 | //-------------------------------------------------------------------- |
| 94 | // Function wrapping |
| 95 | //-------------------------------------------------------------------- |
| 96 | |
| 97 | // This is currently not working(?) --njn |
| 98 | |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 99 | /* Wrapping machinery */ |
| 100 | enum return_type { |
| 101 | RT_RETURN, |
| 102 | RT_LONGJMP, |
| 103 | RT_EXIT, |
| 104 | }; |
| 105 | |
| 106 | typedef struct _FuncWrapper FuncWrapper; |
| 107 | struct _FuncWrapper { |
| 108 | void *(*before)(va_list args); |
| 109 | void (*after) (void *nonce, enum return_type, Word retval); |
| 110 | }; |
| 111 | |
| 112 | extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper); |
| 113 | extern const FuncWrapper *VG_(is_wrapped)(Addr eip); |
| 114 | extern Bool VG_(is_wrapper_return)(Addr eip); |
| 115 | |
| 116 | /* Primary interface for adding wrappers for client-side functions. */ |
| 117 | extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym, |
| 118 | const FuncWrapper *wrapper); |
| 119 | |
| 120 | extern Bool VG_(is_resolved)(const CodeRedirect *redir); |
| 121 | |
| 122 | #endif // __PUB_CORE_REDIR_H |
| 123 | |
| 124 | /*--------------------------------------------------------------------*/ |
| 125 | /*--- end ---*/ |
| 126 | /*--------------------------------------------------------------------*/ |