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