blob: 0ec7327031f4c5627f149d9d94aa8a1d50cd107e [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/*
njnb9c427c2004-12-01 14:14:42 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
nethercote37aac2e2004-09-02 08:54:27 +00009
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 */
nethercote37aac2e2004-09-02 08:54:27 +000035
nethercoteebf1d862004-11-01 18:22:05 +000036#include "basic_types.h"
sewardjb5f6f512005-03-10 23:59:00 +000037#include "tool_asm.h" /* asm stuff */
38#include "tool_arch.h" /* arch-specific tool stuff */
nethercote73b526f2004-10-31 18:48:21 +000039#include "vki.h"
nethercote37aac2e2004-09-02 08:54:27 +000040
sewardj8b635a42004-11-22 19:01:47 +000041#include "libvex.h"
42#include "libvex_ir.h"
43
nethercote37aac2e2004-09-02 08:54:27 +000044/*====================================================================*/
45/*=== Build options and table sizes. ===*/
46/*====================================================================*/
47
48/* You should be able to change these options or sizes, recompile, and
49 still have a working system. */
50
51/* The maximum number of pthreads that we support. This is
52 deliberately not very high since our implementation of some of the
53 scheduler algorithms is surely O(N) in the number of threads, since
54 that's simple, at least. And (in practice) we hope that most
55 programs do not need many threads. */
56#define VG_N_THREADS 100
57
58/* Maximum number of pthread keys available. Again, we start low until
59 the need for a higher number presents itself. */
60#define VG_N_THREAD_KEYS 50
61
nethercote37aac2e2004-09-02 08:54:27 +000062
63/*====================================================================*/
nethercote2e05c332004-09-06 16:43:37 +000064/*=== Useful macros ===*/
nethercote37aac2e2004-09-02 08:54:27 +000065/*====================================================================*/
66
nethercote37aac2e2004-09-02 08:54:27 +000067#define mycat_wrk(aaa,bbb) aaa##bbb
68#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
69
70/* No, really. I _am_ that strange. */
71#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
72
nethercote37aac2e2004-09-02 08:54:27 +000073/* Path to all our library/aux files */
74extern const Char *VG_(libdir);
75
76
77/*====================================================================*/
78/*=== Core/tool interface version ===*/
79/*====================================================================*/
80
81/* The major version number indicates binary-incompatible changes to the
82 interface; if the core and tool major versions don't match, Valgrind
83 will abort. The minor version indicates binary-compatible changes.
nethercote836d46c2004-11-18 12:58:53 +000084
85 (Update: as it happens, we're never using the minor version number, because
86 there's no point in doing so.)
nethercote37aac2e2004-09-02 08:54:27 +000087*/
nethercote836d46c2004-11-18 12:58:53 +000088#define VG_CORE_INTERFACE_MAJOR_VERSION 7
nethercote37aac2e2004-09-02 08:54:27 +000089#define VG_CORE_INTERFACE_MINOR_VERSION 0
90
91typedef struct _ToolInfo {
92 Int sizeof_ToolInfo;
93 Int interface_major_version;
94 Int interface_minor_version;
95
96 /* Initialise tool. Must do the following:
97 - initialise the `details' struct, via the VG_(details_*)() functions
98 - register any helpers called by generated code
99
100 May do the following:
101 - initialise the `needs' struct to indicate certain requirements, via
102 the VG_(needs_*)() functions
103 - initialize all the tool's entrypoints via the VG_(init_*)() functions
104 - register any tool-specific profiling events
105 - any other tool-specific initialisation
106 */
njnd2252832004-11-26 10:53:33 +0000107 void (*tl_pre_clo_init) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000108
109 /* Specifies how big the shadow segment should be as a ratio to the
110 client address space. 0 for no shadow segment. */
111 float shadow_ratio;
112} ToolInfo;
113
114/* Every tool must include this macro somewhere, exactly once. */
115#define VG_DETERMINE_INTERFACE_VERSION(pre_clo_init, shadow) \
njn26f02512004-11-22 18:33:15 +0000116 const ToolInfo TL_(tool_info) = { \
nethercote37aac2e2004-09-02 08:54:27 +0000117 .sizeof_ToolInfo = sizeof(ToolInfo), \
118 .interface_major_version = VG_CORE_INTERFACE_MAJOR_VERSION, \
119 .interface_minor_version = VG_CORE_INTERFACE_MINOR_VERSION, \
njnd2252832004-11-26 10:53:33 +0000120 .tl_pre_clo_init = pre_clo_init, \
nethercote37aac2e2004-09-02 08:54:27 +0000121 .shadow_ratio = shadow, \
122 };
123
124/*====================================================================*/
125/*=== Command-line options ===*/
126/*====================================================================*/
127
128/* Use this for normal null-termination-style string comparison */
129#define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \
130 && VG_(strcmp)((s1),(s2))==0)
131
132/* Use these for recognising tool command line options -- stops comparing
133 once whitespace is reached. */
134#define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2)))
135#define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
136
sewardjb5f6f512005-03-10 23:59:00 +0000137/* Higher-level command-line option recognisers; use in if/else chains */
nethercote37aac2e2004-09-02 08:54:27 +0000138
139#define VG_BOOL_CLO(qq_option, qq_var) \
140 if (VG_CLO_STREQ(arg, qq_option"=yes")) { (qq_var) = True; } \
141 else if (VG_CLO_STREQ(arg, qq_option"=no")) { (qq_var) = False; }
142
143#define VG_STR_CLO(qq_option, qq_var) \
144 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
145 (qq_var) = &arg[ VG_(strlen)(qq_option)+1 ]; \
146 }
147
148#define VG_NUM_CLO(qq_option, qq_var) \
149 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
150 (qq_var) = (Int)VG_(atoll)( &arg[ VG_(strlen)(qq_option)+1 ] ); \
151 }
152
sewardjb5f6f512005-03-10 23:59:00 +0000153/* Bounded integer arg */
nethercote37aac2e2004-09-02 08:54:27 +0000154#define VG_BNUM_CLO(qq_option, qq_var, qq_lo, qq_hi) \
155 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
156 (qq_var) = (Int)VG_(atoll)( &arg[ VG_(strlen)(qq_option)+1 ] ); \
157 if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
158 if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
159 }
160
161
162/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
163extern Int VG_(clo_verbosity);
164
165/* Profile? */
166extern Bool VG_(clo_profile);
167
168/* Call this if a recognised option was bad for some reason.
169 Note: don't use it just because an option was unrecognised -- return 'False'
njn94065fd2004-11-22 19:26:27 +0000170 from TL_(process_cmd_line_option) to indicate that. */
nethercote37aac2e2004-09-02 08:54:27 +0000171extern void VG_(bad_option) ( Char* opt );
172
173/* Client args */
174extern Int VG_(client_argc);
175extern Char** VG_(client_argv);
176
177/* Client environment. Can be inspected with VG_(getenv)() */
178extern Char** VG_(client_envp);
179
180
181/*====================================================================*/
182/*=== Printing messages for the user ===*/
183/*====================================================================*/
184
185/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
186 Should be used for all user output. */
187
188typedef
189 enum { Vg_UserMsg, /* '?' == '=' */
190 Vg_DebugMsg, /* '?' == '-' */
191 Vg_DebugExtraMsg, /* '?' == '+' */
sewardjb5f6f512005-03-10 23:59:00 +0000192 Vg_ClientMsg /* '?' == '*' */
nethercote37aac2e2004-09-02 08:54:27 +0000193 }
194 VgMsgKind;
195
196/* Functions for building a message from multiple parts. */
197extern int VG_(start_msg) ( VgMsgKind kind );
sewardjb5f6f512005-03-10 23:59:00 +0000198extern int VG_(add_to_msg) ( const Char* format, ... );
nethercote37aac2e2004-09-02 08:54:27 +0000199/* Ends and prints the message. Appends a newline. */
200extern int VG_(end_msg) ( void );
201
202/* Send a single-part message. Appends a newline. */
sewardjb5f6f512005-03-10 23:59:00 +0000203extern int VG_(message) ( VgMsgKind kind, const Char* format, ... );
204extern int VG_(vmessage) ( VgMsgKind kind, const Char* format, va_list vargs );
nethercote37aac2e2004-09-02 08:54:27 +0000205
206
207/*====================================================================*/
208/*=== Profiling ===*/
209/*====================================================================*/
210
211/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
212#define VGP_CORE_LIST \
213 /* These ones depend on the core */ \
214 VGP_PAIR(VgpUnc, "unclassified"), \
215 VGP_PAIR(VgpStartup, "startup"), \
216 VGP_PAIR(VgpRun, "running"), \
217 VGP_PAIR(VgpSched, "scheduler"), \
218 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
219 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
220 VGP_PAIR(VgpTranslate, "translate-main"), \
221 VGP_PAIR(VgpToUCode, "to-ucode"), \
222 VGP_PAIR(VgpFromUcode, "from-ucode"), \
223 VGP_PAIR(VgpImprove, "improve"), \
224 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
225 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
226 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
227 VGP_PAIR(VgpDoLRU, "do-lru"), \
228 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
229 VGP_PAIR(VgpExeContext, "exe-context"), \
230 VGP_PAIR(VgpReadSyms, "read-syms"), \
231 VGP_PAIR(VgpSearchSyms, "search-syms"), \
232 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
233 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
234 VGP_PAIR(VgpDemangle, "demangle"), \
235 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
236 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
237 /* These ones depend on the tool */ \
238 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
239 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
240 VGP_PAIR(VgpInstrument, "instrument"), \
njn26f02512004-11-22 18:33:15 +0000241 VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \
242 VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \
243 VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \
nethercote37aac2e2004-09-02 08:54:27 +0000244 VGP_PAIR(VgpFini, "fini")
245
246#define VGP_PAIR(n,name) n
247typedef enum { VGP_CORE_LIST } VgpCoreCC;
248#undef VGP_PAIR
249
250/* When registering tool profiling events, ensure that the 'n' value is in
251 * the range (VgpFini+1..) */
252extern void VGP_(register_profile_event) ( Int n, Char* name );
253
254extern void VGP_(pushcc) ( UInt cc );
255extern void VGP_(popcc) ( UInt cc );
256
257/* Define them only if they haven't already been defined by vg_profile.c */
258#ifndef VGP_PUSHCC
259# define VGP_PUSHCC(x)
260#endif
261#ifndef VGP_POPCC
262# define VGP_POPCC(x)
263#endif
264
265
266/*====================================================================*/
267/*=== Useful stuff to call from generated code ===*/
268/*====================================================================*/
269
270/* ------------------------------------------------------------------ */
271/* General stuff */
272
273/* 64-bit counter for the number of basic blocks done. */
274extern ULong VG_(bbs_done);
275
njnedfa0f62004-11-30 18:08:05 +0000276/* Check if an address/whatever is aligned */
277#define IS_4_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x3))
278#define IS_8_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x7))
279#define IS_16_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0xf))
280#define IS_WORD_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & (sizeof(Addr)-1)))
nethercote37aac2e2004-09-02 08:54:27 +0000281
282
283/* ------------------------------------------------------------------ */
284/* Thread-related stuff */
285
286/* Special magic value for an invalid ThreadId. It corresponds to
287 LinuxThreads using zero as the initial value for
288 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
289#define VG_INVALID_THREADID ((ThreadId)(0))
290
291/* ThreadIds are simply indices into the VG_(threads)[] array. */
292typedef
293 UInt
294 ThreadId;
295
sewardjb5f6f512005-03-10 23:59:00 +0000296/* Get the TID of the thread which currently has the CPU. */
297extern ThreadId VG_(get_running_tid) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000298
299/* Searches through all thread's stacks to see if any match. Returns
300 VG_INVALID_THREADID if none match. */
301extern ThreadId VG_(first_matching_thread_stack)
302 ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
303 void* d );
304
sewardj2a99cf62004-11-24 10:44:19 +0000305/* Get the simulated %esp */
306extern Addr VG_(get_stack_pointer) ( ThreadId tid );
307
nethercote37aac2e2004-09-02 08:54:27 +0000308
309/*====================================================================*/
310/*=== Valgrind's version of libc ===*/
311/*====================================================================*/
312
313/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
314 are its own versions of C library functions, but with VG_ prefixes. Note
315 that the types of some are slightly different to the real ones. Some
316 additional useful functions are provided too; descriptions of how they
317 work are given below. */
318
319#if !defined(NULL)
320# define NULL ((void*)0)
321#endif
322
323
324/* ------------------------------------------------------------------ */
325/* stdio.h
326 *
327 * Note that they all output to the file descriptor given by the
328 * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
329 * Hence no need for VG_(fprintf)().
330 */
331extern UInt VG_(printf) ( const char *format, ... );
332/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
333extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
sewardjb5f6f512005-03-10 23:59:00 +0000334extern UInt VG_(vprintf) ( void(*send)(Char, void *),
335 const Char *format, va_list vargs, void *send_arg );
nethercote37aac2e2004-09-02 08:54:27 +0000336
337extern Int VG_(rename) ( Char* old_name, Char* new_name );
338
339/* ------------------------------------------------------------------ */
340/* stdlib.h */
341
nethercote7ac7f7b2004-11-02 12:36:02 +0000342extern void* VG_(malloc) ( SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000343extern void VG_(free) ( void* p );
nethercote7ac7f7b2004-11-02 12:36:02 +0000344extern void* VG_(calloc) ( SizeT n, SizeT nbytes );
345extern void* VG_(realloc) ( void* p, SizeT size );
346extern void* VG_(malloc_aligned) ( SizeT align_bytes, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000347
348extern void VG_(print_malloc_stats) ( void );
349
sewardjb5f6f512005-03-10 23:59:00 +0000350/* terminate everything */
nethercote37aac2e2004-09-02 08:54:27 +0000351extern void VG_(exit)( Int status )
352 __attribute__ ((__noreturn__));
sewardjb5f6f512005-03-10 23:59:00 +0000353
354/* terminate the calling thread - probably not what you want */
355extern void VG_(exit_single)( Int status )
356 __attribute__ ((__noreturn__));
357
nethercote37aac2e2004-09-02 08:54:27 +0000358/* 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*/
sewardjb5f6f512005-03-10 23:59:00 +0000370extern Int VG_(setrlimit) ( Int resource, const struct vki_rlimit *rlim );
nethercote37aac2e2004-09-02 08:54:27 +0000371
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
sewardjb5f6f512005-03-10 23:59:00 +0000495extern Bool VG_(is_addressable)(Addr p, SizeT sz, UInt prot);
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
sewardjb5f6f512005-03-10 23:59:00 +0000502/* Register an interest in apparently internal faults; used code which
503 wanders around dangerous memory (ie, leakcheck). The catcher is
504 not expected to return. */
505extern void VG_(set_fault_catcher)(void (*catcher)(Int sig, Addr addr));
506
nethercote37aac2e2004-09-02 08:54:27 +0000507/* initialize shadow pages in the range [p, p+sz) This calls
508 init_shadow_page for each one. It should be a lot more efficient
509 for bulk-initializing shadow pages than faulting on each one.
510*/
511extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
512
sewardjb5f6f512005-03-10 23:59:00 +0000513/* Calls into the core used by leak-checking */
514
515/* Calls "add_rootrange" with each range of memory which looks like a
516 plausible source of root pointers. */
517extern void VG_(find_root_memory)(void (*add_rootrange)(Addr addr, SizeT sz));
518
519/* Calls "mark_addr" with register values (which may or may not be pointers) */
520extern void VG_(mark_from_registers)(void (*mark_addr)(Addr addr));
521
nethercote37aac2e2004-09-02 08:54:27 +0000522/* ------------------------------------------------------------------ */
523/* signal.h.
524
525 Note that these use the vk_ (kernel) structure
526 definitions, which are different in places from those that glibc
nethercote73b526f2004-10-31 18:48:21 +0000527 defines. Since we're operating right at the kernel interface, glibc's view
528 of the world is entirely irrelevant. */
nethercote37aac2e2004-09-02 08:54:27 +0000529
530/* --- Signal set ops --- */
nethercote73b526f2004-10-31 18:48:21 +0000531extern Int VG_(sigfillset) ( vki_sigset_t* set );
532extern Int VG_(sigemptyset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000533
sewardjb5f6f512005-03-10 23:59:00 +0000534extern Bool VG_(isfullsigset) ( const vki_sigset_t* set );
535extern Bool VG_(isemptysigset) ( const vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000536
nethercote73b526f2004-10-31 18:48:21 +0000537extern Int VG_(sigaddset) ( vki_sigset_t* set, Int signum );
538extern Int VG_(sigdelset) ( vki_sigset_t* set, Int signum );
sewardjb5f6f512005-03-10 23:59:00 +0000539extern Int VG_(sigismember) ( const vki_sigset_t* set, Int signum );
nethercote37aac2e2004-09-02 08:54:27 +0000540
nethercote73b526f2004-10-31 18:48:21 +0000541extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
542extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
nethercote37aac2e2004-09-02 08:54:27 +0000543
544/* --- Mess with the kernel's sig state --- */
nethercote73b526f2004-10-31 18:48:21 +0000545extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
546 vki_sigset_t* oldset );
547extern Int VG_(sigaction) ( Int signum,
548 const struct vki_sigaction* act,
549 struct vki_sigaction* oldact );
nethercote37aac2e2004-09-02 08:54:27 +0000550
nethercote73b526f2004-10-31 18:48:21 +0000551extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *,
552 const struct vki_timespec * );
nethercote37aac2e2004-09-02 08:54:27 +0000553
nethercote73b526f2004-10-31 18:48:21 +0000554extern Int VG_(signal) ( Int signum, void (*sighandler)(Int) );
555extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
nethercote37aac2e2004-09-02 08:54:27 +0000556
nethercote73b526f2004-10-31 18:48:21 +0000557extern Int VG_(kill) ( Int pid, Int signo );
njnc6168192004-11-29 13:54:10 +0000558extern Int VG_(tkill) ( ThreadId tid, Int signo );
nethercote73b526f2004-10-31 18:48:21 +0000559extern Int VG_(sigpending) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000560
nethercote73b526f2004-10-31 18:48:21 +0000561extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
nethercote37aac2e2004-09-02 08:54:27 +0000562
563/* ------------------------------------------------------------------ */
564/* socket.h. */
565
566extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
567extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
568extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
569 Int *optlen);
570
571/* ------------------------------------------------------------------ */
572/* other, randomly useful functions */
573extern UInt VG_(read_millisecond_timer) ( void );
574
sewardjb5f6f512005-03-10 23:59:00 +0000575extern Bool VG_(has_cpuid) ( void );
576
nethercote37aac2e2004-09-02 08:54:27 +0000577extern void VG_(cpuid) ( UInt eax,
578 UInt *eax_ret, UInt *ebx_ret,
579 UInt *ecx_ret, UInt *edx_ret );
580
nethercote37aac2e2004-09-02 08:54:27 +0000581/*====================================================================*/
582/*=== Execution contexts ===*/
583/*====================================================================*/
584
585/* Generic resolution type used in a few different ways, such as deciding
586 how closely to compare two errors for equality. */
587typedef
588 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
589 VgRes;
590
591typedef
592 struct _ExeContext
593 ExeContext;
594
595/* Compare two ExeContexts. Number of callers considered depends on `res':
596 Vg_LowRes: 2
597 Vg_MedRes: 4
598 Vg_HighRes: all */
599extern Bool VG_(eq_ExeContext) ( VgRes res,
600 ExeContext* e1, ExeContext* e2 );
601
602/* Print an ExeContext. */
603extern void VG_(pp_ExeContext) ( ExeContext* );
604
605/* Take a snapshot of the client's stack. Search our collection of
606 ExeContexts to see if we already have it, and if not, allocate a
607 new one. Either way, return a pointer to the context. Context size
608 controlled by --num-callers option.
609
sewardjb5f6f512005-03-10 23:59:00 +0000610 If called from generated code, use VG_(get_VCPU_tid)() to get the
nethercote37aac2e2004-09-02 08:54:27 +0000611 current ThreadId. If called from non-generated code, the current
612 ThreadId should be passed in by the core.
613*/
614extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
615
nethercote86c5dcb2004-09-05 21:32:37 +0000616/* Get the nth IP from the ExeContext. 0 is the IP of the top function, 1
nethercote37aac2e2004-09-02 08:54:27 +0000617 is its caller, etc. Returns 0 if there isn't one, or if n is greater
618 than VG_(clo_backtrace_size), set by the --num-callers option. */
619extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
620
nethercote86c5dcb2004-09-05 21:32:37 +0000621/* Just grab the client's IP, as a much smaller and cheaper
nethercote37aac2e2004-09-02 08:54:27 +0000622 indication of where they are. Use is basically same as for
623 VG_(get_ExeContext)() above.
624*/
625extern Addr VG_(get_EIP)( ThreadId tid );
626
627/* For tools needing more control over stack traces: walks the stack to get
nethercote86c5dcb2004-09-05 21:32:37 +0000628 instruction pointers from the top stack frames for thread 'tid'. Maximum of
629 'n_ips' addresses put into 'ips'; 0 is the top of the stack, 1 is its
630 caller, etc. */
631extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* ips, UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000632
633/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
634 different input. */
nethercote86c5dcb2004-09-05 21:32:37 +0000635extern void VG_(mini_stack_dump) ( Addr ips[], UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000636
637
638/*====================================================================*/
639/*=== Error reporting ===*/
640/*====================================================================*/
641
642/* ------------------------------------------------------------------ */
643/* Suppressions describe errors which we want to suppress, ie, not
644 show the user, usually because it is caused by a problem in a library
645 which we can't fix, replace or work around. Suppressions are read from
646 a file at startup time. This gives flexibility so that new
647 suppressions can be added to the file as and when needed.
648*/
649
650typedef
651 Int /* Do not make this unsigned! */
652 SuppKind;
653
654/* The tool-relevant parts of a suppression are:
655 kind: what kind of suppression; must be in the range (0..)
656 string: use is optional. NULL by default.
657 extra: use is optional. NULL by default. void* so it's extensible.
658*/
659typedef
660 struct _Supp
661 Supp;
662
njn26f02512004-11-22 18:33:15 +0000663/* Useful in TL_(error_matches_suppression)() */
nethercote37aac2e2004-09-02 08:54:27 +0000664SuppKind VG_(get_supp_kind) ( Supp* su );
665Char* VG_(get_supp_string) ( Supp* su );
666void* VG_(get_supp_extra) ( Supp* su );
667
668/* Must be used in VG_(recognised_suppression)() */
669void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
670/* May be used in VG_(read_extra_suppression_info)() */
671void VG_(set_supp_string) ( Supp* su, Char* string );
672void VG_(set_supp_extra) ( Supp* su, void* extra );
673
674
675/* ------------------------------------------------------------------ */
676/* Error records contain enough info to generate an error report. The idea
677 is that (typically) the same few points in the program generate thousands
678 of errors, and we don't want to spew out a fresh error message for each
679 one. Instead, we use these structures to common up duplicates.
680*/
681
682typedef
683 Int /* Do not make this unsigned! */
684 ErrorKind;
685
686/* The tool-relevant parts of an Error are:
687 kind: what kind of error; must be in the range (0..)
688 addr: use is optional. 0 by default.
689 string: use is optional. NULL by default.
690 extra: use is optional. NULL by default. void* so it's extensible.
691*/
692typedef
693 struct _Error
694 Error;
695
njn26f02512004-11-22 18:33:15 +0000696/* Useful in TL_(error_matches_suppression)(), TL_(pp_Error)(), etc */
nethercote37aac2e2004-09-02 08:54:27 +0000697ExeContext* VG_(get_error_where) ( Error* err );
698SuppKind VG_(get_error_kind) ( Error* err );
699Addr VG_(get_error_address) ( Error* err );
700Char* VG_(get_error_string) ( Error* err );
701void* VG_(get_error_extra) ( Error* err );
702
703/* Call this when an error occurs. It will be recorded if it hasn't been
704 seen before. If it has, the existing error record will have its count
705 incremented.
706
707 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
708 be stack-allocated; it will be copied by the core if needed (but it
709 won't be copied if it's NULL).
710
711 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
712 NULL for them. */
713extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
714 Addr a, Char* s, void* extra );
715
716/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
717 error -- useful for errors that can only happen once. The errors can be
718 suppressed, though. Return value is True if it was suppressed.
719 `print_error' dictates whether to print the error, which is a bit of a
720 hack that's useful sometimes if you just want to know if the error would
721 be suppressed without possibly printing it. `count_error' dictates
722 whether to add the error in the error total count (another mild hack). */
723extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
724 Addr a, Char* s, void* extra,
725 ExeContext* where, Bool print_error,
726 Bool allow_GDB_attach, Bool count_error );
727
728/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
729 Skips leading spaces on the line. Returns True if EOF was hit instead.
730 Useful for reading in extra tool-specific suppression lines. */
731extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
732
733
734/*====================================================================*/
735/*=== Obtaining debug information ===*/
736/*====================================================================*/
737
738/* Get the file/function/line number of the instruction at address
739 'a'. For these four, if debug info for the address is found, it
740 copies the info into the buffer/UInt and returns True. If not, it
741 returns False and nothing is copied. VG_(get_fnname) always
742 demangles C++ function names. VG_(get_fnname_w_offset) is the
743 same, except it appends "+N" to symbol names to indicate offsets. */
744extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
745extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
746extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
747extern Bool VG_(get_fnname_w_offset)
748 ( Addr a, Char* fnname, Int n_fnname );
749
750/* This one is more efficient if getting both filename and line number,
751 because the two lookups are done together. */
752extern Bool VG_(get_filename_linenum)
753 ( Addr a, Char* filename, Int n_filename,
754 UInt* linenum );
755
756/* Succeeds only if we find from debug info that 'a' is the address of the
757 first instruction in a function -- as opposed to VG_(get_fnname) which
758 succeeds if we find from debug info that 'a' is the address of any
759 instruction in a function. Use this to instrument the start of
760 a particular function. Nb: if an executable/shared object is stripped
761 of its symbols, this function will not be able to recognise function
762 entry points within it. */
763extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
764
765/* Succeeds if the address is within a shared object or the main executable.
766 It doesn't matter if debug info is present or not. */
767extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
768
769/* Puts into 'buf' info about the code address %eip: the address, function
770 name (if known) and filename/line number (if known), like this:
771
772 0x4001BF05: realloc (vg_replace_malloc.c:339)
773
774 'n_buf' gives length of 'buf'. Returns 'buf'.
775*/
776extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
777
778/* Returns a string containing an expression for the given
779 address. String is malloced with VG_(malloc)() */
780Char *VG_(describe_addr)(ThreadId, Addr);
781
782/* A way to get information about what segments are mapped */
783typedef struct _SegInfo SegInfo;
784
785/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
786 is present or not. */
787extern SegInfo* VG_(get_obj) ( Addr a );
788
789extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
790extern Addr VG_(seg_start) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000791extern SizeT VG_(seg_size) ( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000792extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000793extern ULong VG_(seg_sym_offset)( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000794
795typedef
796 enum {
797 Vg_SectUnknown,
798 Vg_SectText,
799 Vg_SectData,
800 Vg_SectBSS,
801 Vg_SectGOT,
sewardjb5f6f512005-03-10 23:59:00 +0000802 Vg_SectPLT
nethercote37aac2e2004-09-02 08:54:27 +0000803 }
804 VgSectKind;
805
806extern VgSectKind VG_(seg_sect_kind)(Addr);
807
nethercote37aac2e2004-09-02 08:54:27 +0000808/*====================================================================*/
809/*=== Generic hash table ===*/
810/*====================================================================*/
811
812/* Generic type for a separately-chained hash table. Via a kind of dodgy
813 C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
814 as the first two fields match the sizes of these two fields. Requires
815 a bit of casting by the tool. */
816typedef
817 struct _VgHashNode {
818 struct _VgHashNode * next;
nethercote3d6b6112004-11-04 16:39:43 +0000819 UWord key;
nethercote37aac2e2004-09-02 08:54:27 +0000820 }
821 VgHashNode;
822
823typedef
824 VgHashNode**
825 VgHashTable;
826
827/* Make a new table. */
828extern VgHashTable VG_(HT_construct) ( void );
829
830/* Count the number of nodes in a table. */
831extern Int VG_(HT_count_nodes) ( VgHashTable table );
832
833/* Add a node to the table. */
834extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
835
836/* Looks up a node in the hash table. Also returns the address of the
837 previous node's `next' pointer which allows it to be removed from the
838 list later without having to look it up again. */
nethercote3d6b6112004-11-04 16:39:43 +0000839extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
nethercote37aac2e2004-09-02 08:54:27 +0000840 /*OUT*/VgHashNode*** next_ptr );
841
842/* Allocates an array of pointers to all the shadow chunks of malloc'd
843 blocks. Must be freed with VG_(free)(). */
844extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
845
846/* Returns first node that matches predicate `p', or NULL if none do.
847 Extra arguments can be implicitly passed to `p' using `d' which is an
848 opaque pointer passed to `p' each time it is called. */
849extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
850 Bool (*p)(VgHashNode*, void*),
851 void* d );
852
853/* Applies a function f() once to each node. Again, `d' can be used
854 to pass extra information to the function. */
855extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
856 void (*f)(VgHashNode*, void*),
857 void* d );
858
859/* Destroy a table. */
860extern void VG_(HT_destruct) ( VgHashTable t );
861
862
863/*====================================================================*/
864/*=== A generic skiplist ===*/
865/*====================================================================*/
866
867/*
868 The idea here is that the skiplist puts its per-element data at the
869 end of the structure. When you initialize the skiplist, you tell
870 it what structure your list elements are going to be. Then you
871 should allocate them with VG_(SkipNode_Alloc), which will allocate
872 enough memory for the extra bits.
873 */
nethercote37aac2e2004-09-02 08:54:27 +0000874
875typedef struct _SkipList SkipList;
876typedef struct _SkipNode SkipNode;
877
878typedef Int (*SkipCmp_t)(const void *key1, const void *key2);
879
880struct _SkipList {
881 const Short arena; /* allocation arena */
882 const UShort size; /* structure size (not including SkipNode) */
883 const UShort keyoff; /* key offset */
884 const SkipCmp_t cmp; /* compare two keys */
885 Char * (*strkey)(void *); /* stringify a key (for debugging) */
886 SkipNode *head; /* list head */
887};
888
889/* Use this macro to initialize your skiplist head. The arguments are pretty self explanitory:
890 _type is the type of your element structure
891 _key is the field within that type which you want to use as the key
892 _cmp is the comparison function for keys - it gets two typeof(_key) pointers as args
893 _strkey is a function which can return a string of your key - it's only used for debugging
894 _arena is the arena to use for allocation - -1 is the default
895 */
896#define SKIPLIST_INIT(_type, _key, _cmp, _strkey, _arena) \
897 { \
898 .arena = _arena, \
899 .size = sizeof(_type), \
900 .keyoff = offsetof(_type, _key), \
901 .cmp = _cmp, \
902 .strkey = _strkey, \
903 .head = NULL, \
904 }
905
906/* List operations:
sewardjb5f6f512005-03-10 23:59:00 +0000907 SkipList_Find_* search a list. The 3 variants are:
908 Before: returns a node which is <= key, or NULL if none
909 Exact: returns a node which is == key, or NULL if none
910 After: returns a node which is >= key, or NULL if none
nethercote37aac2e2004-09-02 08:54:27 +0000911 SkipList_Insert inserts a new element into the list. Duplicates are
912 forbidden. The element must have been created with SkipList_Alloc!
913 SkipList_Remove removes an element from the list and returns it. It
914 doesn't free the memory.
915*/
sewardjb5f6f512005-03-10 23:59:00 +0000916extern void *VG_(SkipList_Find_Before) (const SkipList *l, void *key);
917extern void *VG_(SkipList_Find_Exact) (const SkipList *l, void *key);
918extern void *VG_(SkipList_Find_After) (const SkipList *l, void *key);
919extern void VG_(SkipList_Insert) ( SkipList *l, void *data);
920extern void *VG_(SkipList_Remove) ( SkipList *l, void *key);
921
922/* Some useful standard comparisons */
923extern Int VG_(cmp_Addr) (const void *a, const void *b);
924extern Int VG_(cmp_Int) (const void *a, const void *b);
925extern Int VG_(cmp_UInt) (const void *a, const void *b);
926extern Int VG_(cmp_string)(const void *a, const void *b);
nethercote37aac2e2004-09-02 08:54:27 +0000927
928/* Node (element) operations:
929 SkipNode_Alloc: allocate memory for a new element on the list. Must be
930 used before an element can be inserted! Returns NULL if not enough
931 memory.
932 SkipNode_Free: free memory allocated above
933 SkipNode_First: return the first element on the list
934 SkipNode_Next: return the next element after "data" on the list -
935 NULL for none
936
937 You can iterate through a SkipList like this:
938
939 for(x = VG_(SkipNode_First)(&list); // or SkipList_Find
940 x != NULL;
941 x = VG_(SkipNode_Next)(&list, x)) { ... }
942*/
943extern void *VG_(SkipNode_Alloc) (const SkipList *l);
944extern void VG_(SkipNode_Free) (const SkipList *l, void *p);
945extern void *VG_(SkipNode_First) (const SkipList *l);
946extern void *VG_(SkipNode_Next) (const SkipList *l, void *data);
947
njnabb14ad2004-11-24 16:57:16 +0000948
nethercote37aac2e2004-09-02 08:54:27 +0000949/*====================================================================*/
950/*=== Functions for shadow registers ===*/
951/*====================================================================*/
952
njnabb14ad2004-11-24 16:57:16 +0000953// For get/set, 'area' is where the asked-for shadow state will be copied
954// into/from.
955extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
956 SizeT size, UChar* area );
957extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
958 SizeT size, const UChar* area );
nethercote37aac2e2004-09-02 08:54:27 +0000959
960/* This one lets you override the shadow of the return value register for a
njn26f02512004-11-22 18:33:15 +0000961 syscall. Call it from TL_(post_syscall)() (not TL_(pre_syscall)()!) to
nethercote37aac2e2004-09-02 08:54:27 +0000962 override the default shadow register value. */
963extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njncf45fd42004-11-24 16:30:22 +0000964 UWord ret_shadow );
nethercote37aac2e2004-09-02 08:54:27 +0000965
njn26f02512004-11-22 18:33:15 +0000966/* This can be called from TL_(fini)() to find the shadow of the argument
nethercote37aac2e2004-09-02 08:54:27 +0000967 to exit(), ie. the shadow of the program's return value. */
sewardj2a99cf62004-11-24 10:44:19 +0000968extern UInt VG_(get_exit_status_shadow) ( ThreadId );
nethercote37aac2e2004-09-02 08:54:27 +0000969
970
971/*====================================================================*/
972/*=== Specific stuff for replacing malloc() and friends ===*/
973/*====================================================================*/
974
975/* If a tool replaces malloc() et al, the easiest way to do so is to
976 link with vg_replace_malloc.o into its vgpreload_*.so file, and
977 follow the following instructions. You can do it from scratch,
978 though, if you enjoy that sort of thing. */
979
980/* Arena size for valgrind's own malloc(); default value is 0, but can
981 be overridden by tool -- but must be done so *statically*, eg:
982
njn6a22af22004-11-30 14:41:13 +0000983 SizeT VG_(vg_malloc_redzone_szB) = 4;
nethercote37aac2e2004-09-02 08:54:27 +0000984
njn26f02512004-11-22 18:33:15 +0000985 It can't be done from a function like TL_(pre_clo_init)(). So it can't,
nethercote37aac2e2004-09-02 08:54:27 +0000986 for example, be controlled with a command line option, unfortunately. */
njn6a22af22004-11-30 14:41:13 +0000987extern SizeT VG_(vg_malloc_redzone_szB);
nethercote37aac2e2004-09-02 08:54:27 +0000988
njn26f02512004-11-22 18:33:15 +0000989/* Can be called from TL_(malloc) et al to do the actual alloc/freeing. */
nethercote7ac7f7b2004-11-02 12:36:02 +0000990extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000991extern void VG_(cli_free) ( void* p );
992
993/* Check if an address is within a range, allowing for redzones at edges */
nethercote7ac7f7b2004-11-02 12:36:02 +0000994extern Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000995
996/* ------------------------------------------------------------------ */
997/* Some options that can be used by a tool if malloc() et al are replaced.
998 The tool should call the functions in the appropriate places to give
999 control over these aspects of Valgrind's version of malloc(). */
1000
1001/* Round malloc sizes upwards to integral number of words? default: NO */
1002extern Bool VG_(clo_sloppy_malloc);
1003/* DEBUG: print malloc details? default: NO */
1004extern Bool VG_(clo_trace_malloc);
1005/* Minimum alignment in functions that don't specify alignment explicitly.
1006 default: 0, i.e. use default of the machine (== 4) */
nethercote7ac7f7b2004-11-02 12:36:02 +00001007extern UInt VG_(clo_alignment);
nethercote37aac2e2004-09-02 08:54:27 +00001008
1009extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
1010extern void VG_(replacement_malloc_print_usage) ( void );
1011extern void VG_(replacement_malloc_print_debug_usage) ( void );
1012
1013
1014/*====================================================================*/
1015/*=== Tool-specific stuff ===*/
1016/*====================================================================*/
1017
1018/* ------------------------------------------------------------------ */
1019/* Details */
1020
1021/* Default value for avg_translations_sizeB (in bytes), indicating typical
1022 code expansion of about 6:1. */
1023#define VG_DEFAULT_TRANS_SIZEB 100
1024
1025/* Information used in the startup message. `name' also determines the
1026 string used for identifying suppressions in a suppression file as
1027 belonging to this tool. `version' can be NULL, in which case (not
1028 surprisingly) no version info is printed; this mechanism is designed for
1029 tools distributed with Valgrind that share a version number with
1030 Valgrind. Other tools not distributed as part of Valgrind should
1031 probably have their own version number. */
1032extern void VG_(details_name) ( Char* name );
1033extern void VG_(details_version) ( Char* version );
1034extern void VG_(details_description) ( Char* description );
1035extern void VG_(details_copyright_author) ( Char* copyright_author );
1036
1037/* Average size of a translation, in bytes, so that the translation
1038 storage machinery can allocate memory appropriately. Not critical,
1039 setting is optional. */
1040extern void VG_(details_avg_translation_sizeB) ( UInt size );
1041
njn67993252004-11-22 18:02:32 +00001042/* String printed if an `tl_assert' assertion fails or VG_(tool_panic)
nethercote37aac2e2004-09-02 08:54:27 +00001043 is called. Should probably be an email address. */
1044extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
1045
1046/* ------------------------------------------------------------------ */
1047/* Needs */
1048
1049/* Booleans that decide core behaviour, but don't require extra
1050 operations to be defined if `True' */
1051
1052/* Should __libc_freeres() be run? Bugs in it can crash the tool. */
1053extern void VG_(needs_libc_freeres) ( void );
1054
1055/* Want to have errors detected by Valgrind's core reported? Includes:
1056 - pthread API errors (many; eg. unlocking a non-locked mutex)
1057 - invalid file descriptors to blocking syscalls read() and write()
1058 - bad signal numbers passed to sigaction()
1059 - attempt to install signal handler for SIGKILL or SIGSTOP */
1060extern void VG_(needs_core_errors) ( void );
1061
1062/* Booleans that indicate extra operations are defined; if these are True,
1063 the corresponding template functions (given below) must be defined. A
1064 lot like being a member of a type class. */
1065
1066/* Want to report errors from tool? This implies use of suppressions, too. */
njn95ec8702004-11-22 16:46:13 +00001067extern void VG_(needs_tool_errors) ( void );
nethercote37aac2e2004-09-02 08:54:27 +00001068
1069/* Is information kept about specific individual basic blocks? (Eg. for
1070 cachegrind there are cost-centres for every instruction, stored at a
1071 basic block level.) If so, it sometimes has to be discarded, because
1072 .so mmap/munmap-ping or self-modifying code (informed by the
1073 DISCARD_TRANSLATIONS user request) can cause one instruction address
1074 to be used for more than one instruction in one program run... */
1075extern void VG_(needs_basic_block_discards) ( void );
1076
nethercote37aac2e2004-09-02 08:54:27 +00001077/* Tool defines its own command line options? */
1078extern void VG_(needs_command_line_options) ( void );
1079
1080/* Tool defines its own client requests? */
1081extern void VG_(needs_client_requests) ( void );
1082
nethercote37aac2e2004-09-02 08:54:27 +00001083/* Tool does stuff before and/or after system calls? */
1084extern void VG_(needs_syscall_wrapper) ( void );
1085
1086/* Are tool-state sanity checks performed? */
1087extern void VG_(needs_sanity_checks) ( void );
1088
1089/* Do we need to see data symbols? */
1090extern void VG_(needs_data_syms) ( void );
1091
1092/* Does the tool need shadow memory allocated (if you set this, you must also statically initialize
njn26f02512004-11-22 18:33:15 +00001093 float TL_(shadow_ratio) = n./m;
nethercote37aac2e2004-09-02 08:54:27 +00001094 to define how many shadow bits you need per client address space bit.
1095*/
1096extern void VG_(needs_shadow_memory)( void );
njn26f02512004-11-22 18:33:15 +00001097extern float TL_(shadow_ratio);
nethercote37aac2e2004-09-02 08:54:27 +00001098
1099/* ------------------------------------------------------------------ */
1100/* Core events to track */
1101
1102/* Part of the core from which this call was made. Useful for determining
1103 what kind of error message should be emitted. */
1104typedef
njncf45fd42004-11-24 16:30:22 +00001105 enum { Vg_CoreStartup, Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall,
1106 Vg_CoreTranslate, Vg_CoreClientReq }
nethercote37aac2e2004-09-02 08:54:27 +00001107 CorePart;
1108
1109/* Useful to use in VG_(get_Xreg_usage)() */
1110#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
1111 { if (mycat(u->tag,ono) == tag) \
1112 { regs[n] = mycat(u->val,ono); \
1113 isWrites[n] = False; \
1114 n++; \
1115 } \
1116 }
1117#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
1118 { if (mycat(u->tag,ono) == tag) \
1119 { regs[n] = mycat(u->val,ono); \
1120 isWrites[n] = True; \
1121 n++; \
1122 } \
1123 }
1124
1125#endif /* NDEF __TOOL_H */
1126
1127/* gen_toolint.pl will put the VG_(init_*)() functions here: */