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