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