blob: 37435887d51d82978d598e8f6140d04222596dae [file] [log] [blame]
njn204e21b2005-05-29 17:03:54 +00001
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:
njn16eeb4e2005-06-16 03:56:58 +000036// - code replacement: intercepting calls to client functions, and
njn204e21b2005-05-29 17:03:54 +000037// pointing them to a different piece of code.
njn16eeb4e2005-06-16 03:56:58 +000038// - loading notification: telling the core where certain client-space
39// functions are when they get loaded.
njn204e21b2005-05-29 17:03:54 +000040// - function wrapping: add calls to code before and after client
41// functions execute, for inspection and/or modification.
42//
njn16eeb4e2005-06-16 03:56:58 +000043// It's possible that this should be two or three modules.
njn204e21b2005-05-29 17:03:54 +000044//--------------------------------------------------------------------
45
njn16eeb4e2005-06-16 03:56:58 +000046#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.
56void 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
njn3ced4ce2005-06-21 00:07:13 +000064typedef struct _CodeRedirect CodeRedirect;
65
njn16eeb4e2005-06-16 03:56:58 +000066// This is the crucial redirection function. It answers the question:
67// should this code address be redirected somewhere else? It's used just
68// before translating a basic block.
njn204e21b2005-05-29 17:03:54 +000069extern Addr VG_(code_redirect) ( Addr orig );
70
71/* Set up some default redirects */
72extern void VG_(setup_code_redirect_table) ( void );
73
njnd9109c62005-06-26 04:49:25 +000074extern void VG_(resolve_existing_redirs_with_seginfo)(SegInfo *si);
njn204e21b2005-05-29 17:03:54 +000075
njn16eeb4e2005-06-16 03:56:58 +000076
77//--------------------------------------------------------------------
78// Loading notification
79//--------------------------------------------------------------------
80
81/* Functions named with this macro have the property that the core will
82 be told what their address is when they are loaded. This can be useful
83 if the core wants to call them at some point, and so needs to know their
84 address. This is a weaker but more general mechanism than code
85 replacement.
86
87 Functions named with this macro should be in client space, ie. in
88 vg_preload_<tool>.h or vg_preload_core.h. */
89
90#define VG_NOTIFY_ON_LOAD(name) _vgw_##name
91#define VG_NOTIFY_ON_LOAD_PREFIX "_vgw_"
92#define VG_NOTIFY_ON_LOAD_PREFIX_LEN 5
93
njnbc6d84d2005-06-19 18:58:03 +000094// Called by m_main to get our __libc_freeres wrapper.
95extern Addr VG_(get_libc_freeres_wrapper)(void);
njn16eeb4e2005-06-16 03:56:58 +000096
97//--------------------------------------------------------------------
98// Function wrapping
99//--------------------------------------------------------------------
100
101// This is currently not working(?) --njn
102
njn204e21b2005-05-29 17:03:54 +0000103/* Wrapping machinery */
104enum return_type {
105 RT_RETURN,
106 RT_LONGJMP,
107 RT_EXIT,
108};
109
110typedef struct _FuncWrapper FuncWrapper;
111struct _FuncWrapper {
112 void *(*before)(va_list args);
113 void (*after) (void *nonce, enum return_type, Word retval);
114};
115
116extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper);
117extern const FuncWrapper *VG_(is_wrapped)(Addr eip);
118extern Bool VG_(is_wrapper_return)(Addr eip);
119
120/* Primary interface for adding wrappers for client-side functions. */
121extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym,
122 const FuncWrapper *wrapper);
123
124extern Bool VG_(is_resolved)(const CodeRedirect *redir);
125
126#endif // __PUB_CORE_REDIR_H
127
128/*--------------------------------------------------------------------*/
129/*--- end ---*/
130/*--------------------------------------------------------------------*/