blob: e1bf4872e083f5b5c70e084f23fed2ff832c8a61 [file] [log] [blame]
njn204e21b2005-05-29 17:03:54 +00001
2/*--------------------------------------------------------------------*/
njnc0ae7052005-08-25 22:55:19 +00003/*--- Function replacement and wrapping. pub_core_redir.h ---*/
njn204e21b2005-05-29 17:03:54 +00004/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj4d474d02008-02-11 11:34:59 +000010 Copyright (C) 2000-2008 Julian Seward
njn204e21b2005-05-29 17:03:54 +000011 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.
njn204e21b2005-05-29 17:03:54 +000042//--------------------------------------------------------------------
43
njn16eeb4e2005-06-16 03:56:58 +000044#include "pub_tool_redir.h"
45
njn16eeb4e2005-06-16 03:56:58 +000046
47//--------------------------------------------------------------------
sewardj0ec07f32006-01-12 12:32:32 +000048// Notifications - by which we are told of state changes
njn16eeb4e2005-06-16 03:56:58 +000049//--------------------------------------------------------------------
50
sewardjb8b79ad2008-03-03 01:35:41 +000051/* Notify the module of a new DebugInfo (called from m_debuginfo). */
52extern void VG_(redir_notify_new_DebugInfo)( DebugInfo* );
njn16eeb4e2005-06-16 03:56:58 +000053
sewardjb8b79ad2008-03-03 01:35:41 +000054/* Notify the module of the disappearance of a DebugInfo (also called
sewardj0ec07f32006-01-12 12:32:32 +000055 from m_debuginfo). */
sewardjb8b79ad2008-03-03 01:35:41 +000056extern void VG_(redir_notify_delete_DebugInfo)( DebugInfo* );
njn3ced4ce2005-06-21 00:07:13 +000057
sewardj0ec07f32006-01-12 12:32:32 +000058/* Initialise the module, and load initial "hardwired" redirects. */
59extern void VG_(redir_initialise)( void );
njn204e21b2005-05-29 17:03:54 +000060
njn204e21b2005-05-29 17:03:54 +000061
sewardj0ec07f32006-01-12 12:32:32 +000062//--------------------------------------------------------------------
63// Queries
64//--------------------------------------------------------------------
65
66/* This is the crucial redirection function. It answers the question:
67 should this code address be redirected somewhere else? It's used
68 just before translating a basic block. If a redir is found,
69 *isWrap allows to distinguish wrap- from replace- style
70 redirections. */
71extern Addr VG_(redir_do_lookup) ( Addr orig, Bool* isWrap );
njn204e21b2005-05-29 17:03:54 +000072
njn16eeb4e2005-06-16 03:56:58 +000073
74//--------------------------------------------------------------------
75// Loading notification
76//--------------------------------------------------------------------
77
78/* Functions named with this macro have the property that the core will
79 be told what their address is when they are loaded. This can be useful
80 if the core wants to call them at some point, and so needs to know their
81 address. This is a weaker but more general mechanism than code
82 replacement.
83
84 Functions named with this macro should be in client space, ie. in
njn7b4e5ba2005-08-25 22:53:57 +000085 vgpreload_<tool>.h or vgpreload_core.h. */
njn16eeb4e2005-06-16 03:56:58 +000086
sewardj0ec07f32006-01-12 12:32:32 +000087#define VG_NOTIFY_ON_LOAD(name) _vgnU_##name
88#define VG_NOTIFY_ON_LOAD_PREFIX "_vgnU_"
89#define VG_NOTIFY_ON_LOAD_PREFIX_LEN 6
njn16eeb4e2005-06-16 03:56:58 +000090
91
92//--------------------------------------------------------------------
93// Function wrapping
94//--------------------------------------------------------------------
95
96// This is currently not working(?) --njn
97
njn204e21b2005-05-29 17:03:54 +000098/* Wrapping machinery */
sewardj0ec07f32006-01-12 12:32:32 +000099//enum return_type {
100 // RT_RETURN,
101 // RT_LONGJMP,
102 // RT_EXIT,
103 //};
104//
105//typedef struct _FuncWrapper FuncWrapper;
106//struct _FuncWrapper {
107 // void *(*before)(va_list args);
108 // void (*after) (void *nonce, enum return_type, Word retval);
109 //};
110//
111//extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper);
112//extern const FuncWrapper *VG_(is_wrapped)(Addr eip);
113//extern Bool VG_(is_wrapper_return)(Addr eip);
njn204e21b2005-05-29 17:03:54 +0000114
115/* Primary interface for adding wrappers for client-side functions. */
sewardj0ec07f32006-01-12 12:32:32 +0000116//extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym,
117// const FuncWrapper *wrapper);
118//
119//extern Bool VG_(is_resolved)(const CodeRedirect *redir);
njn204e21b2005-05-29 17:03:54 +0000120
121#endif // __PUB_CORE_REDIR_H
122
123/*--------------------------------------------------------------------*/
124/*--- end ---*/
125/*--------------------------------------------------------------------*/