njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | c0ae705 | 2005-08-25 22:55:19 +0000 | [diff] [blame] | 3 | /*--- Function replacement and wrapping. pub_core_redir.h ---*/ |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 10 | Copyright (C) 2000-2017 Julian Seward |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 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: |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 36 | // |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 37 | // - code replacement: intercepting calls to client functions, and |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 38 | // pointing them to a different piece of code. |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 39 | // |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 40 | // - loading notification: telling the core where certain client-space |
| 41 | // functions are when they get loaded. |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 42 | // |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 43 | // - function wrapping: add calls to code before and after client |
| 44 | // functions execute, for inspection and/or modification. |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 45 | // |
| 46 | // - checking of --require-text-symbol= specifications: when a new |
| 47 | // object is loaded, its symbol table is examined, and if a symbol |
| 48 | // (as required by the specifications) is not found then the run |
| 49 | // is aborted. See comment by VG_(clo_n_req_tsyms) in |
| 50 | // pub_core_options.h for background. This doesn't have anything |
| 51 | // to do with function intercepting or wrapping, but it does have |
| 52 | // to do with examining all symbols at object load time, so this |
| 53 | // module seems like a logical place to put it. |
| 54 | // |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 55 | //-------------------------------------------------------------------- |
| 56 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 57 | #include "pub_tool_redir.h" |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 58 | #include "pub_core_basics.h" // Addr |
| 59 | #include "pub_core_debuginfo.h" // DebugInfo |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 60 | |
| 61 | //-------------------------------------------------------------------- |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 62 | // Notifications - by which we are told of state changes |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 63 | //-------------------------------------------------------------------- |
| 64 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 65 | /* Notify the module of a new DebugInfo (called from m_debuginfo). */ |
florian | 518850b | 2014-10-22 22:25:30 +0000 | [diff] [blame] | 66 | extern void VG_(redir_notify_new_DebugInfo)( const DebugInfo* ); |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 67 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 68 | /* Notify the module of the disappearance of a DebugInfo (also called |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 69 | from m_debuginfo). */ |
florian | 518850b | 2014-10-22 22:25:30 +0000 | [diff] [blame] | 70 | extern void VG_(redir_notify_delete_DebugInfo)( const DebugInfo* ); |
njn | 3ced4ce | 2005-06-21 00:07:13 +0000 | [diff] [blame] | 71 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 72 | /* Initialise the module, and load initial "hardwired" redirects. */ |
| 73 | extern void VG_(redir_initialise)( void ); |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 74 | |
tom | d264514 | 2009-10-29 09:27:11 +0000 | [diff] [blame] | 75 | /* Notify the module of a new target for an indirect function. */ |
| 76 | extern void VG_(redir_add_ifunc_target)( Addr old_from, Addr new_from ); |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 77 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 78 | //-------------------------------------------------------------------- |
| 79 | // Queries |
| 80 | //-------------------------------------------------------------------- |
| 81 | |
| 82 | /* This is the crucial redirection function. It answers the question: |
| 83 | should this code address be redirected somewhere else? It's used |
| 84 | just before translating a basic block. If a redir is found, |
| 85 | *isWrap allows to distinguish wrap- from replace- style |
| 86 | redirections. */ |
| 87 | extern Addr VG_(redir_do_lookup) ( Addr orig, Bool* isWrap ); |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 88 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 89 | |
| 90 | //-------------------------------------------------------------------- |
| 91 | // Loading notification |
| 92 | //-------------------------------------------------------------------- |
| 93 | |
| 94 | /* Functions named with this macro have the property that the core will |
| 95 | be told what their address is when they are loaded. This can be useful |
| 96 | if the core wants to call them at some point, and so needs to know their |
| 97 | address. This is a weaker but more general mechanism than code |
| 98 | replacement. |
| 99 | |
| 100 | Functions named with this macro should be in client space, ie. in |
njn | 7b4e5ba | 2005-08-25 22:53:57 +0000 | [diff] [blame] | 101 | vgpreload_<tool>.h or vgpreload_core.h. */ |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 102 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 103 | #define VG_NOTIFY_ON_LOAD(name) _vgnU_##name |
| 104 | #define VG_NOTIFY_ON_LOAD_PREFIX "_vgnU_" |
| 105 | #define VG_NOTIFY_ON_LOAD_PREFIX_LEN 6 |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 106 | |
| 107 | |
| 108 | //-------------------------------------------------------------------- |
| 109 | // Function wrapping |
| 110 | //-------------------------------------------------------------------- |
| 111 | |
| 112 | // This is currently not working(?) --njn |
| 113 | |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 114 | /* Wrapping machinery */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 115 | //enum return_type { |
| 116 | // RT_RETURN, |
| 117 | // RT_LONGJMP, |
| 118 | // RT_EXIT, |
| 119 | //}; |
| 120 | // |
| 121 | //typedef struct _FuncWrapper FuncWrapper; |
| 122 | //struct _FuncWrapper { |
| 123 | // void *(*before)(va_list args); |
| 124 | // void (*after) (void *nonce, enum return_type, Word retval); |
| 125 | //}; |
| 126 | // |
| 127 | //extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper); |
| 128 | //extern const FuncWrapper *VG_(is_wrapped)(Addr eip); |
| 129 | //extern Bool VG_(is_wrapper_return)(Addr eip); |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 130 | |
| 131 | /* Primary interface for adding wrappers for client-side functions. */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 132 | //extern CodeRedirect *VG_(add_wrapper)(const HChar *from_lib, const HChar *from_sym, |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 133 | // const FuncWrapper *wrapper); |
| 134 | // |
| 135 | //extern Bool VG_(is_resolved)(const CodeRedirect *redir); |
njn | 204e21b | 2005-05-29 17:03:54 +0000 | [diff] [blame] | 136 | |
| 137 | #endif // __PUB_CORE_REDIR_H |
| 138 | |
| 139 | /*--------------------------------------------------------------------*/ |
| 140 | /*--- end ---*/ |
| 141 | /*--------------------------------------------------------------------*/ |