blob: f6690fe4d279162aedecafaaa08d22e039be9c71 [file] [log] [blame]
njn43b9a8a2005-05-10 04:37:01 +00001
2/*--------------------------------------------------------------------*/
3/*--- The core/tool interface. pub_core_tooliface.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 Julian Seward
njn43b9a8a2005-05-10 04:37:01 +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_TOOLIFACE_H
32#define __PUB_CORE_TOOLIFACE_H
33
34#include "pub_tool_tooliface.h"
35
36//--------------------------------------------------------------------
37// PURPOSE: This module encapsulates the key parts of the core/tool
38// interface: 'details', 'needs' and 'trackable events'.
39//--------------------------------------------------------------------
40
41// Note the use of C's comma operator here -- it means that we execute both
42// statements, and the rvalue of the whole thing is the rvalue of the last
43// statement. This lets us say "x = VG_TDICT_CALL(...)" in the required
44// places, while still checking the assertion.
45#define VG_TDICT_CALL(fn, args...) \
46 ( tl_assert2(VG_(tdict).fn, \
47 "you forgot to set VgToolInterface function '" #fn "'"), \
48 VG_(tdict).fn(args) )
49
50#define VG_TRACK(fn, args...) \
51 do { \
52 if (VG_(tdict).track_##fn) \
53 VG_(tdict).track_##fn(args); \
54 } while(0)
55
56/* These structs are not exposed to tools to mitigate possibility of
57 binary-incompatibilities when the core/tool interface changes. Instead,
njnc7561b92005-06-19 01:24:32 +000058 set functions are provided (see include/pub_tool_tooliface.h). */
njn43b9a8a2005-05-10 04:37:01 +000059
60/* ---------------------------------------------------------------------
61 'Details'
62 ------------------------------------------------------------------ */
63
64typedef
65 struct {
66 Char* name;
67 Char* version;
68 Char* description;
69 Char* copyright_author;
70 Char* bug_reports_to;
71 UInt avg_translation_sizeB;
72 }
73 VgDetails;
74
75extern VgDetails VG_(details);
76
77/* ---------------------------------------------------------------------
78 'Needs'
79 ------------------------------------------------------------------ */
80
81typedef
82 struct {
83 Bool libc_freeres;
84 Bool core_errors;
85 Bool tool_errors;
sewardj0b9d74a2006-12-24 02:24:11 +000086 Bool superblock_discards;
njn43b9a8a2005-05-10 04:37:01 +000087 Bool command_line_options;
88 Bool client_requests;
njn43b9a8a2005-05-10 04:37:01 +000089 Bool syscall_wrapper;
90 Bool sanity_checks;
91 Bool data_syms;
njnfc51f8d2005-06-21 03:20:17 +000092 Bool malloc_replacement;
njnca54af32006-04-16 10:25:43 +000093 Bool xml_output;
sewardj81651dc2007-08-28 06:05:20 +000094 Bool final_IR_tidy_pass;
njn43b9a8a2005-05-10 04:37:01 +000095 }
96 VgNeeds;
97
98extern VgNeeds VG_(needs);
99
100/* ---------------------------------------------------------------------
101 The dictionary of callable tool functions
102 ------------------------------------------------------------------ */
103
104typedef struct {
105 // -- 'Needs'-related functions ----------------------------------
106 // Basic functions
107 void (*tool_pre_clo_init) (void);
108 void (*tool_post_clo_init)(void);
sewardj0b9d74a2006-12-24 02:24:11 +0000109 IRSB* (*tool_instrument) (VgCallbackClosure*,
110 IRSB*,
sewardj461df9c2006-01-17 02:06:39 +0000111 VexGuestLayout*, VexGuestExtents*,
112 IRType, IRType);
njn43b9a8a2005-05-10 04:37:01 +0000113 void (*tool_fini) (Int);
114
115 // VG_(needs).core_errors
116 // (none)
117
118 // VG_(needs).tool_errors
119 Bool (*tool_eq_Error) (VgRes, Error*, Error*);
120 void (*tool_pp_Error) (Error*);
sewardjadb102f2007-11-09 23:21:44 +0000121 Bool tool_show_ThreadIDs_for_errors;
njn43b9a8a2005-05-10 04:37:01 +0000122 UInt (*tool_update_extra) (Error*);
123 Bool (*tool_recognised_suppression) (Char*, Supp*);
124 Bool (*tool_read_extra_suppression_info) (Int, Char*, Int, Supp*);
125 Bool (*tool_error_matches_suppression) (Error*, Supp*);
126 Char* (*tool_get_error_name) (Error*);
127 void (*tool_print_extra_suppression_info)(Error*);
128
sewardj0b9d74a2006-12-24 02:24:11 +0000129 // VG_(needs).superblock_discards
130 void (*tool_discard_superblock_info)(Addr64, VexGuestExtents);
njn43b9a8a2005-05-10 04:37:01 +0000131
132 // VG_(needs).command_line_options
133 Bool (*tool_process_cmd_line_option)(Char*);
134 void (*tool_print_usage) (void);
135 void (*tool_print_debug_usage) (void);
136
137 // VG_(needs).client_requests
138 Bool (*tool_handle_client_request)(ThreadId, UWord*, UWord*);
139
140 // VG_(needs).syscall_wrapper
141 void (*tool_pre_syscall) (ThreadId, UInt);
sewardja8d8e232005-06-07 20:04:56 +0000142 void (*tool_post_syscall)(ThreadId, UInt, SysRes);
njn43b9a8a2005-05-10 04:37:01 +0000143
144 // VG_(needs).sanity_checks
145 Bool (*tool_cheap_sanity_check)(void);
146 Bool (*tool_expensive_sanity_check)(void);
147
njnfc51f8d2005-06-21 03:20:17 +0000148 // VG_(needs).malloc_replacement
149 void* (*tool_malloc) (ThreadId, SizeT);
150 void* (*tool___builtin_new) (ThreadId, SizeT);
151 void* (*tool___builtin_vec_new) (ThreadId, SizeT);
152 void* (*tool_memalign) (ThreadId, SizeT, SizeT);
153 void* (*tool_calloc) (ThreadId, SizeT, SizeT);
154 void (*tool_free) (ThreadId, void*);
155 void (*tool___builtin_delete) (ThreadId, void*);
156 void (*tool___builtin_vec_delete)(ThreadId, void*);
157 void* (*tool_realloc) (ThreadId, void*, SizeT);
158 SizeT tool_client_redzone_szB;
159
sewardj81651dc2007-08-28 06:05:20 +0000160 // VG_(needs).final_IR_tidy_pass
161 IRSB* (*tool_final_IR_tidy_pass) (IRSB*);
162
njn43b9a8a2005-05-10 04:37:01 +0000163 // -- Event tracking functions ------------------------------------
164 void (*track_new_mem_startup) (Addr, SizeT, Bool, Bool, Bool);
165 void (*track_new_mem_stack_signal)(Addr, SizeT);
166 void (*track_new_mem_brk) (Addr, SizeT);
167 void (*track_new_mem_mmap) (Addr, SizeT, Bool, Bool, Bool);
168
sewardj45f4e7c2005-09-27 19:20:21 +0000169 void (*track_copy_mem_remap) (Addr src, Addr dst, SizeT);
njn43b9a8a2005-05-10 04:37:01 +0000170 void (*track_change_mem_mprotect) (Addr, SizeT, Bool, Bool, Bool);
171 void (*track_die_mem_stack_signal)(Addr, SizeT);
172 void (*track_die_mem_brk) (Addr, SizeT);
173 void (*track_die_mem_munmap) (Addr, SizeT);
174
sewardjf5c8e372006-02-12 15:42:20 +0000175 void VG_REGPARM(1) (*track_new_mem_stack_4) (Addr);
176 void VG_REGPARM(1) (*track_new_mem_stack_8) (Addr);
177 void VG_REGPARM(1) (*track_new_mem_stack_12) (Addr);
178 void VG_REGPARM(1) (*track_new_mem_stack_16) (Addr);
179 void VG_REGPARM(1) (*track_new_mem_stack_32) (Addr);
180 void VG_REGPARM(1) (*track_new_mem_stack_112)(Addr);
181 void VG_REGPARM(1) (*track_new_mem_stack_128)(Addr);
182 void VG_REGPARM(1) (*track_new_mem_stack_144)(Addr);
183 void VG_REGPARM(1) (*track_new_mem_stack_160)(Addr);
njn43b9a8a2005-05-10 04:37:01 +0000184 void (*track_new_mem_stack)(Addr, SizeT);
185
sewardjf5c8e372006-02-12 15:42:20 +0000186 void VG_REGPARM(1) (*track_die_mem_stack_4) (Addr);
187 void VG_REGPARM(1) (*track_die_mem_stack_8) (Addr);
188 void VG_REGPARM(1) (*track_die_mem_stack_12) (Addr);
189 void VG_REGPARM(1) (*track_die_mem_stack_16) (Addr);
190 void VG_REGPARM(1) (*track_die_mem_stack_32) (Addr);
191 void VG_REGPARM(1) (*track_die_mem_stack_112)(Addr);
192 void VG_REGPARM(1) (*track_die_mem_stack_128)(Addr);
193 void VG_REGPARM(1) (*track_die_mem_stack_144)(Addr);
194 void VG_REGPARM(1) (*track_die_mem_stack_160)(Addr);
njn43b9a8a2005-05-10 04:37:01 +0000195 void (*track_die_mem_stack)(Addr, SizeT);
196
197 void (*track_ban_mem_stack)(Addr, SizeT);
198
199 void (*track_pre_mem_read) (CorePart, ThreadId, Char*, Addr, SizeT);
200 void (*track_pre_mem_read_asciiz)(CorePart, ThreadId, Char*, Addr);
201 void (*track_pre_mem_write) (CorePart, ThreadId, Char*, Addr, SizeT);
202 void (*track_post_mem_write) (CorePart, ThreadId, Addr, SizeT);
203
204 void (*track_pre_reg_read) (CorePart, ThreadId, Char*, OffT, SizeT);
205 void (*track_post_reg_write)(CorePart, ThreadId, OffT, SizeT);
206 void (*track_post_reg_write_clientcall_return)(ThreadId, OffT, SizeT, Addr);
207
njn3e32c872006-12-24 07:51:17 +0000208 void (*track_start_client_code)(ThreadId, ULong);
209 void (*track_stop_client_code) (ThreadId, ULong);
njn43b9a8a2005-05-10 04:37:01 +0000210
sewardjadb102f2007-11-09 23:21:44 +0000211 void (*track_pre_thread_ll_create)(ThreadId, ThreadId);
212 void (*track_pre_thread_ll_exit) (ThreadId);
njn43b9a8a2005-05-10 04:37:01 +0000213
njn43b9a8a2005-05-10 04:37:01 +0000214 void (*track_pre_deliver_signal) (ThreadId, Int sigNo, Bool);
215 void (*track_post_deliver_signal)(ThreadId, Int sigNo);
216
njn43b9a8a2005-05-10 04:37:01 +0000217} VgToolInterface;
218
219extern VgToolInterface VG_(tdict);
220
221/* ---------------------------------------------------------------------
222 Miscellaneous functions
223 ------------------------------------------------------------------ */
224
sewardj45f4e7c2005-09-27 19:20:21 +0000225Bool VG_(sanity_check_needs) ( Char** failmsg );
njn43b9a8a2005-05-10 04:37:01 +0000226
227#endif // __PUB_CORE_TOOLIFACE_H
228
229/*--------------------------------------------------------------------*/
230/*--- end ---*/
231/*--------------------------------------------------------------------*/