nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1 | /*-*- c -*- ----------------------------------------------------------*/ |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 2 | /*--- Header for lots of tool stuff. tool.h ---*/ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 3 | /*--------------------------------------------------------------------*/ |
| 4 | |
| 5 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 6 | This file is part of Valgrind, a dynamic binary instrumentation |
| 7 | framework. |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 8 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 9 | Copyright (C) 2000-2005 Julian Seward |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 10 | jseward@acm.org |
| 11 | |
| 12 | This program is free software; you can redistribute it and/or |
| 13 | modify it under the terms of the GNU General Public License as |
| 14 | published by the Free Software Foundation; either version 2 of the |
| 15 | License, or (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, but |
| 18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 25 | 02111-1307, USA. |
| 26 | |
| 27 | The GNU General Public License is contained in the file COPYING. |
| 28 | */ |
| 29 | |
| 30 | #ifndef __TOOL_H |
| 31 | #define __TOOL_H |
| 32 | |
| 33 | #include <stdarg.h> /* ANSI varargs stuff */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 34 | |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 35 | #include "basic_types.h" |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 36 | #include "tool_asm.h" /* asm stuff */ |
| 37 | #include "tool_arch.h" /* arch-specific tool stuff */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 38 | #include "vki.h" |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 39 | |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 40 | #include "pub_tool_errormgr.h" // needed for 'Error', 'Supp' |
| 41 | #include "pub_tool_execontext.h" // needed for 'ExeContext' |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 42 | |
sewardj | 8b635a4 | 2004-11-22 19:01:47 +0000 | [diff] [blame] | 43 | #include "libvex.h" |
| 44 | #include "libvex_ir.h" |
| 45 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 46 | /*====================================================================*/ |
| 47 | /*=== Build options and table sizes. ===*/ |
| 48 | /*====================================================================*/ |
| 49 | |
| 50 | /* You should be able to change these options or sizes, recompile, and |
| 51 | still have a working system. */ |
| 52 | |
| 53 | /* The maximum number of pthreads that we support. This is |
| 54 | deliberately not very high since our implementation of some of the |
| 55 | scheduler algorithms is surely O(N) in the number of threads, since |
| 56 | that's simple, at least. And (in practice) we hope that most |
| 57 | programs do not need many threads. */ |
| 58 | #define VG_N_THREADS 100 |
| 59 | |
| 60 | /* Maximum number of pthread keys available. Again, we start low until |
| 61 | the need for a higher number presents itself. */ |
| 62 | #define VG_N_THREAD_KEYS 50 |
| 63 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 64 | |
| 65 | /*====================================================================*/ |
nethercote | 2e05c33 | 2004-09-06 16:43:37 +0000 | [diff] [blame] | 66 | /*=== Useful macros ===*/ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 67 | /*====================================================================*/ |
| 68 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 69 | /* No, really. I _am_ that strange. */ |
| 70 | #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn) |
| 71 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 72 | /* Path to all our library/aux files */ |
| 73 | extern const Char *VG_(libdir); |
| 74 | |
| 75 | |
| 76 | /*====================================================================*/ |
| 77 | /*=== Core/tool interface version ===*/ |
| 78 | /*====================================================================*/ |
| 79 | |
| 80 | /* The major version number indicates binary-incompatible changes to the |
| 81 | interface; if the core and tool major versions don't match, Valgrind |
| 82 | will abort. The minor version indicates binary-compatible changes. |
nethercote | 836d46c | 2004-11-18 12:58:53 +0000 | [diff] [blame] | 83 | |
| 84 | (Update: as it happens, we're never using the minor version number, because |
| 85 | there's no point in doing so.) |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 86 | */ |
nethercote | 836d46c | 2004-11-18 12:58:53 +0000 | [diff] [blame] | 87 | #define VG_CORE_INTERFACE_MAJOR_VERSION 7 |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 88 | #define VG_CORE_INTERFACE_MINOR_VERSION 0 |
| 89 | |
| 90 | typedef struct _ToolInfo { |
| 91 | Int sizeof_ToolInfo; |
| 92 | Int interface_major_version; |
| 93 | Int interface_minor_version; |
| 94 | |
| 95 | /* Initialise tool. Must do the following: |
| 96 | - initialise the `details' struct, via the VG_(details_*)() functions |
| 97 | - register any helpers called by generated code |
| 98 | |
| 99 | May do the following: |
| 100 | - initialise the `needs' struct to indicate certain requirements, via |
| 101 | the VG_(needs_*)() functions |
| 102 | - initialize all the tool's entrypoints via the VG_(init_*)() functions |
| 103 | - register any tool-specific profiling events |
| 104 | - any other tool-specific initialisation |
| 105 | */ |
njn | d225283 | 2004-11-26 10:53:33 +0000 | [diff] [blame] | 106 | void (*tl_pre_clo_init) ( void ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 107 | |
| 108 | /* Specifies how big the shadow segment should be as a ratio to the |
| 109 | client address space. 0 for no shadow segment. */ |
| 110 | float shadow_ratio; |
| 111 | } ToolInfo; |
| 112 | |
| 113 | /* Every tool must include this macro somewhere, exactly once. */ |
| 114 | #define VG_DETERMINE_INTERFACE_VERSION(pre_clo_init, shadow) \ |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 115 | const ToolInfo TL_(tool_info) = { \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 116 | .sizeof_ToolInfo = sizeof(ToolInfo), \ |
| 117 | .interface_major_version = VG_CORE_INTERFACE_MAJOR_VERSION, \ |
| 118 | .interface_minor_version = VG_CORE_INTERFACE_MINOR_VERSION, \ |
njn | d225283 | 2004-11-26 10:53:33 +0000 | [diff] [blame] | 119 | .tl_pre_clo_init = pre_clo_init, \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 120 | .shadow_ratio = shadow, \ |
| 121 | }; |
| 122 | |
| 123 | /*====================================================================*/ |
| 124 | /*=== Command-line options ===*/ |
| 125 | /*====================================================================*/ |
| 126 | |
| 127 | /* Use this for normal null-termination-style string comparison */ |
| 128 | #define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \ |
| 129 | && VG_(strcmp)((s1),(s2))==0) |
| 130 | |
| 131 | /* Use these for recognising tool command line options -- stops comparing |
| 132 | once whitespace is reached. */ |
| 133 | #define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2))) |
| 134 | #define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn))) |
| 135 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 136 | /* Higher-level command-line option recognisers; use in if/else chains */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 137 | |
njn | 45270a2 | 2005-03-27 01:00:11 +0000 | [diff] [blame] | 138 | #define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \ |
| 139 | if (VG_CLO_STREQ(qq_arg, qq_option"=yes")) { (qq_var) = True; } \ |
| 140 | else if (VG_CLO_STREQ(qq_arg, qq_option"=no")) { (qq_var) = False; } |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 141 | |
njn | 45270a2 | 2005-03-27 01:00:11 +0000 | [diff] [blame] | 142 | #define VG_STR_CLO(qq_arg, qq_option, qq_var) \ |
| 143 | if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \ |
| 144 | (qq_var) = &qq_arg[ VG_(strlen)(qq_option)+1 ]; \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 145 | } |
| 146 | |
njn | 45270a2 | 2005-03-27 01:00:11 +0000 | [diff] [blame] | 147 | #define VG_NUM_CLO(qq_arg, qq_option, qq_var) \ |
| 148 | if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \ |
| 149 | (qq_var) = (Int)VG_(atoll)( &qq_arg[ VG_(strlen)(qq_option)+1 ] ); \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 150 | } |
| 151 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 152 | /* Bounded integer arg */ |
njn | 45270a2 | 2005-03-27 01:00:11 +0000 | [diff] [blame] | 153 | #define VG_BNUM_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \ |
| 154 | if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \ |
| 155 | (qq_var) = (Int)VG_(atoll)( &qq_arg[ VG_(strlen)(qq_option)+1 ] ); \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 156 | if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \ |
| 157 | if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \ |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */ |
| 162 | extern Int VG_(clo_verbosity); |
| 163 | |
| 164 | /* Profile? */ |
| 165 | extern Bool VG_(clo_profile); |
| 166 | |
| 167 | /* Call this if a recognised option was bad for some reason. |
| 168 | Note: don't use it just because an option was unrecognised -- return 'False' |
njn | 94065fd | 2004-11-22 19:26:27 +0000 | [diff] [blame] | 169 | from TL_(process_cmd_line_option) to indicate that. */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 170 | extern void VG_(bad_option) ( Char* opt ); |
| 171 | |
| 172 | /* Client args */ |
| 173 | extern Int VG_(client_argc); |
| 174 | extern Char** VG_(client_argv); |
| 175 | |
| 176 | /* Client environment. Can be inspected with VG_(getenv)() */ |
| 177 | extern Char** VG_(client_envp); |
| 178 | |
| 179 | |
| 180 | /*====================================================================*/ |
| 181 | /*=== Printing messages for the user ===*/ |
| 182 | /*====================================================================*/ |
| 183 | |
| 184 | /* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind. |
| 185 | Should be used for all user output. */ |
| 186 | |
| 187 | typedef |
| 188 | enum { Vg_UserMsg, /* '?' == '=' */ |
| 189 | Vg_DebugMsg, /* '?' == '-' */ |
| 190 | Vg_DebugExtraMsg, /* '?' == '+' */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 191 | Vg_ClientMsg /* '?' == '*' */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 192 | } |
| 193 | VgMsgKind; |
| 194 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 195 | /* Send a single-part message. Appends a newline. */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 196 | extern int VG_(message) ( VgMsgKind kind, const Char* format, ... ); |
| 197 | extern int VG_(vmessage) ( VgMsgKind kind, const Char* format, va_list vargs ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 198 | |
| 199 | |
| 200 | /*====================================================================*/ |
| 201 | /*=== Profiling ===*/ |
| 202 | /*====================================================================*/ |
| 203 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 204 | /* Nb: VG_(register_profile_event)() relies on VgpUnc being the first one */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 205 | #define VGP_CORE_LIST \ |
| 206 | /* These ones depend on the core */ \ |
| 207 | VGP_PAIR(VgpUnc, "unclassified"), \ |
| 208 | VGP_PAIR(VgpStartup, "startup"), \ |
| 209 | VGP_PAIR(VgpRun, "running"), \ |
| 210 | VGP_PAIR(VgpSched, "scheduler"), \ |
| 211 | VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \ |
| 212 | VGP_PAIR(VgpCliMalloc, "client malloc/free"), \ |
| 213 | VGP_PAIR(VgpTranslate, "translate-main"), \ |
| 214 | VGP_PAIR(VgpToUCode, "to-ucode"), \ |
| 215 | VGP_PAIR(VgpFromUcode, "from-ucode"), \ |
| 216 | VGP_PAIR(VgpImprove, "improve"), \ |
| 217 | VGP_PAIR(VgpESPUpdate, "ESP-update"), \ |
| 218 | VGP_PAIR(VgpRegAlloc, "reg-alloc"), \ |
| 219 | VGP_PAIR(VgpLiveness, "liveness-analysis"), \ |
| 220 | VGP_PAIR(VgpDoLRU, "do-lru"), \ |
| 221 | VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \ |
| 222 | VGP_PAIR(VgpExeContext, "exe-context"), \ |
| 223 | VGP_PAIR(VgpReadSyms, "read-syms"), \ |
| 224 | VGP_PAIR(VgpSearchSyms, "search-syms"), \ |
| 225 | VGP_PAIR(VgpAddToT, "add-to-transtab"), \ |
| 226 | VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \ |
| 227 | VGP_PAIR(VgpDemangle, "demangle"), \ |
| 228 | VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \ |
| 229 | VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \ |
| 230 | /* These ones depend on the tool */ \ |
| 231 | VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \ |
| 232 | VGP_PAIR(VgpPostCloInit, "post-clo-init"), \ |
| 233 | VGP_PAIR(VgpInstrument, "instrument"), \ |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 234 | VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \ |
| 235 | VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \ |
| 236 | VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 237 | VGP_PAIR(VgpFini, "fini") |
| 238 | |
| 239 | #define VGP_PAIR(n,name) n |
| 240 | typedef enum { VGP_CORE_LIST } VgpCoreCC; |
| 241 | #undef VGP_PAIR |
| 242 | |
| 243 | /* When registering tool profiling events, ensure that the 'n' value is in |
| 244 | * the range (VgpFini+1..) */ |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 245 | extern void VG_(register_profile_event) ( Int n, Char* name ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 246 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 247 | extern void VG_(pushcc) ( UInt cc ); |
| 248 | extern void VG_(popcc) ( UInt cc ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 249 | |
| 250 | /* Define them only if they haven't already been defined by vg_profile.c */ |
| 251 | #ifndef VGP_PUSHCC |
| 252 | # define VGP_PUSHCC(x) |
| 253 | #endif |
| 254 | #ifndef VGP_POPCC |
| 255 | # define VGP_POPCC(x) |
| 256 | #endif |
| 257 | |
| 258 | |
| 259 | /*====================================================================*/ |
| 260 | /*=== Useful stuff to call from generated code ===*/ |
| 261 | /*====================================================================*/ |
| 262 | |
| 263 | /* ------------------------------------------------------------------ */ |
| 264 | /* General stuff */ |
| 265 | |
njn | edfa0f6 | 2004-11-30 18:08:05 +0000 | [diff] [blame] | 266 | /* Check if an address/whatever is aligned */ |
njn | be91aae | 2005-03-27 01:42:41 +0000 | [diff] [blame] | 267 | #define VG_IS_4_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x3)) |
| 268 | #define VG_IS_8_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0x7)) |
| 269 | #define VG_IS_16_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & 0xf)) |
| 270 | #define VG_IS_WORD_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & (sizeof(Addr)-1))) |
| 271 | #define VG_IS_PAGE_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & (VKI_PAGE_SIZE-1))) |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 272 | |
| 273 | |
| 274 | /* ------------------------------------------------------------------ */ |
| 275 | /* Thread-related stuff */ |
| 276 | |
| 277 | /* Special magic value for an invalid ThreadId. It corresponds to |
| 278 | LinuxThreads using zero as the initial value for |
| 279 | pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */ |
| 280 | #define VG_INVALID_THREADID ((ThreadId)(0)) |
| 281 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 282 | /* Get the TID of the thread which currently has the CPU. */ |
| 283 | extern ThreadId VG_(get_running_tid) ( void ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 284 | |
| 285 | /* Searches through all thread's stacks to see if any match. Returns |
| 286 | VG_INVALID_THREADID if none match. */ |
| 287 | extern ThreadId VG_(first_matching_thread_stack) |
| 288 | ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ), |
| 289 | void* d ); |
| 290 | |
njn | 6751613 | 2005-03-22 04:02:43 +0000 | [diff] [blame] | 291 | /* Get parts of the client's state. */ |
| 292 | extern Addr VG_(get_SP) ( ThreadId tid ); |
| 293 | extern Addr VG_(get_IP) ( ThreadId tid ); |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 294 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 295 | |
| 296 | /*====================================================================*/ |
| 297 | /*=== Valgrind's version of libc ===*/ |
| 298 | /*====================================================================*/ |
| 299 | |
| 300 | /* Valgrind doesn't use libc at all, for good reasons (trust us). So here |
| 301 | are its own versions of C library functions, but with VG_ prefixes. Note |
| 302 | that the types of some are slightly different to the real ones. Some |
| 303 | additional useful functions are provided too; descriptions of how they |
| 304 | work are given below. */ |
| 305 | |
| 306 | #if !defined(NULL) |
| 307 | # define NULL ((void*)0) |
| 308 | #endif |
| 309 | |
| 310 | |
| 311 | /* ------------------------------------------------------------------ */ |
| 312 | /* stdio.h |
| 313 | * |
| 314 | * Note that they all output to the file descriptor given by the |
| 315 | * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr). |
| 316 | * Hence no need for VG_(fprintf)(). |
| 317 | */ |
| 318 | extern UInt VG_(printf) ( const char *format, ... ); |
| 319 | /* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */ |
| 320 | extern UInt VG_(sprintf) ( Char* buf, Char *format, ... ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 321 | |
| 322 | extern Int VG_(rename) ( Char* old_name, Char* new_name ); |
| 323 | |
| 324 | /* ------------------------------------------------------------------ */ |
| 325 | /* stdlib.h */ |
| 326 | |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 327 | extern void* VG_(malloc) ( SizeT nbytes ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 328 | extern void VG_(free) ( void* p ); |
njn | 926ed47 | 2005-03-11 04:44:10 +0000 | [diff] [blame] | 329 | extern void* VG_(calloc) ( SizeT n, SizeT bytes_per_elem ); |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 330 | extern void* VG_(realloc) ( void* p, SizeT size ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 331 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 332 | /* terminate everything */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 333 | extern void VG_(exit)( Int status ) |
| 334 | __attribute__ ((__noreturn__)); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 335 | |
| 336 | /* terminate the calling thread - probably not what you want */ |
| 337 | extern void VG_(exit_single)( Int status ) |
| 338 | __attribute__ ((__noreturn__)); |
| 339 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 340 | /* Prints a panic message (a constant string), appends newline and bug |
| 341 | reporting info, aborts. */ |
| 342 | __attribute__ ((__noreturn__)) |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 343 | extern void VG_(tool_panic) ( Char* str ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 344 | |
| 345 | /* Looks up VG_(client_envp) */ |
| 346 | extern Char* VG_(getenv) ( Char* name ); |
| 347 | |
| 348 | /* Get client resource limit*/ |
| 349 | extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim ); |
| 350 | |
| 351 | /* Set client resource limit*/ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 352 | extern Int VG_(setrlimit) ( Int resource, const struct vki_rlimit *rlim ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 353 | |
| 354 | /* Crude stand-in for the glibc system() call. */ |
| 355 | extern Int VG_(system) ( Char* cmd ); |
| 356 | |
| 357 | extern Long VG_(atoll) ( Char* str ); |
| 358 | |
| 359 | /* Like atoll(), but converts a number of base 16 */ |
| 360 | extern Long VG_(atoll16) ( Char* str ); |
| 361 | |
| 362 | /* Like atoll(), but converts a number of base 2..36 */ |
| 363 | extern Long VG_(atoll36) ( UInt base, Char* str ); |
| 364 | |
| 365 | /* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */ |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 366 | extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size, |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 367 | Int (*compar)(void*, void*) ); |
| 368 | |
| 369 | |
| 370 | /* ------------------------------------------------------------------ */ |
| 371 | /* ctype.h */ |
| 372 | extern Bool VG_(isspace) ( Char c ); |
| 373 | extern Bool VG_(isdigit) ( Char c ); |
| 374 | extern Char VG_(toupper) ( Char c ); |
| 375 | |
| 376 | |
| 377 | /* ------------------------------------------------------------------ */ |
| 378 | /* string.h */ |
| 379 | extern Int VG_(strlen) ( const Char* str ); |
| 380 | extern Char* VG_(strcat) ( Char* dest, const Char* src ); |
| 381 | extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n ); |
| 382 | extern Char* VG_(strpbrk) ( const Char* s, const Char* accept ); |
| 383 | extern Char* VG_(strcpy) ( Char* dest, const Char* src ); |
| 384 | extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest ); |
| 385 | extern Int VG_(strcmp) ( const Char* s1, const Char* s2 ); |
| 386 | extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax ); |
| 387 | extern Char* VG_(strstr) ( const Char* haystack, Char* needle ); |
| 388 | extern Char* VG_(strchr) ( const Char* s, Char c ); |
| 389 | extern Char* VG_(strrchr) ( const Char* s, Char c ); |
| 390 | extern Char* VG_(strdup) ( const Char* s); |
| 391 | extern void* VG_(memcpy) ( void *d, const void *s, Int sz ); |
| 392 | extern void* VG_(memset) ( void *s, Int c, Int sz ); |
| 393 | extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n ); |
| 394 | |
| 395 | /* Like strcmp() and strncmp(), but stop comparing at any whitespace. */ |
| 396 | extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ); |
| 397 | extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax ); |
| 398 | |
| 399 | /* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the |
| 400 | last character. */ |
| 401 | extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest ); |
| 402 | |
| 403 | /* Mini-regexp function. Searches for 'pat' in 'str'. Supports |
| 404 | * meta-symbols '*' and '?'. '\' escapes meta-symbols. */ |
| 405 | extern Bool VG_(string_match) ( const Char* pat, const Char* str ); |
| 406 | |
| 407 | |
| 408 | /* ------------------------------------------------------------------ */ |
| 409 | /* math.h */ |
| 410 | /* Returns the base-2 logarithm of x. */ |
| 411 | extern Int VG_(log2) ( Int x ); |
| 412 | |
| 413 | |
| 414 | /* ------------------------------------------------------------------ */ |
| 415 | /* unistd.h, fcntl.h, sys/stat.h */ |
| 416 | extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count ); |
| 417 | extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize ); |
| 418 | extern Int VG_(getpid) ( void ); |
| 419 | extern Int VG_(getppid) ( void ); |
| 420 | extern Int VG_(getpgrp) ( void ); |
| 421 | extern Int VG_(gettid) ( void ); |
| 422 | extern Int VG_(setpgid) ( Int pid, Int pgrp ); |
| 423 | |
| 424 | extern Int VG_(open) ( const Char* pathname, Int flags, Int mode ); |
| 425 | extern Int VG_(read) ( Int fd, void* buf, Int count); |
| 426 | extern Int VG_(write) ( Int fd, const void* buf, Int count); |
nethercote | 5b9fafd | 2004-11-04 18:39:22 +0000 | [diff] [blame] | 427 | extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 428 | extern void VG_(close) ( Int fd ); |
| 429 | |
| 430 | extern Int VG_(pipe) ( Int fd[2] ); |
| 431 | |
| 432 | /* Nb: VG_(rename)() declared in stdio.h section above */ |
| 433 | extern Int VG_(unlink) ( Char* file_name ); |
| 434 | extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf ); |
| 435 | extern Int VG_(fstat) ( Int fd, struct vki_stat* buf ); |
| 436 | extern Int VG_(dup2) ( Int oldfd, Int newfd ); |
| 437 | |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 438 | extern Char* VG_(getcwd) ( Char* buf, SizeT size ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 439 | |
| 440 | /* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself. |
| 441 | String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d. |
| 442 | Returns False if it fails. Will fail if the pathname is > 65535 bytes. */ |
| 443 | extern Bool VG_(getcwd_alloc) ( Char** cwd ); |
| 444 | |
| 445 | /* ------------------------------------------------------------------ */ |
| 446 | /* assert.h */ |
| 447 | /* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */ |
njn | 8c74b00 | 2005-03-27 01:25:38 +0000 | [diff] [blame] | 448 | |
| 449 | /* This odd definition lets us stringify VG_(x) function names to |
| 450 | "vgPlain_x". We need to do two macroexpansions to get the VG_ macro |
| 451 | expanded before stringifying. */ |
| 452 | #define VG_STRINGIFY_WRK(x) #x |
| 453 | #define VG_STRINGIFY(x) VG_STRINGIFY_WRK(x) |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 454 | |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 455 | #define tl_assert(expr) \ |
| 456 | ((void) ((expr) ? 0 : \ |
| 457 | (VG_(assert_fail) (/*isCore?*/False, VG_STRINGIFY(expr), \ |
| 458 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 459 | ""), \ |
| 460 | 0))) |
| 461 | |
| 462 | #define tl_assert2(expr, format, args...) \ |
| 463 | ((void) ((expr) ? 0 : \ |
| 464 | (VG_(assert_fail) (/*isCore?*/False, VG_STRINGIFY(expr), \ |
| 465 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 466 | format, ##args), \ |
| 467 | 0))) |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 468 | |
| 469 | __attribute__ ((__noreturn__)) |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 470 | extern void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file, |
| 471 | Int line, const Char* fn, |
| 472 | const Char* format, ... ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 473 | |
| 474 | /* ------------------------------------------------------------------ */ |
| 475 | /* Get memory by anonymous mmap. */ |
nethercote | 8b5f40c | 2004-11-02 13:29:50 +0000 | [diff] [blame] | 476 | extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 477 | |
| 478 | extern Bool VG_(is_client_addr) (Addr a); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 479 | |
| 480 | extern Bool VG_(is_shadow_addr) (Addr a); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 481 | extern Addr VG_(get_shadow_size)(void); |
| 482 | |
| 483 | extern void *VG_(shadow_alloc)(UInt size); |
| 484 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 485 | extern Bool VG_(is_addressable)(Addr p, SizeT sz, UInt prot); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 486 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 487 | /* Register an interest in apparently internal faults; used code which |
| 488 | wanders around dangerous memory (ie, leakcheck). The catcher is |
| 489 | not expected to return. */ |
| 490 | extern void VG_(set_fault_catcher)(void (*catcher)(Int sig, Addr addr)); |
| 491 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 492 | /* initialize shadow pages in the range [p, p+sz) This calls |
| 493 | init_shadow_page for each one. It should be a lot more efficient |
| 494 | for bulk-initializing shadow pages than faulting on each one. |
| 495 | */ |
| 496 | extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init); |
| 497 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 498 | /* Calls into the core used by leak-checking */ |
| 499 | |
| 500 | /* Calls "add_rootrange" with each range of memory which looks like a |
| 501 | plausible source of root pointers. */ |
| 502 | extern void VG_(find_root_memory)(void (*add_rootrange)(Addr addr, SizeT sz)); |
| 503 | |
| 504 | /* Calls "mark_addr" with register values (which may or may not be pointers) */ |
| 505 | extern void VG_(mark_from_registers)(void (*mark_addr)(Addr addr)); |
| 506 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 507 | /* ------------------------------------------------------------------ */ |
| 508 | /* signal.h. |
| 509 | |
| 510 | Note that these use the vk_ (kernel) structure |
| 511 | definitions, which are different in places from those that glibc |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 512 | defines. Since we're operating right at the kernel interface, glibc's view |
| 513 | of the world is entirely irrelevant. */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 514 | |
| 515 | /* --- Signal set ops --- */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 516 | extern Int VG_(sigfillset) ( vki_sigset_t* set ); |
| 517 | extern Int VG_(sigemptyset) ( vki_sigset_t* set ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 518 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 519 | extern Bool VG_(isfullsigset) ( const vki_sigset_t* set ); |
| 520 | extern Bool VG_(isemptysigset) ( const vki_sigset_t* set ); |
njn | 4c4d57b | 2005-03-26 20:03:07 +0000 | [diff] [blame] | 521 | extern Bool VG_(iseqsigset) ( const vki_sigset_t* set1, |
| 522 | const vki_sigset_t* set2 ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 523 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 524 | extern Int VG_(sigaddset) ( vki_sigset_t* set, Int signum ); |
| 525 | extern Int VG_(sigdelset) ( vki_sigset_t* set, Int signum ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 526 | extern Int VG_(sigismember) ( const vki_sigset_t* set, Int signum ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 527 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 528 | extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src ); |
| 529 | extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 530 | |
| 531 | /* --- Mess with the kernel's sig state --- */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 532 | extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set, |
| 533 | vki_sigset_t* oldset ); |
| 534 | extern Int VG_(sigaction) ( Int signum, |
| 535 | const struct vki_sigaction* act, |
| 536 | struct vki_sigaction* oldact ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 537 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 538 | extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *, |
| 539 | const struct vki_timespec * ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 540 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 541 | extern Int VG_(signal) ( Int signum, void (*sighandler)(Int) ); |
| 542 | extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 543 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 544 | extern Int VG_(kill) ( Int pid, Int signo ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 545 | extern Int VG_(tkill) ( ThreadId tid, Int signo ); |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 546 | extern Int VG_(sigpending) ( vki_sigset_t* set ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 547 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 548 | extern Int VG_(waitpid) ( Int pid, Int *status, Int options ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 549 | |
| 550 | /* ------------------------------------------------------------------ */ |
| 551 | /* socket.h. */ |
| 552 | |
| 553 | extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen); |
| 554 | extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen); |
| 555 | extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval, |
| 556 | Int *optlen); |
| 557 | |
| 558 | /* ------------------------------------------------------------------ */ |
| 559 | /* other, randomly useful functions */ |
| 560 | extern UInt VG_(read_millisecond_timer) ( void ); |
| 561 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 562 | extern Bool VG_(has_cpuid) ( void ); |
| 563 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 564 | extern void VG_(cpuid) ( UInt eax, |
| 565 | UInt *eax_ret, UInt *ebx_ret, |
| 566 | UInt *ecx_ret, UInt *edx_ret ); |
| 567 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 568 | /*====================================================================*/ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 569 | /*=== Obtaining debug information ===*/ |
| 570 | /*====================================================================*/ |
| 571 | |
| 572 | /* Get the file/function/line number of the instruction at address |
| 573 | 'a'. For these four, if debug info for the address is found, it |
| 574 | copies the info into the buffer/UInt and returns True. If not, it |
| 575 | returns False and nothing is copied. VG_(get_fnname) always |
| 576 | demangles C++ function names. VG_(get_fnname_w_offset) is the |
| 577 | same, except it appends "+N" to symbol names to indicate offsets. */ |
| 578 | extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename ); |
| 579 | extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname ); |
| 580 | extern Bool VG_(get_linenum) ( Addr a, UInt* linenum ); |
| 581 | extern Bool VG_(get_fnname_w_offset) |
| 582 | ( Addr a, Char* fnname, Int n_fnname ); |
| 583 | |
| 584 | /* This one is more efficient if getting both filename and line number, |
| 585 | because the two lookups are done together. */ |
| 586 | extern Bool VG_(get_filename_linenum) |
| 587 | ( Addr a, Char* filename, Int n_filename, |
| 588 | UInt* linenum ); |
| 589 | |
| 590 | /* Succeeds only if we find from debug info that 'a' is the address of the |
| 591 | first instruction in a function -- as opposed to VG_(get_fnname) which |
| 592 | succeeds if we find from debug info that 'a' is the address of any |
| 593 | instruction in a function. Use this to instrument the start of |
| 594 | a particular function. Nb: if an executable/shared object is stripped |
| 595 | of its symbols, this function will not be able to recognise function |
| 596 | entry points within it. */ |
| 597 | extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname ); |
| 598 | |
| 599 | /* Succeeds if the address is within a shared object or the main executable. |
| 600 | It doesn't matter if debug info is present or not. */ |
| 601 | extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname ); |
| 602 | |
| 603 | /* Puts into 'buf' info about the code address %eip: the address, function |
| 604 | name (if known) and filename/line number (if known), like this: |
| 605 | |
| 606 | 0x4001BF05: realloc (vg_replace_malloc.c:339) |
| 607 | |
| 608 | 'n_buf' gives length of 'buf'. Returns 'buf'. |
| 609 | */ |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 610 | extern Char* VG_(describe_IP)(Addr eip, Char* buf, Int n_buf); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 611 | |
| 612 | /* Returns a string containing an expression for the given |
| 613 | address. String is malloced with VG_(malloc)() */ |
| 614 | Char *VG_(describe_addr)(ThreadId, Addr); |
| 615 | |
| 616 | /* A way to get information about what segments are mapped */ |
| 617 | typedef struct _SegInfo SegInfo; |
| 618 | |
| 619 | /* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info |
| 620 | is present or not. */ |
| 621 | extern SegInfo* VG_(get_obj) ( Addr a ); |
| 622 | |
| 623 | extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg ); |
| 624 | extern Addr VG_(seg_start) ( const SegInfo *seg ); |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 625 | extern SizeT VG_(seg_size) ( const SegInfo *seg ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 626 | extern const UChar* VG_(seg_filename) ( const SegInfo *seg ); |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 627 | extern ULong VG_(seg_sym_offset)( const SegInfo *seg ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 628 | |
| 629 | typedef |
| 630 | enum { |
| 631 | Vg_SectUnknown, |
| 632 | Vg_SectText, |
| 633 | Vg_SectData, |
| 634 | Vg_SectBSS, |
| 635 | Vg_SectGOT, |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 636 | Vg_SectPLT |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 637 | } |
| 638 | VgSectKind; |
| 639 | |
| 640 | extern VgSectKind VG_(seg_sect_kind)(Addr); |
| 641 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 642 | /*====================================================================*/ |
| 643 | /*=== Generic hash table ===*/ |
| 644 | /*====================================================================*/ |
| 645 | |
| 646 | /* Generic type for a separately-chained hash table. Via a kind of dodgy |
| 647 | C-as-C++ style inheritance, tools can extend the VgHashNode type, so long |
| 648 | as the first two fields match the sizes of these two fields. Requires |
| 649 | a bit of casting by the tool. */ |
| 650 | typedef |
| 651 | struct _VgHashNode { |
| 652 | struct _VgHashNode * next; |
nethercote | 3d6b611 | 2004-11-04 16:39:43 +0000 | [diff] [blame] | 653 | UWord key; |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 654 | } |
| 655 | VgHashNode; |
| 656 | |
| 657 | typedef |
| 658 | VgHashNode** |
| 659 | VgHashTable; |
| 660 | |
njn | 0674acb | 2005-03-13 06:04:49 +0000 | [diff] [blame] | 661 | /* Make a new table. Allocates the memory with VG_(calloc)(), so can be freed |
| 662 | * with VG_(free)(). */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 663 | extern VgHashTable VG_(HT_construct) ( void ); |
| 664 | |
| 665 | /* Count the number of nodes in a table. */ |
| 666 | extern Int VG_(HT_count_nodes) ( VgHashTable table ); |
| 667 | |
| 668 | /* Add a node to the table. */ |
| 669 | extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node ); |
| 670 | |
| 671 | /* Looks up a node in the hash table. Also returns the address of the |
| 672 | previous node's `next' pointer which allows it to be removed from the |
| 673 | list later without having to look it up again. */ |
nethercote | 3d6b611 | 2004-11-04 16:39:43 +0000 | [diff] [blame] | 674 | extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key, |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 675 | /*OUT*/VgHashNode*** next_ptr ); |
| 676 | |
| 677 | /* Allocates an array of pointers to all the shadow chunks of malloc'd |
| 678 | blocks. Must be freed with VG_(free)(). */ |
| 679 | extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows ); |
| 680 | |
| 681 | /* Returns first node that matches predicate `p', or NULL if none do. |
| 682 | Extra arguments can be implicitly passed to `p' using `d' which is an |
| 683 | opaque pointer passed to `p' each time it is called. */ |
| 684 | extern VgHashNode* VG_(HT_first_match) ( VgHashTable t, |
| 685 | Bool (*p)(VgHashNode*, void*), |
| 686 | void* d ); |
| 687 | |
| 688 | /* Applies a function f() once to each node. Again, `d' can be used |
| 689 | to pass extra information to the function. */ |
| 690 | extern void VG_(HT_apply_to_all_nodes)( VgHashTable t, |
| 691 | void (*f)(VgHashNode*, void*), |
| 692 | void* d ); |
| 693 | |
| 694 | /* Destroy a table. */ |
| 695 | extern void VG_(HT_destruct) ( VgHashTable t ); |
| 696 | |
| 697 | |
| 698 | /*====================================================================*/ |
| 699 | /*=== A generic skiplist ===*/ |
| 700 | /*====================================================================*/ |
| 701 | |
| 702 | /* |
| 703 | The idea here is that the skiplist puts its per-element data at the |
| 704 | end of the structure. When you initialize the skiplist, you tell |
| 705 | it what structure your list elements are going to be. Then you |
| 706 | should allocate them with VG_(SkipNode_Alloc), which will allocate |
| 707 | enough memory for the extra bits. |
| 708 | */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 709 | |
| 710 | typedef struct _SkipList SkipList; |
| 711 | typedef struct _SkipNode SkipNode; |
| 712 | |
| 713 | typedef Int (*SkipCmp_t)(const void *key1, const void *key2); |
| 714 | |
| 715 | struct _SkipList { |
| 716 | const Short arena; /* allocation arena */ |
| 717 | const UShort size; /* structure size (not including SkipNode) */ |
| 718 | const UShort keyoff; /* key offset */ |
| 719 | const SkipCmp_t cmp; /* compare two keys */ |
| 720 | Char * (*strkey)(void *); /* stringify a key (for debugging) */ |
| 721 | SkipNode *head; /* list head */ |
| 722 | }; |
| 723 | |
| 724 | /* Use this macro to initialize your skiplist head. The arguments are pretty self explanitory: |
| 725 | _type is the type of your element structure |
| 726 | _key is the field within that type which you want to use as the key |
| 727 | _cmp is the comparison function for keys - it gets two typeof(_key) pointers as args |
| 728 | _strkey is a function which can return a string of your key - it's only used for debugging |
| 729 | _arena is the arena to use for allocation - -1 is the default |
| 730 | */ |
njn | be91aae | 2005-03-27 01:42:41 +0000 | [diff] [blame] | 731 | #define VG_SKIPLIST_INIT(_type, _key, _cmp, _strkey, _arena) \ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 732 | { \ |
| 733 | .arena = _arena, \ |
| 734 | .size = sizeof(_type), \ |
| 735 | .keyoff = offsetof(_type, _key), \ |
| 736 | .cmp = _cmp, \ |
| 737 | .strkey = _strkey, \ |
| 738 | .head = NULL, \ |
| 739 | } |
| 740 | |
| 741 | /* List operations: |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 742 | SkipList_Find_* search a list. The 3 variants are: |
| 743 | Before: returns a node which is <= key, or NULL if none |
| 744 | Exact: returns a node which is == key, or NULL if none |
| 745 | After: returns a node which is >= key, or NULL if none |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 746 | SkipList_Insert inserts a new element into the list. Duplicates are |
| 747 | forbidden. The element must have been created with SkipList_Alloc! |
| 748 | SkipList_Remove removes an element from the list and returns it. It |
| 749 | doesn't free the memory. |
| 750 | */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 751 | extern void *VG_(SkipList_Find_Before) (const SkipList *l, void *key); |
| 752 | extern void *VG_(SkipList_Find_Exact) (const SkipList *l, void *key); |
| 753 | extern void *VG_(SkipList_Find_After) (const SkipList *l, void *key); |
| 754 | extern void VG_(SkipList_Insert) ( SkipList *l, void *data); |
| 755 | extern void *VG_(SkipList_Remove) ( SkipList *l, void *key); |
| 756 | |
| 757 | /* Some useful standard comparisons */ |
| 758 | extern Int VG_(cmp_Addr) (const void *a, const void *b); |
| 759 | extern Int VG_(cmp_Int) (const void *a, const void *b); |
| 760 | extern Int VG_(cmp_UInt) (const void *a, const void *b); |
| 761 | extern Int VG_(cmp_string)(const void *a, const void *b); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 762 | |
| 763 | /* Node (element) operations: |
| 764 | SkipNode_Alloc: allocate memory for a new element on the list. Must be |
| 765 | used before an element can be inserted! Returns NULL if not enough |
| 766 | memory. |
| 767 | SkipNode_Free: free memory allocated above |
| 768 | SkipNode_First: return the first element on the list |
| 769 | SkipNode_Next: return the next element after "data" on the list - |
| 770 | NULL for none |
| 771 | |
| 772 | You can iterate through a SkipList like this: |
| 773 | |
| 774 | for(x = VG_(SkipNode_First)(&list); // or SkipList_Find |
| 775 | x != NULL; |
| 776 | x = VG_(SkipNode_Next)(&list, x)) { ... } |
| 777 | */ |
| 778 | extern void *VG_(SkipNode_Alloc) (const SkipList *l); |
| 779 | extern void VG_(SkipNode_Free) (const SkipList *l, void *p); |
| 780 | extern void *VG_(SkipNode_First) (const SkipList *l); |
| 781 | extern void *VG_(SkipNode_Next) (const SkipList *l, void *data); |
| 782 | |
njn | abb14ad | 2004-11-24 16:57:16 +0000 | [diff] [blame] | 783 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 784 | /*====================================================================*/ |
| 785 | /*=== Functions for shadow registers ===*/ |
| 786 | /*====================================================================*/ |
| 787 | |
njn | abb14ad | 2004-11-24 16:57:16 +0000 | [diff] [blame] | 788 | // For get/set, 'area' is where the asked-for shadow state will be copied |
| 789 | // into/from. |
| 790 | extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset, |
| 791 | SizeT size, UChar* area ); |
| 792 | extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset, |
| 793 | SizeT size, const UChar* area ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 794 | |
| 795 | /* This one lets you override the shadow of the return value register for a |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 796 | syscall. Call it from TL_(post_syscall)() (not TL_(pre_syscall)()!) to |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 797 | override the default shadow register value. */ |
| 798 | extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid, |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 799 | UWord ret_shadow ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 800 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 801 | /* This can be called from TL_(fini)() to find the shadow of the argument |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 802 | to exit(), ie. the shadow of the program's return value. */ |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 803 | extern UInt VG_(get_exit_status_shadow) ( ThreadId ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 804 | |
| 805 | |
| 806 | /*====================================================================*/ |
| 807 | /*=== Specific stuff for replacing malloc() and friends ===*/ |
| 808 | /*====================================================================*/ |
| 809 | |
| 810 | /* If a tool replaces malloc() et al, the easiest way to do so is to |
| 811 | link with vg_replace_malloc.o into its vgpreload_*.so file, and |
| 812 | follow the following instructions. You can do it from scratch, |
| 813 | though, if you enjoy that sort of thing. */ |
| 814 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 815 | /* Can be called from TL_(malloc) et al to do the actual alloc/freeing. */ |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 816 | extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 817 | extern void VG_(cli_free) ( void* p ); |
| 818 | |
| 819 | /* Check if an address is within a range, allowing for redzones at edges */ |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 820 | extern Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 821 | |
| 822 | /* ------------------------------------------------------------------ */ |
| 823 | /* Some options that can be used by a tool if malloc() et al are replaced. |
| 824 | The tool should call the functions in the appropriate places to give |
| 825 | control over these aspects of Valgrind's version of malloc(). */ |
| 826 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 827 | /* DEBUG: print malloc details? default: NO */ |
| 828 | extern Bool VG_(clo_trace_malloc); |
| 829 | /* Minimum alignment in functions that don't specify alignment explicitly. |
njn | 38629a7 | 2005-03-13 06:03:45 +0000 | [diff] [blame] | 830 | default: VG_MIN_MALLOC_SZB */ |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 831 | extern UInt VG_(clo_alignment); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 832 | |
| 833 | extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg ); |
| 834 | extern void VG_(replacement_malloc_print_usage) ( void ); |
| 835 | extern void VG_(replacement_malloc_print_debug_usage) ( void ); |
| 836 | |
| 837 | |
| 838 | /*====================================================================*/ |
| 839 | /*=== Tool-specific stuff ===*/ |
| 840 | /*====================================================================*/ |
| 841 | |
| 842 | /* ------------------------------------------------------------------ */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 843 | /* Basic tool functions */ |
| 844 | |
| 845 | extern void VG_(basic_tool_funcs)( |
| 846 | void(*post_clo_init)(void), |
| 847 | IRBB*(*instrument)(IRBB* bb_in, VexGuestLayout* layout, |
| 848 | IRType gWordTy, IRType hWordTy ), |
| 849 | void(*fini)(Int) |
| 850 | ); |
| 851 | |
| 852 | /* ------------------------------------------------------------------ */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 853 | /* Details */ |
| 854 | |
| 855 | /* Default value for avg_translations_sizeB (in bytes), indicating typical |
| 856 | code expansion of about 6:1. */ |
| 857 | #define VG_DEFAULT_TRANS_SIZEB 100 |
| 858 | |
| 859 | /* Information used in the startup message. `name' also determines the |
| 860 | string used for identifying suppressions in a suppression file as |
| 861 | belonging to this tool. `version' can be NULL, in which case (not |
| 862 | surprisingly) no version info is printed; this mechanism is designed for |
| 863 | tools distributed with Valgrind that share a version number with |
| 864 | Valgrind. Other tools not distributed as part of Valgrind should |
| 865 | probably have their own version number. */ |
| 866 | extern void VG_(details_name) ( Char* name ); |
| 867 | extern void VG_(details_version) ( Char* version ); |
| 868 | extern void VG_(details_description) ( Char* description ); |
| 869 | extern void VG_(details_copyright_author) ( Char* copyright_author ); |
| 870 | |
| 871 | /* Average size of a translation, in bytes, so that the translation |
| 872 | storage machinery can allocate memory appropriately. Not critical, |
| 873 | setting is optional. */ |
| 874 | extern void VG_(details_avg_translation_sizeB) ( UInt size ); |
| 875 | |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 876 | /* String printed if an `tl_assert' assertion fails or VG_(tool_panic) |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 877 | is called. Should probably be an email address. */ |
| 878 | extern void VG_(details_bug_reports_to) ( Char* bug_reports_to ); |
| 879 | |
| 880 | /* ------------------------------------------------------------------ */ |
| 881 | /* Needs */ |
| 882 | |
| 883 | /* Booleans that decide core behaviour, but don't require extra |
| 884 | operations to be defined if `True' */ |
| 885 | |
| 886 | /* Should __libc_freeres() be run? Bugs in it can crash the tool. */ |
| 887 | extern void VG_(needs_libc_freeres) ( void ); |
| 888 | |
| 889 | /* Want to have errors detected by Valgrind's core reported? Includes: |
| 890 | - pthread API errors (many; eg. unlocking a non-locked mutex) |
| 891 | - invalid file descriptors to blocking syscalls read() and write() |
| 892 | - bad signal numbers passed to sigaction() |
| 893 | - attempt to install signal handler for SIGKILL or SIGSTOP */ |
| 894 | extern void VG_(needs_core_errors) ( void ); |
| 895 | |
| 896 | /* Booleans that indicate extra operations are defined; if these are True, |
| 897 | the corresponding template functions (given below) must be defined. A |
| 898 | lot like being a member of a type class. */ |
| 899 | |
| 900 | /* Want to report errors from tool? This implies use of suppressions, too. */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 901 | extern void VG_(needs_tool_errors) ( |
| 902 | // Identify if two errors are equal, or equal enough. `res' indicates how |
| 903 | // close is "close enough". `res' should be passed on as necessary, eg. if |
| 904 | // the Error's `extra' part contains an ExeContext, `res' should be |
| 905 | // passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other |
| 906 | // than that, probably don't worry about it unless you have lots of very |
| 907 | // similar errors occurring. |
| 908 | Bool (*eq_Error)(VgRes res, Error* e1, Error* e2), |
| 909 | |
| 910 | // Print error context. |
| 911 | void (*pp_Error)(Error* err), |
| 912 | |
| 913 | // Should fill in any details that could be postponed until after the |
| 914 | // decision whether to ignore the error (ie. details not affecting the |
| 915 | // result of TL_(eq_Error)()). This saves time when errors are ignored. |
| 916 | // Yuk. |
| 917 | // Return value: must be the size of the `extra' part in bytes -- used by |
| 918 | // the core to make a copy. |
| 919 | UInt (*update_extra)(Error* err), |
| 920 | |
| 921 | // Return value indicates recognition. If recognised, must set skind using |
| 922 | // VG_(set_supp_kind)(). |
| 923 | Bool (*recognised_suppression)(Char* name, Supp* su), |
| 924 | |
| 925 | // Read any extra info for this suppression kind. Most likely for filling |
| 926 | // in the `extra' and `string' parts (with VG_(set_supp_{extra, string})()) |
| 927 | // of a suppression if necessary. Should return False if a syntax error |
| 928 | // occurred, True otherwise. |
| 929 | Bool (*read_extra_suppression_info)(Int fd, Char* buf, Int nBuf, Supp* su), |
| 930 | |
| 931 | // This should just check the kinds match and maybe some stuff in the |
| 932 | // `string' and `extra' field if appropriate (using VG_(get_supp_*)() to |
| 933 | // get the relevant suppression parts). |
| 934 | Bool (*error_matches_suppression)(Error* err, Supp* su), |
| 935 | |
| 936 | // This should return the suppression name, for --gen-suppressions, or NULL |
| 937 | // if that error type cannot be suppressed. This is the inverse of |
| 938 | // TL_(recognised_suppression)(). |
| 939 | Char* (*get_error_name)(Error* err), |
| 940 | |
| 941 | // This should print any extra info for the error, for --gen-suppressions, |
| 942 | // including the newline. This is the inverse of |
| 943 | // TL_(read_extra_suppression_info)(). |
| 944 | void (*print_extra_suppression_info)(Error* err) |
| 945 | ); |
| 946 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 947 | |
| 948 | /* Is information kept about specific individual basic blocks? (Eg. for |
| 949 | cachegrind there are cost-centres for every instruction, stored at a |
| 950 | basic block level.) If so, it sometimes has to be discarded, because |
| 951 | .so mmap/munmap-ping or self-modifying code (informed by the |
| 952 | DISCARD_TRANSLATIONS user request) can cause one instruction address |
| 953 | to be used for more than one instruction in one program run... */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 954 | extern void VG_(needs_basic_block_discards) ( |
| 955 | // Should discard any information that pertains to specific basic blocks |
| 956 | // or instructions within the address range given. |
| 957 | void (*discard_basic_block_info)(Addr a, SizeT size) |
| 958 | ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 959 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 960 | /* Tool defines its own command line options? */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 961 | extern void VG_(needs_command_line_options) ( |
| 962 | // Return True if option was recognised. Presumably sets some state to |
| 963 | // record the option as well. |
| 964 | Bool (*process_cmd_line_option)(Char* argv), |
| 965 | |
| 966 | // Print out command line usage for options for normal tool operation. |
| 967 | void (*print_usage)(void), |
| 968 | |
| 969 | // Print out command line usage for options for debugging the tool. |
| 970 | void (*print_debug_usage)(void) |
| 971 | ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 972 | |
| 973 | /* Tool defines its own client requests? */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 974 | extern void VG_(needs_client_requests) ( |
| 975 | // If using client requests, the number of the first request should be equal |
| 976 | // to VG_USERREQ_TOOL_BASE('X', 'Y'), where 'X' and 'Y' form a suitable two |
| 977 | // character identification for the string. The second and subsequent |
| 978 | // requests should follow. |
| 979 | // |
| 980 | // This function should use the VG_IS_TOOL_USERREQ macro (in |
| 981 | // include/valgrind.h) to first check if it's a request for this tool. Then |
| 982 | // should handle it if it's recognised (and return True), or return False if |
| 983 | // not recognised. arg_block[0] holds the request number, any further args |
| 984 | // from the request are in arg_block[1..]. 'ret' is for the return value... |
| 985 | // it should probably be filled, if only with 0. |
| 986 | Bool (*handle_client_request)(ThreadId tid, UWord* arg_block, UWord* ret) |
| 987 | ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 988 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 989 | /* Tool does stuff before and/or after system calls? */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 990 | // Nb: If either of the pre_ functions malloc() something to return, the |
| 991 | // corresponding post_ function had better free() it! |
| 992 | extern void VG_(needs_syscall_wrapper) ( |
| 993 | void (* pre_syscall)(ThreadId tid, UInt syscallno), |
| 994 | void (*post_syscall)(ThreadId tid, UInt syscallno, Int res) |
| 995 | ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 996 | |
| 997 | /* Are tool-state sanity checks performed? */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 998 | // Can be useful for ensuring a tool's correctness. TL_(cheap_sanity_check) |
| 999 | // is called very frequently; TL_(expensive_sanity_check) is called less |
| 1000 | // frequently and can be more involved. |
| 1001 | extern void VG_(needs_sanity_checks) ( |
| 1002 | Bool(*cheap_sanity_check)(void), |
| 1003 | Bool(*expensive_sanity_check)(void) |
| 1004 | ); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1005 | |
| 1006 | /* Do we need to see data symbols? */ |
| 1007 | extern void VG_(needs_data_syms) ( void ); |
| 1008 | |
| 1009 | /* Does the tool need shadow memory allocated (if you set this, you must also statically initialize |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1010 | float TL_(shadow_ratio) = n./m; |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1011 | to define how many shadow bits you need per client address space bit. |
| 1012 | */ |
| 1013 | extern void VG_(needs_shadow_memory)( void ); |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 1014 | extern float TL_(shadow_ratio); |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1015 | |
| 1016 | /* ------------------------------------------------------------------ */ |
njn | 8a97c6d | 2005-03-31 04:37:24 +0000 | [diff] [blame] | 1017 | /* Malloc replacement */ |
| 1018 | |
| 1019 | // The 'p' prefix avoids GCC complaints about overshadowing global names. |
| 1020 | extern void VG_(malloc_funcs)( |
| 1021 | void* (*pmalloc) ( ThreadId tid, SizeT n ), |
| 1022 | void* (*p__builtin_new) ( ThreadId tid, SizeT n ), |
| 1023 | void* (*p__builtin_vec_new) ( ThreadId tid, SizeT n ), |
| 1024 | void* (*pmemalign) ( ThreadId tid, SizeT align, SizeT n ), |
| 1025 | void* (*pcalloc) ( ThreadId tid, SizeT nmemb, SizeT size1 ), |
| 1026 | void (*pfree) ( ThreadId tid, void* p ), |
| 1027 | void (*p__builtin_delete) ( ThreadId tid, void* p ), |
| 1028 | void (*p__builtin_vec_delete) ( ThreadId tid, void* p ), |
| 1029 | void* (*prealloc) ( ThreadId tid, void* p, SizeT new_size ), |
| 1030 | SizeT client_malloc_redzone_szB |
| 1031 | ); |
| 1032 | |
| 1033 | /* ------------------------------------------------------------------ */ |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1034 | /* Core events to track */ |
| 1035 | |
| 1036 | /* Part of the core from which this call was made. Useful for determining |
| 1037 | what kind of error message should be emitted. */ |
| 1038 | typedef |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 1039 | enum { Vg_CoreStartup, Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, |
| 1040 | Vg_CoreTranslate, Vg_CoreClientReq } |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1041 | CorePart; |
| 1042 | |
nethercote | 37aac2e | 2004-09-02 08:54:27 +0000 | [diff] [blame] | 1043 | #endif /* NDEF __TOOL_H */ |
| 1044 | |
| 1045 | /* gen_toolint.pl will put the VG_(init_*)() functions here: */ |