njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- The only header your skin will ever need to #include... ---*/ |
| 4 | /*--- vg_skin.h ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 8 | This file is part of Valgrind, an extensible x86 protected-mode |
| 9 | emulator for monitoring program execution on x86-Unixes. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 12 | jseward@acm.org |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file COPYING. |
| 30 | */ |
| 31 | |
| 32 | #ifndef __VG_SKIN_H |
| 33 | #define __VG_SKIN_H |
| 34 | |
| 35 | #include <stdarg.h> /* ANSI varargs stuff */ |
| 36 | #include <setjmp.h> /* for jmp_buf */ |
| 37 | |
| 38 | #include "vg_constants_skin.h" |
| 39 | |
| 40 | |
| 41 | /*====================================================================*/ |
| 42 | /*=== Build options and table sizes. ===*/ |
| 43 | /*====================================================================*/ |
| 44 | |
| 45 | /* You should be able to change these options or sizes, recompile, and |
| 46 | still have a working system. */ |
| 47 | |
| 48 | /* The maximum number of pthreads that we support. This is |
| 49 | deliberately not very high since our implementation of some of the |
| 50 | scheduler algorithms is surely O(N) in the number of threads, since |
| 51 | that's simple, at least. And (in practice) we hope that most |
| 52 | programs do not need many threads. */ |
| 53 | #define VG_N_THREADS 50 |
| 54 | |
| 55 | /* Maximum number of pthread keys available. Again, we start low until |
| 56 | the need for a higher number presents itself. */ |
| 57 | #define VG_N_THREAD_KEYS 50 |
| 58 | |
| 59 | /* Total number of integer registers available for allocation -- all of |
| 60 | them except %esp, %ebp. %ebp permanently points at VG_(baseBlock). |
| 61 | |
| 62 | If you change this you'll have to also change at least these: |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 63 | - VG_(rank_to_realreg)() |
| 64 | - VG_(realreg_to_rank)() |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 65 | - ppRegsLiveness() |
| 66 | - the RegsLive type (maybe -- RegsLive type must have more than |
| 67 | VG_MAX_REALREGS bits) |
| 68 | |
| 69 | Do not change this unless you really know what you are doing! */ |
| 70 | #define VG_MAX_REALREGS 6 |
| 71 | |
| 72 | |
| 73 | /*====================================================================*/ |
njn | 1a1dd8b | 2002-09-27 10:42:20 +0000 | [diff] [blame] | 74 | /*=== Basic types, useful macros ===*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 75 | /*====================================================================*/ |
| 76 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 77 | typedef unsigned char UChar; |
| 78 | typedef unsigned short UShort; |
| 79 | typedef unsigned int UInt; |
| 80 | typedef unsigned long long int ULong; |
| 81 | |
| 82 | typedef signed char Char; |
| 83 | typedef signed short Short; |
| 84 | typedef signed int Int; |
| 85 | typedef signed long long int Long; |
| 86 | |
| 87 | typedef unsigned int Addr; |
| 88 | |
| 89 | typedef unsigned char Bool; |
| 90 | #define False ((Bool)0) |
| 91 | #define True ((Bool)1) |
| 92 | |
| 93 | |
njn | 1a1dd8b | 2002-09-27 10:42:20 +0000 | [diff] [blame] | 94 | #define mycat_wrk(aaa,bbb) aaa##bbb |
| 95 | #define mycat(aaa,bbb) mycat_wrk(aaa,bbb) |
| 96 | |
| 97 | /* No, really. I _am_ that strange. */ |
| 98 | #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn) |
| 99 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 100 | /* --------------------------------------------------------------------- |
| 101 | Now the basic types are set up, we can haul in the kernel-interface |
| 102 | definitions. |
| 103 | ------------------------------------------------------------------ */ |
| 104 | |
njn25 | 74bb476 | 2002-09-24 11:23:50 +0000 | [diff] [blame] | 105 | #include "../coregrind/vg_kerneliface.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 106 | |
| 107 | |
| 108 | /*====================================================================*/ |
njn | 27f1a38 | 2002-11-08 15:48:16 +0000 | [diff] [blame] | 109 | /*=== Core/skin interface version ===*/ |
| 110 | /*====================================================================*/ |
| 111 | |
| 112 | /* The major version number indicates binary-incompatible changes to the |
| 113 | interface; if the core and skin major versions don't match, Valgrind |
| 114 | will abort. The minor version indicates binary-compatible changes. |
| 115 | |
| 116 | We don't want the variables themselves in the core, only in the skins, |
| 117 | hence the #ifndef. But the core needs to know of their existence, hence |
| 118 | the #else branch. Phew. |
| 119 | |
| 120 | In summary: skins don't need to do anything, the core works it all out. |
| 121 | */ |
| 122 | |
| 123 | #define VG_CORE_INTERFACE_MAJOR_VERSION 1 |
| 124 | #define VG_CORE_INTERFACE_MINOR_VERSION 1 |
| 125 | |
| 126 | extern const Int VG_(skin_interface_major_version); |
| 127 | extern const Int VG_(skin_interface_minor_version); |
| 128 | |
| 129 | /* Every skin must define this macro somewhere, exactly once. */ |
| 130 | #define VG_DETERMINE_INTERFACE_VERSION \ |
| 131 | const Int VG_(skin_interface_major_version) = VG_CORE_INTERFACE_MAJOR_VERSION; \ |
| 132 | const Int VG_(skin_interface_minor_version) = VG_CORE_INTERFACE_MINOR_VERSION; |
| 133 | |
| 134 | /*====================================================================*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 135 | /*=== Command-line options ===*/ |
| 136 | /*====================================================================*/ |
| 137 | |
| 138 | /* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */ |
| 139 | extern Int VG_(clo_verbosity); |
| 140 | |
| 141 | /* Profile? */ |
| 142 | extern Bool VG_(clo_profile); |
| 143 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 144 | /* Call this if a recognised option was bad for some reason. |
| 145 | Note: don't use it just because an option was unrecognised -- return 'False' |
| 146 | from SKN_(process_cmd_line_option) to indicate that. */ |
| 147 | extern void VG_(bad_option) ( Char* opt ); |
| 148 | |
| 149 | /* Client args */ |
| 150 | extern Int VG_(client_argc); |
| 151 | extern Char** VG_(client_argv); |
| 152 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 153 | /* Client environment. Can be inspected with VG_(getenv)() */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 154 | extern Char** VG_(client_envp); |
| 155 | |
| 156 | |
| 157 | /*====================================================================*/ |
| 158 | /*=== Printing messages for the user ===*/ |
| 159 | /*====================================================================*/ |
| 160 | |
| 161 | /* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind. |
| 162 | Should be used for all user output. */ |
| 163 | |
| 164 | typedef |
| 165 | enum { Vg_UserMsg, /* '?' == '=' */ |
| 166 | Vg_DebugMsg, /* '?' == '-' */ |
| 167 | Vg_DebugExtraMsg /* '?' == '+' */ |
| 168 | } |
| 169 | VgMsgKind; |
| 170 | |
| 171 | /* Functions for building a message from multiple parts. */ |
| 172 | extern void VG_(start_msg) ( VgMsgKind kind ); |
| 173 | extern void VG_(add_to_msg) ( Char* format, ... ); |
| 174 | /* Ends and prints the message. Appends a newline. */ |
| 175 | extern void VG_(end_msg) ( void ); |
| 176 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 177 | /* Send a single-part message. Appends a newline. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 178 | extern void VG_(message) ( VgMsgKind kind, Char* format, ... ); |
| 179 | |
| 180 | |
| 181 | /*====================================================================*/ |
| 182 | /*=== Profiling ===*/ |
| 183 | /*====================================================================*/ |
| 184 | |
| 185 | /* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */ |
| 186 | #define VGP_CORE_LIST \ |
| 187 | /* These ones depend on the core */ \ |
| 188 | VGP_PAIR(VgpUnc, "unclassified"), \ |
| 189 | VGP_PAIR(VgpRun, "running"), \ |
| 190 | VGP_PAIR(VgpSched, "scheduler"), \ |
| 191 | VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \ |
| 192 | VGP_PAIR(VgpCliMalloc, "client malloc/free"), \ |
| 193 | VGP_PAIR(VgpStack, "adjust-stack"), \ |
| 194 | VGP_PAIR(VgpTranslate, "translate-main"), \ |
| 195 | VGP_PAIR(VgpToUCode, "to-ucode"), \ |
| 196 | VGP_PAIR(VgpFromUcode, "from-ucode"), \ |
| 197 | VGP_PAIR(VgpImprove, "improve"), \ |
| 198 | VGP_PAIR(VgpRegAlloc, "reg-alloc"), \ |
| 199 | VGP_PAIR(VgpLiveness, "liveness-analysis"), \ |
| 200 | VGP_PAIR(VgpDoLRU, "do-lru"), \ |
| 201 | VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \ |
| 202 | VGP_PAIR(VgpInitMem, "init-memory"), \ |
| 203 | VGP_PAIR(VgpExeContext, "exe-context"), \ |
| 204 | VGP_PAIR(VgpReadSyms, "read-syms"), \ |
| 205 | VGP_PAIR(VgpSearchSyms, "search-syms"), \ |
| 206 | VGP_PAIR(VgpAddToT, "add-to-transtab"), \ |
| 207 | VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \ |
| 208 | VGP_PAIR(VgpDemangle, "demangle"), \ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 209 | VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \ |
| 210 | VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 211 | /* These ones depend on the skin */ \ |
| 212 | VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \ |
| 213 | VGP_PAIR(VgpPostCloInit, "post-clo-init"), \ |
| 214 | VGP_PAIR(VgpInstrument, "instrument"), \ |
| 215 | VGP_PAIR(VgpSkinSysWrap, "skin-syscall-wrapper"), \ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 216 | VGP_PAIR(VgpSkinCheapSanity, "skin-cheap-sanity"), \ |
| 217 | VGP_PAIR(VgpSkinExpensiveSanity, "skin-expensive-sanity"), \ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 218 | VGP_PAIR(VgpFini, "fini") |
| 219 | |
| 220 | #define VGP_PAIR(n,name) n |
| 221 | typedef enum { VGP_CORE_LIST } VgpCoreCC; |
| 222 | #undef VGP_PAIR |
| 223 | |
| 224 | /* When registering skin profiling events, ensure that the 'n' value is in |
| 225 | * the range (VgpFini+1..) */ |
| 226 | extern void VGP_(register_profile_event) ( Int n, Char* name ); |
| 227 | |
| 228 | extern void VGP_(pushcc) ( UInt cc ); |
| 229 | extern void VGP_(popcc) ( UInt cc ); |
| 230 | |
| 231 | /* Define them only if they haven't already been defined by vg_profile.c */ |
| 232 | #ifndef VGP_PUSHCC |
| 233 | # define VGP_PUSHCC(x) |
| 234 | #endif |
| 235 | #ifndef VGP_POPCC |
| 236 | # define VGP_POPCC(x) |
| 237 | #endif |
| 238 | |
| 239 | |
| 240 | /*====================================================================*/ |
| 241 | /*=== Useful stuff to call from generated code ===*/ |
| 242 | /*====================================================================*/ |
| 243 | |
| 244 | /* ------------------------------------------------------------------ */ |
| 245 | /* General stuff */ |
| 246 | |
njn | 4155712 | 2002-10-14 09:25:37 +0000 | [diff] [blame] | 247 | /* 64-bit counter for the number of basic blocks done. */ |
| 248 | extern ULong VG_(bbs_done); |
| 249 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 250 | /* Get the simulated %esp */ |
| 251 | extern Addr VG_(get_stack_pointer) ( void ); |
| 252 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 253 | /* Detect if an address is within Valgrind's stack or Valgrind's |
| 254 | m_state_static; useful for memory leak detectors to tell if a block |
| 255 | is used by Valgrind (and thus can be ignored). */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 256 | extern Bool VG_(within_stack)(Addr a); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 257 | extern Bool VG_(within_m_state_static)(Addr a); |
| 258 | |
| 259 | /* Check if an address is 4-byte aligned */ |
| 260 | #define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3)) |
| 261 | |
| 262 | |
| 263 | /* ------------------------------------------------------------------ */ |
| 264 | /* Thread-related stuff */ |
| 265 | |
| 266 | /* Special magic value for an invalid ThreadId. It corresponds to |
| 267 | LinuxThreads using zero as the initial value for |
| 268 | pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */ |
| 269 | #define VG_INVALID_THREADID ((ThreadId)(0)) |
| 270 | |
| 271 | /* ThreadIds are simply indices into the vg_threads[] array. */ |
| 272 | typedef |
| 273 | UInt |
| 274 | ThreadId; |
| 275 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 276 | /* struct _ThreadState defined elsewhere; ThreadState is abstract as its |
| 277 | definition is not important for skins. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 278 | typedef |
| 279 | struct _ThreadState |
| 280 | ThreadState; |
| 281 | |
sewardj | 7ab2aca | 2002-10-20 19:40:32 +0000 | [diff] [blame] | 282 | extern ThreadId VG_(get_current_tid) ( void ); |
sewardj | b52a1b0 | 2002-10-23 21:38:22 +0000 | [diff] [blame] | 283 | extern ThreadId VG_(get_current_or_recent_tid) ( void ); |
sewardj | 7ab2aca | 2002-10-20 19:40:32 +0000 | [diff] [blame] | 284 | extern ThreadId VG_(get_tid_from_ThreadState) ( ThreadState* ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 285 | extern ThreadState* VG_(get_ThreadState) ( ThreadId tid ); |
| 286 | |
| 287 | |
| 288 | /*====================================================================*/ |
| 289 | /*=== Valgrind's version of libc ===*/ |
| 290 | /*====================================================================*/ |
| 291 | |
| 292 | /* Valgrind doesn't use libc at all, for good reasons (trust us). So here |
| 293 | are its own versions of C library functions, but with VG_ prefixes. Note |
| 294 | that the types of some are slightly different to the real ones. Some |
| 295 | extra useful functions are provided too; descriptions of how they work |
| 296 | are given below. */ |
| 297 | |
| 298 | #if !defined(NULL) |
| 299 | # define NULL ((void*)0) |
| 300 | #endif |
| 301 | |
| 302 | |
| 303 | /* ------------------------------------------------------------------ */ |
| 304 | /* stdio.h |
| 305 | * |
| 306 | * Note that they all output to the file descriptor given by the |
| 307 | * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no |
| 308 | * need for VG_(fprintf)(). |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 309 | */ |
sewardj | 78e3cd9 | 2002-10-22 04:45:48 +0000 | [diff] [blame] | 310 | extern UInt VG_(printf) ( const char *format, ... ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 311 | /* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */ |
sewardj | 78e3cd9 | 2002-10-22 04:45:48 +0000 | [diff] [blame] | 312 | extern UInt VG_(sprintf) ( Char* buf, Char *format, ... ); |
| 313 | extern UInt VG_(vprintf) ( void(*send)(Char), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 314 | const Char *format, va_list vargs ); |
| 315 | |
njn | 4155712 | 2002-10-14 09:25:37 +0000 | [diff] [blame] | 316 | extern Int VG_(rename) ( Char* old_name, Char* new_name ); |
| 317 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 318 | /* ------------------------------------------------------------------ */ |
| 319 | /* stdlib.h */ |
| 320 | |
| 321 | extern void* VG_(malloc) ( Int nbytes ); |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 322 | extern void VG_(free) ( void* p ); |
| 323 | extern void* VG_(calloc) ( Int n, Int nbytes ); |
| 324 | extern void* VG_(realloc) ( void* p, Int size ); |
| 325 | extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 326 | |
| 327 | extern void VG_(print_malloc_stats) ( void ); |
| 328 | |
| 329 | |
| 330 | extern void VG_(exit)( Int status ) |
| 331 | __attribute__ ((__noreturn__)); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 332 | /* Prints a panic message (a constant string), appends newline and bug |
| 333 | reporting info, aborts. */ |
| 334 | __attribute__ ((__noreturn__)) |
| 335 | extern void VG_(skin_panic) ( Char* str ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 336 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 337 | /* Looks up VG_(client_envp) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 338 | extern Char* VG_(getenv) ( Char* name ); |
| 339 | |
| 340 | /* Crude stand-in for the glibc system() call. */ |
| 341 | extern Int VG_(system) ( Char* cmd ); |
| 342 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 343 | extern Long VG_(atoll) ( Char* str ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 344 | |
| 345 | /* Like atoll(), but converts a number of base 2..36 */ |
| 346 | extern Long VG_(atoll36) ( UInt base, Char* str ); |
| 347 | |
| 348 | |
| 349 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 350 | /* ctype.h */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 351 | extern Bool VG_(isspace) ( Char c ); |
| 352 | extern Bool VG_(isdigit) ( Char c ); |
| 353 | extern Char VG_(toupper) ( Char c ); |
| 354 | |
| 355 | |
| 356 | /* ------------------------------------------------------------------ */ |
| 357 | /* string.h */ |
| 358 | extern Int VG_(strlen) ( const Char* str ); |
| 359 | extern Char* VG_(strcat) ( Char* dest, const Char* src ); |
| 360 | extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n ); |
| 361 | extern Char* VG_(strpbrk) ( const Char* s, const Char* accept ); |
| 362 | extern Char* VG_(strcpy) ( Char* dest, const Char* src ); |
| 363 | extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest ); |
| 364 | extern Int VG_(strcmp) ( const Char* s1, const Char* s2 ); |
| 365 | extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax ); |
| 366 | extern Char* VG_(strstr) ( const Char* haystack, Char* needle ); |
| 367 | extern Char* VG_(strchr) ( const Char* s, Char c ); |
| 368 | extern Char* VG_(strdup) ( const Char* s); |
sewardj | 7ab2aca | 2002-10-20 19:40:32 +0000 | [diff] [blame] | 369 | extern void* VG_(memcpy) ( void *d, const void *s, Int sz ); |
| 370 | extern void* VG_(memset) ( void *s, Int c, Int sz ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 371 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 372 | /* Like strcmp() and strncmp(), but stop comparing at any whitespace. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 373 | extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 374 | extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax ); |
| 375 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 376 | /* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the |
| 377 | last character. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 378 | extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest ); |
| 379 | |
| 380 | /* Mini-regexp function. Searches for 'pat' in 'str'. Supports |
| 381 | * meta-symbols '*' and '?'. '\' escapes meta-symbols. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 382 | extern Bool VG_(string_match) ( Char* pat, Char* str ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 383 | |
| 384 | |
| 385 | /* ------------------------------------------------------------------ */ |
| 386 | /* math.h */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 387 | /* Returns the base-2 logarithm of x. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 388 | extern Int VG_(log2) ( Int x ); |
| 389 | |
| 390 | |
| 391 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 392 | /* unistd.h, fcntl.h, sys/stat.h */ |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 393 | extern Int VG_(getpid) ( void ); |
| 394 | extern Int VG_(getppid) ( void ); |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 395 | |
njn | 4aca2d2 | 2002-10-04 10:29:38 +0000 | [diff] [blame] | 396 | extern Int VG_(open) ( const Char* pathname, Int flags, Int mode ); |
| 397 | extern Int VG_(read) ( Int fd, void* buf, Int count); |
| 398 | extern Int VG_(write) ( Int fd, void* buf, Int count); |
| 399 | extern void VG_(close) ( Int fd ); |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 400 | |
njn | 4155712 | 2002-10-14 09:25:37 +0000 | [diff] [blame] | 401 | /* Nb: VG_(rename)() declared in stdio.h section above */ |
njn | 4aca2d2 | 2002-10-04 10:29:38 +0000 | [diff] [blame] | 402 | extern Int VG_(unlink) ( Char* file_name ); |
| 403 | extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 404 | |
| 405 | |
| 406 | /* ------------------------------------------------------------------ */ |
| 407 | /* assert.h */ |
| 408 | /* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */ |
| 409 | #define VG__STRING(__str) #__str |
| 410 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 411 | #define sk_assert(expr) \ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 412 | ((void) ((expr) ? 0 : \ |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 413 | (VG_(skin_assert_fail) (VG__STRING(expr), \ |
| 414 | __FILE__, __LINE__, \ |
| 415 | __PRETTY_FUNCTION__), 0))) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 416 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 417 | __attribute__ ((__noreturn__)) |
| 418 | extern void VG_(skin_assert_fail) ( Char* expr, Char* file, |
| 419 | Int line, Char* fn ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 420 | |
| 421 | |
| 422 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 423 | /* system/mman.h */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 424 | extern void* VG_(mmap)( void* start, UInt length, |
| 425 | UInt prot, UInt flags, UInt fd, UInt offset ); |
| 426 | extern Int VG_(munmap)( void* start, Int length ); |
| 427 | |
| 428 | /* Get memory by anonymous mmap. */ |
| 429 | extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who ); |
| 430 | |
| 431 | |
| 432 | /* ------------------------------------------------------------------ */ |
| 433 | /* signal.h. |
| 434 | |
| 435 | Note that these use the vk_ (kernel) structure |
| 436 | definitions, which are different in places from those that glibc |
| 437 | defines -- hence the 'k' prefix. Since we're operating right at the |
| 438 | kernel interface, glibc's view of the world is entirely irrelevant. */ |
| 439 | |
| 440 | /* --- Signal set ops --- */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 441 | extern Int VG_(ksigfillset) ( vki_ksigset_t* set ); |
| 442 | extern Int VG_(ksigemptyset) ( vki_ksigset_t* set ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 443 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 444 | extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set ); |
| 445 | extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 446 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 447 | extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum ); |
| 448 | extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 449 | extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum ); |
| 450 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 451 | extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src ); |
| 452 | extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 453 | |
| 454 | /* --- Mess with the kernel's sig state --- */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 455 | extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 456 | vki_ksigset_t* oldset ); |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 457 | extern Int VG_(ksigaction) ( Int signum, |
| 458 | const vki_ksigaction* act, |
| 459 | vki_ksigaction* oldact ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 460 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 461 | extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) ); |
| 462 | extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 463 | |
sewardj | dcaf312 | 2002-09-30 23:12:33 +0000 | [diff] [blame] | 464 | extern Int VG_(kkill) ( Int pid, Int signo ); |
| 465 | extern Int VG_(ksigpending) ( vki_ksigset_t* set ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 466 | |
| 467 | |
| 468 | /*====================================================================*/ |
| 469 | /*=== UCode definition ===*/ |
| 470 | /*====================================================================*/ |
| 471 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 472 | /* Tags which describe what operands are. Must fit into 4 bits, which |
| 473 | they clearly do. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 474 | typedef |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 475 | enum { TempReg =0, /* virtual temp-reg */ |
| 476 | ArchReg =1, /* simulated integer reg */ |
| 477 | ArchRegS =2, /* simulated segment reg */ |
| 478 | RealReg =3, /* real machine's real reg */ |
| 479 | SpillNo =4, /* spill slot location */ |
| 480 | Literal =5, /* literal; .lit32 field has actual value */ |
| 481 | Lit16 =6, /* literal; .val[123] field has actual value */ |
| 482 | NoValue =7 /* operand not in use */ |
| 483 | } |
| 484 | Tag; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 485 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 486 | /* Invalid register numbers (can't be negative) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 487 | #define INVALID_TEMPREG 999999999 |
| 488 | #define INVALID_REALREG 999999999 |
| 489 | |
| 490 | /* Microinstruction opcodes. */ |
| 491 | typedef |
| 492 | enum { |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 493 | NOP, /* Null op */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 494 | |
sewardj | 7a5ebcf | 2002-11-13 22:42:13 +0000 | [diff] [blame^] | 495 | LOCK, /* Indicate the existance of a LOCK prefix (functionally NOP) */ |
| 496 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 497 | /* Moving values around */ |
| 498 | GET, PUT, /* simulated register <--> TempReg */ |
| 499 | GETF, PUTF, /* simulated %eflags <--> TempReg */ |
| 500 | LOAD, STORE, /* memory <--> TempReg */ |
| 501 | MOV, /* TempReg <--> TempReg */ |
| 502 | CMOV, /* Used for cmpxchg and cmov */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 503 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 504 | /* Arithmetic/logical ops */ |
| 505 | ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */ |
| 506 | AND, OR, XOR, NOT, /* Boolean ops */ |
| 507 | SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */ |
| 508 | NEG, /* Negate */ |
| 509 | INC, DEC, /* Increment/decrement */ |
| 510 | BSWAP, /* Big-endian <--> little-endian */ |
| 511 | CC2VAL, /* Condition code --> 0 or 1 */ |
| 512 | WIDEN, /* Signed or unsigned widening */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 513 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 514 | /* Conditional or unconditional jump */ |
| 515 | JMP, |
| 516 | |
| 517 | /* FPU ops */ |
| 518 | FPU, /* Doesn't touch memory */ |
| 519 | FPU_R, FPU_W, /* Reads/writes memory */ |
| 520 | |
| 521 | /* Not strictly needed, but improve address calculation translations. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 522 | LEA1, /* reg2 := const + reg1 */ |
| 523 | LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */ |
| 524 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 525 | /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg is zero. */ |
| 526 | JIFZ, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 527 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 528 | /* Advance the simulated %eip by some small (< 128) number. */ |
| 529 | INCEIP, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 530 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 531 | /* Dealing with segment registers */ |
| 532 | GETSEG, PUTSEG, /* simulated segment register <--> TempReg */ |
| 533 | USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */ |
| 534 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 535 | /* Not for translating x86 calls -- only to call helpers */ |
| 536 | CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */ |
| 537 | PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */ |
| 538 | CALLM, /* Call assembly-code helper */ |
| 539 | |
| 540 | /* Not for translating x86 calls -- only to call C helper functions of |
| 541 | up to three arguments (or two if the functions has a return value). |
| 542 | Arguments and return value must be word-sized. More arguments can |
| 543 | be faked with global variables (eg. use VG_(set_global_var)()). |
| 544 | |
| 545 | Seven possibilities: 'arg[123]' show where args go, 'ret' shows |
| 546 | where return value goes (if present). |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 547 | |
| 548 | CCALL(-, -, - ) void f(void) |
| 549 | CCALL(arg1, -, - ) void f(UInt arg1) |
| 550 | CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2) |
| 551 | CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3) |
| 552 | CCALL(-, -, ret ) UInt f(UInt) |
| 553 | CCALL(arg1, -, ret ) UInt f(UInt arg1) |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 554 | CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 555 | CCALL, |
| 556 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 557 | /* This opcode makes it easy for skins that extend UCode to do this to |
| 558 | avoid opcode overlap: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 559 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 560 | enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 561 | |
| 562 | WARNING: Do not add new opcodes after this one! They can be added |
| 563 | before, though. */ |
| 564 | DUMMY_FINAL_UOPCODE |
| 565 | } |
| 566 | Opcode; |
| 567 | |
| 568 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 569 | /* Condition codes, using the Intel encoding. CondAlways is an extra. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 570 | typedef |
| 571 | enum { |
| 572 | CondO = 0, /* overflow */ |
| 573 | CondNO = 1, /* no overflow */ |
| 574 | CondB = 2, /* below */ |
| 575 | CondNB = 3, /* not below */ |
| 576 | CondZ = 4, /* zero */ |
| 577 | CondNZ = 5, /* not zero */ |
| 578 | CondBE = 6, /* below or equal */ |
| 579 | CondNBE = 7, /* not below or equal */ |
| 580 | CondS = 8, /* negative */ |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 581 | CondNS = 9, /* not negative */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 582 | CondP = 10, /* parity even */ |
| 583 | CondNP = 11, /* not parity even */ |
| 584 | CondL = 12, /* jump less */ |
| 585 | CondNL = 13, /* not less */ |
| 586 | CondLE = 14, /* less or equal */ |
| 587 | CondNLE = 15, /* not less or equal */ |
| 588 | CondAlways = 16 /* Jump always */ |
| 589 | } |
| 590 | Condcode; |
| 591 | |
| 592 | |
| 593 | /* Descriptions of additional properties of *unconditional* jumps. */ |
| 594 | typedef |
| 595 | enum { |
| 596 | JmpBoring=0, /* boring unconditional jump */ |
| 597 | JmpCall=1, /* jump due to an x86 call insn */ |
| 598 | JmpRet=2, /* jump due to an x86 ret insn */ |
| 599 | JmpSyscall=3, /* do a system call, then jump */ |
| 600 | JmpClientReq=4 /* do a client request, then jump */ |
| 601 | } |
| 602 | JmpKind; |
| 603 | |
| 604 | |
| 605 | /* Flags. User-level code can only read/write O(verflow), S(ign), |
| 606 | Z(ero), A(ux-carry), C(arry), P(arity), and may also write |
| 607 | D(irection). That's a total of 7 flags. A FlagSet is a bitset, |
| 608 | thusly: |
| 609 | 76543210 |
| 610 | DOSZACP |
| 611 | and bit 7 must always be zero since it is unused. |
| 612 | */ |
| 613 | typedef UChar FlagSet; |
| 614 | |
| 615 | #define FlagD (1<<6) |
| 616 | #define FlagO (1<<5) |
| 617 | #define FlagS (1<<4) |
| 618 | #define FlagZ (1<<3) |
| 619 | #define FlagA (1<<2) |
| 620 | #define FlagC (1<<1) |
| 621 | #define FlagP (1<<0) |
| 622 | |
| 623 | #define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP) |
| 624 | #define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP) |
| 625 | #define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP) |
| 626 | #define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP) |
| 627 | #define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP) |
| 628 | #define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP) |
| 629 | #define FlagsZCP ( FlagZ | FlagC | FlagP) |
| 630 | #define FlagsOC (FlagO | FlagC ) |
| 631 | #define FlagsAC ( FlagA | FlagC ) |
| 632 | |
| 633 | #define FlagsALL (FlagsOSZACP | FlagD) |
| 634 | #define FlagsEmpty (FlagSet)0 |
| 635 | |
| 636 | |
| 637 | /* Liveness of general purpose registers, useful for code generation. |
| 638 | Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first |
| 639 | reg's liveness in bit 0, last reg's in bit N-1. Note that |
| 640 | these rankings don't match the Intel register ordering. */ |
| 641 | typedef UInt RRegSet; |
| 642 | |
| 643 | #define ALL_RREGS_DEAD 0 /* 0000...00b */ |
njn | e7c258c | 2002-10-03 08:57:01 +0000 | [diff] [blame] | 644 | #define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 645 | #define UNIT_RREGSET(rank) (1 << (rank)) |
| 646 | |
| 647 | #define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank)) |
| 648 | #define SET_RREG_LIVENESS(rank,rregs_live,b) \ |
| 649 | do { RRegSet unit = UNIT_RREGSET(rank); \ |
| 650 | if (b) rregs_live |= unit; \ |
| 651 | else rregs_live &= ~unit; \ |
| 652 | } while(0) |
| 653 | |
| 654 | |
| 655 | /* A Micro (u)-instruction. */ |
| 656 | typedef |
| 657 | struct { |
| 658 | /* word 1 */ |
| 659 | UInt lit32; /* 32-bit literal */ |
| 660 | |
| 661 | /* word 2 */ |
| 662 | UShort val1; /* first operand */ |
| 663 | UShort val2; /* second operand */ |
| 664 | |
| 665 | /* word 3 */ |
| 666 | UShort val3; /* third operand */ |
| 667 | UChar opcode; /* opcode */ |
| 668 | UChar size; /* data transfer size */ |
| 669 | |
| 670 | /* word 4 */ |
| 671 | FlagSet flags_r; /* :: FlagSet */ |
| 672 | FlagSet flags_w; /* :: FlagSet */ |
| 673 | UChar tag1:4; /* first operand tag */ |
| 674 | UChar tag2:4; /* second operand tag */ |
| 675 | UChar tag3:4; /* third operand tag */ |
| 676 | UChar extra4b:4; /* Spare field, used by WIDEN for src |
| 677 | -size, and by LEA2 for scale (1,2,4 or 8), |
| 678 | and by JMPs for original x86 instr size */ |
| 679 | |
| 680 | /* word 5 */ |
| 681 | UChar cond; /* condition, for jumps */ |
| 682 | Bool signed_widen:1; /* signed or unsigned WIDEN ? */ |
| 683 | JmpKind jmpkind:3; /* additional properties of unconditional JMP */ |
| 684 | |
| 685 | /* Additional properties for UInstrs that call C functions: |
| 686 | - CCALL |
| 687 | - PUT (when %ESP is the target) |
| 688 | - possibly skin-specific UInstrs |
| 689 | */ |
| 690 | UChar argc:2; /* Number of args, max 3 */ |
| 691 | UChar regparms_n:2; /* Number of args passed in registers */ |
| 692 | Bool has_ret_val:1; /* Function has return value? */ |
| 693 | |
| 694 | /* RealReg liveness; only sensical after reg alloc and liveness |
| 695 | analysis done. This info is a little bit arch-specific -- |
| 696 | VG_MAX_REALREGS can vary on different architectures. Note that |
| 697 | to use this information requires converting between register ranks |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 698 | and the Intel register numbers, using VG_(realreg_to_rank)() |
| 699 | and/or VG_(rank_to_realreg)() */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 700 | RRegSet regs_live_after:VG_MAX_REALREGS; |
| 701 | } |
| 702 | UInstr; |
| 703 | |
| 704 | |
| 705 | /* Expandable arrays of uinstrs. */ |
| 706 | typedef |
| 707 | struct { |
| 708 | Int used; |
| 709 | Int size; |
| 710 | UInstr* instrs; |
| 711 | Int nextTemp; |
| 712 | } |
| 713 | UCodeBlock; |
| 714 | |
| 715 | |
| 716 | /*====================================================================*/ |
| 717 | /*=== Instrumenting UCode ===*/ |
| 718 | /*====================================================================*/ |
| 719 | |
| 720 | /* A structure for communicating TempReg and RealReg uses of UInstrs. */ |
| 721 | typedef |
| 722 | struct { |
| 723 | Int num; |
| 724 | Bool isWrite; |
| 725 | } |
| 726 | RegUse; |
| 727 | |
| 728 | /* Find what this instruction does to its regs. Tag indicates whether we're |
| 729 | * considering TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc). |
| 730 | * Useful for analysis/optimisation passes. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 731 | extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, RegUse* arr ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 732 | |
| 733 | |
| 734 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 735 | /* Used to register helper functions to be called from generated code. A |
| 736 | limited number of compact helpers can be registered; the code generated |
| 737 | to call them is slightly shorter -- so register the mostly frequently |
| 738 | called helpers as compact. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 739 | extern void VG_(register_compact_helper) ( Addr a ); |
| 740 | extern void VG_(register_noncompact_helper) ( Addr a ); |
| 741 | |
| 742 | |
| 743 | /* ------------------------------------------------------------------ */ |
| 744 | /* Virtual register allocation */ |
| 745 | |
| 746 | /* Get a new virtual register */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 747 | extern Int VG_(get_new_temp) ( UCodeBlock* cb ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 748 | |
| 749 | /* Get a new virtual shadow register */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 750 | extern Int VG_(get_new_shadow) ( UCodeBlock* cb ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 751 | |
| 752 | /* Get a virtual register's corresponding virtual shadow register */ |
| 753 | #define SHADOW(tempreg) ((tempreg)+1) |
| 754 | |
| 755 | |
| 756 | /* ------------------------------------------------------------------ */ |
| 757 | /* Low-level UInstr builders */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 758 | extern void VG_(new_NOP) ( UInstr* u ); |
| 759 | extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz ); |
| 760 | extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 761 | Tag tag1, UInt val1 ); |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 762 | extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 763 | Tag tag1, UInt val1, |
| 764 | Tag tag2, UInt val2 ); |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 765 | extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 766 | Tag tag1, UInt val1, |
| 767 | Tag tag2, UInt val2, |
| 768 | Tag tag3, UInt val3 ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 769 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 770 | extern void VG_(set_flag_RW) ( UInstr* u, FlagSet fr, FlagSet fw ); |
| 771 | extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 ); |
| 772 | extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc, |
| 773 | UChar regparms_n, Bool has_ret_val ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 774 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 775 | extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr ); |
| 776 | |
| 777 | extern Bool VG_(any_flag_use)( UInstr* u ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 778 | |
njn | ac6c176 | 2002-10-04 14:34:15 +0000 | [diff] [blame] | 779 | /* Macro versions of the above; just shorter to type. */ |
| 780 | #define uInstr0 VG_(new_UInstr0) |
| 781 | #define uInstr1 VG_(new_UInstr1) |
| 782 | #define uInstr2 VG_(new_UInstr2) |
| 783 | #define uInstr3 VG_(new_UInstr3) |
| 784 | #define uLiteral VG_(set_lit_field) |
| 785 | #define uCCall VG_(set_ccall_fields) |
| 786 | #define newTemp VG_(get_new_temp) |
| 787 | #define newShadow VG_(get_new_shadow) |
| 788 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 789 | /* Refer to `the last instruction stuffed in' (can be lvalue). */ |
| 790 | #define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1] |
| 791 | |
| 792 | |
| 793 | /* ------------------------------------------------------------------ */ |
| 794 | /* Higher-level UInstr sequence builders */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 795 | extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f); |
| 796 | extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1, |
| 797 | UInt regparms_n); |
| 798 | extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2, |
| 799 | UInt regparms_n); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 800 | |
| 801 | /* One way around the 3-arg C function limit is to pass args via global |
| 802 | * variables... ugly, but it works. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 803 | extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 804 | |
| 805 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 806 | /* Allocating/freeing basic blocks of UCode */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 807 | extern UCodeBlock* VG_(alloc_UCodeBlock) ( void ); |
| 808 | extern void VG_(free_UCodeBlock) ( UCodeBlock* cb ); |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 809 | |
| 810 | /* ------------------------------------------------------------------ */ |
| 811 | /* UCode pretty/ugly printing. Probably only useful to call from a skin |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 812 | if VG_(needs).extended_UCode == True. */ |
| 813 | |
| 814 | /* When True, all generated code is/should be printed. */ |
| 815 | extern Bool VG_(print_codegen); |
| 816 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 817 | /* Pretty/ugly printing functions */ |
| 818 | extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title ); |
| 819 | extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u ); |
| 820 | extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u ); |
| 821 | extern void VG_(up_UInstr) ( Int instrNo, UInstr* u ); |
| 822 | extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc ); |
| 823 | extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo, |
| 824 | Int sz, Bool parens ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 825 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 826 | |
| 827 | /*====================================================================*/ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 828 | /*=== Generating x86 code from UCode ===*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 829 | /*====================================================================*/ |
| 830 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 831 | /* All this only necessary for skins with VG_(needs).extends_UCode == True. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 832 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 833 | /* This is the Intel register encoding -- integer regs. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 834 | #define R_EAX 0 |
| 835 | #define R_ECX 1 |
| 836 | #define R_EDX 2 |
| 837 | #define R_EBX 3 |
| 838 | #define R_ESP 4 |
| 839 | #define R_EBP 5 |
| 840 | #define R_ESI 6 |
| 841 | #define R_EDI 7 |
| 842 | |
| 843 | #define R_AL (0+R_EAX) |
| 844 | #define R_CL (0+R_ECX) |
| 845 | #define R_DL (0+R_EDX) |
| 846 | #define R_BL (0+R_EBX) |
| 847 | #define R_AH (4+R_EAX) |
| 848 | #define R_CH (4+R_ECX) |
| 849 | #define R_DH (4+R_EDX) |
| 850 | #define R_BH (4+R_EBX) |
| 851 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 852 | /* This is the Intel register encoding -- segment regs. */ |
| 853 | #define R_ES 0 |
| 854 | #define R_CS 1 |
| 855 | #define R_SS 2 |
| 856 | #define R_DS 3 |
| 857 | #define R_FS 4 |
| 858 | #define R_GS 5 |
| 859 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 860 | /* For pretty printing x86 code */ |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 861 | extern Char* VG_(name_of_seg_reg) ( Int sreg ); |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 862 | extern Char* VG_(name_of_int_reg) ( Int size, Int reg ); |
| 863 | extern Char VG_(name_of_int_size) ( Int size ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 864 | |
njn | ac6c176 | 2002-10-04 14:34:15 +0000 | [diff] [blame] | 865 | /* Shorter macros for convenience */ |
| 866 | #define nameIReg VG_(name_of_int_reg) |
| 867 | #define nameISize VG_(name_of_int_size) |
| 868 | #define nameSReg VG_(name_of_seg_reg) |
| 869 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 870 | /* Randomly useful things */ |
| 871 | extern UInt VG_(extend_s_8to32) ( UInt x ); |
| 872 | |
| 873 | /* Code emitters */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 874 | extern void VG_(emitB) ( UInt b ); |
| 875 | extern void VG_(emitW) ( UInt w ); |
| 876 | extern void VG_(emitL) ( UInt l ); |
| 877 | extern void VG_(new_emit) ( void ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 878 | |
| 879 | /* Finding offsets */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 880 | extern Int VG_(helper_offset) ( Addr a ); |
| 881 | extern Int VG_(shadow_reg_offset) ( Int arch ); |
| 882 | extern Int VG_(shadow_flags_offset) ( void ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 883 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 884 | /* Convert reg ranks <-> Intel register ordering, for using register |
| 885 | liveness information. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 886 | extern Int VG_(realreg_to_rank) ( Int realreg ); |
| 887 | extern Int VG_(rank_to_realreg) ( Int rank ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 888 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 889 | /* Call a subroutine. Does no argument passing, stack manipulations, etc. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 890 | extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 891 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 892 | /* For calling C functions -- saves caller save regs, pushes args, calls, |
| 893 | clears the stack, restores caller save regs. `fn' must be registered in |
| 894 | the baseBlock first. Acceptable tags are RealReg and Literal. Optimises |
| 895 | things, eg. by not preserving non-live caller-save registers. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 896 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 897 | WARNING: a UInstr should *not* be translated with synth_ccall() followed |
| 898 | by some other x86 assembly code; this will invalidate the results of |
| 899 | vg_realreg_liveness_analysis() and everything will fall over. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 900 | extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[], |
| 901 | Tag tagv[], Int ret_reg, |
| 902 | RRegSet regs_live_before, |
| 903 | RRegSet regs_live_after ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 904 | |
| 905 | /* Addressing modes */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 906 | extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg ); |
| 907 | extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 908 | |
| 909 | /* v-size (4, or 2 with OSO) insn emitters */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 910 | extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg ); |
| 911 | extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg ); |
| 912 | extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 ); |
| 913 | extern void VG_(emit_nonshiftopv_lit_reg)( Int sz, Opcode opc, UInt lit, |
| 914 | Int reg ); |
| 915 | extern void VG_(emit_shiftopv_lit_reg) ( Int sz, Opcode opc, UInt lit, |
| 916 | Int reg ); |
| 917 | extern void VG_(emit_nonshiftopv_reg_reg)( Int sz, Opcode opc, |
| 918 | Int reg1, Int reg2 ); |
| 919 | extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg ); |
| 920 | extern void VG_(emit_unaryopv_reg) ( Int sz, Opcode opc, Int reg ); |
| 921 | extern void VG_(emit_pushv_reg) ( Int sz, Int reg ); |
| 922 | extern void VG_(emit_popv_reg) ( Int sz, Int reg ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 923 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 924 | extern void VG_(emit_pushl_lit32) ( UInt int32 ); |
| 925 | extern void VG_(emit_pushl_lit8) ( Int lit8 ); |
| 926 | extern void VG_(emit_cmpl_zero_reg) ( Int reg ); |
| 927 | extern void VG_(emit_swapl_reg_EAX) ( Int reg ); |
| 928 | extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off, |
| 929 | Int memreg ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 930 | |
| 931 | /* b-size (1 byte) instruction emitters */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 932 | extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg ); |
| 933 | extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg ); |
| 934 | extern void VG_(emit_unaryopb_reg) ( Opcode opc, Int reg ); |
| 935 | extern void VG_(emit_testb_lit_reg) ( UInt lit, Int reg ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 936 | |
| 937 | /* zero-extended load emitters */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 938 | extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg ); |
| 939 | extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 940 | |
| 941 | /* misc instruction emitters */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 942 | extern void VG_(emit_call_reg) ( Int reg ); |
| 943 | extern void VG_(emit_add_lit_to_esp) ( Int lit ); |
| 944 | extern void VG_(emit_jcondshort_delta) ( Condcode cond, Int delta ); |
| 945 | extern void VG_(emit_pushal) ( void ); |
| 946 | extern void VG_(emit_popal) ( void ); |
| 947 | extern void VG_(emit_AMD_prefetch_reg) ( Int reg ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 948 | |
| 949 | |
| 950 | /*====================================================================*/ |
| 951 | /*=== Execution contexts ===*/ |
| 952 | /*====================================================================*/ |
| 953 | |
| 954 | /* Generic resolution type used in a few different ways, such as deciding |
| 955 | how closely to compare two errors for equality. */ |
| 956 | typedef |
| 957 | enum { Vg_LowRes, Vg_MedRes, Vg_HighRes } |
| 958 | VgRes; |
| 959 | |
| 960 | typedef |
| 961 | struct _ExeContext |
| 962 | ExeContext; |
| 963 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 964 | /* Compare two ExeContexts. Number of callers considered depends on `res': |
| 965 | Vg_LowRes: 2 |
| 966 | Vg_MedRes: 4 |
| 967 | Vg_HighRes: all */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 968 | extern Bool VG_(eq_ExeContext) ( VgRes res, |
| 969 | ExeContext* e1, ExeContext* e2 ); |
| 970 | |
| 971 | /* Print an ExeContext. */ |
| 972 | extern void VG_(pp_ExeContext) ( ExeContext* ); |
| 973 | |
| 974 | /* Take a snapshot of the client's stack. Search our collection of |
| 975 | ExeContexts to see if we already have it, and if not, allocate a |
| 976 | new one. Either way, return a pointer to the context. */ |
| 977 | extern ExeContext* VG_(get_ExeContext) ( ThreadState *tst ); |
| 978 | |
sewardj | 499e3de | 2002-11-13 22:22:25 +0000 | [diff] [blame] | 979 | /* Just grab the client's EIP, as a much smaller and cheaper |
| 980 | indication of where they are. */ |
| 981 | extern Addr VG_(get_EIP)( ThreadState *tst ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 982 | |
| 983 | /*====================================================================*/ |
| 984 | /*=== Error reporting ===*/ |
| 985 | /*====================================================================*/ |
| 986 | |
| 987 | /* ------------------------------------------------------------------ */ |
| 988 | /* Suppressions describe errors which we want to suppress, ie, not |
| 989 | show the user, usually because it is caused by a problem in a library |
| 990 | which we can't fix, replace or work around. Suppressions are read from |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 991 | a file at startup time. This gives flexibility so that new |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 992 | suppressions can be added to the file as and when needed. |
| 993 | */ |
| 994 | |
| 995 | typedef |
| 996 | Int /* Do not make this unsigned! */ |
| 997 | SuppKind; |
| 998 | |
| 999 | /* An extensible (via the 'extra' field) suppression record. This holds |
| 1000 | the suppression details of interest to a skin. Skins can use a normal |
| 1001 | enum (with element values in the normal range (0..)) for `skind'. |
| 1002 | |
| 1003 | If VG_(needs).report_errors==True, for each suppression read in by core |
| 1004 | SKN_(recognised_suppression)() and SKN_(read_extra_suppression_info) will |
| 1005 | be called. The `skind' field is filled in by the value returned in the |
| 1006 | argument of the first function; the second function can fill in the |
| 1007 | `string' and `extra' fields if it wants. |
| 1008 | */ |
| 1009 | typedef |
| 1010 | struct { |
| 1011 | /* What kind of suppression. Must use the range (0..) */ |
| 1012 | SuppKind skind; |
| 1013 | /* String -- use is optional. NULL by default. */ |
| 1014 | Char* string; |
| 1015 | /* Anything else -- use is optional. NULL by default. */ |
| 1016 | void* extra; |
| 1017 | } |
| 1018 | SkinSupp; |
| 1019 | |
| 1020 | |
| 1021 | /* ------------------------------------------------------------------ */ |
| 1022 | /* Error records contain enough info to generate an error report. The idea |
| 1023 | is that (typically) the same few points in the program generate thousands |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1024 | of errors, and we don't want to spew out a fresh error message for each |
| 1025 | one. Instead, we use these structures to common up duplicates. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1026 | */ |
| 1027 | |
| 1028 | typedef |
| 1029 | Int /* Do not make this unsigned! */ |
| 1030 | ErrorKind; |
| 1031 | |
| 1032 | /* An extensible (via the 'extra' field) error record. This holds |
| 1033 | the error details of interest to a skin. Skins can use a normal |
| 1034 | enum (with element values in the normal range (0..)) for `ekind'. |
| 1035 | |
| 1036 | When errors are found and recorded with VG_(maybe_record_error)(), all |
| 1037 | the skin must do is pass in the four parameters; core will |
| 1038 | allocate/initialise the error record. |
| 1039 | */ |
| 1040 | typedef |
| 1041 | struct { |
| 1042 | /* Used by ALL. Must be in the range (0..) */ |
| 1043 | Int ekind; |
| 1044 | /* Used frequently */ |
| 1045 | Addr addr; |
| 1046 | /* Used frequently */ |
| 1047 | Char* string; |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1048 | /* For any skin-specific extras */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1049 | void* extra; |
| 1050 | } |
| 1051 | SkinError; |
| 1052 | |
| 1053 | |
| 1054 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1055 | /* Call this when an error occurs. It will be recorded if it hasn't been |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1056 | seen before. If it has, the existing error record will have its count |
| 1057 | incremented. |
| 1058 | |
| 1059 | If the error occurs in generated code, 'tst' should be NULL. If the |
| 1060 | error occurs in non-generated code, 'tst' should be non-NULL. The |
| 1061 | `extra' field can be stack-allocated; it will be copied (using |
| 1062 | SKN_(dup_extra_and_update)()) if needed. But it won't be copied |
| 1063 | if it's NULL. |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1064 | |
| 1065 | If no 'a', 's' or 'extra' of interest needs to be recorded, just use |
| 1066 | NULL for them. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1067 | */ |
| 1068 | extern void VG_(maybe_record_error) ( ThreadState* tst, ErrorKind ekind, |
| 1069 | Addr a, Char* s, void* extra ); |
| 1070 | |
| 1071 | /* Gets a non-blank, non-comment line of at most nBuf chars from fd. |
| 1072 | Skips leading spaces on the line. Returns True if EOF was hit instead. |
| 1073 | Useful for reading in extra skin-specific suppression lines. |
| 1074 | */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 1075 | extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1076 | |
| 1077 | |
| 1078 | /*====================================================================*/ |
| 1079 | /*=== Obtaining debug information ===*/ |
| 1080 | /*====================================================================*/ |
| 1081 | |
| 1082 | /* Get the file/function/line number of the instruction at address 'a'. |
| 1083 | For these four, if debug info for the address is found, it copies the |
| 1084 | info into the buffer/UInt and returns True. If not, it returns False and |
| 1085 | nothing is copied. VG_(get_fnname) always demangles C++ function names. |
| 1086 | */ |
| 1087 | extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename ); |
| 1088 | extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname ); |
| 1089 | extern Bool VG_(get_linenum) ( Addr a, UInt* linenum ); |
| 1090 | |
| 1091 | /* This one is more efficient if getting both filename and line number, |
| 1092 | because the two lookups are done together. */ |
| 1093 | extern Bool VG_(get_filename_linenum) |
| 1094 | ( Addr a, Char* filename, Int n_filename, |
| 1095 | UInt* linenum ); |
| 1096 | |
| 1097 | /* Succeeds only if we find from debug info that 'a' is the address of the |
| 1098 | first instruction in a function -- as opposed to VG_(get_fnname) which |
| 1099 | succeeds if we find from debug info that 'a' is the address of any |
| 1100 | instruction in a function. Use this to instrument the start of |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1101 | a particular function. Nb: if an executable/shared object is stripped |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1102 | of its symbols, this function will not be able to recognise function |
| 1103 | entry points within it. */ |
| 1104 | extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* filename, Int n_filename ); |
| 1105 | |
| 1106 | /* Succeeds if the address is within a shared object or the main executable. |
| 1107 | It doesn't matter if debug info is present or not. */ |
| 1108 | extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname ); |
| 1109 | |
sewardj | 4710438 | 2002-10-20 18:35:48 +0000 | [diff] [blame] | 1110 | /* A way to get information about what segments are mapped */ |
| 1111 | typedef struct _SegInfo SegInfo; |
| 1112 | |
| 1113 | extern const SegInfo* VG_(next_seginfo)(const SegInfo *); |
| 1114 | extern Addr VG_(seg_start)(const SegInfo *); |
| 1115 | extern UInt VG_(seg_size)(const SegInfo *); |
| 1116 | extern const UChar* VG_(seg_filename)(const SegInfo *); |
| 1117 | extern UInt VG_(seg_sym_offset)(const SegInfo *); |
| 1118 | |
| 1119 | typedef |
| 1120 | enum { |
| 1121 | Vg_SectUnknown, |
| 1122 | Vg_SectText, |
sewardj | 8fe15a3 | 2002-10-20 19:29:21 +0000 | [diff] [blame] | 1123 | Vg_SectData, |
| 1124 | Vg_SectBSS, |
sewardj | 4710438 | 2002-10-20 18:35:48 +0000 | [diff] [blame] | 1125 | Vg_SectGOT, |
sewardj | 8fe15a3 | 2002-10-20 19:29:21 +0000 | [diff] [blame] | 1126 | Vg_SectPLT, |
sewardj | 4710438 | 2002-10-20 18:35:48 +0000 | [diff] [blame] | 1127 | } |
| 1128 | VgSectKind; |
| 1129 | |
| 1130 | extern VgSectKind VG_(seg_sect_kind)(Addr); |
| 1131 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1132 | |
| 1133 | /*====================================================================*/ |
| 1134 | /*=== Shadow chunks and block-finding ===*/ |
| 1135 | /*====================================================================*/ |
| 1136 | |
| 1137 | typedef |
| 1138 | enum { |
| 1139 | Vg_AllocMalloc = 0, |
| 1140 | Vg_AllocNew = 1, |
| 1141 | Vg_AllocNewVec = 2 |
| 1142 | } |
| 1143 | VgAllocKind; |
| 1144 | |
| 1145 | /* Description of a malloc'd chunk. skin_extra[] part can be used by |
| 1146 | the skin; size of array is given by VG_(needs).sizeof_shadow_chunk. */ |
| 1147 | typedef |
| 1148 | struct _ShadowChunk { |
| 1149 | struct _ShadowChunk* next; |
| 1150 | UInt size : 30; /* size requested */ |
| 1151 | VgAllocKind allockind : 2; /* which wrapper did the allocation */ |
| 1152 | Addr data; /* ptr to actual block */ |
| 1153 | UInt skin_extra[0]; /* extra skin-specific info */ |
| 1154 | } |
| 1155 | ShadowChunk; |
| 1156 | |
| 1157 | /* Use this to free blocks if VG_(needs).alternative_free == True. |
| 1158 | It frees the ShadowChunk and the malloc'd block it points to. */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 1159 | extern void VG_(free_ShadowChunk) ( ShadowChunk* sc ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1160 | |
| 1161 | /* Makes an array of pointers to all the shadow chunks of malloc'd blocks */ |
| 1162 | extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows ); |
| 1163 | |
| 1164 | /* Determines if address 'a' is within the bounds of the block at start. |
| 1165 | Allows a little 'slop' round the edges. */ |
| 1166 | extern Bool VG_(addr_is_in_block) ( Addr a, Addr start, UInt size ); |
| 1167 | |
| 1168 | /* Searches through currently malloc'd blocks until a matching one is found. |
| 1169 | Returns NULL if none match. Extra arguments can be implicitly passed to |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1170 | p using nested functions; see memcheck/mc_errcontext.c for an example. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1171 | extern ShadowChunk* VG_(any_matching_mallocd_ShadowChunks) |
| 1172 | ( Bool (*p) ( ShadowChunk* )); |
| 1173 | |
| 1174 | /* Searches through all thread's stacks to see if any match. Returns |
| 1175 | * VG_INVALID_THREADID if none match. */ |
| 1176 | extern ThreadId VG_(any_matching_thread_stack) |
| 1177 | ( Bool (*p) ( Addr stack_min, Addr stack_max )); |
| 1178 | |
sewardj | a449568 | 2002-10-21 07:29:59 +0000 | [diff] [blame] | 1179 | /* Do memory leak detection. */ |
| 1180 | extern void VG_(generic_detect_memory_leaks) ( |
| 1181 | Bool is_valid_64k_chunk ( UInt ), |
| 1182 | Bool is_valid_address ( Addr ), |
| 1183 | ExeContext* get_where ( ShadowChunk* ), |
| 1184 | VgRes leak_resolution, |
| 1185 | Bool show_reachable |
| 1186 | ); |
| 1187 | |
| 1188 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1189 | /*====================================================================*/ |
| 1190 | /*=== Skin-specific stuff ===*/ |
| 1191 | /*====================================================================*/ |
| 1192 | |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1193 | /* ------------------------------------------------------------------ */ |
| 1194 | /* Details */ |
| 1195 | typedef |
| 1196 | struct { |
| 1197 | /* Information used in the startup message. `name' also determines the |
| 1198 | string used for identifying suppressions in a suppression file as |
| 1199 | belonging to this skin. `version' can be NULL, in which case (not |
| 1200 | surprisingly) no version info is printed; this mechanism is |
| 1201 | designed for skins distributed with Valgrind that share a version |
| 1202 | number with Valgrind. Other skins not distributed as part of |
| 1203 | Valgrind should probably have their own version number. */ |
| 1204 | Char* name; |
| 1205 | Char* version; |
| 1206 | Char* description; |
| 1207 | Char* copyright_author; |
| 1208 | |
| 1209 | /* String printed if an `sk_assert' assertion fails or VG_(skin_panic) |
| 1210 | is called. Should probably be an email address. */ |
| 1211 | Char* bug_reports_to; |
| 1212 | } |
| 1213 | VgDetails; |
| 1214 | |
| 1215 | extern VgDetails VG_(details); |
| 1216 | |
| 1217 | /* ------------------------------------------------------------------ */ |
| 1218 | /* Needs */ |
| 1219 | |
| 1220 | /* If new fields are added to this type, update: |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1221 | * - vg_main.c:initialisation of VG_(needs) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1222 | * - vg_main.c:sanity_check_needs() |
| 1223 | * |
| 1224 | * If the name of this type or any of its fields change, update: |
| 1225 | * - dependent comments (just search for "VG_(needs)"). |
| 1226 | */ |
| 1227 | typedef |
| 1228 | struct { |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1229 | /* Booleans that decide core behaviour, but don't require extra |
| 1230 | operations to be defined if `True' */ |
| 1231 | |
| 1232 | /* Should __libc_freeres() be run? Bugs in it can crash the skin. */ |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1233 | Bool libc_freeres; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1234 | |
| 1235 | /* Want to have errors detected by Valgrind's core reported? Includes: |
| 1236 | - pthread API errors (many; eg. unlocking a non-locked mutex) |
| 1237 | - silly arguments to malloc() et al (eg. negative size) |
| 1238 | - invalid file descriptors to blocking syscalls read() and write() |
| 1239 | - bad signal numbers passed to sigaction() |
| 1240 | - attempt to install signal handler for SIGKILL or SIGSTOP */ |
| 1241 | Bool core_errors; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1242 | |
| 1243 | /* Booleans that indicate extra operations are defined; if these are |
| 1244 | True, the corresponding template functions (given below) must be |
| 1245 | defined. A lot like being a member of a type class. */ |
| 1246 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1247 | /* Want to report errors from the skin? This implies use of |
| 1248 | suppressions, too. */ |
| 1249 | Bool skin_errors; |
| 1250 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1251 | /* Is information kept about specific individual basic blocks? (Eg. for |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1252 | cachegrind there are cost-centres for every instruction, stored at a |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1253 | basic block level.) If so, it sometimes has to be discarded, because |
| 1254 | .so mmap/munmap-ping or self-modifying code (informed by the |
| 1255 | DISCARD_TRANSLATIONS user request) can cause one instruction address |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1256 | to be used for more than one instruction in one program run... */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1257 | Bool basic_block_discards; |
| 1258 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1259 | /* Skin maintains information about each register? */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1260 | Bool shadow_regs; |
| 1261 | |
| 1262 | /* Skin defines its own command line options? */ |
| 1263 | Bool command_line_options; |
| 1264 | /* Skin defines its own client requests? */ |
| 1265 | Bool client_requests; |
| 1266 | |
| 1267 | /* Skin defines its own UInstrs? */ |
| 1268 | Bool extended_UCode; |
| 1269 | |
| 1270 | /* Skin does stuff before and/or after system calls? */ |
| 1271 | Bool syscall_wrapper; |
| 1272 | |
| 1273 | /* Size, in words, of extra info about malloc'd blocks recorded by |
| 1274 | skin. Be careful to get this right or you'll get seg faults! */ |
| 1275 | UInt sizeof_shadow_block; |
| 1276 | |
| 1277 | /* Skin does free()s itself? */ |
| 1278 | Bool alternative_free; |
| 1279 | |
| 1280 | /* Are skin-state sanity checks performed? */ |
| 1281 | Bool sanity_checks; |
sewardj | 8fe15a3 | 2002-10-20 19:29:21 +0000 | [diff] [blame] | 1282 | |
| 1283 | /* Do we need to see data symbols? */ |
| 1284 | Bool data_syms; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1285 | } |
| 1286 | VgNeeds; |
| 1287 | |
| 1288 | extern VgNeeds VG_(needs); |
| 1289 | |
| 1290 | |
| 1291 | /* ------------------------------------------------------------------ */ |
| 1292 | /* Core events to track */ |
| 1293 | |
| 1294 | /* Part of the core from which this call was made. Useful for determining |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1295 | what kind of error message should be emitted. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1296 | typedef |
| 1297 | enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate } |
| 1298 | CorePart; |
| 1299 | |
| 1300 | /* Events happening in core to track. To be notified, assign a function |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1301 | to the function pointer. To ignore an event, don't do anything |
| 1302 | (default assignment is to NULL in which case the call is skipped). */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1303 | typedef |
| 1304 | struct { |
| 1305 | /* Memory events */ |
| 1306 | void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx ); |
| 1307 | void (*new_mem_heap) ( Addr a, UInt len, Bool is_inited ); |
| 1308 | void (*new_mem_stack) ( Addr a, UInt len ); |
| 1309 | void (*new_mem_stack_aligned) ( Addr a, UInt len ); |
| 1310 | void (*new_mem_stack_signal) ( Addr a, UInt len ); |
| 1311 | void (*new_mem_brk) ( Addr a, UInt len ); |
sewardj | 40f8ebe | 2002-10-23 21:46:13 +0000 | [diff] [blame] | 1312 | void (*new_mem_mmap) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1313 | |
| 1314 | void (*copy_mem_heap) ( Addr from, Addr to, UInt len ); |
| 1315 | void (*copy_mem_remap) ( Addr from, Addr to, UInt len ); |
sewardj | 40f8ebe | 2002-10-23 21:46:13 +0000 | [diff] [blame] | 1316 | void (*change_mem_mprotect) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1317 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1318 | /* Used on redzones around malloc'd blocks and at end of stack */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1319 | void (*ban_mem_heap) ( Addr a, UInt len ); |
| 1320 | void (*ban_mem_stack) ( Addr a, UInt len ); |
| 1321 | |
| 1322 | void (*die_mem_heap) ( Addr a, UInt len ); |
| 1323 | void (*die_mem_stack) ( Addr a, UInt len ); |
| 1324 | void (*die_mem_stack_aligned) ( Addr a, UInt len ); |
| 1325 | void (*die_mem_stack_signal) ( Addr a, UInt len ); |
| 1326 | void (*die_mem_brk) ( Addr a, UInt len ); |
| 1327 | void (*die_mem_munmap) ( Addr a, UInt len ); |
| 1328 | |
| 1329 | void (*bad_free) ( ThreadState* tst, Addr a ); |
| 1330 | void (*mismatched_free) ( ThreadState* tst, Addr a ); |
| 1331 | |
| 1332 | void (*pre_mem_read) ( CorePart part, ThreadState* tst, |
| 1333 | Char* s, Addr a, UInt size ); |
| 1334 | void (*pre_mem_read_asciiz) ( CorePart part, ThreadState* tst, |
| 1335 | Char* s, Addr a ); |
| 1336 | void (*pre_mem_write) ( CorePart part, ThreadState* tst, |
| 1337 | Char* s, Addr a, UInt size ); |
| 1338 | /* Not implemented yet -- have to add in lots of places, which is a |
| 1339 | pain. Won't bother unless/until there's a need. */ |
| 1340 | /* void (*post_mem_read) ( ThreadState* tst, Char* s, |
| 1341 | Addr a, UInt size ); */ |
| 1342 | void (*post_mem_write) ( Addr a, UInt size ); |
| 1343 | |
| 1344 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1345 | /* Scheduler events (not exhaustive) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1346 | void (*thread_run) ( ThreadId tid ); |
| 1347 | |
| 1348 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1349 | /* Mutex events (not exhaustive) */ |
sewardj | dca8411 | 2002-11-13 22:29:34 +0000 | [diff] [blame] | 1350 | |
| 1351 | /* Called before a thread can block while waiting for a mutex |
| 1352 | (called regardless of whether the thread will block or |
| 1353 | not) */ |
| 1354 | void (*pre_mutex_lock) ( ThreadId tid, |
| 1355 | void* /*pthread_mutex_t* */ mutex ); |
| 1356 | /* Called once the thread actually holds the mutex (always |
| 1357 | paired with pre_mutex_lock) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1358 | void (*post_mutex_lock) ( ThreadId tid, |
| 1359 | void* /*pthread_mutex_t* */ mutex ); |
sewardj | dca8411 | 2002-11-13 22:29:34 +0000 | [diff] [blame] | 1360 | /* Called after a thread has released a mutex (no need for a |
| 1361 | corresponding pre_mutex_unlock, because unlocking can't |
| 1362 | block) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1363 | void (*post_mutex_unlock) ( ThreadId tid, |
| 1364 | void* /*pthread_mutex_t* */ mutex ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1365 | |
sewardj | dca8411 | 2002-11-13 22:29:34 +0000 | [diff] [blame] | 1366 | /* Called during thread create, before the new thread has run |
| 1367 | any instructions (or touched any memory). */ |
sewardj | c4a810d | 2002-11-13 22:25:51 +0000 | [diff] [blame] | 1368 | void (*post_thread_create)( ThreadId tid, ThreadId child ); |
sewardj | dca8411 | 2002-11-13 22:29:34 +0000 | [diff] [blame] | 1369 | /* Called once the joinee thread is terminated and the joining |
| 1370 | thread is about to resume. */ |
sewardj | c4a810d | 2002-11-13 22:25:51 +0000 | [diff] [blame] | 1371 | void (*post_thread_join) ( ThreadId joiner, ThreadId joinee ); |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1372 | |
| 1373 | /* Others... thread, condition variable, signal events... */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1374 | /* ... */ |
| 1375 | } |
| 1376 | VgTrackEvents; |
| 1377 | |
| 1378 | /* Declare the struct instance */ |
| 1379 | extern VgTrackEvents VG_(track_events); |
| 1380 | |
| 1381 | |
| 1382 | /* ------------------------------------------------------------------ */ |
| 1383 | /* Template functions */ |
| 1384 | |
| 1385 | /* These are the parameterised functions in the core. The default definitions |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1386 | are overridden by LD_PRELOADed skin version. At the very least, a skin |
| 1387 | must define the fundamental template functions. Depending on what needs |
| 1388 | are set, extra template functions will be used too. Functions are |
| 1389 | grouped under the needs that govern their use. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1390 | |
| 1391 | |
| 1392 | /* ------------------------------------------------------------------ */ |
| 1393 | /* Fundamental template functions */ |
| 1394 | |
| 1395 | /* Initialise skin. Must do the following: |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1396 | - initialise the `details' struct |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1397 | - register any helpers called by generated code |
| 1398 | |
| 1399 | May do the following: |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1400 | - initialise the `needs' struct to indicate certain requirements |
| 1401 | - initialise the `track' struct to indicate core events of interest |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1402 | - register any skin-specific profiling events |
| 1403 | - any other skin-specific initialisation |
| 1404 | */ |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1405 | extern void SK_(pre_clo_init) ( VgDetails* details, VgNeeds* needs, |
| 1406 | VgTrackEvents* track ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1407 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1408 | /* Do initialisation that can only be done after command line processing. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1409 | extern void SK_(post_clo_init)( void ); |
| 1410 | |
| 1411 | /* Instrument a basic block. Must be a true function, ie. the same input |
| 1412 | always results in the same output, because basic blocks can be |
| 1413 | retranslated. Unless you're doing something really strange... |
| 1414 | 'orig_addr' is the address of the first instruction in the block. */ |
| 1415 | extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr ); |
| 1416 | |
| 1417 | /* Finish up, print out any results, etc. */ |
| 1418 | extern void SK_(fini) ( void ); |
| 1419 | |
| 1420 | |
| 1421 | /* ------------------------------------------------------------------ */ |
| 1422 | /* VG_(needs).report_errors */ |
| 1423 | |
| 1424 | /* Identify if two errors are equal, or equal enough. `res' indicates how |
| 1425 | close is "close enough". `res' should be passed on as necessary, eg. if |
| 1426 | the SkinError's extra field contains an ExeContext, `res' should be |
| 1427 | passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other |
| 1428 | than that, probably don't worry about it unless you have lots of very |
| 1429 | similar errors occurring. |
| 1430 | */ |
| 1431 | extern Bool SK_(eq_SkinError) ( VgRes res, |
| 1432 | SkinError* e1, SkinError* e2 ); |
| 1433 | |
| 1434 | /* Print error context. The passed function pp_ExeContext() can be (and |
| 1435 | probably should be) used to print the location of the error. */ |
| 1436 | extern void SK_(pp_SkinError) ( SkinError* ec, void (*pp_ExeContext)(void) ); |
| 1437 | |
| 1438 | /* Copy the ec->extra part and replace ec->extra with the new copy. This is |
| 1439 | necessary to move from a temporary stack copy to a permanent heap one. |
| 1440 | |
| 1441 | Then fill in any details that could be postponed until after the decision |
| 1442 | whether to ignore the error (ie. details not affecting the result of |
| 1443 | SK_(eq_SkinError)()). This saves time when errors are ignored. |
| 1444 | |
| 1445 | Yuk. |
| 1446 | */ |
| 1447 | extern void SK_(dup_extra_and_update)(SkinError* ec); |
| 1448 | |
| 1449 | /* Return value indicates recognition. If recognised, type goes in `skind'. */ |
| 1450 | extern Bool SK_(recognised_suppression) ( Char* name, SuppKind *skind ); |
| 1451 | |
| 1452 | /* Read any extra info for this suppression kind. For filling up the |
| 1453 | `string' and `extra' fields in a `SkinSupp' struct if necessary. */ |
| 1454 | extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1455 | Int nBuf, SkinSupp *s ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1456 | |
| 1457 | /* This should just check the kinds match and maybe some stuff in the |
| 1458 | 'extra' field if appropriate */ |
| 1459 | extern Bool SK_(error_matches_suppression)(SkinError* ec, SkinSupp* su); |
| 1460 | |
| 1461 | |
| 1462 | /* ------------------------------------------------------------------ */ |
| 1463 | /* VG_(needs).basic_block_discards */ |
| 1464 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1465 | /* Should discard any information that pertains to specific basic blocks |
| 1466 | or instructions within the address range given. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1467 | extern void SK_(discard_basic_block_info) ( Addr a, UInt size ); |
| 1468 | |
| 1469 | |
| 1470 | /* ------------------------------------------------------------------ */ |
| 1471 | /* VG_(needs).shadow_regs */ |
| 1472 | |
| 1473 | /* Valid values for general registers and EFLAGS register, for initialising |
| 1474 | and updating registers when written in certain places in core. */ |
| 1475 | extern void SK_(written_shadow_regs_values) ( UInt* gen_reg, UInt* eflags ); |
| 1476 | |
| 1477 | |
| 1478 | /* ------------------------------------------------------------------ */ |
| 1479 | /* VG_(needs).command_line_options */ |
| 1480 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1481 | /* Return True if option was recognised. Presumably sets some state to |
| 1482 | record the option as well. */ |
| 1483 | extern Bool SK_(process_cmd_line_option) ( Char* argv ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1484 | |
| 1485 | /* Print out command line usage for skin options */ |
| 1486 | extern Char* SK_(usage) ( void ); |
| 1487 | |
| 1488 | |
| 1489 | /* ------------------------------------------------------------------ */ |
| 1490 | /* VG_(needs).client_requests */ |
| 1491 | |
sewardj | 3404251 | 2002-10-22 04:14:35 +0000 | [diff] [blame] | 1492 | extern Bool SK_(handle_client_request) ( ThreadState* tst, UInt* arg_block, UInt *ret ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1493 | |
| 1494 | |
| 1495 | /* ------------------------------------------------------------------ */ |
| 1496 | /* VG_(needs).extends_UCode */ |
| 1497 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 1498 | /* Useful to use in VG_(get_Xreg_usage)() */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1499 | #define VG_UINSTR_READS_REG(ono) \ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1500 | { if (mycat(u->tag,ono) == tag) \ |
| 1501 | { arr[n].num = mycat(u->val,ono); \ |
| 1502 | arr[n].isWrite = False; \ |
| 1503 | n++; \ |
| 1504 | } \ |
| 1505 | } |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1506 | #define VG_UINSTR_WRITES_REG(ono) \ |
| 1507 | { if (mycat(u->tag,ono) == tag) \ |
| 1508 | { arr[n].num = mycat(u->val,ono); \ |
| 1509 | arr[n].isWrite = True; \ |
| 1510 | n++; \ |
| 1511 | } \ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 1514 | /* 'X' prefix indicates eXtended UCode. */ |
| 1515 | extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, RegUse* arr ); |
| 1516 | extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before ); |
| 1517 | extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1518 | UInstr* u ); |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 1519 | extern Char* SK_(name_XUOpcode) ( Opcode opc ); |
| 1520 | extern void SK_(pp_XUInstr) ( UInstr* u ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1521 | |
| 1522 | |
| 1523 | /* ------------------------------------------------------------------ */ |
| 1524 | /* VG_(needs).syscall_wrapper */ |
| 1525 | |
| 1526 | /* If either of the pre_ functions malloc() something to return, the |
| 1527 | * corresponding post_ function had better free() it! |
| 1528 | */ |
| 1529 | extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno, |
| 1530 | Bool is_blocking ); |
| 1531 | extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno, |
| 1532 | void* pre_result, Int res, |
| 1533 | Bool is_blocking ); |
| 1534 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1535 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1536 | /* ------------------------------------------------------------------ */ |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1537 | /* VG_(needs).sizeof_shadow_chunk (if > 0) */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1538 | |
| 1539 | extern void SK_(complete_shadow_chunk) ( ShadowChunk* sc, ThreadState* tst ); |
| 1540 | |
| 1541 | |
| 1542 | /* ------------------------------------------------------------------ */ |
| 1543 | /* VG_(needs).alternative_free */ |
| 1544 | |
| 1545 | extern void SK_(alt_free) ( ShadowChunk* sc, ThreadState* tst ); |
| 1546 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1547 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1548 | /* --------------------------------------------------------------------- |
| 1549 | VG_(needs).sanity_checks */ |
| 1550 | |
njn | d5bb0a5 | 2002-09-27 10:24:48 +0000 | [diff] [blame] | 1551 | /* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check) |
| 1552 | is called very frequently; SK_(expensive_sanity_check) is called less |
| 1553 | frequently and can be more involved. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1554 | extern Bool SK_(cheap_sanity_check) ( void ); |
| 1555 | extern Bool SK_(expensive_sanity_check) ( void ); |
| 1556 | |
| 1557 | |
| 1558 | #endif /* NDEF __VG_SKIN_H */ |
| 1559 | |
| 1560 | /*--------------------------------------------------------------------*/ |
| 1561 | /*--- end vg_skin.h ---*/ |
| 1562 | /*--------------------------------------------------------------------*/ |
| 1563 | |