drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / coregrind / pub_core_redir.h
blobb88ca98f922c6233761ca6e0e3332dcaa3426724
2 /*--------------------------------------------------------------------*/
3 /*--- Function replacement and wrapping. pub_core_redir.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.org
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_CORE_REDIR_H
30 #define __PUB_CORE_REDIR_H
32 //--------------------------------------------------------------------
33 // PURPOSE: This module deals with:
35 // - code replacement: intercepting calls to client functions, and
36 // pointing them to a different piece of code.
38 // - loading notification: telling the core where certain client-space
39 // functions are when they get loaded.
41 // - function wrapping: add calls to code before and after client
42 // functions execute, for inspection and/or modification.
44 // - checking of --require-text-symbol= specifications: when a new
45 // object is loaded, its symbol table is examined, and if a symbol
46 // (as required by the specifications) is not found then the run
47 // is aborted. See comment by VG_(clo_n_req_tsyms) in
48 // pub_core_options.h for background. This doesn't have anything
49 // to do with function intercepting or wrapping, but it does have
50 // to do with examining all symbols at object load time, so this
51 // module seems like a logical place to put it.
53 //--------------------------------------------------------------------
55 #include "pub_tool_redir.h"
56 #include "pub_core_basics.h" // Addr
57 #include "pub_core_debuginfo.h" // DebugInfo
59 //--------------------------------------------------------------------
60 // Notifications - by which we are told of state changes
61 //--------------------------------------------------------------------
63 /* Notify the module of a new DebugInfo (called from m_debuginfo). */
64 extern void VG_(redir_notify_new_DebugInfo)( const DebugInfo* );
66 /* Notify the module of the disappearance of a DebugInfo (also called
67 from m_debuginfo). */
68 extern void VG_(redir_notify_delete_DebugInfo)( const DebugInfo* );
70 /* Initialise the module, and load initial "hardwired" redirects. */
71 extern void VG_(redir_initialise)( void );
73 /* Notify the module of a new target for an indirect function. */
74 extern void VG_(redir_add_ifunc_target)( Addr old_from, Addr new_from );
76 //--------------------------------------------------------------------
77 // Queries
78 //--------------------------------------------------------------------
80 /* This is the crucial redirection function. It answers the question:
81 should this code address be redirected somewhere else? It's used
82 just before translating a basic block. If a redir is found,
83 *isWrap allows to distinguish wrap- from replace- style
84 redirections. */
85 extern Addr VG_(redir_do_lookup) ( Addr orig, Bool* isWrap );
88 //--------------------------------------------------------------------
89 // Loading notification
90 //--------------------------------------------------------------------
92 /* Functions named with this macro have the property that the core will
93 be told what their address is when they are loaded. This can be useful
94 if the core wants to call them at some point, and so needs to know their
95 address. This is a weaker but more general mechanism than code
96 replacement.
98 Functions named with this macro should be in client space, ie. in
99 vgpreload_<tool>.h or vgpreload_core.h. */
101 #define VG_NOTIFY_ON_LOAD(name) _vgnU_##name
102 #define VG_NOTIFY_ON_LOAD_PREFIX "_vgnU_"
103 #define VG_NOTIFY_ON_LOAD_PREFIX_LEN 6
106 //--------------------------------------------------------------------
107 // Function wrapping
108 //--------------------------------------------------------------------
110 // This is currently not working(?) --njn
112 /* Wrapping machinery */
113 //enum return_type {
114 // RT_RETURN,
115 // RT_LONGJMP,
116 // RT_EXIT,
117 //};
119 //typedef struct _FuncWrapper FuncWrapper;
120 //struct _FuncWrapper {
121 // void *(*before)(va_list args);
122 // void (*after) (void *nonce, enum return_type, Word retval);
123 //};
125 //extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper);
126 //extern const FuncWrapper *VG_(is_wrapped)(Addr eip);
127 //extern Bool VG_(is_wrapper_return)(Addr eip);
129 /* Primary interface for adding wrappers for client-side functions. */
130 //extern CodeRedirect *VG_(add_wrapper)(const HChar *from_lib, const HChar *from_sym,
131 // const FuncWrapper *wrapper);
133 //extern Bool VG_(is_resolved)(const CodeRedirect *redir);
135 #endif // __PUB_CORE_REDIR_H
137 /*--------------------------------------------------------------------*/
138 /*--- end ---*/
139 /*--------------------------------------------------------------------*/