blob: d734d450624a5420b201a017875c9cb06a748237 [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
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.
njn204e21b2005-05-29 17:03:54 +000067extern Addr VG_(code_redirect) ( Addr orig );
68
69/* Set up some default redirects */
70extern void VG_(setup_code_redirect_table) ( void );
71
njn204e21b2005-05-29 17:03:54 +000072extern void VG_(resolve_seg_redirs)(SegInfo *si);
73
njn16eeb4e2005-06-16 03:56:58 +000074
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
njn204e21b2005-05-29 17:03:54 +000099/* Wrapping machinery */
100enum return_type {
101 RT_RETURN,
102 RT_LONGJMP,
103 RT_EXIT,
104};
105
106typedef struct _FuncWrapper FuncWrapper;
107struct _FuncWrapper {
108 void *(*before)(va_list args);
109 void (*after) (void *nonce, enum return_type, Word retval);
110};
111
112extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper);
113extern const FuncWrapper *VG_(is_wrapped)(Addr eip);
114extern Bool VG_(is_wrapper_return)(Addr eip);
115
116/* Primary interface for adding wrappers for client-side functions. */
117extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym,
118 const FuncWrapper *wrapper);
119
120extern Bool VG_(is_resolved)(const CodeRedirect *redir);
121
122#endif // __PUB_CORE_REDIR_H
123
124/*--------------------------------------------------------------------*/
125/*--- end ---*/
126/*--------------------------------------------------------------------*/