blob: 50ca9510ed7e166806378a828c1342b7e0c4c838 [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 */
njnd2252832004-11-26 10:53:33 +0000108 void (*tl_pre_clo_init) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000109
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, \
njnd2252832004-11-26 10:53:33 +0000121 .tl_pre_clo_init = pre_clo_init, \
nethercote37aac2e2004-09-02 08:54:27 +0000122 .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
njnedfa0f62004-11-30 18:08:05 +0000277/* Check if an address/whatever is aligned */
278#define IS_4_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x3))
279#define IS_8_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x7))
280#define IS_16_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0xf))
281#define IS_WORD_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & (sizeof(Addr)-1)))
nethercote37aac2e2004-09-02 08:54:27 +0000282
283
284/* ------------------------------------------------------------------ */
285/* Thread-related stuff */
286
287/* Special magic value for an invalid ThreadId. It corresponds to
288 LinuxThreads using zero as the initial value for
289 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
290#define VG_INVALID_THREADID ((ThreadId)(0))
291
292/* ThreadIds are simply indices into the VG_(threads)[] array. */
293typedef
294 UInt
295 ThreadId;
296
sewardj2a99cf62004-11-24 10:44:19 +0000297/* Returns the tid of the currently running thread. Only call it when
298 running generated code. It will barf if there is no running thread.
299 Will never return zero.
300*/
301extern ThreadId VG_(get_current_tid) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000302
sewardj2a99cf62004-11-24 10:44:19 +0000303/* Does the scheduler think we are running generated code right now? */
304extern Bool VG_(running_a_thread) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000305
306/* Searches through all thread's stacks to see if any match. Returns
307 VG_INVALID_THREADID if none match. */
308extern ThreadId VG_(first_matching_thread_stack)
309 ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
310 void* d );
311
sewardj2a99cf62004-11-24 10:44:19 +0000312/* Get the simulated %esp */
313extern Addr VG_(get_stack_pointer) ( ThreadId tid );
314
nethercote37aac2e2004-09-02 08:54:27 +0000315
316/*====================================================================*/
317/*=== Valgrind's version of libc ===*/
318/*====================================================================*/
319
320/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
321 are its own versions of C library functions, but with VG_ prefixes. Note
322 that the types of some are slightly different to the real ones. Some
323 additional useful functions are provided too; descriptions of how they
324 work are given below. */
325
326#if !defined(NULL)
327# define NULL ((void*)0)
328#endif
329
330
331/* ------------------------------------------------------------------ */
332/* stdio.h
333 *
334 * Note that they all output to the file descriptor given by the
335 * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
336 * Hence no need for VG_(fprintf)().
337 */
338extern UInt VG_(printf) ( const char *format, ... );
339/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
340extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
341extern UInt VG_(vprintf) ( void(*send)(Char),
342 const Char *format, va_list vargs );
343
344extern Int VG_(rename) ( Char* old_name, Char* new_name );
345
346/* ------------------------------------------------------------------ */
347/* stdlib.h */
348
nethercote7ac7f7b2004-11-02 12:36:02 +0000349extern void* VG_(malloc) ( SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000350extern void VG_(free) ( void* p );
nethercote7ac7f7b2004-11-02 12:36:02 +0000351extern void* VG_(calloc) ( SizeT n, SizeT nbytes );
352extern void* VG_(realloc) ( void* p, SizeT size );
353extern void* VG_(malloc_aligned) ( SizeT align_bytes, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000354
355extern void VG_(print_malloc_stats) ( void );
356
357
358extern void VG_(exit)( Int status )
359 __attribute__ ((__noreturn__));
360/* Prints a panic message (a constant string), appends newline and bug
361 reporting info, aborts. */
362__attribute__ ((__noreturn__))
njn67993252004-11-22 18:02:32 +0000363extern void VG_(tool_panic) ( Char* str );
nethercote37aac2e2004-09-02 08:54:27 +0000364
365/* Looks up VG_(client_envp) */
366extern Char* VG_(getenv) ( Char* name );
367
368/* Get client resource limit*/
369extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
370
371/* Set client resource limit*/
372extern Int VG_(setrlimit) ( Int resource, struct vki_rlimit *rlim );
373
374/* Crude stand-in for the glibc system() call. */
375extern Int VG_(system) ( Char* cmd );
376
377extern Long VG_(atoll) ( Char* str );
378
379/* Like atoll(), but converts a number of base 16 */
380extern Long VG_(atoll16) ( Char* str );
381
382/* Like atoll(), but converts a number of base 2..36 */
383extern Long VG_(atoll36) ( UInt base, Char* str );
384
385/* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */
nethercote928a5f72004-11-03 18:10:37 +0000386extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size,
nethercote37aac2e2004-09-02 08:54:27 +0000387 Int (*compar)(void*, void*) );
388
389
390/* ------------------------------------------------------------------ */
391/* ctype.h */
392extern Bool VG_(isspace) ( Char c );
393extern Bool VG_(isdigit) ( Char c );
394extern Char VG_(toupper) ( Char c );
395
396
397/* ------------------------------------------------------------------ */
398/* string.h */
399extern Int VG_(strlen) ( const Char* str );
400extern Char* VG_(strcat) ( Char* dest, const Char* src );
401extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
402extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
403extern Char* VG_(strcpy) ( Char* dest, const Char* src );
404extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
405extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
406extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
407extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
408extern Char* VG_(strchr) ( const Char* s, Char c );
409extern Char* VG_(strrchr) ( const Char* s, Char c );
410extern Char* VG_(strdup) ( const Char* s);
411extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
412extern void* VG_(memset) ( void *s, Int c, Int sz );
413extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
414
415/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
416extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
417extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
418
419/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
420 last character. */
421extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
422
423/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
424 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
425extern Bool VG_(string_match) ( const Char* pat, const Char* str );
426
427
428/* ------------------------------------------------------------------ */
429/* math.h */
430/* Returns the base-2 logarithm of x. */
431extern Int VG_(log2) ( Int x );
432
433
434/* ------------------------------------------------------------------ */
435/* unistd.h, fcntl.h, sys/stat.h */
436extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count );
437extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
438extern Int VG_(getpid) ( void );
439extern Int VG_(getppid) ( void );
440extern Int VG_(getpgrp) ( void );
441extern Int VG_(gettid) ( void );
442extern Int VG_(setpgid) ( Int pid, Int pgrp );
443
444extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
445extern Int VG_(read) ( Int fd, void* buf, Int count);
446extern Int VG_(write) ( Int fd, const void* buf, Int count);
nethercote5b9fafd2004-11-04 18:39:22 +0000447extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
nethercote37aac2e2004-09-02 08:54:27 +0000448extern void VG_(close) ( Int fd );
449
450extern Int VG_(pipe) ( Int fd[2] );
451
452/* Nb: VG_(rename)() declared in stdio.h section above */
453extern Int VG_(unlink) ( Char* file_name );
454extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
455extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
456extern Int VG_(dup2) ( Int oldfd, Int newfd );
457
nethercote928a5f72004-11-03 18:10:37 +0000458extern Char* VG_(getcwd) ( Char* buf, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000459
460/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
461 String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
462 Returns False if it fails. Will fail if the pathname is > 65535 bytes. */
463extern Bool VG_(getcwd_alloc) ( Char** cwd );
464
465/* ------------------------------------------------------------------ */
466/* assert.h */
467/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
468#define VG__STRING(__str) #__str
469
njnca82cc02004-11-22 17:18:48 +0000470#define tl_assert(expr) \
nethercote37aac2e2004-09-02 08:54:27 +0000471 ((void) ((expr) ? 0 : \
njn94065fd2004-11-22 19:26:27 +0000472 (VG_(tool_assert_fail) (VG__STRING(expr), \
nethercote37aac2e2004-09-02 08:54:27 +0000473 __FILE__, __LINE__, \
474 __PRETTY_FUNCTION__), 0)))
475
476__attribute__ ((__noreturn__))
njn94065fd2004-11-22 19:26:27 +0000477extern void VG_(tool_assert_fail) ( const Char* expr, const Char* file,
nethercote37aac2e2004-09-02 08:54:27 +0000478 Int line, const Char* fn );
479
480
481/* ------------------------------------------------------------------ */
482/* Get memory by anonymous mmap. */
nethercote8b5f40c2004-11-02 13:29:50 +0000483extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
nethercote37aac2e2004-09-02 08:54:27 +0000484
485extern Bool VG_(is_client_addr) (Addr a);
486extern Addr VG_(get_client_base)(void);
487extern Addr VG_(get_client_end) (void);
488extern Addr VG_(get_client_size)(void);
489
490extern Bool VG_(is_shadow_addr) (Addr a);
491extern Addr VG_(get_shadow_base)(void);
492extern Addr VG_(get_shadow_end) (void);
493extern Addr VG_(get_shadow_size)(void);
494
495extern void *VG_(shadow_alloc)(UInt size);
496
nethercote928a5f72004-11-03 18:10:37 +0000497extern Bool VG_(is_addressable)(Addr p, SizeT sz);
nethercote37aac2e2004-09-02 08:54:27 +0000498
nethercote928a5f72004-11-03 18:10:37 +0000499extern Addr VG_(client_alloc)(Addr base, SizeT len, UInt prot, UInt flags);
nethercote37aac2e2004-09-02 08:54:27 +0000500extern void VG_(client_free)(Addr addr);
501
502extern Bool VG_(is_valgrind_addr)(Addr a);
503
504/* initialize shadow pages in the range [p, p+sz) This calls
505 init_shadow_page for each one. It should be a lot more efficient
506 for bulk-initializing shadow pages than faulting on each one.
507*/
508extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
509
510/* ------------------------------------------------------------------ */
511/* signal.h.
512
513 Note that these use the vk_ (kernel) structure
514 definitions, which are different in places from those that glibc
nethercote73b526f2004-10-31 18:48:21 +0000515 defines. Since we're operating right at the kernel interface, glibc's view
516 of the world is entirely irrelevant. */
nethercote37aac2e2004-09-02 08:54:27 +0000517
518/* --- Signal set ops --- */
nethercote73b526f2004-10-31 18:48:21 +0000519extern Int VG_(sigfillset) ( vki_sigset_t* set );
520extern Int VG_(sigemptyset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000521
nethercote73b526f2004-10-31 18:48:21 +0000522extern Bool VG_(isfullsigset) ( vki_sigset_t* set );
523extern Bool VG_(isemptysigset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000524
nethercote73b526f2004-10-31 18:48:21 +0000525extern Int VG_(sigaddset) ( vki_sigset_t* set, Int signum );
526extern Int VG_(sigdelset) ( vki_sigset_t* set, Int signum );
527extern Int VG_(sigismember) ( vki_sigset_t* set, Int signum );
nethercote37aac2e2004-09-02 08:54:27 +0000528
nethercote73b526f2004-10-31 18:48:21 +0000529extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
530extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
nethercote37aac2e2004-09-02 08:54:27 +0000531
532/* --- Mess with the kernel's sig state --- */
nethercote73b526f2004-10-31 18:48:21 +0000533extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
534 vki_sigset_t* oldset );
535extern Int VG_(sigaction) ( Int signum,
536 const struct vki_sigaction* act,
537 struct vki_sigaction* oldact );
nethercote37aac2e2004-09-02 08:54:27 +0000538
nethercote73b526f2004-10-31 18:48:21 +0000539extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *,
540 const struct vki_timespec * );
nethercote37aac2e2004-09-02 08:54:27 +0000541
nethercote73b526f2004-10-31 18:48:21 +0000542extern Int VG_(signal) ( Int signum, void (*sighandler)(Int) );
543extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
nethercote37aac2e2004-09-02 08:54:27 +0000544
nethercote73b526f2004-10-31 18:48:21 +0000545extern Int VG_(kill) ( Int pid, Int signo );
njnc6168192004-11-29 13:54:10 +0000546extern Int VG_(tkill) ( ThreadId tid, Int signo );
nethercote73b526f2004-10-31 18:48:21 +0000547extern Int VG_(sigpending) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000548
nethercote73b526f2004-10-31 18:48:21 +0000549extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
nethercote37aac2e2004-09-02 08:54:27 +0000550
551/* ------------------------------------------------------------------ */
552/* socket.h. */
553
554extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
555extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
556extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
557 Int *optlen);
558
559/* ------------------------------------------------------------------ */
560/* other, randomly useful functions */
561extern UInt VG_(read_millisecond_timer) ( void );
562
563extern void VG_(cpuid) ( UInt eax,
564 UInt *eax_ret, UInt *ebx_ret,
565 UInt *ecx_ret, UInt *edx_ret );
566
nethercote37aac2e2004-09-02 08:54:27 +0000567/*====================================================================*/
568/*=== Execution contexts ===*/
569/*====================================================================*/
570
571/* Generic resolution type used in a few different ways, such as deciding
572 how closely to compare two errors for equality. */
573typedef
574 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
575 VgRes;
576
577typedef
578 struct _ExeContext
579 ExeContext;
580
581/* Compare two ExeContexts. Number of callers considered depends on `res':
582 Vg_LowRes: 2
583 Vg_MedRes: 4
584 Vg_HighRes: all */
585extern Bool VG_(eq_ExeContext) ( VgRes res,
586 ExeContext* e1, ExeContext* e2 );
587
588/* Print an ExeContext. */
589extern void VG_(pp_ExeContext) ( ExeContext* );
590
591/* Take a snapshot of the client's stack. Search our collection of
592 ExeContexts to see if we already have it, and if not, allocate a
593 new one. Either way, return a pointer to the context. Context size
594 controlled by --num-callers option.
595
596 If called from generated code, use VG_(get_current_tid)() to get the
597 current ThreadId. If called from non-generated code, the current
598 ThreadId should be passed in by the core.
599*/
600extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
601
nethercote86c5dcb2004-09-05 21:32:37 +0000602/* Get the nth IP from the ExeContext. 0 is the IP of the top function, 1
nethercote37aac2e2004-09-02 08:54:27 +0000603 is its caller, etc. Returns 0 if there isn't one, or if n is greater
604 than VG_(clo_backtrace_size), set by the --num-callers option. */
605extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
606
nethercote86c5dcb2004-09-05 21:32:37 +0000607/* Just grab the client's IP, as a much smaller and cheaper
nethercote37aac2e2004-09-02 08:54:27 +0000608 indication of where they are. Use is basically same as for
609 VG_(get_ExeContext)() above.
610*/
611extern Addr VG_(get_EIP)( ThreadId tid );
612
613/* For tools needing more control over stack traces: walks the stack to get
nethercote86c5dcb2004-09-05 21:32:37 +0000614 instruction pointers from the top stack frames for thread 'tid'. Maximum of
615 'n_ips' addresses put into 'ips'; 0 is the top of the stack, 1 is its
616 caller, etc. */
617extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* ips, UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000618
619/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
620 different input. */
nethercote86c5dcb2004-09-05 21:32:37 +0000621extern void VG_(mini_stack_dump) ( Addr ips[], UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000622
623
624/*====================================================================*/
625/*=== Error reporting ===*/
626/*====================================================================*/
627
628/* ------------------------------------------------------------------ */
629/* Suppressions describe errors which we want to suppress, ie, not
630 show the user, usually because it is caused by a problem in a library
631 which we can't fix, replace or work around. Suppressions are read from
632 a file at startup time. This gives flexibility so that new
633 suppressions can be added to the file as and when needed.
634*/
635
636typedef
637 Int /* Do not make this unsigned! */
638 SuppKind;
639
640/* The tool-relevant parts of a suppression are:
641 kind: what kind of suppression; must be in the range (0..)
642 string: use is optional. NULL by default.
643 extra: use is optional. NULL by default. void* so it's extensible.
644*/
645typedef
646 struct _Supp
647 Supp;
648
njn26f02512004-11-22 18:33:15 +0000649/* Useful in TL_(error_matches_suppression)() */
nethercote37aac2e2004-09-02 08:54:27 +0000650SuppKind VG_(get_supp_kind) ( Supp* su );
651Char* VG_(get_supp_string) ( Supp* su );
652void* VG_(get_supp_extra) ( Supp* su );
653
654/* Must be used in VG_(recognised_suppression)() */
655void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
656/* May be used in VG_(read_extra_suppression_info)() */
657void VG_(set_supp_string) ( Supp* su, Char* string );
658void VG_(set_supp_extra) ( Supp* su, void* extra );
659
660
661/* ------------------------------------------------------------------ */
662/* Error records contain enough info to generate an error report. The idea
663 is that (typically) the same few points in the program generate thousands
664 of errors, and we don't want to spew out a fresh error message for each
665 one. Instead, we use these structures to common up duplicates.
666*/
667
668typedef
669 Int /* Do not make this unsigned! */
670 ErrorKind;
671
672/* The tool-relevant parts of an Error are:
673 kind: what kind of error; must be in the range (0..)
674 addr: use is optional. 0 by default.
675 string: use is optional. NULL by default.
676 extra: use is optional. NULL by default. void* so it's extensible.
677*/
678typedef
679 struct _Error
680 Error;
681
njn26f02512004-11-22 18:33:15 +0000682/* Useful in TL_(error_matches_suppression)(), TL_(pp_Error)(), etc */
nethercote37aac2e2004-09-02 08:54:27 +0000683ExeContext* VG_(get_error_where) ( Error* err );
684SuppKind VG_(get_error_kind) ( Error* err );
685Addr VG_(get_error_address) ( Error* err );
686Char* VG_(get_error_string) ( Error* err );
687void* VG_(get_error_extra) ( Error* err );
688
689/* Call this when an error occurs. It will be recorded if it hasn't been
690 seen before. If it has, the existing error record will have its count
691 incremented.
692
693 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
694 be stack-allocated; it will be copied by the core if needed (but it
695 won't be copied if it's NULL).
696
697 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
698 NULL for them. */
699extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
700 Addr a, Char* s, void* extra );
701
702/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
703 error -- useful for errors that can only happen once. The errors can be
704 suppressed, though. Return value is True if it was suppressed.
705 `print_error' dictates whether to print the error, which is a bit of a
706 hack that's useful sometimes if you just want to know if the error would
707 be suppressed without possibly printing it. `count_error' dictates
708 whether to add the error in the error total count (another mild hack). */
709extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
710 Addr a, Char* s, void* extra,
711 ExeContext* where, Bool print_error,
712 Bool allow_GDB_attach, Bool count_error );
713
714/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
715 Skips leading spaces on the line. Returns True if EOF was hit instead.
716 Useful for reading in extra tool-specific suppression lines. */
717extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
718
719
720/*====================================================================*/
721/*=== Obtaining debug information ===*/
722/*====================================================================*/
723
724/* Get the file/function/line number of the instruction at address
725 'a'. For these four, if debug info for the address is found, it
726 copies the info into the buffer/UInt and returns True. If not, it
727 returns False and nothing is copied. VG_(get_fnname) always
728 demangles C++ function names. VG_(get_fnname_w_offset) is the
729 same, except it appends "+N" to symbol names to indicate offsets. */
730extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
731extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
732extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
733extern Bool VG_(get_fnname_w_offset)
734 ( Addr a, Char* fnname, Int n_fnname );
735
736/* This one is more efficient if getting both filename and line number,
737 because the two lookups are done together. */
738extern Bool VG_(get_filename_linenum)
739 ( Addr a, Char* filename, Int n_filename,
740 UInt* linenum );
741
742/* Succeeds only if we find from debug info that 'a' is the address of the
743 first instruction in a function -- as opposed to VG_(get_fnname) which
744 succeeds if we find from debug info that 'a' is the address of any
745 instruction in a function. Use this to instrument the start of
746 a particular function. Nb: if an executable/shared object is stripped
747 of its symbols, this function will not be able to recognise function
748 entry points within it. */
749extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
750
751/* Succeeds if the address is within a shared object or the main executable.
752 It doesn't matter if debug info is present or not. */
753extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
754
755/* Puts into 'buf' info about the code address %eip: the address, function
756 name (if known) and filename/line number (if known), like this:
757
758 0x4001BF05: realloc (vg_replace_malloc.c:339)
759
760 'n_buf' gives length of 'buf'. Returns 'buf'.
761*/
762extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
763
764/* Returns a string containing an expression for the given
765 address. String is malloced with VG_(malloc)() */
766Char *VG_(describe_addr)(ThreadId, Addr);
767
768/* A way to get information about what segments are mapped */
769typedef struct _SegInfo SegInfo;
770
771/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
772 is present or not. */
773extern SegInfo* VG_(get_obj) ( Addr a );
774
775extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
776extern Addr VG_(seg_start) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000777extern SizeT VG_(seg_size) ( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000778extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000779extern ULong VG_(seg_sym_offset)( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000780
781typedef
782 enum {
783 Vg_SectUnknown,
784 Vg_SectText,
785 Vg_SectData,
786 Vg_SectBSS,
787 Vg_SectGOT,
788 Vg_SectPLT,
789 }
790 VgSectKind;
791
792extern VgSectKind VG_(seg_sect_kind)(Addr);
793
nethercote37aac2e2004-09-02 08:54:27 +0000794/*====================================================================*/
795/*=== Generic hash table ===*/
796/*====================================================================*/
797
798/* Generic type for a separately-chained hash table. Via a kind of dodgy
799 C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
800 as the first two fields match the sizes of these two fields. Requires
801 a bit of casting by the tool. */
802typedef
803 struct _VgHashNode {
804 struct _VgHashNode * next;
nethercote3d6b6112004-11-04 16:39:43 +0000805 UWord key;
nethercote37aac2e2004-09-02 08:54:27 +0000806 }
807 VgHashNode;
808
809typedef
810 VgHashNode**
811 VgHashTable;
812
813/* Make a new table. */
814extern VgHashTable VG_(HT_construct) ( void );
815
816/* Count the number of nodes in a table. */
817extern Int VG_(HT_count_nodes) ( VgHashTable table );
818
819/* Add a node to the table. */
820extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
821
822/* Looks up a node in the hash table. Also returns the address of the
823 previous node's `next' pointer which allows it to be removed from the
824 list later without having to look it up again. */
nethercote3d6b6112004-11-04 16:39:43 +0000825extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
nethercote37aac2e2004-09-02 08:54:27 +0000826 /*OUT*/VgHashNode*** next_ptr );
827
828/* Allocates an array of pointers to all the shadow chunks of malloc'd
829 blocks. Must be freed with VG_(free)(). */
830extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
831
832/* Returns first node that matches predicate `p', or NULL if none do.
833 Extra arguments can be implicitly passed to `p' using `d' which is an
834 opaque pointer passed to `p' each time it is called. */
835extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
836 Bool (*p)(VgHashNode*, void*),
837 void* d );
838
839/* Applies a function f() once to each node. Again, `d' can be used
840 to pass extra information to the function. */
841extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
842 void (*f)(VgHashNode*, void*),
843 void* d );
844
845/* Destroy a table. */
846extern void VG_(HT_destruct) ( VgHashTable t );
847
848
849/*====================================================================*/
850/*=== A generic skiplist ===*/
851/*====================================================================*/
852
853/*
854 The idea here is that the skiplist puts its per-element data at the
855 end of the structure. When you initialize the skiplist, you tell
856 it what structure your list elements are going to be. Then you
857 should allocate them with VG_(SkipNode_Alloc), which will allocate
858 enough memory for the extra bits.
859 */
nethercote37aac2e2004-09-02 08:54:27 +0000860
861typedef struct _SkipList SkipList;
862typedef struct _SkipNode SkipNode;
863
864typedef Int (*SkipCmp_t)(const void *key1, const void *key2);
865
866struct _SkipList {
867 const Short arena; /* allocation arena */
868 const UShort size; /* structure size (not including SkipNode) */
869 const UShort keyoff; /* key offset */
870 const SkipCmp_t cmp; /* compare two keys */
871 Char * (*strkey)(void *); /* stringify a key (for debugging) */
872 SkipNode *head; /* list head */
873};
874
875/* Use this macro to initialize your skiplist head. The arguments are pretty self explanitory:
876 _type is the type of your element structure
877 _key is the field within that type which you want to use as the key
878 _cmp is the comparison function for keys - it gets two typeof(_key) pointers as args
879 _strkey is a function which can return a string of your key - it's only used for debugging
880 _arena is the arena to use for allocation - -1 is the default
881 */
882#define SKIPLIST_INIT(_type, _key, _cmp, _strkey, _arena) \
883 { \
884 .arena = _arena, \
885 .size = sizeof(_type), \
886 .keyoff = offsetof(_type, _key), \
887 .cmp = _cmp, \
888 .strkey = _strkey, \
889 .head = NULL, \
890 }
891
892/* List operations:
893 SkipList_Find searchs a list. If it can't find an exact match, it either
894 returns NULL or a pointer to the element before where k would go
895 SkipList_Insert inserts a new element into the list. Duplicates are
896 forbidden. The element must have been created with SkipList_Alloc!
897 SkipList_Remove removes an element from the list and returns it. It
898 doesn't free the memory.
899*/
900extern void *VG_(SkipList_Find) (const SkipList *l, void *key);
901extern void VG_(SkipList_Insert)( SkipList *l, void *data);
902extern void *VG_(SkipList_Remove)( SkipList *l, void *key);
903
904/* Node (element) operations:
905 SkipNode_Alloc: allocate memory for a new element on the list. Must be
906 used before an element can be inserted! Returns NULL if not enough
907 memory.
908 SkipNode_Free: free memory allocated above
909 SkipNode_First: return the first element on the list
910 SkipNode_Next: return the next element after "data" on the list -
911 NULL for none
912
913 You can iterate through a SkipList like this:
914
915 for(x = VG_(SkipNode_First)(&list); // or SkipList_Find
916 x != NULL;
917 x = VG_(SkipNode_Next)(&list, x)) { ... }
918*/
919extern void *VG_(SkipNode_Alloc) (const SkipList *l);
920extern void VG_(SkipNode_Free) (const SkipList *l, void *p);
921extern void *VG_(SkipNode_First) (const SkipList *l);
922extern void *VG_(SkipNode_Next) (const SkipList *l, void *data);
923
njnabb14ad2004-11-24 16:57:16 +0000924
nethercote37aac2e2004-09-02 08:54:27 +0000925/*====================================================================*/
926/*=== Functions for shadow registers ===*/
927/*====================================================================*/
928
njnabb14ad2004-11-24 16:57:16 +0000929// For get/set, 'area' is where the asked-for shadow state will be copied
930// into/from.
931extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
932 SizeT size, UChar* area );
933extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
934 SizeT size, const UChar* area );
nethercote37aac2e2004-09-02 08:54:27 +0000935
936/* This one lets you override the shadow of the return value register for a
njn26f02512004-11-22 18:33:15 +0000937 syscall. Call it from TL_(post_syscall)() (not TL_(pre_syscall)()!) to
nethercote37aac2e2004-09-02 08:54:27 +0000938 override the default shadow register value. */
939extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njncf45fd42004-11-24 16:30:22 +0000940 UWord ret_shadow );
nethercote37aac2e2004-09-02 08:54:27 +0000941
njn26f02512004-11-22 18:33:15 +0000942/* This can be called from TL_(fini)() to find the shadow of the argument
nethercote37aac2e2004-09-02 08:54:27 +0000943 to exit(), ie. the shadow of the program's return value. */
sewardj2a99cf62004-11-24 10:44:19 +0000944extern UInt VG_(get_exit_status_shadow) ( ThreadId );
nethercote37aac2e2004-09-02 08:54:27 +0000945
946
947/*====================================================================*/
948/*=== Specific stuff for replacing malloc() and friends ===*/
949/*====================================================================*/
950
951/* If a tool replaces malloc() et al, the easiest way to do so is to
952 link with vg_replace_malloc.o into its vgpreload_*.so file, and
953 follow the following instructions. You can do it from scratch,
954 though, if you enjoy that sort of thing. */
955
956/* Arena size for valgrind's own malloc(); default value is 0, but can
957 be overridden by tool -- but must be done so *statically*, eg:
958
njn6a22af22004-11-30 14:41:13 +0000959 SizeT VG_(vg_malloc_redzone_szB) = 4;
nethercote37aac2e2004-09-02 08:54:27 +0000960
njn26f02512004-11-22 18:33:15 +0000961 It can't be done from a function like TL_(pre_clo_init)(). So it can't,
nethercote37aac2e2004-09-02 08:54:27 +0000962 for example, be controlled with a command line option, unfortunately. */
njn6a22af22004-11-30 14:41:13 +0000963extern SizeT VG_(vg_malloc_redzone_szB);
nethercote37aac2e2004-09-02 08:54:27 +0000964
njn26f02512004-11-22 18:33:15 +0000965/* Can be called from TL_(malloc) et al to do the actual alloc/freeing. */
nethercote7ac7f7b2004-11-02 12:36:02 +0000966extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000967extern void VG_(cli_free) ( void* p );
968
969/* Check if an address is within a range, allowing for redzones at edges */
nethercote7ac7f7b2004-11-02 12:36:02 +0000970extern Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000971
972/* ------------------------------------------------------------------ */
973/* Some options that can be used by a tool if malloc() et al are replaced.
974 The tool should call the functions in the appropriate places to give
975 control over these aspects of Valgrind's version of malloc(). */
976
977/* Round malloc sizes upwards to integral number of words? default: NO */
978extern Bool VG_(clo_sloppy_malloc);
979/* DEBUG: print malloc details? default: NO */
980extern Bool VG_(clo_trace_malloc);
981/* Minimum alignment in functions that don't specify alignment explicitly.
982 default: 0, i.e. use default of the machine (== 4) */
nethercote7ac7f7b2004-11-02 12:36:02 +0000983extern UInt VG_(clo_alignment);
nethercote37aac2e2004-09-02 08:54:27 +0000984
985extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
986extern void VG_(replacement_malloc_print_usage) ( void );
987extern void VG_(replacement_malloc_print_debug_usage) ( void );
988
989
990/*====================================================================*/
991/*=== Tool-specific stuff ===*/
992/*====================================================================*/
993
994/* ------------------------------------------------------------------ */
995/* Details */
996
997/* Default value for avg_translations_sizeB (in bytes), indicating typical
998 code expansion of about 6:1. */
999#define VG_DEFAULT_TRANS_SIZEB 100
1000
1001/* Information used in the startup message. `name' also determines the
1002 string used for identifying suppressions in a suppression file as
1003 belonging to this tool. `version' can be NULL, in which case (not
1004 surprisingly) no version info is printed; this mechanism is designed for
1005 tools distributed with Valgrind that share a version number with
1006 Valgrind. Other tools not distributed as part of Valgrind should
1007 probably have their own version number. */
1008extern void VG_(details_name) ( Char* name );
1009extern void VG_(details_version) ( Char* version );
1010extern void VG_(details_description) ( Char* description );
1011extern void VG_(details_copyright_author) ( Char* copyright_author );
1012
1013/* Average size of a translation, in bytes, so that the translation
1014 storage machinery can allocate memory appropriately. Not critical,
1015 setting is optional. */
1016extern void VG_(details_avg_translation_sizeB) ( UInt size );
1017
njn67993252004-11-22 18:02:32 +00001018/* String printed if an `tl_assert' assertion fails or VG_(tool_panic)
nethercote37aac2e2004-09-02 08:54:27 +00001019 is called. Should probably be an email address. */
1020extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
1021
1022/* ------------------------------------------------------------------ */
1023/* Needs */
1024
1025/* Booleans that decide core behaviour, but don't require extra
1026 operations to be defined if `True' */
1027
1028/* Should __libc_freeres() be run? Bugs in it can crash the tool. */
1029extern void VG_(needs_libc_freeres) ( void );
1030
1031/* Want to have errors detected by Valgrind's core reported? Includes:
1032 - pthread API errors (many; eg. unlocking a non-locked mutex)
1033 - invalid file descriptors to blocking syscalls read() and write()
1034 - bad signal numbers passed to sigaction()
1035 - attempt to install signal handler for SIGKILL or SIGSTOP */
1036extern void VG_(needs_core_errors) ( void );
1037
1038/* Booleans that indicate extra operations are defined; if these are True,
1039 the corresponding template functions (given below) must be defined. A
1040 lot like being a member of a type class. */
1041
1042/* Want to report errors from tool? This implies use of suppressions, too. */
njn95ec8702004-11-22 16:46:13 +00001043extern void VG_(needs_tool_errors) ( void );
nethercote37aac2e2004-09-02 08:54:27 +00001044
1045/* Is information kept about specific individual basic blocks? (Eg. for
1046 cachegrind there are cost-centres for every instruction, stored at a
1047 basic block level.) If so, it sometimes has to be discarded, because
1048 .so mmap/munmap-ping or self-modifying code (informed by the
1049 DISCARD_TRANSLATIONS user request) can cause one instruction address
1050 to be used for more than one instruction in one program run... */
1051extern void VG_(needs_basic_block_discards) ( void );
1052
nethercote37aac2e2004-09-02 08:54:27 +00001053/* Tool defines its own command line options? */
1054extern void VG_(needs_command_line_options) ( void );
1055
1056/* Tool defines its own client requests? */
1057extern void VG_(needs_client_requests) ( void );
1058
nethercote37aac2e2004-09-02 08:54:27 +00001059/* Tool does stuff before and/or after system calls? */
1060extern void VG_(needs_syscall_wrapper) ( void );
1061
1062/* Are tool-state sanity checks performed? */
1063extern void VG_(needs_sanity_checks) ( void );
1064
1065/* Do we need to see data symbols? */
1066extern void VG_(needs_data_syms) ( void );
1067
1068/* Does the tool need shadow memory allocated (if you set this, you must also statically initialize
njn26f02512004-11-22 18:33:15 +00001069 float TL_(shadow_ratio) = n./m;
nethercote37aac2e2004-09-02 08:54:27 +00001070 to define how many shadow bits you need per client address space bit.
1071*/
1072extern void VG_(needs_shadow_memory)( void );
njn26f02512004-11-22 18:33:15 +00001073extern float TL_(shadow_ratio);
nethercote37aac2e2004-09-02 08:54:27 +00001074
1075/* ------------------------------------------------------------------ */
1076/* Core events to track */
1077
1078/* Part of the core from which this call was made. Useful for determining
1079 what kind of error message should be emitted. */
1080typedef
njncf45fd42004-11-24 16:30:22 +00001081 enum { Vg_CoreStartup, Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall,
1082 Vg_CoreTranslate, Vg_CoreClientReq }
nethercote37aac2e2004-09-02 08:54:27 +00001083 CorePart;
1084
1085/* Useful to use in VG_(get_Xreg_usage)() */
1086#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
1087 { if (mycat(u->tag,ono) == tag) \
1088 { regs[n] = mycat(u->val,ono); \
1089 isWrites[n] = False; \
1090 n++; \
1091 } \
1092 }
1093#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
1094 { if (mycat(u->tag,ono) == tag) \
1095 { regs[n] = mycat(u->val,ono); \
1096 isWrites[n] = True; \
1097 n++; \
1098 } \
1099 }
1100
1101#endif /* NDEF __TOOL_H */
1102
1103/* gen_toolint.pl will put the VG_(init_*)() functions here: */