blob: 90500290d98b57b5cca0d5864904a937c1d397d0 [file] [log] [blame]
nethercote37aac2e2004-09-02 08:54:27 +00001/*-*- c -*- ----------------------------------------------------------*/
2/*--- The only header your tool will ever need to #include... ---*/
3/*--- tool.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, an extensible x86 protected-mode
8 emulator for monitoring program execution on x86-Unixes.
9
10 Copyright (C) 2000-2004 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 __TOOL_H
32#define __TOOL_H
33
34#include <stdarg.h> /* ANSI varargs stuff */
35#include <setjmp.h> /* for jmp_buf */
36
nethercoteebf1d862004-11-01 18:22:05 +000037#include "basic_types.h"
nethercote13343132004-09-02 15:49:09 +000038#include "tool_asm.h" // asm stuff
nethercotec06e2132004-09-03 13:45:29 +000039#include "tool_arch.h" // arch-specific tool stuff
nethercote73b526f2004-10-31 18:48:21 +000040#include "vki.h"
nethercote37aac2e2004-09-02 08:54:27 +000041
sewardj8b635a42004-11-22 19:01:47 +000042#include "libvex.h"
43#include "libvex_ir.h"
44
nethercote37aac2e2004-09-02 08:54:27 +000045/*====================================================================*/
46/*=== Build options and table sizes. ===*/
47/*====================================================================*/
48
49/* You should be able to change these options or sizes, recompile, and
50 still have a working system. */
51
52/* The maximum number of pthreads that we support. This is
53 deliberately not very high since our implementation of some of the
54 scheduler algorithms is surely O(N) in the number of threads, since
55 that's simple, at least. And (in practice) we hope that most
56 programs do not need many threads. */
57#define VG_N_THREADS 100
58
59/* Maximum number of pthread keys available. Again, we start low until
60 the need for a higher number presents itself. */
61#define VG_N_THREAD_KEYS 50
62
nethercote37aac2e2004-09-02 08:54:27 +000063
64/*====================================================================*/
nethercote2e05c332004-09-06 16:43:37 +000065/*=== Useful macros ===*/
nethercote37aac2e2004-09-02 08:54:27 +000066/*====================================================================*/
67
nethercote37aac2e2004-09-02 08:54:27 +000068#define mycat_wrk(aaa,bbb) aaa##bbb
69#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
70
71/* No, really. I _am_ that strange. */
72#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
73
nethercote37aac2e2004-09-02 08:54:27 +000074/* Path to all our library/aux files */
75extern const Char *VG_(libdir);
76
77
78/*====================================================================*/
79/*=== Core/tool interface version ===*/
80/*====================================================================*/
81
82/* The major version number indicates binary-incompatible changes to the
83 interface; if the core and tool major versions don't match, Valgrind
84 will abort. The minor version indicates binary-compatible changes.
nethercote836d46c2004-11-18 12:58:53 +000085
86 (Update: as it happens, we're never using the minor version number, because
87 there's no point in doing so.)
nethercote37aac2e2004-09-02 08:54:27 +000088*/
nethercote836d46c2004-11-18 12:58:53 +000089#define VG_CORE_INTERFACE_MAJOR_VERSION 7
nethercote37aac2e2004-09-02 08:54:27 +000090#define VG_CORE_INTERFACE_MINOR_VERSION 0
91
92typedef struct _ToolInfo {
93 Int sizeof_ToolInfo;
94 Int interface_major_version;
95 Int interface_minor_version;
96
97 /* Initialise tool. Must do the following:
98 - initialise the `details' struct, via the VG_(details_*)() functions
99 - register any helpers called by generated code
100
101 May do the following:
102 - initialise the `needs' struct to indicate certain requirements, via
103 the VG_(needs_*)() functions
104 - initialize all the tool's entrypoints via the VG_(init_*)() functions
105 - register any tool-specific profiling events
106 - any other tool-specific initialisation
107 */
108 void (*sk_pre_clo_init) ( void );
109
110 /* Specifies how big the shadow segment should be as a ratio to the
111 client address space. 0 for no shadow segment. */
112 float shadow_ratio;
113} ToolInfo;
114
115/* Every tool must include this macro somewhere, exactly once. */
116#define VG_DETERMINE_INTERFACE_VERSION(pre_clo_init, shadow) \
njn26f02512004-11-22 18:33:15 +0000117 const ToolInfo TL_(tool_info) = { \
nethercote37aac2e2004-09-02 08:54:27 +0000118 .sizeof_ToolInfo = sizeof(ToolInfo), \
119 .interface_major_version = VG_CORE_INTERFACE_MAJOR_VERSION, \
120 .interface_minor_version = VG_CORE_INTERFACE_MINOR_VERSION, \
121 .sk_pre_clo_init = pre_clo_init, \
122 .shadow_ratio = shadow, \
123 };
124
125/*====================================================================*/
126/*=== Command-line options ===*/
127/*====================================================================*/
128
129/* Use this for normal null-termination-style string comparison */
130#define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \
131 && VG_(strcmp)((s1),(s2))==0)
132
133/* Use these for recognising tool command line options -- stops comparing
134 once whitespace is reached. */
135#define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2)))
136#define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
137
138// Higher-level command-line option recognisers; use in if/else chains
139
140#define VG_BOOL_CLO(qq_option, qq_var) \
141 if (VG_CLO_STREQ(arg, qq_option"=yes")) { (qq_var) = True; } \
142 else if (VG_CLO_STREQ(arg, qq_option"=no")) { (qq_var) = False; }
143
144#define VG_STR_CLO(qq_option, qq_var) \
145 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
146 (qq_var) = &arg[ VG_(strlen)(qq_option)+1 ]; \
147 }
148
149#define VG_NUM_CLO(qq_option, qq_var) \
150 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
151 (qq_var) = (Int)VG_(atoll)( &arg[ VG_(strlen)(qq_option)+1 ] ); \
152 }
153
154// Bounded integer arg
155#define VG_BNUM_CLO(qq_option, qq_var, qq_lo, qq_hi) \
156 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
157 (qq_var) = (Int)VG_(atoll)( &arg[ VG_(strlen)(qq_option)+1 ] ); \
158 if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
159 if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
160 }
161
162
163/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
164extern Int VG_(clo_verbosity);
165
166/* Profile? */
167extern Bool VG_(clo_profile);
168
169/* Call this if a recognised option was bad for some reason.
170 Note: don't use it just because an option was unrecognised -- return 'False'
njn94065fd2004-11-22 19:26:27 +0000171 from TL_(process_cmd_line_option) to indicate that. */
nethercote37aac2e2004-09-02 08:54:27 +0000172extern void VG_(bad_option) ( Char* opt );
173
174/* Client args */
175extern Int VG_(client_argc);
176extern Char** VG_(client_argv);
177
178/* Client environment. Can be inspected with VG_(getenv)() */
179extern Char** VG_(client_envp);
180
181
182/*====================================================================*/
183/*=== Printing messages for the user ===*/
184/*====================================================================*/
185
186/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
187 Should be used for all user output. */
188
189typedef
190 enum { Vg_UserMsg, /* '?' == '=' */
191 Vg_DebugMsg, /* '?' == '-' */
192 Vg_DebugExtraMsg, /* '?' == '+' */
193 Vg_ClientMsg, /* '?' == '*' */
194 }
195 VgMsgKind;
196
197/* Functions for building a message from multiple parts. */
198extern int VG_(start_msg) ( VgMsgKind kind );
199extern int VG_(add_to_msg) ( Char* format, ... );
200/* Ends and prints the message. Appends a newline. */
201extern int VG_(end_msg) ( void );
202
203/* Send a single-part message. Appends a newline. */
204extern int VG_(message) ( VgMsgKind kind, Char* format, ... );
205extern int VG_(vmessage) ( VgMsgKind kind, Char* format, va_list vargs );
206
207
208/*====================================================================*/
209/*=== Profiling ===*/
210/*====================================================================*/
211
212/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
213#define VGP_CORE_LIST \
214 /* These ones depend on the core */ \
215 VGP_PAIR(VgpUnc, "unclassified"), \
216 VGP_PAIR(VgpStartup, "startup"), \
217 VGP_PAIR(VgpRun, "running"), \
218 VGP_PAIR(VgpSched, "scheduler"), \
219 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
220 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
221 VGP_PAIR(VgpTranslate, "translate-main"), \
222 VGP_PAIR(VgpToUCode, "to-ucode"), \
223 VGP_PAIR(VgpFromUcode, "from-ucode"), \
224 VGP_PAIR(VgpImprove, "improve"), \
225 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
226 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
227 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
228 VGP_PAIR(VgpDoLRU, "do-lru"), \
229 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
230 VGP_PAIR(VgpExeContext, "exe-context"), \
231 VGP_PAIR(VgpReadSyms, "read-syms"), \
232 VGP_PAIR(VgpSearchSyms, "search-syms"), \
233 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
234 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
235 VGP_PAIR(VgpDemangle, "demangle"), \
236 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
237 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
238 /* These ones depend on the tool */ \
239 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
240 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
241 VGP_PAIR(VgpInstrument, "instrument"), \
njn26f02512004-11-22 18:33:15 +0000242 VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \
243 VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \
244 VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \
nethercote37aac2e2004-09-02 08:54:27 +0000245 VGP_PAIR(VgpFini, "fini")
246
247#define VGP_PAIR(n,name) n
248typedef enum { VGP_CORE_LIST } VgpCoreCC;
249#undef VGP_PAIR
250
251/* When registering tool profiling events, ensure that the 'n' value is in
252 * the range (VgpFini+1..) */
253extern void VGP_(register_profile_event) ( Int n, Char* name );
254
255extern void VGP_(pushcc) ( UInt cc );
256extern void VGP_(popcc) ( UInt cc );
257
258/* Define them only if they haven't already been defined by vg_profile.c */
259#ifndef VGP_PUSHCC
260# define VGP_PUSHCC(x)
261#endif
262#ifndef VGP_POPCC
263# define VGP_POPCC(x)
264#endif
265
266
267/*====================================================================*/
268/*=== Useful stuff to call from generated code ===*/
269/*====================================================================*/
270
271/* ------------------------------------------------------------------ */
272/* General stuff */
273
274/* 64-bit counter for the number of basic blocks done. */
275extern ULong VG_(bbs_done);
276
nethercote37aac2e2004-09-02 08:54:27 +0000277/* Check if an address is 4-byte aligned */
278#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3))
279#define IS_ALIGNED8_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 7))
280
281
282/* ------------------------------------------------------------------ */
283/* Thread-related stuff */
284
285/* Special magic value for an invalid ThreadId. It corresponds to
286 LinuxThreads using zero as the initial value for
287 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
288#define VG_INVALID_THREADID ((ThreadId)(0))
289
290/* ThreadIds are simply indices into the VG_(threads)[] array. */
291typedef
292 UInt
293 ThreadId;
294
sewardj2a99cf62004-11-24 10:44:19 +0000295/* Returns the tid of the currently running thread. Only call it when
296 running generated code. It will barf if there is no running thread.
297 Will never return zero.
298*/
299extern ThreadId VG_(get_current_tid) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000300
sewardj2a99cf62004-11-24 10:44:19 +0000301/* Does the scheduler think we are running generated code right now? */
302extern Bool VG_(running_a_thread) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000303
304/* Searches through all thread's stacks to see if any match. Returns
305 VG_INVALID_THREADID if none match. */
306extern ThreadId VG_(first_matching_thread_stack)
307 ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
308 void* d );
309
sewardj2a99cf62004-11-24 10:44:19 +0000310/* Get the simulated %esp */
311extern Addr VG_(get_stack_pointer) ( ThreadId tid );
312
nethercote37aac2e2004-09-02 08:54:27 +0000313
314/*====================================================================*/
315/*=== Valgrind's version of libc ===*/
316/*====================================================================*/
317
318/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
319 are its own versions of C library functions, but with VG_ prefixes. Note
320 that the types of some are slightly different to the real ones. Some
321 additional useful functions are provided too; descriptions of how they
322 work are given below. */
323
324#if !defined(NULL)
325# define NULL ((void*)0)
326#endif
327
328
329/* ------------------------------------------------------------------ */
330/* stdio.h
331 *
332 * Note that they all output to the file descriptor given by the
333 * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
334 * Hence no need for VG_(fprintf)().
335 */
336extern UInt VG_(printf) ( const char *format, ... );
337/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
338extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
339extern UInt VG_(vprintf) ( void(*send)(Char),
340 const Char *format, va_list vargs );
341
342extern Int VG_(rename) ( Char* old_name, Char* new_name );
343
344/* ------------------------------------------------------------------ */
345/* stdlib.h */
346
nethercote7ac7f7b2004-11-02 12:36:02 +0000347extern void* VG_(malloc) ( SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000348extern void VG_(free) ( void* p );
nethercote7ac7f7b2004-11-02 12:36:02 +0000349extern void* VG_(calloc) ( SizeT n, SizeT nbytes );
350extern void* VG_(realloc) ( void* p, SizeT size );
351extern void* VG_(malloc_aligned) ( SizeT align_bytes, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000352
353extern void VG_(print_malloc_stats) ( void );
354
355
356extern void VG_(exit)( Int status )
357 __attribute__ ((__noreturn__));
358/* Prints a panic message (a constant string), appends newline and bug
359 reporting info, aborts. */
360__attribute__ ((__noreturn__))
njn67993252004-11-22 18:02:32 +0000361extern void VG_(tool_panic) ( Char* str );
nethercote37aac2e2004-09-02 08:54:27 +0000362
363/* Looks up VG_(client_envp) */
364extern Char* VG_(getenv) ( Char* name );
365
366/* Get client resource limit*/
367extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
368
369/* Set client resource limit*/
370extern Int VG_(setrlimit) ( Int resource, struct vki_rlimit *rlim );
371
372/* Crude stand-in for the glibc system() call. */
373extern Int VG_(system) ( Char* cmd );
374
375extern Long VG_(atoll) ( Char* str );
376
377/* Like atoll(), but converts a number of base 16 */
378extern Long VG_(atoll16) ( Char* str );
379
380/* Like atoll(), but converts a number of base 2..36 */
381extern Long VG_(atoll36) ( UInt base, Char* str );
382
383/* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */
nethercote928a5f72004-11-03 18:10:37 +0000384extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size,
nethercote37aac2e2004-09-02 08:54:27 +0000385 Int (*compar)(void*, void*) );
386
387
388/* ------------------------------------------------------------------ */
389/* ctype.h */
390extern Bool VG_(isspace) ( Char c );
391extern Bool VG_(isdigit) ( Char c );
392extern Char VG_(toupper) ( Char c );
393
394
395/* ------------------------------------------------------------------ */
396/* string.h */
397extern Int VG_(strlen) ( const Char* str );
398extern Char* VG_(strcat) ( Char* dest, const Char* src );
399extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
400extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
401extern Char* VG_(strcpy) ( Char* dest, const Char* src );
402extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
403extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
404extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
405extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
406extern Char* VG_(strchr) ( const Char* s, Char c );
407extern Char* VG_(strrchr) ( const Char* s, Char c );
408extern Char* VG_(strdup) ( const Char* s);
409extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
410extern void* VG_(memset) ( void *s, Int c, Int sz );
411extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
412
413/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
414extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
415extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
416
417/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
418 last character. */
419extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
420
421/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
422 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
423extern Bool VG_(string_match) ( const Char* pat, const Char* str );
424
425
426/* ------------------------------------------------------------------ */
427/* math.h */
428/* Returns the base-2 logarithm of x. */
429extern Int VG_(log2) ( Int x );
430
431
432/* ------------------------------------------------------------------ */
433/* unistd.h, fcntl.h, sys/stat.h */
434extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count );
435extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
436extern Int VG_(getpid) ( void );
437extern Int VG_(getppid) ( void );
438extern Int VG_(getpgrp) ( void );
439extern Int VG_(gettid) ( void );
440extern Int VG_(setpgid) ( Int pid, Int pgrp );
441
442extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
443extern Int VG_(read) ( Int fd, void* buf, Int count);
444extern Int VG_(write) ( Int fd, const void* buf, Int count);
nethercote5b9fafd2004-11-04 18:39:22 +0000445extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
nethercote37aac2e2004-09-02 08:54:27 +0000446extern void VG_(close) ( Int fd );
447
448extern Int VG_(pipe) ( Int fd[2] );
449
450/* Nb: VG_(rename)() declared in stdio.h section above */
451extern Int VG_(unlink) ( Char* file_name );
452extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
453extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
454extern Int VG_(dup2) ( Int oldfd, Int newfd );
455
nethercote928a5f72004-11-03 18:10:37 +0000456extern Char* VG_(getcwd) ( Char* buf, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000457
458/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
459 String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
460 Returns False if it fails. Will fail if the pathname is > 65535 bytes. */
461extern Bool VG_(getcwd_alloc) ( Char** cwd );
462
463/* ------------------------------------------------------------------ */
464/* assert.h */
465/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
466#define VG__STRING(__str) #__str
467
njnca82cc02004-11-22 17:18:48 +0000468#define tl_assert(expr) \
nethercote37aac2e2004-09-02 08:54:27 +0000469 ((void) ((expr) ? 0 : \
njn94065fd2004-11-22 19:26:27 +0000470 (VG_(tool_assert_fail) (VG__STRING(expr), \
nethercote37aac2e2004-09-02 08:54:27 +0000471 __FILE__, __LINE__, \
472 __PRETTY_FUNCTION__), 0)))
473
474__attribute__ ((__noreturn__))
njn94065fd2004-11-22 19:26:27 +0000475extern void VG_(tool_assert_fail) ( const Char* expr, const Char* file,
nethercote37aac2e2004-09-02 08:54:27 +0000476 Int line, const Char* fn );
477
478
479/* ------------------------------------------------------------------ */
480/* Get memory by anonymous mmap. */
nethercote8b5f40c2004-11-02 13:29:50 +0000481extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
nethercote37aac2e2004-09-02 08:54:27 +0000482
483extern Bool VG_(is_client_addr) (Addr a);
484extern Addr VG_(get_client_base)(void);
485extern Addr VG_(get_client_end) (void);
486extern Addr VG_(get_client_size)(void);
487
488extern Bool VG_(is_shadow_addr) (Addr a);
489extern Addr VG_(get_shadow_base)(void);
490extern Addr VG_(get_shadow_end) (void);
491extern Addr VG_(get_shadow_size)(void);
492
493extern void *VG_(shadow_alloc)(UInt size);
494
nethercote928a5f72004-11-03 18:10:37 +0000495extern Bool VG_(is_addressable)(Addr p, SizeT sz);
nethercote37aac2e2004-09-02 08:54:27 +0000496
nethercote928a5f72004-11-03 18:10:37 +0000497extern Addr VG_(client_alloc)(Addr base, SizeT len, UInt prot, UInt flags);
nethercote37aac2e2004-09-02 08:54:27 +0000498extern void VG_(client_free)(Addr addr);
499
500extern Bool VG_(is_valgrind_addr)(Addr a);
501
502/* initialize shadow pages in the range [p, p+sz) This calls
503 init_shadow_page for each one. It should be a lot more efficient
504 for bulk-initializing shadow pages than faulting on each one.
505*/
506extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
507
508/* ------------------------------------------------------------------ */
509/* signal.h.
510
511 Note that these use the vk_ (kernel) structure
512 definitions, which are different in places from those that glibc
nethercote73b526f2004-10-31 18:48:21 +0000513 defines. Since we're operating right at the kernel interface, glibc's view
514 of the world is entirely irrelevant. */
nethercote37aac2e2004-09-02 08:54:27 +0000515
516/* --- Signal set ops --- */
nethercote73b526f2004-10-31 18:48:21 +0000517extern Int VG_(sigfillset) ( vki_sigset_t* set );
518extern Int VG_(sigemptyset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000519
nethercote73b526f2004-10-31 18:48:21 +0000520extern Bool VG_(isfullsigset) ( vki_sigset_t* set );
521extern Bool VG_(isemptysigset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000522
nethercote73b526f2004-10-31 18:48:21 +0000523extern Int VG_(sigaddset) ( vki_sigset_t* set, Int signum );
524extern Int VG_(sigdelset) ( vki_sigset_t* set, Int signum );
525extern Int VG_(sigismember) ( vki_sigset_t* set, Int signum );
nethercote37aac2e2004-09-02 08:54:27 +0000526
nethercote73b526f2004-10-31 18:48:21 +0000527extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
528extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
nethercote37aac2e2004-09-02 08:54:27 +0000529
530/* --- Mess with the kernel's sig state --- */
nethercote73b526f2004-10-31 18:48:21 +0000531extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
532 vki_sigset_t* oldset );
533extern Int VG_(sigaction) ( Int signum,
534 const struct vki_sigaction* act,
535 struct vki_sigaction* oldact );
nethercote37aac2e2004-09-02 08:54:27 +0000536
nethercote73b526f2004-10-31 18:48:21 +0000537extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *,
538 const struct vki_timespec * );
nethercote37aac2e2004-09-02 08:54:27 +0000539
nethercote73b526f2004-10-31 18:48:21 +0000540extern Int VG_(signal) ( Int signum, void (*sighandler)(Int) );
541extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
nethercote37aac2e2004-09-02 08:54:27 +0000542
nethercote73b526f2004-10-31 18:48:21 +0000543extern Int VG_(kill) ( Int pid, Int signo );
544extern Int VG_(tkill) ( Int pid, Int signo );
545extern Int VG_(sigpending) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000546
nethercote73b526f2004-10-31 18:48:21 +0000547extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
nethercote37aac2e2004-09-02 08:54:27 +0000548
549/* ------------------------------------------------------------------ */
550/* socket.h. */
551
552extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
553extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
554extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
555 Int *optlen);
556
557/* ------------------------------------------------------------------ */
558/* other, randomly useful functions */
559extern UInt VG_(read_millisecond_timer) ( void );
560
561extern void VG_(cpuid) ( UInt eax,
562 UInt *eax_ret, UInt *ebx_ret,
563 UInt *ecx_ret, UInt *edx_ret );
564
nethercote37aac2e2004-09-02 08:54:27 +0000565/*====================================================================*/
566/*=== Execution contexts ===*/
567/*====================================================================*/
568
569/* Generic resolution type used in a few different ways, such as deciding
570 how closely to compare two errors for equality. */
571typedef
572 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
573 VgRes;
574
575typedef
576 struct _ExeContext
577 ExeContext;
578
579/* Compare two ExeContexts. Number of callers considered depends on `res':
580 Vg_LowRes: 2
581 Vg_MedRes: 4
582 Vg_HighRes: all */
583extern Bool VG_(eq_ExeContext) ( VgRes res,
584 ExeContext* e1, ExeContext* e2 );
585
586/* Print an ExeContext. */
587extern void VG_(pp_ExeContext) ( ExeContext* );
588
589/* Take a snapshot of the client's stack. Search our collection of
590 ExeContexts to see if we already have it, and if not, allocate a
591 new one. Either way, return a pointer to the context. Context size
592 controlled by --num-callers option.
593
594 If called from generated code, use VG_(get_current_tid)() to get the
595 current ThreadId. If called from non-generated code, the current
596 ThreadId should be passed in by the core.
597*/
598extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
599
nethercote86c5dcb2004-09-05 21:32:37 +0000600/* Get the nth IP from the ExeContext. 0 is the IP of the top function, 1
nethercote37aac2e2004-09-02 08:54:27 +0000601 is its caller, etc. Returns 0 if there isn't one, or if n is greater
602 than VG_(clo_backtrace_size), set by the --num-callers option. */
603extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
604
nethercote86c5dcb2004-09-05 21:32:37 +0000605/* Just grab the client's IP, as a much smaller and cheaper
nethercote37aac2e2004-09-02 08:54:27 +0000606 indication of where they are. Use is basically same as for
607 VG_(get_ExeContext)() above.
608*/
609extern Addr VG_(get_EIP)( ThreadId tid );
610
611/* For tools needing more control over stack traces: walks the stack to get
nethercote86c5dcb2004-09-05 21:32:37 +0000612 instruction pointers from the top stack frames for thread 'tid'. Maximum of
613 'n_ips' addresses put into 'ips'; 0 is the top of the stack, 1 is its
614 caller, etc. */
615extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* ips, UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000616
617/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
618 different input. */
nethercote86c5dcb2004-09-05 21:32:37 +0000619extern void VG_(mini_stack_dump) ( Addr ips[], UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000620
621
622/*====================================================================*/
623/*=== Error reporting ===*/
624/*====================================================================*/
625
626/* ------------------------------------------------------------------ */
627/* Suppressions describe errors which we want to suppress, ie, not
628 show the user, usually because it is caused by a problem in a library
629 which we can't fix, replace or work around. Suppressions are read from
630 a file at startup time. This gives flexibility so that new
631 suppressions can be added to the file as and when needed.
632*/
633
634typedef
635 Int /* Do not make this unsigned! */
636 SuppKind;
637
638/* The tool-relevant parts of a suppression are:
639 kind: what kind of suppression; must be in the range (0..)
640 string: use is optional. NULL by default.
641 extra: use is optional. NULL by default. void* so it's extensible.
642*/
643typedef
644 struct _Supp
645 Supp;
646
njn26f02512004-11-22 18:33:15 +0000647/* Useful in TL_(error_matches_suppression)() */
nethercote37aac2e2004-09-02 08:54:27 +0000648SuppKind VG_(get_supp_kind) ( Supp* su );
649Char* VG_(get_supp_string) ( Supp* su );
650void* VG_(get_supp_extra) ( Supp* su );
651
652/* Must be used in VG_(recognised_suppression)() */
653void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
654/* May be used in VG_(read_extra_suppression_info)() */
655void VG_(set_supp_string) ( Supp* su, Char* string );
656void VG_(set_supp_extra) ( Supp* su, void* extra );
657
658
659/* ------------------------------------------------------------------ */
660/* Error records contain enough info to generate an error report. The idea
661 is that (typically) the same few points in the program generate thousands
662 of errors, and we don't want to spew out a fresh error message for each
663 one. Instead, we use these structures to common up duplicates.
664*/
665
666typedef
667 Int /* Do not make this unsigned! */
668 ErrorKind;
669
670/* The tool-relevant parts of an Error are:
671 kind: what kind of error; must be in the range (0..)
672 addr: use is optional. 0 by default.
673 string: use is optional. NULL by default.
674 extra: use is optional. NULL by default. void* so it's extensible.
675*/
676typedef
677 struct _Error
678 Error;
679
njn26f02512004-11-22 18:33:15 +0000680/* Useful in TL_(error_matches_suppression)(), TL_(pp_Error)(), etc */
nethercote37aac2e2004-09-02 08:54:27 +0000681ExeContext* VG_(get_error_where) ( Error* err );
682SuppKind VG_(get_error_kind) ( Error* err );
683Addr VG_(get_error_address) ( Error* err );
684Char* VG_(get_error_string) ( Error* err );
685void* VG_(get_error_extra) ( Error* err );
686
687/* Call this when an error occurs. It will be recorded if it hasn't been
688 seen before. If it has, the existing error record will have its count
689 incremented.
690
691 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
692 be stack-allocated; it will be copied by the core if needed (but it
693 won't be copied if it's NULL).
694
695 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
696 NULL for them. */
697extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
698 Addr a, Char* s, void* extra );
699
700/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
701 error -- useful for errors that can only happen once. The errors can be
702 suppressed, though. Return value is True if it was suppressed.
703 `print_error' dictates whether to print the error, which is a bit of a
704 hack that's useful sometimes if you just want to know if the error would
705 be suppressed without possibly printing it. `count_error' dictates
706 whether to add the error in the error total count (another mild hack). */
707extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
708 Addr a, Char* s, void* extra,
709 ExeContext* where, Bool print_error,
710 Bool allow_GDB_attach, Bool count_error );
711
712/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
713 Skips leading spaces on the line. Returns True if EOF was hit instead.
714 Useful for reading in extra tool-specific suppression lines. */
715extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
716
717
718/*====================================================================*/
719/*=== Obtaining debug information ===*/
720/*====================================================================*/
721
722/* Get the file/function/line number of the instruction at address
723 'a'. For these four, if debug info for the address is found, it
724 copies the info into the buffer/UInt and returns True. If not, it
725 returns False and nothing is copied. VG_(get_fnname) always
726 demangles C++ function names. VG_(get_fnname_w_offset) is the
727 same, except it appends "+N" to symbol names to indicate offsets. */
728extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
729extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
730extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
731extern Bool VG_(get_fnname_w_offset)
732 ( Addr a, Char* fnname, Int n_fnname );
733
734/* This one is more efficient if getting both filename and line number,
735 because the two lookups are done together. */
736extern Bool VG_(get_filename_linenum)
737 ( Addr a, Char* filename, Int n_filename,
738 UInt* linenum );
739
740/* Succeeds only if we find from debug info that 'a' is the address of the
741 first instruction in a function -- as opposed to VG_(get_fnname) which
742 succeeds if we find from debug info that 'a' is the address of any
743 instruction in a function. Use this to instrument the start of
744 a particular function. Nb: if an executable/shared object is stripped
745 of its symbols, this function will not be able to recognise function
746 entry points within it. */
747extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
748
749/* Succeeds if the address is within a shared object or the main executable.
750 It doesn't matter if debug info is present or not. */
751extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
752
753/* Puts into 'buf' info about the code address %eip: the address, function
754 name (if known) and filename/line number (if known), like this:
755
756 0x4001BF05: realloc (vg_replace_malloc.c:339)
757
758 'n_buf' gives length of 'buf'. Returns 'buf'.
759*/
760extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
761
762/* Returns a string containing an expression for the given
763 address. String is malloced with VG_(malloc)() */
764Char *VG_(describe_addr)(ThreadId, Addr);
765
766/* A way to get information about what segments are mapped */
767typedef struct _SegInfo SegInfo;
768
769/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
770 is present or not. */
771extern SegInfo* VG_(get_obj) ( Addr a );
772
773extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
774extern Addr VG_(seg_start) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000775extern SizeT VG_(seg_size) ( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000776extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000777extern ULong VG_(seg_sym_offset)( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000778
779typedef
780 enum {
781 Vg_SectUnknown,
782 Vg_SectText,
783 Vg_SectData,
784 Vg_SectBSS,
785 Vg_SectGOT,
786 Vg_SectPLT,
787 }
788 VgSectKind;
789
790extern VgSectKind VG_(seg_sect_kind)(Addr);
791
nethercote37aac2e2004-09-02 08:54:27 +0000792/*====================================================================*/
793/*=== Generic hash table ===*/
794/*====================================================================*/
795
796/* Generic type for a separately-chained hash table. Via a kind of dodgy
797 C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
798 as the first two fields match the sizes of these two fields. Requires
799 a bit of casting by the tool. */
800typedef
801 struct _VgHashNode {
802 struct _VgHashNode * next;
nethercote3d6b6112004-11-04 16:39:43 +0000803 UWord key;
nethercote37aac2e2004-09-02 08:54:27 +0000804 }
805 VgHashNode;
806
807typedef
808 VgHashNode**
809 VgHashTable;
810
811/* Make a new table. */
812extern VgHashTable VG_(HT_construct) ( void );
813
814/* Count the number of nodes in a table. */
815extern Int VG_(HT_count_nodes) ( VgHashTable table );
816
817/* Add a node to the table. */
818extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
819
820/* Looks up a node in the hash table. Also returns the address of the
821 previous node's `next' pointer which allows it to be removed from the
822 list later without having to look it up again. */
nethercote3d6b6112004-11-04 16:39:43 +0000823extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
nethercote37aac2e2004-09-02 08:54:27 +0000824 /*OUT*/VgHashNode*** next_ptr );
825
826/* Allocates an array of pointers to all the shadow chunks of malloc'd
827 blocks. Must be freed with VG_(free)(). */
828extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
829
830/* Returns first node that matches predicate `p', or NULL if none do.
831 Extra arguments can be implicitly passed to `p' using `d' which is an
832 opaque pointer passed to `p' each time it is called. */
833extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
834 Bool (*p)(VgHashNode*, void*),
835 void* d );
836
837/* Applies a function f() once to each node. Again, `d' can be used
838 to pass extra information to the function. */
839extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
840 void (*f)(VgHashNode*, void*),
841 void* d );
842
843/* Destroy a table. */
844extern void VG_(HT_destruct) ( VgHashTable t );
845
846
847/*====================================================================*/
848/*=== A generic skiplist ===*/
849/*====================================================================*/
850
851/*
852 The idea here is that the skiplist puts its per-element data at the
853 end of the structure. When you initialize the skiplist, you tell
854 it what structure your list elements are going to be. Then you
855 should allocate them with VG_(SkipNode_Alloc), which will allocate
856 enough memory for the extra bits.
857 */
858#include <stddef.h> /* for offsetof */
859
860typedef struct _SkipList SkipList;
861typedef struct _SkipNode SkipNode;
862
863typedef Int (*SkipCmp_t)(const void *key1, const void *key2);
864
865struct _SkipList {
866 const Short arena; /* allocation arena */
867 const UShort size; /* structure size (not including SkipNode) */
868 const UShort keyoff; /* key offset */
869 const SkipCmp_t cmp; /* compare two keys */
870 Char * (*strkey)(void *); /* stringify a key (for debugging) */
871 SkipNode *head; /* list head */
872};
873
874/* Use this macro to initialize your skiplist head. The arguments are pretty self explanitory:
875 _type is the type of your element structure
876 _key is the field within that type which you want to use as the key
877 _cmp is the comparison function for keys - it gets two typeof(_key) pointers as args
878 _strkey is a function which can return a string of your key - it's only used for debugging
879 _arena is the arena to use for allocation - -1 is the default
880 */
881#define SKIPLIST_INIT(_type, _key, _cmp, _strkey, _arena) \
882 { \
883 .arena = _arena, \
884 .size = sizeof(_type), \
885 .keyoff = offsetof(_type, _key), \
886 .cmp = _cmp, \
887 .strkey = _strkey, \
888 .head = NULL, \
889 }
890
891/* List operations:
892 SkipList_Find searchs a list. If it can't find an exact match, it either
893 returns NULL or a pointer to the element before where k would go
894 SkipList_Insert inserts a new element into the list. Duplicates are
895 forbidden. The element must have been created with SkipList_Alloc!
896 SkipList_Remove removes an element from the list and returns it. It
897 doesn't free the memory.
898*/
899extern void *VG_(SkipList_Find) (const SkipList *l, void *key);
900extern void VG_(SkipList_Insert)( SkipList *l, void *data);
901extern void *VG_(SkipList_Remove)( SkipList *l, void *key);
902
903/* Node (element) operations:
904 SkipNode_Alloc: allocate memory for a new element on the list. Must be
905 used before an element can be inserted! Returns NULL if not enough
906 memory.
907 SkipNode_Free: free memory allocated above
908 SkipNode_First: return the first element on the list
909 SkipNode_Next: return the next element after "data" on the list -
910 NULL for none
911
912 You can iterate through a SkipList like this:
913
914 for(x = VG_(SkipNode_First)(&list); // or SkipList_Find
915 x != NULL;
916 x = VG_(SkipNode_Next)(&list, x)) { ... }
917*/
918extern void *VG_(SkipNode_Alloc) (const SkipList *l);
919extern void VG_(SkipNode_Free) (const SkipList *l, void *p);
920extern void *VG_(SkipNode_First) (const SkipList *l);
921extern void *VG_(SkipNode_Next) (const SkipList *l, void *data);
922
njnabb14ad2004-11-24 16:57:16 +0000923
nethercote37aac2e2004-09-02 08:54:27 +0000924/*====================================================================*/
925/*=== Functions for shadow registers ===*/
926/*====================================================================*/
927
njnabb14ad2004-11-24 16:57:16 +0000928// For get/set, 'area' is where the asked-for shadow state will be copied
929// into/from.
930extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
931 SizeT size, UChar* area );
932extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
933 SizeT size, const UChar* area );
nethercote37aac2e2004-09-02 08:54:27 +0000934
935/* This one lets you override the shadow of the return value register for a
njn26f02512004-11-22 18:33:15 +0000936 syscall. Call it from TL_(post_syscall)() (not TL_(pre_syscall)()!) to
nethercote37aac2e2004-09-02 08:54:27 +0000937 override the default shadow register value. */
938extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njncf45fd42004-11-24 16:30:22 +0000939 UWord ret_shadow );
nethercote37aac2e2004-09-02 08:54:27 +0000940
njn26f02512004-11-22 18:33:15 +0000941/* This can be called from TL_(fini)() to find the shadow of the argument
nethercote37aac2e2004-09-02 08:54:27 +0000942 to exit(), ie. the shadow of the program's return value. */
sewardj2a99cf62004-11-24 10:44:19 +0000943extern UInt VG_(get_exit_status_shadow) ( ThreadId );
nethercote37aac2e2004-09-02 08:54:27 +0000944
945
946/*====================================================================*/
947/*=== Specific stuff for replacing malloc() and friends ===*/
948/*====================================================================*/
949
950/* If a tool replaces malloc() et al, the easiest way to do so is to
951 link with vg_replace_malloc.o into its vgpreload_*.so file, and
952 follow the following instructions. You can do it from scratch,
953 though, if you enjoy that sort of thing. */
954
955/* Arena size for valgrind's own malloc(); default value is 0, but can
956 be overridden by tool -- but must be done so *statically*, eg:
957
nethercote7ac7f7b2004-11-02 12:36:02 +0000958 UInt VG_(vg_malloc_redzone_szB) = 4;
nethercote37aac2e2004-09-02 08:54:27 +0000959
njn26f02512004-11-22 18:33:15 +0000960 It can't be done from a function like TL_(pre_clo_init)(). So it can't,
nethercote37aac2e2004-09-02 08:54:27 +0000961 for example, be controlled with a command line option, unfortunately. */
962extern UInt VG_(vg_malloc_redzone_szB);
963
njn26f02512004-11-22 18:33:15 +0000964/* Can be called from TL_(malloc) et al to do the actual alloc/freeing. */
nethercote7ac7f7b2004-11-02 12:36:02 +0000965extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000966extern void VG_(cli_free) ( void* p );
967
968/* Check if an address is within a range, allowing for redzones at edges */
nethercote7ac7f7b2004-11-02 12:36:02 +0000969extern Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000970
971/* ------------------------------------------------------------------ */
972/* Some options that can be used by a tool if malloc() et al are replaced.
973 The tool should call the functions in the appropriate places to give
974 control over these aspects of Valgrind's version of malloc(). */
975
976/* Round malloc sizes upwards to integral number of words? default: NO */
977extern Bool VG_(clo_sloppy_malloc);
978/* DEBUG: print malloc details? default: NO */
979extern Bool VG_(clo_trace_malloc);
980/* Minimum alignment in functions that don't specify alignment explicitly.
981 default: 0, i.e. use default of the machine (== 4) */
nethercote7ac7f7b2004-11-02 12:36:02 +0000982extern UInt VG_(clo_alignment);
nethercote37aac2e2004-09-02 08:54:27 +0000983
984extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
985extern void VG_(replacement_malloc_print_usage) ( void );
986extern void VG_(replacement_malloc_print_debug_usage) ( void );
987
988
989/*====================================================================*/
990/*=== Tool-specific stuff ===*/
991/*====================================================================*/
992
993/* ------------------------------------------------------------------ */
994/* Details */
995
996/* Default value for avg_translations_sizeB (in bytes), indicating typical
997 code expansion of about 6:1. */
998#define VG_DEFAULT_TRANS_SIZEB 100
999
1000/* Information used in the startup message. `name' also determines the
1001 string used for identifying suppressions in a suppression file as
1002 belonging to this tool. `version' can be NULL, in which case (not
1003 surprisingly) no version info is printed; this mechanism is designed for
1004 tools distributed with Valgrind that share a version number with
1005 Valgrind. Other tools not distributed as part of Valgrind should
1006 probably have their own version number. */
1007extern void VG_(details_name) ( Char* name );
1008extern void VG_(details_version) ( Char* version );
1009extern void VG_(details_description) ( Char* description );
1010extern void VG_(details_copyright_author) ( Char* copyright_author );
1011
1012/* Average size of a translation, in bytes, so that the translation
1013 storage machinery can allocate memory appropriately. Not critical,
1014 setting is optional. */
1015extern void VG_(details_avg_translation_sizeB) ( UInt size );
1016
njn67993252004-11-22 18:02:32 +00001017/* String printed if an `tl_assert' assertion fails or VG_(tool_panic)
nethercote37aac2e2004-09-02 08:54:27 +00001018 is called. Should probably be an email address. */
1019extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
1020
1021/* ------------------------------------------------------------------ */
1022/* Needs */
1023
1024/* Booleans that decide core behaviour, but don't require extra
1025 operations to be defined if `True' */
1026
1027/* Should __libc_freeres() be run? Bugs in it can crash the tool. */
1028extern void VG_(needs_libc_freeres) ( void );
1029
1030/* Want to have errors detected by Valgrind's core reported? Includes:
1031 - pthread API errors (many; eg. unlocking a non-locked mutex)
1032 - invalid file descriptors to blocking syscalls read() and write()
1033 - bad signal numbers passed to sigaction()
1034 - attempt to install signal handler for SIGKILL or SIGSTOP */
1035extern void VG_(needs_core_errors) ( void );
1036
1037/* Booleans that indicate extra operations are defined; if these are True,
1038 the corresponding template functions (given below) must be defined. A
1039 lot like being a member of a type class. */
1040
1041/* Want to report errors from tool? This implies use of suppressions, too. */
njn95ec8702004-11-22 16:46:13 +00001042extern void VG_(needs_tool_errors) ( void );
nethercote37aac2e2004-09-02 08:54:27 +00001043
1044/* Is information kept about specific individual basic blocks? (Eg. for
1045 cachegrind there are cost-centres for every instruction, stored at a
1046 basic block level.) If so, it sometimes has to be discarded, because
1047 .so mmap/munmap-ping or self-modifying code (informed by the
1048 DISCARD_TRANSLATIONS user request) can cause one instruction address
1049 to be used for more than one instruction in one program run... */
1050extern void VG_(needs_basic_block_discards) ( void );
1051
nethercote37aac2e2004-09-02 08:54:27 +00001052/* Tool defines its own command line options? */
1053extern void VG_(needs_command_line_options) ( void );
1054
1055/* Tool defines its own client requests? */
1056extern void VG_(needs_client_requests) ( void );
1057
nethercote37aac2e2004-09-02 08:54:27 +00001058/* Tool does stuff before and/or after system calls? */
1059extern void VG_(needs_syscall_wrapper) ( void );
1060
1061/* Are tool-state sanity checks performed? */
1062extern void VG_(needs_sanity_checks) ( void );
1063
1064/* Do we need to see data symbols? */
1065extern void VG_(needs_data_syms) ( void );
1066
1067/* Does the tool need shadow memory allocated (if you set this, you must also statically initialize
njn26f02512004-11-22 18:33:15 +00001068 float TL_(shadow_ratio) = n./m;
nethercote37aac2e2004-09-02 08:54:27 +00001069 to define how many shadow bits you need per client address space bit.
1070*/
1071extern void VG_(needs_shadow_memory)( void );
njn26f02512004-11-22 18:33:15 +00001072extern float TL_(shadow_ratio);
nethercote37aac2e2004-09-02 08:54:27 +00001073
1074/* ------------------------------------------------------------------ */
1075/* Core events to track */
1076
1077/* Part of the core from which this call was made. Useful for determining
1078 what kind of error message should be emitted. */
1079typedef
njncf45fd42004-11-24 16:30:22 +00001080 enum { Vg_CoreStartup, Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall,
1081 Vg_CoreTranslate, Vg_CoreClientReq }
nethercote37aac2e2004-09-02 08:54:27 +00001082 CorePart;
1083
1084/* Useful to use in VG_(get_Xreg_usage)() */
1085#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
1086 { if (mycat(u->tag,ono) == tag) \
1087 { regs[n] = mycat(u->val,ono); \
1088 isWrites[n] = False; \
1089 n++; \
1090 } \
1091 }
1092#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
1093 { if (mycat(u->tag,ono) == tag) \
1094 { regs[n] = mycat(u->val,ono); \
1095 isWrites[n] = True; \
1096 n++; \
1097 } \
1098 }
1099
1100#endif /* NDEF __TOOL_H */
1101
1102/* gen_toolint.pl will put the VG_(init_*)() functions here: */