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