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