blob: a75bbad803adce06ecfd937c9f182c7c6f454937 [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
njn53612422005-03-12 16:22:54 +000010 Copyright (C) 2000-2005 Julian Seward
nethercote37aac2e2004-09-02 08:54:27 +000011 jseward@acm.org
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
31#ifndef __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
nethercote37aac2e2004-09-02 08:54:27 +0000196/* Send a single-part message. Appends a newline. */
sewardjb5f6f512005-03-10 23:59:00 +0000197extern int VG_(message) ( VgMsgKind kind, const Char* format, ... );
198extern int VG_(vmessage) ( VgMsgKind kind, const Char* format, va_list vargs );
nethercote37aac2e2004-09-02 08:54:27 +0000199
200
201/*====================================================================*/
202/*=== Profiling ===*/
203/*====================================================================*/
204
205/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
206#define VGP_CORE_LIST \
207 /* These ones depend on the core */ \
208 VGP_PAIR(VgpUnc, "unclassified"), \
209 VGP_PAIR(VgpStartup, "startup"), \
210 VGP_PAIR(VgpRun, "running"), \
211 VGP_PAIR(VgpSched, "scheduler"), \
212 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
213 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
214 VGP_PAIR(VgpTranslate, "translate-main"), \
215 VGP_PAIR(VgpToUCode, "to-ucode"), \
216 VGP_PAIR(VgpFromUcode, "from-ucode"), \
217 VGP_PAIR(VgpImprove, "improve"), \
218 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
219 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
220 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
221 VGP_PAIR(VgpDoLRU, "do-lru"), \
222 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
223 VGP_PAIR(VgpExeContext, "exe-context"), \
224 VGP_PAIR(VgpReadSyms, "read-syms"), \
225 VGP_PAIR(VgpSearchSyms, "search-syms"), \
226 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
227 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
228 VGP_PAIR(VgpDemangle, "demangle"), \
229 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
230 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
231 /* These ones depend on the tool */ \
232 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
233 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
234 VGP_PAIR(VgpInstrument, "instrument"), \
njn26f02512004-11-22 18:33:15 +0000235 VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \
236 VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \
237 VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \
nethercote37aac2e2004-09-02 08:54:27 +0000238 VGP_PAIR(VgpFini, "fini")
239
240#define VGP_PAIR(n,name) n
241typedef enum { VGP_CORE_LIST } VgpCoreCC;
242#undef VGP_PAIR
243
244/* When registering tool profiling events, ensure that the 'n' value is in
245 * the range (VgpFini+1..) */
246extern void VGP_(register_profile_event) ( Int n, Char* name );
247
248extern void VGP_(pushcc) ( UInt cc );
249extern void VGP_(popcc) ( UInt cc );
250
251/* Define them only if they haven't already been defined by vg_profile.c */
252#ifndef VGP_PUSHCC
253# define VGP_PUSHCC(x)
254#endif
255#ifndef VGP_POPCC
256# define VGP_POPCC(x)
257#endif
258
259
260/*====================================================================*/
261/*=== Useful stuff to call from generated code ===*/
262/*====================================================================*/
263
264/* ------------------------------------------------------------------ */
265/* General stuff */
266
267/* 64-bit counter for the number of basic blocks done. */
268extern ULong VG_(bbs_done);
269
njnedfa0f62004-11-30 18:08:05 +0000270/* Check if an address/whatever is aligned */
271#define IS_4_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x3))
272#define IS_8_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x7))
273#define IS_16_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0xf))
274#define IS_WORD_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & (sizeof(Addr)-1)))
nethercote37aac2e2004-09-02 08:54:27 +0000275
276
277/* ------------------------------------------------------------------ */
278/* Thread-related stuff */
279
280/* Special magic value for an invalid ThreadId. It corresponds to
281 LinuxThreads using zero as the initial value for
282 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
283#define VG_INVALID_THREADID ((ThreadId)(0))
284
285/* ThreadIds are simply indices into the VG_(threads)[] array. */
286typedef
287 UInt
288 ThreadId;
289
sewardjb5f6f512005-03-10 23:59:00 +0000290/* Get the TID of the thread which currently has the CPU. */
291extern ThreadId VG_(get_running_tid) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000292
293/* Searches through all thread's stacks to see if any match. Returns
294 VG_INVALID_THREADID if none match. */
295extern ThreadId VG_(first_matching_thread_stack)
296 ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
297 void* d );
298
sewardj2a99cf62004-11-24 10:44:19 +0000299/* Get the simulated %esp */
300extern Addr VG_(get_stack_pointer) ( ThreadId tid );
301
nethercote37aac2e2004-09-02 08:54:27 +0000302
303/*====================================================================*/
304/*=== Valgrind's version of libc ===*/
305/*====================================================================*/
306
307/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
308 are its own versions of C library functions, but with VG_ prefixes. Note
309 that the types of some are slightly different to the real ones. Some
310 additional useful functions are provided too; descriptions of how they
311 work are given below. */
312
313#if !defined(NULL)
314# define NULL ((void*)0)
315#endif
316
317
318/* ------------------------------------------------------------------ */
319/* stdio.h
320 *
321 * Note that they all output to the file descriptor given by the
322 * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
323 * Hence no need for VG_(fprintf)().
324 */
325extern UInt VG_(printf) ( const char *format, ... );
326/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
327extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
sewardjb5f6f512005-03-10 23:59:00 +0000328extern UInt VG_(vprintf) ( void(*send)(Char, void *),
329 const Char *format, va_list vargs, void *send_arg );
nethercote37aac2e2004-09-02 08:54:27 +0000330
331extern Int VG_(rename) ( Char* old_name, Char* new_name );
332
333/* ------------------------------------------------------------------ */
334/* stdlib.h */
335
nethercote7ac7f7b2004-11-02 12:36:02 +0000336extern void* VG_(malloc) ( SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000337extern void VG_(free) ( void* p );
njn926ed472005-03-11 04:44:10 +0000338extern void* VG_(calloc) ( SizeT n, SizeT bytes_per_elem );
nethercote7ac7f7b2004-11-02 12:36:02 +0000339extern void* VG_(realloc) ( void* p, SizeT size );
340extern void* VG_(malloc_aligned) ( SizeT align_bytes, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000341
sewardjb5f6f512005-03-10 23:59:00 +0000342/* terminate everything */
nethercote37aac2e2004-09-02 08:54:27 +0000343extern void VG_(exit)( Int status )
344 __attribute__ ((__noreturn__));
sewardjb5f6f512005-03-10 23:59:00 +0000345
346/* terminate the calling thread - probably not what you want */
347extern void VG_(exit_single)( Int status )
348 __attribute__ ((__noreturn__));
349
nethercote37aac2e2004-09-02 08:54:27 +0000350/* Prints a panic message (a constant string), appends newline and bug
351 reporting info, aborts. */
352__attribute__ ((__noreturn__))
njn67993252004-11-22 18:02:32 +0000353extern void VG_(tool_panic) ( Char* str );
nethercote37aac2e2004-09-02 08:54:27 +0000354
355/* Looks up VG_(client_envp) */
356extern Char* VG_(getenv) ( Char* name );
357
358/* Get client resource limit*/
359extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
360
361/* Set client resource limit*/
sewardjb5f6f512005-03-10 23:59:00 +0000362extern Int VG_(setrlimit) ( Int resource, const struct vki_rlimit *rlim );
nethercote37aac2e2004-09-02 08:54:27 +0000363
364/* Crude stand-in for the glibc system() call. */
365extern Int VG_(system) ( Char* cmd );
366
367extern Long VG_(atoll) ( Char* str );
368
369/* Like atoll(), but converts a number of base 16 */
370extern Long VG_(atoll16) ( Char* str );
371
372/* Like atoll(), but converts a number of base 2..36 */
373extern Long VG_(atoll36) ( UInt base, Char* str );
374
375/* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */
nethercote928a5f72004-11-03 18:10:37 +0000376extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size,
nethercote37aac2e2004-09-02 08:54:27 +0000377 Int (*compar)(void*, void*) );
378
379
380/* ------------------------------------------------------------------ */
381/* ctype.h */
382extern Bool VG_(isspace) ( Char c );
383extern Bool VG_(isdigit) ( Char c );
384extern Char VG_(toupper) ( Char c );
385
386
387/* ------------------------------------------------------------------ */
388/* string.h */
389extern Int VG_(strlen) ( const Char* str );
390extern Char* VG_(strcat) ( Char* dest, const Char* src );
391extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
392extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
393extern Char* VG_(strcpy) ( Char* dest, const Char* src );
394extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
395extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
396extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
397extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
398extern Char* VG_(strchr) ( const Char* s, Char c );
399extern Char* VG_(strrchr) ( const Char* s, Char c );
400extern Char* VG_(strdup) ( const Char* s);
401extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
402extern void* VG_(memset) ( void *s, Int c, Int sz );
403extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
404
405/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
406extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
407extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
408
409/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
410 last character. */
411extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
412
413/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
414 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
415extern Bool VG_(string_match) ( const Char* pat, const Char* str );
416
417
418/* ------------------------------------------------------------------ */
419/* math.h */
420/* Returns the base-2 logarithm of x. */
421extern Int VG_(log2) ( Int x );
422
423
424/* ------------------------------------------------------------------ */
425/* unistd.h, fcntl.h, sys/stat.h */
426extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count );
427extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
428extern Int VG_(getpid) ( void );
429extern Int VG_(getppid) ( void );
430extern Int VG_(getpgrp) ( void );
431extern Int VG_(gettid) ( void );
432extern Int VG_(setpgid) ( Int pid, Int pgrp );
433
434extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
435extern Int VG_(read) ( Int fd, void* buf, Int count);
436extern Int VG_(write) ( Int fd, const void* buf, Int count);
nethercote5b9fafd2004-11-04 18:39:22 +0000437extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
nethercote37aac2e2004-09-02 08:54:27 +0000438extern void VG_(close) ( Int fd );
439
440extern Int VG_(pipe) ( Int fd[2] );
441
442/* Nb: VG_(rename)() declared in stdio.h section above */
443extern Int VG_(unlink) ( Char* file_name );
444extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
445extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
446extern Int VG_(dup2) ( Int oldfd, Int newfd );
447
nethercote928a5f72004-11-03 18:10:37 +0000448extern Char* VG_(getcwd) ( Char* buf, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000449
450/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
451 String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
452 Returns False if it fails. Will fail if the pathname is > 65535 bytes. */
453extern Bool VG_(getcwd_alloc) ( Char** cwd );
454
455/* ------------------------------------------------------------------ */
456/* assert.h */
457/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
458#define VG__STRING(__str) #__str
459
njnca82cc02004-11-22 17:18:48 +0000460#define tl_assert(expr) \
nethercote37aac2e2004-09-02 08:54:27 +0000461 ((void) ((expr) ? 0 : \
njn94065fd2004-11-22 19:26:27 +0000462 (VG_(tool_assert_fail) (VG__STRING(expr), \
nethercote37aac2e2004-09-02 08:54:27 +0000463 __FILE__, __LINE__, \
464 __PRETTY_FUNCTION__), 0)))
465
466__attribute__ ((__noreturn__))
njn94065fd2004-11-22 19:26:27 +0000467extern void VG_(tool_assert_fail) ( const Char* expr, const Char* file,
nethercote37aac2e2004-09-02 08:54:27 +0000468 Int line, const Char* fn );
469
470
471/* ------------------------------------------------------------------ */
472/* Get memory by anonymous mmap. */
nethercote8b5f40c2004-11-02 13:29:50 +0000473extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
nethercote37aac2e2004-09-02 08:54:27 +0000474
475extern Bool VG_(is_client_addr) (Addr a);
476extern Addr VG_(get_client_base)(void);
477extern Addr VG_(get_client_end) (void);
478extern Addr VG_(get_client_size)(void);
479
480extern Bool VG_(is_shadow_addr) (Addr a);
481extern Addr VG_(get_shadow_base)(void);
482extern Addr VG_(get_shadow_end) (void);
483extern Addr VG_(get_shadow_size)(void);
484
485extern void *VG_(shadow_alloc)(UInt size);
486
sewardjb5f6f512005-03-10 23:59:00 +0000487extern Bool VG_(is_addressable)(Addr p, SizeT sz, UInt prot);
nethercote37aac2e2004-09-02 08:54:27 +0000488
nethercote928a5f72004-11-03 18:10:37 +0000489extern Addr VG_(client_alloc)(Addr base, SizeT len, UInt prot, UInt flags);
nethercote37aac2e2004-09-02 08:54:27 +0000490extern void VG_(client_free)(Addr addr);
491
492extern Bool VG_(is_valgrind_addr)(Addr a);
493
sewardjb5f6f512005-03-10 23:59:00 +0000494/* Register an interest in apparently internal faults; used code which
495 wanders around dangerous memory (ie, leakcheck). The catcher is
496 not expected to return. */
497extern void VG_(set_fault_catcher)(void (*catcher)(Int sig, Addr addr));
498
nethercote37aac2e2004-09-02 08:54:27 +0000499/* initialize shadow pages in the range [p, p+sz) This calls
500 init_shadow_page for each one. It should be a lot more efficient
501 for bulk-initializing shadow pages than faulting on each one.
502*/
503extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
504
sewardjb5f6f512005-03-10 23:59:00 +0000505/* Calls into the core used by leak-checking */
506
507/* Calls "add_rootrange" with each range of memory which looks like a
508 plausible source of root pointers. */
509extern void VG_(find_root_memory)(void (*add_rootrange)(Addr addr, SizeT sz));
510
511/* Calls "mark_addr" with register values (which may or may not be pointers) */
512extern void VG_(mark_from_registers)(void (*mark_addr)(Addr addr));
513
nethercote37aac2e2004-09-02 08:54:27 +0000514/* ------------------------------------------------------------------ */
515/* signal.h.
516
517 Note that these use the vk_ (kernel) structure
518 definitions, which are different in places from those that glibc
nethercote73b526f2004-10-31 18:48:21 +0000519 defines. Since we're operating right at the kernel interface, glibc's view
520 of the world is entirely irrelevant. */
nethercote37aac2e2004-09-02 08:54:27 +0000521
522/* --- Signal set ops --- */
nethercote73b526f2004-10-31 18:48:21 +0000523extern Int VG_(sigfillset) ( vki_sigset_t* set );
524extern Int VG_(sigemptyset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000525
sewardjb5f6f512005-03-10 23:59:00 +0000526extern Bool VG_(isfullsigset) ( const vki_sigset_t* set );
527extern Bool VG_(isemptysigset) ( const vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000528
nethercote73b526f2004-10-31 18:48:21 +0000529extern Int VG_(sigaddset) ( vki_sigset_t* set, Int signum );
530extern Int VG_(sigdelset) ( vki_sigset_t* set, Int signum );
sewardjb5f6f512005-03-10 23:59:00 +0000531extern Int VG_(sigismember) ( const vki_sigset_t* set, Int signum );
nethercote37aac2e2004-09-02 08:54:27 +0000532
nethercote73b526f2004-10-31 18:48:21 +0000533extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
534extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
nethercote37aac2e2004-09-02 08:54:27 +0000535
536/* --- Mess with the kernel's sig state --- */
nethercote73b526f2004-10-31 18:48:21 +0000537extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
538 vki_sigset_t* oldset );
539extern Int VG_(sigaction) ( Int signum,
540 const struct vki_sigaction* act,
541 struct vki_sigaction* oldact );
nethercote37aac2e2004-09-02 08:54:27 +0000542
nethercote73b526f2004-10-31 18:48:21 +0000543extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *,
544 const struct vki_timespec * );
nethercote37aac2e2004-09-02 08:54:27 +0000545
nethercote73b526f2004-10-31 18:48:21 +0000546extern Int VG_(signal) ( Int signum, void (*sighandler)(Int) );
547extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
nethercote37aac2e2004-09-02 08:54:27 +0000548
nethercote73b526f2004-10-31 18:48:21 +0000549extern Int VG_(kill) ( Int pid, Int signo );
njnc6168192004-11-29 13:54:10 +0000550extern Int VG_(tkill) ( ThreadId tid, Int signo );
nethercote73b526f2004-10-31 18:48:21 +0000551extern Int VG_(sigpending) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000552
nethercote73b526f2004-10-31 18:48:21 +0000553extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
nethercote37aac2e2004-09-02 08:54:27 +0000554
555/* ------------------------------------------------------------------ */
556/* socket.h. */
557
558extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
559extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
560extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
561 Int *optlen);
562
563/* ------------------------------------------------------------------ */
564/* other, randomly useful functions */
565extern UInt VG_(read_millisecond_timer) ( void );
566
sewardjb5f6f512005-03-10 23:59:00 +0000567extern Bool VG_(has_cpuid) ( void );
568
nethercote37aac2e2004-09-02 08:54:27 +0000569extern void VG_(cpuid) ( UInt eax,
570 UInt *eax_ret, UInt *ebx_ret,
571 UInt *ecx_ret, UInt *edx_ret );
572
nethercote37aac2e2004-09-02 08:54:27 +0000573/*====================================================================*/
574/*=== Execution contexts ===*/
575/*====================================================================*/
576
577/* Generic resolution type used in a few different ways, such as deciding
578 how closely to compare two errors for equality. */
579typedef
580 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
581 VgRes;
582
583typedef
584 struct _ExeContext
585 ExeContext;
586
587/* Compare two ExeContexts. Number of callers considered depends on `res':
588 Vg_LowRes: 2
589 Vg_MedRes: 4
590 Vg_HighRes: all */
591extern Bool VG_(eq_ExeContext) ( VgRes res,
592 ExeContext* e1, ExeContext* e2 );
593
594/* Print an ExeContext. */
595extern void VG_(pp_ExeContext) ( ExeContext* );
596
597/* Take a snapshot of the client's stack. Search our collection of
598 ExeContexts to see if we already have it, and if not, allocate a
599 new one. Either way, return a pointer to the context. Context size
600 controlled by --num-callers option.
601
sewardjb5f6f512005-03-10 23:59:00 +0000602 If called from generated code, use VG_(get_VCPU_tid)() to get the
nethercote37aac2e2004-09-02 08:54:27 +0000603 current ThreadId. If called from non-generated code, the current
604 ThreadId should be passed in by the core.
605*/
606extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
607
nethercote86c5dcb2004-09-05 21:32:37 +0000608/* Get the nth IP from the ExeContext. 0 is the IP of the top function, 1
nethercote37aac2e2004-09-02 08:54:27 +0000609 is its caller, etc. Returns 0 if there isn't one, or if n is greater
610 than VG_(clo_backtrace_size), set by the --num-callers option. */
611extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
612
nethercote86c5dcb2004-09-05 21:32:37 +0000613/* Just grab the client's IP, as a much smaller and cheaper
nethercote37aac2e2004-09-02 08:54:27 +0000614 indication of where they are. Use is basically same as for
615 VG_(get_ExeContext)() above.
616*/
617extern Addr VG_(get_EIP)( ThreadId tid );
618
619/* For tools needing more control over stack traces: walks the stack to get
nethercote86c5dcb2004-09-05 21:32:37 +0000620 instruction pointers from the top stack frames for thread 'tid'. Maximum of
621 'n_ips' addresses put into 'ips'; 0 is the top of the stack, 1 is its
622 caller, etc. */
623extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* ips, UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000624
625/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
626 different input. */
nethercote86c5dcb2004-09-05 21:32:37 +0000627extern void VG_(mini_stack_dump) ( Addr ips[], UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000628
629
630/*====================================================================*/
631/*=== Error reporting ===*/
632/*====================================================================*/
633
634/* ------------------------------------------------------------------ */
635/* Suppressions describe errors which we want to suppress, ie, not
636 show the user, usually because it is caused by a problem in a library
637 which we can't fix, replace or work around. Suppressions are read from
638 a file at startup time. This gives flexibility so that new
639 suppressions can be added to the file as and when needed.
640*/
641
642typedef
643 Int /* Do not make this unsigned! */
644 SuppKind;
645
646/* The tool-relevant parts of a suppression are:
647 kind: what kind of suppression; must be in the range (0..)
648 string: use is optional. NULL by default.
649 extra: use is optional. NULL by default. void* so it's extensible.
650*/
651typedef
652 struct _Supp
653 Supp;
654
njn26f02512004-11-22 18:33:15 +0000655/* Useful in TL_(error_matches_suppression)() */
nethercote37aac2e2004-09-02 08:54:27 +0000656SuppKind VG_(get_supp_kind) ( Supp* su );
657Char* VG_(get_supp_string) ( Supp* su );
658void* VG_(get_supp_extra) ( Supp* su );
659
660/* Must be used in VG_(recognised_suppression)() */
661void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
662/* May be used in VG_(read_extra_suppression_info)() */
663void VG_(set_supp_string) ( Supp* su, Char* string );
664void VG_(set_supp_extra) ( Supp* su, void* extra );
665
666
667/* ------------------------------------------------------------------ */
668/* Error records contain enough info to generate an error report. The idea
669 is that (typically) the same few points in the program generate thousands
670 of errors, and we don't want to spew out a fresh error message for each
671 one. Instead, we use these structures to common up duplicates.
672*/
673
674typedef
675 Int /* Do not make this unsigned! */
676 ErrorKind;
677
678/* The tool-relevant parts of an Error are:
679 kind: what kind of error; must be in the range (0..)
680 addr: use is optional. 0 by default.
681 string: use is optional. NULL by default.
682 extra: use is optional. NULL by default. void* so it's extensible.
683*/
684typedef
685 struct _Error
686 Error;
687
njn26f02512004-11-22 18:33:15 +0000688/* Useful in TL_(error_matches_suppression)(), TL_(pp_Error)(), etc */
nethercote37aac2e2004-09-02 08:54:27 +0000689ExeContext* VG_(get_error_where) ( Error* err );
690SuppKind VG_(get_error_kind) ( Error* err );
691Addr VG_(get_error_address) ( Error* err );
692Char* VG_(get_error_string) ( Error* err );
693void* VG_(get_error_extra) ( Error* err );
694
695/* Call this when an error occurs. It will be recorded if it hasn't been
696 seen before. If it has, the existing error record will have its count
697 incremented.
698
699 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
700 be stack-allocated; it will be copied by the core if needed (but it
701 won't be copied if it's NULL).
702
703 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
704 NULL for them. */
705extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
706 Addr a, Char* s, void* extra );
707
708/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
709 error -- useful for errors that can only happen once. The errors can be
710 suppressed, though. Return value is True if it was suppressed.
711 `print_error' dictates whether to print the error, which is a bit of a
712 hack that's useful sometimes if you just want to know if the error would
713 be suppressed without possibly printing it. `count_error' dictates
714 whether to add the error in the error total count (another mild hack). */
715extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
716 Addr a, Char* s, void* extra,
717 ExeContext* where, Bool print_error,
718 Bool allow_GDB_attach, Bool count_error );
719
720/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
721 Skips leading spaces on the line. Returns True if EOF was hit instead.
722 Useful for reading in extra tool-specific suppression lines. */
723extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
724
725
726/*====================================================================*/
727/*=== Obtaining debug information ===*/
728/*====================================================================*/
729
730/* Get the file/function/line number of the instruction at address
731 'a'. For these four, if debug info for the address is found, it
732 copies the info into the buffer/UInt and returns True. If not, it
733 returns False and nothing is copied. VG_(get_fnname) always
734 demangles C++ function names. VG_(get_fnname_w_offset) is the
735 same, except it appends "+N" to symbol names to indicate offsets. */
736extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
737extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
738extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
739extern Bool VG_(get_fnname_w_offset)
740 ( Addr a, Char* fnname, Int n_fnname );
741
742/* This one is more efficient if getting both filename and line number,
743 because the two lookups are done together. */
744extern Bool VG_(get_filename_linenum)
745 ( Addr a, Char* filename, Int n_filename,
746 UInt* linenum );
747
748/* Succeeds only if we find from debug info that 'a' is the address of the
749 first instruction in a function -- as opposed to VG_(get_fnname) which
750 succeeds if we find from debug info that 'a' is the address of any
751 instruction in a function. Use this to instrument the start of
752 a particular function. Nb: if an executable/shared object is stripped
753 of its symbols, this function will not be able to recognise function
754 entry points within it. */
755extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
756
757/* Succeeds if the address is within a shared object or the main executable.
758 It doesn't matter if debug info is present or not. */
759extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
760
761/* Puts into 'buf' info about the code address %eip: the address, function
762 name (if known) and filename/line number (if known), like this:
763
764 0x4001BF05: realloc (vg_replace_malloc.c:339)
765
766 'n_buf' gives length of 'buf'. Returns 'buf'.
767*/
768extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
769
770/* Returns a string containing an expression for the given
771 address. String is malloced with VG_(malloc)() */
772Char *VG_(describe_addr)(ThreadId, Addr);
773
774/* A way to get information about what segments are mapped */
775typedef struct _SegInfo SegInfo;
776
777/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
778 is present or not. */
779extern SegInfo* VG_(get_obj) ( Addr a );
780
781extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
782extern Addr VG_(seg_start) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000783extern SizeT VG_(seg_size) ( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000784extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000785extern ULong VG_(seg_sym_offset)( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000786
787typedef
788 enum {
789 Vg_SectUnknown,
790 Vg_SectText,
791 Vg_SectData,
792 Vg_SectBSS,
793 Vg_SectGOT,
sewardjb5f6f512005-03-10 23:59:00 +0000794 Vg_SectPLT
nethercote37aac2e2004-09-02 08:54:27 +0000795 }
796 VgSectKind;
797
798extern VgSectKind VG_(seg_sect_kind)(Addr);
799
nethercote37aac2e2004-09-02 08:54:27 +0000800/*====================================================================*/
801/*=== Generic hash table ===*/
802/*====================================================================*/
803
804/* Generic type for a separately-chained hash table. Via a kind of dodgy
805 C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
806 as the first two fields match the sizes of these two fields. Requires
807 a bit of casting by the tool. */
808typedef
809 struct _VgHashNode {
810 struct _VgHashNode * next;
nethercote3d6b6112004-11-04 16:39:43 +0000811 UWord key;
nethercote37aac2e2004-09-02 08:54:27 +0000812 }
813 VgHashNode;
814
815typedef
816 VgHashNode**
817 VgHashTable;
818
819/* Make a new table. */
820extern VgHashTable VG_(HT_construct) ( void );
821
822/* Count the number of nodes in a table. */
823extern Int VG_(HT_count_nodes) ( VgHashTable table );
824
825/* Add a node to the table. */
826extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
827
828/* Looks up a node in the hash table. Also returns the address of the
829 previous node's `next' pointer which allows it to be removed from the
830 list later without having to look it up again. */
nethercote3d6b6112004-11-04 16:39:43 +0000831extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
nethercote37aac2e2004-09-02 08:54:27 +0000832 /*OUT*/VgHashNode*** next_ptr );
833
834/* Allocates an array of pointers to all the shadow chunks of malloc'd
835 blocks. Must be freed with VG_(free)(). */
836extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
837
838/* Returns first node that matches predicate `p', or NULL if none do.
839 Extra arguments can be implicitly passed to `p' using `d' which is an
840 opaque pointer passed to `p' each time it is called. */
841extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
842 Bool (*p)(VgHashNode*, void*),
843 void* d );
844
845/* Applies a function f() once to each node. Again, `d' can be used
846 to pass extra information to the function. */
847extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
848 void (*f)(VgHashNode*, void*),
849 void* d );
850
851/* Destroy a table. */
852extern void VG_(HT_destruct) ( VgHashTable t );
853
854
855/*====================================================================*/
856/*=== A generic skiplist ===*/
857/*====================================================================*/
858
859/*
860 The idea here is that the skiplist puts its per-element data at the
861 end of the structure. When you initialize the skiplist, you tell
862 it what structure your list elements are going to be. Then you
863 should allocate them with VG_(SkipNode_Alloc), which will allocate
864 enough memory for the extra bits.
865 */
nethercote37aac2e2004-09-02 08:54:27 +0000866
867typedef struct _SkipList SkipList;
868typedef struct _SkipNode SkipNode;
869
870typedef Int (*SkipCmp_t)(const void *key1, const void *key2);
871
872struct _SkipList {
873 const Short arena; /* allocation arena */
874 const UShort size; /* structure size (not including SkipNode) */
875 const UShort keyoff; /* key offset */
876 const SkipCmp_t cmp; /* compare two keys */
877 Char * (*strkey)(void *); /* stringify a key (for debugging) */
878 SkipNode *head; /* list head */
879};
880
881/* Use this macro to initialize your skiplist head. The arguments are pretty self explanitory:
882 _type is the type of your element structure
883 _key is the field within that type which you want to use as the key
884 _cmp is the comparison function for keys - it gets two typeof(_key) pointers as args
885 _strkey is a function which can return a string of your key - it's only used for debugging
886 _arena is the arena to use for allocation - -1 is the default
887 */
888#define SKIPLIST_INIT(_type, _key, _cmp, _strkey, _arena) \
889 { \
890 .arena = _arena, \
891 .size = sizeof(_type), \
892 .keyoff = offsetof(_type, _key), \
893 .cmp = _cmp, \
894 .strkey = _strkey, \
895 .head = NULL, \
896 }
897
898/* List operations:
sewardjb5f6f512005-03-10 23:59:00 +0000899 SkipList_Find_* search a list. The 3 variants are:
900 Before: returns a node which is <= key, or NULL if none
901 Exact: returns a node which is == key, or NULL if none
902 After: returns a node which is >= key, or NULL if none
nethercote37aac2e2004-09-02 08:54:27 +0000903 SkipList_Insert inserts a new element into the list. Duplicates are
904 forbidden. The element must have been created with SkipList_Alloc!
905 SkipList_Remove removes an element from the list and returns it. It
906 doesn't free the memory.
907*/
sewardjb5f6f512005-03-10 23:59:00 +0000908extern void *VG_(SkipList_Find_Before) (const SkipList *l, void *key);
909extern void *VG_(SkipList_Find_Exact) (const SkipList *l, void *key);
910extern void *VG_(SkipList_Find_After) (const SkipList *l, void *key);
911extern void VG_(SkipList_Insert) ( SkipList *l, void *data);
912extern void *VG_(SkipList_Remove) ( SkipList *l, void *key);
913
914/* Some useful standard comparisons */
915extern Int VG_(cmp_Addr) (const void *a, const void *b);
916extern Int VG_(cmp_Int) (const void *a, const void *b);
917extern Int VG_(cmp_UInt) (const void *a, const void *b);
918extern Int VG_(cmp_string)(const void *a, const void *b);
nethercote37aac2e2004-09-02 08:54:27 +0000919
920/* Node (element) operations:
921 SkipNode_Alloc: allocate memory for a new element on the list. Must be
922 used before an element can be inserted! Returns NULL if not enough
923 memory.
924 SkipNode_Free: free memory allocated above
925 SkipNode_First: return the first element on the list
926 SkipNode_Next: return the next element after "data" on the list -
927 NULL for none
928
929 You can iterate through a SkipList like this:
930
931 for(x = VG_(SkipNode_First)(&list); // or SkipList_Find
932 x != NULL;
933 x = VG_(SkipNode_Next)(&list, x)) { ... }
934*/
935extern void *VG_(SkipNode_Alloc) (const SkipList *l);
936extern void VG_(SkipNode_Free) (const SkipList *l, void *p);
937extern void *VG_(SkipNode_First) (const SkipList *l);
938extern void *VG_(SkipNode_Next) (const SkipList *l, void *data);
939
njnabb14ad2004-11-24 16:57:16 +0000940
nethercote37aac2e2004-09-02 08:54:27 +0000941/*====================================================================*/
942/*=== Functions for shadow registers ===*/
943/*====================================================================*/
944
njnabb14ad2004-11-24 16:57:16 +0000945// For get/set, 'area' is where the asked-for shadow state will be copied
946// into/from.
947extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
948 SizeT size, UChar* area );
949extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
950 SizeT size, const UChar* area );
nethercote37aac2e2004-09-02 08:54:27 +0000951
952/* This one lets you override the shadow of the return value register for a
njn26f02512004-11-22 18:33:15 +0000953 syscall. Call it from TL_(post_syscall)() (not TL_(pre_syscall)()!) to
nethercote37aac2e2004-09-02 08:54:27 +0000954 override the default shadow register value. */
955extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njncf45fd42004-11-24 16:30:22 +0000956 UWord ret_shadow );
nethercote37aac2e2004-09-02 08:54:27 +0000957
njn26f02512004-11-22 18:33:15 +0000958/* This can be called from TL_(fini)() to find the shadow of the argument
nethercote37aac2e2004-09-02 08:54:27 +0000959 to exit(), ie. the shadow of the program's return value. */
sewardj2a99cf62004-11-24 10:44:19 +0000960extern UInt VG_(get_exit_status_shadow) ( ThreadId );
nethercote37aac2e2004-09-02 08:54:27 +0000961
962
963/*====================================================================*/
964/*=== Specific stuff for replacing malloc() and friends ===*/
965/*====================================================================*/
966
967/* If a tool replaces malloc() et al, the easiest way to do so is to
968 link with vg_replace_malloc.o into its vgpreload_*.so file, and
969 follow the following instructions. You can do it from scratch,
970 though, if you enjoy that sort of thing. */
971
972/* Arena size for valgrind's own malloc(); default value is 0, but can
973 be overridden by tool -- but must be done so *statically*, eg:
974
njn6a22af22004-11-30 14:41:13 +0000975 SizeT VG_(vg_malloc_redzone_szB) = 4;
nethercote37aac2e2004-09-02 08:54:27 +0000976
njn26f02512004-11-22 18:33:15 +0000977 It can't be done from a function like TL_(pre_clo_init)(). So it can't,
nethercote37aac2e2004-09-02 08:54:27 +0000978 for example, be controlled with a command line option, unfortunately. */
njn6a22af22004-11-30 14:41:13 +0000979extern SizeT VG_(vg_malloc_redzone_szB);
nethercote37aac2e2004-09-02 08:54:27 +0000980
njn26f02512004-11-22 18:33:15 +0000981/* Can be called from TL_(malloc) et al to do the actual alloc/freeing. */
nethercote7ac7f7b2004-11-02 12:36:02 +0000982extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000983extern void VG_(cli_free) ( void* p );
984
985/* Check if an address is within a range, allowing for redzones at edges */
nethercote7ac7f7b2004-11-02 12:36:02 +0000986extern Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000987
988/* ------------------------------------------------------------------ */
989/* Some options that can be used by a tool if malloc() et al are replaced.
990 The tool should call the functions in the appropriate places to give
991 control over these aspects of Valgrind's version of malloc(). */
992
993/* Round malloc sizes upwards to integral number of words? default: NO */
994extern Bool VG_(clo_sloppy_malloc);
995/* DEBUG: print malloc details? default: NO */
996extern Bool VG_(clo_trace_malloc);
997/* Minimum alignment in functions that don't specify alignment explicitly.
998 default: 0, i.e. use default of the machine (== 4) */
nethercote7ac7f7b2004-11-02 12:36:02 +0000999extern UInt VG_(clo_alignment);
nethercote37aac2e2004-09-02 08:54:27 +00001000
1001extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
1002extern void VG_(replacement_malloc_print_usage) ( void );
1003extern void VG_(replacement_malloc_print_debug_usage) ( void );
1004
1005
1006/*====================================================================*/
1007/*=== Tool-specific stuff ===*/
1008/*====================================================================*/
1009
1010/* ------------------------------------------------------------------ */
1011/* Details */
1012
1013/* Default value for avg_translations_sizeB (in bytes), indicating typical
1014 code expansion of about 6:1. */
1015#define VG_DEFAULT_TRANS_SIZEB 100
1016
1017/* Information used in the startup message. `name' also determines the
1018 string used for identifying suppressions in a suppression file as
1019 belonging to this tool. `version' can be NULL, in which case (not
1020 surprisingly) no version info is printed; this mechanism is designed for
1021 tools distributed with Valgrind that share a version number with
1022 Valgrind. Other tools not distributed as part of Valgrind should
1023 probably have their own version number. */
1024extern void VG_(details_name) ( Char* name );
1025extern void VG_(details_version) ( Char* version );
1026extern void VG_(details_description) ( Char* description );
1027extern void VG_(details_copyright_author) ( Char* copyright_author );
1028
1029/* Average size of a translation, in bytes, so that the translation
1030 storage machinery can allocate memory appropriately. Not critical,
1031 setting is optional. */
1032extern void VG_(details_avg_translation_sizeB) ( UInt size );
1033
njn67993252004-11-22 18:02:32 +00001034/* String printed if an `tl_assert' assertion fails or VG_(tool_panic)
nethercote37aac2e2004-09-02 08:54:27 +00001035 is called. Should probably be an email address. */
1036extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
1037
1038/* ------------------------------------------------------------------ */
1039/* Needs */
1040
1041/* Booleans that decide core behaviour, but don't require extra
1042 operations to be defined if `True' */
1043
1044/* Should __libc_freeres() be run? Bugs in it can crash the tool. */
1045extern void VG_(needs_libc_freeres) ( void );
1046
1047/* Want to have errors detected by Valgrind's core reported? Includes:
1048 - pthread API errors (many; eg. unlocking a non-locked mutex)
1049 - invalid file descriptors to blocking syscalls read() and write()
1050 - bad signal numbers passed to sigaction()
1051 - attempt to install signal handler for SIGKILL or SIGSTOP */
1052extern void VG_(needs_core_errors) ( void );
1053
1054/* Booleans that indicate extra operations are defined; if these are True,
1055 the corresponding template functions (given below) must be defined. A
1056 lot like being a member of a type class. */
1057
1058/* Want to report errors from tool? This implies use of suppressions, too. */
njn95ec8702004-11-22 16:46:13 +00001059extern void VG_(needs_tool_errors) ( void );
nethercote37aac2e2004-09-02 08:54:27 +00001060
1061/* Is information kept about specific individual basic blocks? (Eg. for
1062 cachegrind there are cost-centres for every instruction, stored at a
1063 basic block level.) If so, it sometimes has to be discarded, because
1064 .so mmap/munmap-ping or self-modifying code (informed by the
1065 DISCARD_TRANSLATIONS user request) can cause one instruction address
1066 to be used for more than one instruction in one program run... */
1067extern void VG_(needs_basic_block_discards) ( void );
1068
nethercote37aac2e2004-09-02 08:54:27 +00001069/* Tool defines its own command line options? */
1070extern void VG_(needs_command_line_options) ( void );
1071
1072/* Tool defines its own client requests? */
1073extern void VG_(needs_client_requests) ( void );
1074
nethercote37aac2e2004-09-02 08:54:27 +00001075/* Tool does stuff before and/or after system calls? */
1076extern void VG_(needs_syscall_wrapper) ( void );
1077
1078/* Are tool-state sanity checks performed? */
1079extern void VG_(needs_sanity_checks) ( void );
1080
1081/* Do we need to see data symbols? */
1082extern void VG_(needs_data_syms) ( void );
1083
1084/* Does the tool need shadow memory allocated (if you set this, you must also statically initialize
njn26f02512004-11-22 18:33:15 +00001085 float TL_(shadow_ratio) = n./m;
nethercote37aac2e2004-09-02 08:54:27 +00001086 to define how many shadow bits you need per client address space bit.
1087*/
1088extern void VG_(needs_shadow_memory)( void );
njn26f02512004-11-22 18:33:15 +00001089extern float TL_(shadow_ratio);
nethercote37aac2e2004-09-02 08:54:27 +00001090
1091/* ------------------------------------------------------------------ */
1092/* Core events to track */
1093
1094/* Part of the core from which this call was made. Useful for determining
1095 what kind of error message should be emitted. */
1096typedef
njncf45fd42004-11-24 16:30:22 +00001097 enum { Vg_CoreStartup, Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall,
1098 Vg_CoreTranslate, Vg_CoreClientReq }
nethercote37aac2e2004-09-02 08:54:27 +00001099 CorePart;
1100
1101/* Useful to use in VG_(get_Xreg_usage)() */
1102#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
1103 { if (mycat(u->tag,ono) == tag) \
1104 { regs[n] = mycat(u->val,ono); \
1105 isWrites[n] = False; \
1106 n++; \
1107 } \
1108 }
1109#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
1110 { if (mycat(u->tag,ono) == tag) \
1111 { regs[n] = mycat(u->val,ono); \
1112 isWrites[n] = True; \
1113 n++; \
1114 } \
1115 }
1116
1117#endif /* NDEF __TOOL_H */
1118
1119/* gen_toolint.pl will put the VG_(init_*)() functions here: */