sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A header file for all parts of Valgrind. ---*/ |
| 4 | /*--- Include no other! ---*/ |
| 5 | /*--- vg_include.h ---*/ |
| 6 | /*--------------------------------------------------------------------*/ |
| 7 | |
| 8 | /* |
| 9 | This file is part of Valgrind, an x86 protected-mode emulator |
| 10 | designed for debugging and profiling binaries on x86-Unixes. |
| 11 | |
| 12 | Copyright (C) 2000-2002 Julian Seward |
| 13 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 14 | |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License as |
| 17 | published by the Free Software Foundation; either version 2 of the |
| 18 | License, or (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 28 | 02111-1307, USA. |
| 29 | |
| 30 | The GNU General Public License is contained in the file LICENSE. |
| 31 | */ |
| 32 | |
| 33 | #ifndef __VG_INCLUDE_H |
| 34 | #define __VG_INCLUDE_H |
| 35 | |
| 36 | |
| 37 | #include <stdarg.h> /* ANSI varargs stuff */ |
| 38 | #include <setjmp.h> /* for jmp_buf */ |
| 39 | |
| 40 | |
| 41 | /* --------------------------------------------------------------------- |
sewardj | 2d94c11 | 2002-06-03 01:25:54 +0000 | [diff] [blame] | 42 | Where to send bug reports to. |
| 43 | ------------------------------------------------------------------ */ |
| 44 | |
| 45 | #define VG_EMAIL_ADDR "jseward@acm.org" |
| 46 | |
| 47 | |
| 48 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 49 | Build options and table sizes. You should be able to change these |
| 50 | options or sizes, recompile, and still have a working system. |
| 51 | ------------------------------------------------------------------ */ |
| 52 | |
| 53 | #include "vg_constants.h" |
| 54 | |
| 55 | |
| 56 | /* Set to 1 to enable time profiling. Since this uses SIGPROF, we |
| 57 | don't want this permanently enabled -- only for profiling |
| 58 | builds. */ |
| 59 | #if 0 |
| 60 | # define VG_PROFILE |
| 61 | #endif |
| 62 | |
| 63 | |
| 64 | /* Total number of integer registers available for allocation. That's |
| 65 | all of them except %esp, %edi and %ebp. %edi is a general spare |
| 66 | temporary. %ebp permanently points at VG_(baseBlock). Note that |
| 67 | it's important that this tie in with what rankToRealRegNo() says. |
| 68 | DO NOT CHANGE THIS VALUE FROM 5. ! */ |
| 69 | #define VG_MAX_REALREGS 5 |
| 70 | |
| 71 | /* Total number of spill slots available for allocation, if a TempReg |
| 72 | doesn't make it into a RealReg. Just bomb the entire system if |
| 73 | this value is too small; we don't expect it will ever get |
| 74 | particularly high. */ |
| 75 | #define VG_MAX_SPILLSLOTS 24 |
| 76 | |
| 77 | |
| 78 | /* Constants for the slow translation lookup cache. */ |
| 79 | #define VG_TRANSTAB_SLOW_BITS 11 |
| 80 | #define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS) |
| 81 | #define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1) |
| 82 | |
| 83 | /* Size of a buffer used for creating messages. */ |
| 84 | #define M_VG_MSGBUF 10000 |
| 85 | |
| 86 | /* Size of a smallish table used to read /proc/self/map entries. */ |
sewardj | ebc8233 | 2002-04-24 14:44:23 +0000 | [diff] [blame] | 87 | #define M_PROCMAP_BUF 50000 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 88 | |
| 89 | /* Max length of pathname to a .so/executable file. */ |
| 90 | #define M_VG_LIBNAMESTR 100 |
| 91 | |
| 92 | /* Max length of a text fragment used to construct error messages. */ |
| 93 | #define M_VG_ERRTXT 512 |
| 94 | |
| 95 | /* Max length of the string copied from env var VG_ARGS at startup. */ |
| 96 | #define M_VG_CMDLINE_STRLEN 1000 |
| 97 | |
| 98 | /* Max number of options for Valgrind which we can handle. */ |
| 99 | #define M_VG_CMDLINE_OPTS 100 |
| 100 | |
| 101 | /* After this many different unsuppressed errors have been observed, |
| 102 | be more conservative about collecting new ones. */ |
| 103 | #define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50 |
| 104 | |
| 105 | /* After this many different unsuppressed errors have been observed, |
| 106 | stop collecting errors at all, and tell the user their program is |
| 107 | evidently a steaming pile of camel dung. */ |
sewardj | 1bebcbf | 2002-04-24 21:24:18 +0000 | [diff] [blame] | 108 | #define M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN 300 |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 109 | |
| 110 | /* After this many total errors have been observed, stop collecting |
| 111 | errors at all. Counterpart to M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN. */ |
sewardj | 1bebcbf | 2002-04-24 21:24:18 +0000 | [diff] [blame] | 112 | #define M_VG_COLLECT_NO_ERRORS_AFTER_FOUND 30000 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 113 | |
| 114 | /* These many bytes below %ESP are considered addressible if we're |
| 115 | doing the --workaround-gcc296-bugs hack. */ |
sewardj | b581a13 | 2002-05-08 00:32:50 +0000 | [diff] [blame] | 116 | #define VG_GCC296_BUG_STACK_SLOP 1024 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 117 | |
| 118 | /* The maximum number of calls we're prepared to save in a |
| 119 | backtrace. */ |
| 120 | #define VG_DEEPEST_BACKTRACE 50 |
| 121 | |
| 122 | /* Number of lists in which we keep track of malloc'd but not free'd |
| 123 | blocks. Should be prime. */ |
| 124 | #define VG_N_MALLOCLISTS 997 |
| 125 | |
| 126 | /* Number of lists in which we keep track of ExeContexts. Should be |
| 127 | prime. */ |
| 128 | #define VG_N_EC_LISTS /*997*/ 4999 |
| 129 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 130 | /* Defines the thread-scheduling timeslice, in terms of the number of |
| 131 | basic blocks we attempt to run each thread for. Smaller values |
| 132 | give finer interleaving but much increased scheduling overheads. */ |
sewardj | 4505b9e | 2002-05-28 11:27:31 +0000 | [diff] [blame] | 133 | #define VG_SCHEDULING_QUANTUM 50000 |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 134 | |
| 135 | /* The maximum number of pthreads that we support. This is |
| 136 | deliberately not very high since our implementation of some of the |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 137 | scheduler algorithms is surely O(N) in the number of threads, since |
| 138 | that's simple, at least. And (in practice) we hope that most |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 139 | programs do not need many threads. */ |
sewardj | 8208ae8 | 2002-06-17 14:25:00 +0000 | [diff] [blame] | 140 | #define VG_N_THREADS 50 |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 141 | |
| 142 | /* Maximum number of pthread keys available. Again, we start low until |
| 143 | the need for a higher number presents itself. */ |
sewardj | 8208ae8 | 2002-06-17 14:25:00 +0000 | [diff] [blame] | 144 | #define VG_N_THREAD_KEYS 50 |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 145 | |
| 146 | /* Number of file descriptors that can simultaneously be waited on for |
| 147 | I/O to complete. Perhaps this should be the same as VG_N_THREADS |
| 148 | (surely a thread can't wait on more than one fd at once?. Who |
| 149 | knows.) */ |
| 150 | #define VG_N_WAITING_FDS 10 |
| 151 | |
sewardj | bf290b9 | 2002-05-01 02:28:01 +0000 | [diff] [blame] | 152 | /* Stack size for a thread. We try and check that they do not go |
| 153 | beyond it. */ |
sewardj | f0b0645 | 2002-06-04 08:38:04 +0000 | [diff] [blame] | 154 | #define VG_PTHREAD_STACK_SIZE (1 << 20) |
sewardj | bf290b9 | 2002-05-01 02:28:01 +0000 | [diff] [blame] | 155 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 156 | /* Number of entries in the semaphore-remapping table. */ |
| 157 | #define VG_N_SEMAPHORES 50 |
| 158 | |
| 159 | /* Number of entries in the rwlock-remapping table. */ |
| 160 | #define VG_N_RWLOCKS 50 |
| 161 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 162 | /* Number of entries in each thread's cleanup stack. */ |
| 163 | #define VG_N_CLEANUPSTACK 8 |
| 164 | |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 165 | /* Number of entries in each thread's fork-handler stack. */ |
| 166 | #define VG_N_FORKHANDLERSTACK 2 |
| 167 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 168 | |
| 169 | /* --------------------------------------------------------------------- |
| 170 | Basic types |
| 171 | ------------------------------------------------------------------ */ |
| 172 | |
| 173 | typedef unsigned char UChar; |
| 174 | typedef unsigned short UShort; |
| 175 | typedef unsigned int UInt; |
| 176 | typedef unsigned long long int ULong; |
| 177 | |
| 178 | typedef signed char Char; |
| 179 | typedef signed short Short; |
| 180 | typedef signed int Int; |
| 181 | typedef signed long long int Long; |
| 182 | |
| 183 | typedef unsigned int Addr; |
| 184 | |
| 185 | typedef unsigned char Bool; |
| 186 | #define False ((Bool)0) |
| 187 | #define True ((Bool)1) |
| 188 | |
| 189 | #define mycat_wrk(aaa,bbb) aaa##bbb |
| 190 | #define mycat(aaa,bbb) mycat_wrk(aaa,bbb) |
| 191 | |
| 192 | /* Just pray that gcc's constant folding works properly ... */ |
| 193 | #define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \ |
| 194 | ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \ |
| 195 | | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0)) |
| 196 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 197 | /* For cache simulation */ |
| 198 | typedef struct { |
| 199 | int size; /* bytes */ |
| 200 | int assoc; |
| 201 | int line_size; /* bytes */ |
| 202 | } cache_t; |
| 203 | |
| 204 | #define UNDEFINED_CACHE ((cache_t) { -1, -1, -1 }) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 205 | |
| 206 | /* --------------------------------------------------------------------- |
| 207 | Now the basic types are set up, we can haul in the kernel-interface |
| 208 | definitions. |
| 209 | ------------------------------------------------------------------ */ |
| 210 | |
| 211 | #include "./vg_kerneliface.h" |
| 212 | |
| 213 | |
| 214 | /* --------------------------------------------------------------------- |
| 215 | Command-line-settable options |
| 216 | ------------------------------------------------------------------ */ |
| 217 | |
| 218 | #define VG_CLO_SMC_NONE 0 |
| 219 | #define VG_CLO_SMC_SOME 1 |
| 220 | #define VG_CLO_SMC_ALL 2 |
| 221 | |
| 222 | #define VG_CLO_MAX_SFILES 10 |
| 223 | |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 224 | /* Should we stop collecting errors if too many appear? default: YES */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 225 | extern Bool VG_(clo_error_limit); |
sewardj | 97ced73 | 2002-03-25 00:07:36 +0000 | [diff] [blame] | 226 | /* Shall we V-check addrs (they are always A checked too): default: YES */ |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 227 | extern Bool VG_(clo_check_addrVs); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 228 | /* Enquire about whether to attach to GDB at errors? default: NO */ |
| 229 | extern Bool VG_(clo_GDB_attach); |
| 230 | /* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */ |
| 231 | extern Int VG_(sanity_level); |
| 232 | /* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */ |
| 233 | extern Int VG_(clo_verbosity); |
| 234 | /* Automatically attempt to demangle C++ names? default: YES */ |
| 235 | extern Bool VG_(clo_demangle); |
| 236 | /* Do leak check at exit? default: NO */ |
| 237 | extern Bool VG_(clo_leak_check); |
| 238 | /* In leak check, show reachable-but-not-freed blocks? default: NO */ |
| 239 | extern Bool VG_(clo_show_reachable); |
| 240 | /* How closely should we compare ExeContexts in leak records? default: 2 */ |
| 241 | extern Int VG_(clo_leak_resolution); |
| 242 | /* Round malloc sizes upwards to integral number of words? default: |
| 243 | NO */ |
| 244 | extern Bool VG_(clo_sloppy_malloc); |
sewardj | 246d466 | 2002-06-14 10:17:05 +0000 | [diff] [blame] | 245 | /* Minimum alignment in functions that don't specify alignment explicitly. |
| 246 | default: 0, i.e. use default of the machine (== 4) */ |
| 247 | extern Int VG_(clo_alignment); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 248 | /* Allow loads from partially-valid addresses? default: YES */ |
| 249 | extern Bool VG_(clo_partial_loads_ok); |
| 250 | /* Simulate child processes? default: NO */ |
| 251 | extern Bool VG_(clo_trace_children); |
| 252 | /* The file id on which we send all messages. default: 2 (stderr). */ |
| 253 | extern Int VG_(clo_logfile_fd); |
| 254 | /* Max volume of the freed blocks queue. */ |
| 255 | extern Int VG_(clo_freelist_vol); |
| 256 | /* Assume accesses immediately below %esp are due to gcc-2.96 bugs. |
| 257 | default: NO */ |
| 258 | extern Bool VG_(clo_workaround_gcc296_bugs); |
| 259 | |
| 260 | /* The number of suppression files specified. */ |
| 261 | extern Int VG_(clo_n_suppressions); |
| 262 | /* The names of the suppression files. */ |
| 263 | extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
| 264 | |
| 265 | /* Single stepping? default: NO */ |
| 266 | extern Bool VG_(clo_single_step); |
| 267 | /* Code improvement? default: YES */ |
| 268 | extern Bool VG_(clo_optimise); |
| 269 | /* Memory-check instrumentation? default: YES */ |
| 270 | extern Bool VG_(clo_instrument); |
| 271 | /* DEBUG: clean up instrumented code? default: YES */ |
| 272 | extern Bool VG_(clo_cleanup); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 273 | /* Cache simulation instrumentation? default: NO */ |
| 274 | extern Bool VG_(clo_cachesim); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 275 | /* I1 cache configuration. default: undefined */ |
| 276 | extern cache_t VG_(clo_I1_cache); |
| 277 | /* D1 cache configuration. default: undefined */ |
| 278 | extern cache_t VG_(clo_D1_cache); |
| 279 | /* L2 cache configuration. default: undefined */ |
| 280 | extern cache_t VG_(clo_L2_cache); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 281 | /* SMC write checks? default: SOME (1,2,4 byte movs to mem) */ |
| 282 | extern Int VG_(clo_smc_check); |
| 283 | /* DEBUG: print system calls? default: NO */ |
| 284 | extern Bool VG_(clo_trace_syscalls); |
| 285 | /* DEBUG: print signal details? default: NO */ |
| 286 | extern Bool VG_(clo_trace_signals); |
| 287 | /* DEBUG: print symtab details? default: NO */ |
| 288 | extern Bool VG_(clo_trace_symtab); |
| 289 | /* DEBUG: print malloc details? default: NO */ |
| 290 | extern Bool VG_(clo_trace_malloc); |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 291 | /* DEBUG: print thread scheduling events? default: NO */ |
| 292 | extern Bool VG_(clo_trace_sched); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 293 | /* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1 |
| 294 | (some), 2 (all) */ |
| 295 | extern Int VG_(clo_trace_pthread_level); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 296 | /* Stop after this many basic blocks. default: Infinity. */ |
| 297 | extern ULong VG_(clo_stop_after); |
| 298 | /* Display gory details for the k'th most popular error. default: |
| 299 | Infinity. */ |
| 300 | extern Int VG_(clo_dump_error); |
| 301 | /* Number of parents of a backtrace. Default: 8. */ |
| 302 | extern Int VG_(clo_backtrace_size); |
sewardj | 3984b85 | 2002-05-12 03:00:17 +0000 | [diff] [blame] | 303 | /* Engage miscellaneous wierd hacks needed for some progs. */ |
sewardj | 8d365b5 | 2002-05-12 10:52:16 +0000 | [diff] [blame] | 304 | extern Char* VG_(clo_weird_hacks); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 305 | |
| 306 | |
| 307 | /* --------------------------------------------------------------------- |
| 308 | Debugging and profiling stuff |
| 309 | ------------------------------------------------------------------ */ |
| 310 | |
| 311 | /* No, really. I _am_ that strange. */ |
| 312 | #define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn) |
| 313 | |
| 314 | /* Tools for building messages from multiple parts. */ |
| 315 | typedef |
| 316 | enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg } |
| 317 | VgMsgKind; |
| 318 | |
| 319 | extern void VG_(start_msg) ( VgMsgKind kind ); |
| 320 | extern void VG_(add_to_msg) ( Char* format, ... ); |
| 321 | extern void VG_(end_msg) ( void ); |
| 322 | |
| 323 | /* Send a simple, single-part message. */ |
| 324 | extern void VG_(message) ( VgMsgKind kind, Char* format, ... ); |
| 325 | |
| 326 | /* Create a logfile into which messages can be dumped. */ |
| 327 | extern void VG_(startup_logging) ( void ); |
| 328 | extern void VG_(shutdown_logging) ( void ); |
| 329 | |
| 330 | |
| 331 | /* Profiling stuff */ |
| 332 | #ifdef VG_PROFILE |
| 333 | |
| 334 | #define VGP_M_STACK 10 |
| 335 | |
sewardj | 671ff54 | 2002-05-07 09:25:30 +0000 | [diff] [blame] | 336 | #define VGP_M_CCS 26 /* == the # of elems in VGP_LIST */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 337 | #define VGP_LIST \ |
sewardj | 671ff54 | 2002-05-07 09:25:30 +0000 | [diff] [blame] | 338 | VGP_PAIR(VgpUnc=0, "unclassified"), \ |
| 339 | VGP_PAIR(VgpRun, "running"), \ |
| 340 | VGP_PAIR(VgpSched, "scheduler"), \ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 341 | VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \ |
| 342 | VGP_PAIR(VgpCliMalloc, "client malloc/free"), \ |
| 343 | VGP_PAIR(VgpTranslate, "translate-main"), \ |
| 344 | VGP_PAIR(VgpToUCode, "to-ucode"), \ |
| 345 | VGP_PAIR(VgpFromUcode, "from-ucode"), \ |
| 346 | VGP_PAIR(VgpImprove, "improve"), \ |
| 347 | VGP_PAIR(VgpInstrument, "instrument"), \ |
| 348 | VGP_PAIR(VgpCleanup, "cleanup"), \ |
| 349 | VGP_PAIR(VgpRegAlloc, "reg-alloc"), \ |
| 350 | VGP_PAIR(VgpDoLRU, "do-lru"), \ |
| 351 | VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \ |
| 352 | VGP_PAIR(VgpInitAudit, "init-mem-audit"), \ |
| 353 | VGP_PAIR(VgpExeContext, "exe-context"), \ |
| 354 | VGP_PAIR(VgpReadSyms, "read-syms"), \ |
| 355 | VGP_PAIR(VgpAddToT, "add-to-transtab"), \ |
| 356 | VGP_PAIR(VgpSARP, "set-addr-range-perms"), \ |
| 357 | VGP_PAIR(VgpSyscall, "syscall wrapper"), \ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 358 | VGP_PAIR(VgpCacheInstrument, "cache instrument"), \ |
| 359 | VGP_PAIR(VgpCacheGetBBCC,"cache get BBCC"), \ |
| 360 | VGP_PAIR(VgpCacheSimulate, "cache simulate"), \ |
| 361 | VGP_PAIR(VgpCacheDump, "cache stats dump"), \ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 362 | VGP_PAIR(VgpSpare1, "spare 1"), \ |
| 363 | VGP_PAIR(VgpSpare2, "spare 2") |
| 364 | |
| 365 | #define VGP_PAIR(enumname,str) enumname |
| 366 | typedef enum { VGP_LIST } VgpCC; |
| 367 | #undef VGP_PAIR |
| 368 | |
| 369 | extern void VGP_(init_profiling) ( void ); |
| 370 | extern void VGP_(done_profiling) ( void ); |
| 371 | extern void VGP_(pushcc) ( VgpCC ); |
| 372 | extern void VGP_(popcc) ( void ); |
| 373 | |
| 374 | #define VGP_PUSHCC(cc) VGP_(pushcc)(cc) |
| 375 | #define VGP_POPCC VGP_(popcc)() |
| 376 | |
| 377 | #else |
| 378 | |
| 379 | #define VGP_PUSHCC(cc) /* */ |
| 380 | #define VGP_POPCC /* */ |
| 381 | |
| 382 | #endif /* VG_PROFILE */ |
| 383 | |
| 384 | |
| 385 | /* --------------------------------------------------------------------- |
| 386 | Exports of vg_malloc2.c |
| 387 | ------------------------------------------------------------------ */ |
| 388 | |
| 389 | /* Allocation arenas. |
| 390 | SYMTAB is for Valgrind's symbol table storage. |
| 391 | CLIENT is for the client's mallocs/frees. |
| 392 | DEMANGLE is for the C++ demangler. |
| 393 | EXECTXT is for storing ExeContexts. |
| 394 | ERRCTXT is for storing ErrContexts. |
| 395 | PRIVATE is for Valgrind general stuff. |
| 396 | TRANSIENT is for very short-term use. It should be empty |
| 397 | in between uses. |
| 398 | When adding a new arena, remember also to add it |
| 399 | to ensure_mm_init(). |
| 400 | */ |
| 401 | typedef Int ArenaId; |
| 402 | |
| 403 | #define VG_N_ARENAS 7 |
| 404 | |
| 405 | #define VG_AR_PRIVATE 0 /* :: ArenaId */ |
| 406 | #define VG_AR_SYMTAB 1 /* :: ArenaId */ |
| 407 | #define VG_AR_CLIENT 2 /* :: ArenaId */ |
| 408 | #define VG_AR_DEMANGLE 3 /* :: ArenaId */ |
| 409 | #define VG_AR_EXECTXT 4 /* :: ArenaId */ |
| 410 | #define VG_AR_ERRCTXT 5 /* :: ArenaId */ |
| 411 | #define VG_AR_TRANSIENT 6 /* :: ArenaId */ |
| 412 | |
| 413 | extern void* VG_(malloc) ( ArenaId arena, Int nbytes ); |
| 414 | extern void VG_(free) ( ArenaId arena, void* ptr ); |
| 415 | extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes ); |
| 416 | extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size ); |
| 417 | extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB, |
| 418 | Int req_pszB ); |
| 419 | |
| 420 | extern void VG_(mallocSanityCheckArena) ( ArenaId arena ); |
| 421 | extern void VG_(mallocSanityCheckAll) ( void ); |
| 422 | |
| 423 | extern void VG_(show_all_arena_stats) ( void ); |
| 424 | extern Bool VG_(is_empty_arena) ( ArenaId aid ); |
| 425 | |
| 426 | |
| 427 | /* The red-zone size for the client. This can be arbitrary, but |
| 428 | unfortunately must be set at compile time. */ |
| 429 | #define VG_AR_CLIENT_REDZONE_SZW 4 |
| 430 | |
| 431 | #define VG_AR_CLIENT_REDZONE_SZB \ |
| 432 | (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD) |
| 433 | |
| 434 | |
| 435 | /* --------------------------------------------------------------------- |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 436 | Exports of vg_clientfuns.c |
| 437 | ------------------------------------------------------------------ */ |
| 438 | |
| 439 | /* This doesn't export code or data that valgrind.so needs to link |
| 440 | against. However, the scheduler does need to know the following |
| 441 | request codes. A few, publically-visible, request codes are also |
| 442 | defined in valgrind.h. */ |
| 443 | |
| 444 | #define VG_USERREQ__MALLOC 0x2001 |
| 445 | #define VG_USERREQ__BUILTIN_NEW 0x2002 |
| 446 | #define VG_USERREQ__BUILTIN_VEC_NEW 0x2003 |
| 447 | |
| 448 | #define VG_USERREQ__FREE 0x2004 |
| 449 | #define VG_USERREQ__BUILTIN_DELETE 0x2005 |
| 450 | #define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006 |
| 451 | |
| 452 | #define VG_USERREQ__CALLOC 0x2007 |
| 453 | #define VG_USERREQ__REALLOC 0x2008 |
| 454 | #define VG_USERREQ__MEMALIGN 0x2009 |
| 455 | |
| 456 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 457 | /* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn |
| 458 | MUST NOT return -- ever. Eventually it will do either __QUIT or |
| 459 | __WAIT_JOINER. */ |
| 460 | #define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001 |
| 461 | |
| 462 | /* ( no-args ): calling thread disappears from the system forever. |
| 463 | Reclaim resources. */ |
| 464 | #define VG_USERREQ__QUIT 0x3002 |
| 465 | |
| 466 | /* ( void* ): calling thread waits for joiner and returns the void* to |
| 467 | it. */ |
| 468 | #define VG_USERREQ__WAIT_JOINER 0x3003 |
| 469 | |
| 470 | /* ( ThreadId, void** ): wait to join a thread. */ |
| 471 | #define VG_USERREQ__PTHREAD_JOIN 0x3004 |
| 472 | |
| 473 | /* Set cancellation state and type for this thread. */ |
| 474 | #define VG_USERREQ__SET_CANCELSTATE 0x3005 |
| 475 | #define VG_USERREQ__SET_CANCELTYPE 0x3006 |
| 476 | |
| 477 | /* ( no-args ): Test if we are at a cancellation point. */ |
| 478 | #define VG_USERREQ__TESTCANCEL 0x3007 |
| 479 | |
| 480 | /* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call |
| 481 | with this arg to indicate that a cancel is now pending for the |
| 482 | specified thread. */ |
| 483 | #define VG_USERREQ__SET_CANCELPEND 0x3008 |
| 484 | |
| 485 | /* Set/get detach state for this thread. */ |
| 486 | #define VG_USERREQ__SET_OR_GET_DETACH 0x3009 |
| 487 | |
| 488 | #define VG_USERREQ__PTHREAD_GET_THREADID 0x300B |
| 489 | #define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C |
| 490 | #define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D |
| 491 | #define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E |
| 492 | #define VG_USERREQ__PTHREAD_COND_WAIT 0x300F |
| 493 | #define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010 |
| 494 | #define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011 |
| 495 | #define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012 |
| 496 | #define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013 |
| 497 | #define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014 |
| 498 | #define VG_USERREQ__PTHREAD_SETSPECIFIC 0x3015 |
| 499 | #define VG_USERREQ__PTHREAD_GETSPECIFIC 0x3016 |
| 500 | #define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017 |
| 501 | #define VG_USERREQ__PTHREAD_SIGMASK 0x3018 |
| 502 | #define VG_USERREQ__SIGWAIT 0x3019 |
| 503 | #define VG_USERREQ__PTHREAD_KILL 0x301A |
| 504 | #define VG_USERREQ__PTHREAD_YIELD 0x301B |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 505 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 506 | #define VG_USERREQ__CLEANUP_PUSH 0x3020 |
| 507 | #define VG_USERREQ__CLEANUP_POP 0x3021 |
sewardj | 870497a | 2002-05-29 01:06:47 +0000 | [diff] [blame] | 508 | #define VG_USERREQ__GET_KEY_D_AND_S 0x3022 |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 509 | |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 510 | #define VG_USERREQ__NUKE_OTHER_THREADS 0x3023 |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 511 | |
| 512 | /* Ask how many signal handler returns have happened to this |
| 513 | thread. */ |
sewardj | 9a2224b | 2002-06-19 10:17:40 +0000 | [diff] [blame] | 514 | #define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024 |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 515 | |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 516 | /* Get/set entries for a thread's pthread_atfork stack. */ |
| 517 | #define VG_USERREQ__SET_FHSTACK_USED 0x3025 |
| 518 | #define VG_USERREQ__GET_FHSTACK_USED 0x3026 |
| 519 | #define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027 |
| 520 | #define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028 |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 521 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 522 | /* Cosmetic ... */ |
| 523 | #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101 |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 524 | /* Log a pthread error from client-space. Cosmetic. */ |
| 525 | #define VG_USERREQ__PTHREAD_ERROR 0x3102 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 526 | |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 527 | /* |
| 528 | In vg_constants.h: |
| 529 | #define VG_USERREQ__SIGNAL_RETURNS 0x4001 |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 530 | */ |
| 531 | |
| 532 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 533 | /* --------------------------------------------------------------------- |
| 534 | Constants pertaining to the simulated CPU state, VG_(baseBlock), |
| 535 | which need to go here to avoid ugly circularities. |
| 536 | ------------------------------------------------------------------ */ |
| 537 | |
| 538 | /* How big is the saved FPU state? */ |
| 539 | #define VG_SIZE_OF_FPUSTATE 108 |
| 540 | /* ... and in words ... */ |
| 541 | #define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4) |
| 542 | |
| 543 | |
| 544 | /* --------------------------------------------------------------------- |
| 545 | Exports of vg_scheduler.c |
| 546 | ------------------------------------------------------------------ */ |
| 547 | |
| 548 | /* ThreadIds are simply indices into the vg_threads[] array. */ |
| 549 | typedef |
| 550 | UInt |
| 551 | ThreadId; |
| 552 | |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 553 | /* Special magic value for an invalid ThreadId. It corresponds to |
| 554 | LinuxThreads using zero as the initial value for |
| 555 | pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */ |
| 556 | #define VG_INVALID_THREADID ((ThreadId)(0)) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 557 | |
| 558 | typedef |
| 559 | enum { |
| 560 | VgTs_Empty, /* this slot is not in use */ |
| 561 | VgTs_Runnable, /* waiting to be scheduled */ |
| 562 | VgTs_WaitJoiner, /* waiting for someone to do join on me */ |
| 563 | VgTs_WaitJoinee, /* waiting for the thread I did join on */ |
| 564 | VgTs_WaitFD, /* waiting for I/O completion on a fd */ |
| 565 | VgTs_WaitMX, /* waiting on a mutex */ |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 566 | VgTs_WaitCV, /* waiting on a condition variable */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 567 | VgTs_WaitSIG, /* waiting due to sigwait() */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 568 | VgTs_Sleeping /* sleeping for a while */ |
| 569 | } |
| 570 | ThreadStatus; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 571 | |
| 572 | /* An entry in a threads's cleanup stack. */ |
| 573 | typedef |
| 574 | struct { |
| 575 | void (*fn)(void*); |
| 576 | void* arg; |
| 577 | } |
| 578 | CleanupEntry; |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 579 | |
| 580 | /* An entry in a thread's fork-handler stack. */ |
| 581 | typedef |
| 582 | struct { |
| 583 | void (*prepare)(void); |
| 584 | void (*parent)(void); |
| 585 | void (*child)(void); |
| 586 | } |
| 587 | ForkHandlerEntry; |
| 588 | |
| 589 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 590 | typedef |
| 591 | struct { |
sewardj | 6072c36 | 2002-04-19 14:40:57 +0000 | [diff] [blame] | 592 | /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED. |
| 593 | The thread identity is simply the index in vg_threads[]. |
| 594 | ThreadId == 1 is the root thread and has the special property |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 595 | that we don't try and allocate or deallocate its stack. For |
| 596 | convenience of generating error message, we also put the |
| 597 | ThreadId in this tid field, but be aware that it should |
sewardj | 604ec3c | 2002-04-18 22:38:41 +0000 | [diff] [blame] | 598 | ALWAYS == the index in vg_threads[]. */ |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 599 | ThreadId tid; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 600 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 601 | /* Current scheduling status. |
| 602 | |
| 603 | Complications: whenever this is set to VgTs_WaitMX, you |
| 604 | should also set .m_edx to whatever the required return value |
| 605 | is for pthread_mutex_lock / pthread_cond_timedwait for when |
| 606 | the mutex finally gets unblocked. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 607 | ThreadStatus status; |
| 608 | |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 609 | /* When .status == WaitMX, points to the mutex I am waiting for. |
| 610 | When .status == WaitCV, points to the mutex associated with |
| 611 | the condition variable indicated by the .associated_cv field. |
| 612 | In all other cases, should be NULL. */ |
| 613 | void* /* pthread_mutex_t* */ associated_mx; |
| 614 | |
| 615 | /* When .status == WaitCV, points to the condition variable I am |
| 616 | waiting for. In all other cases, should be NULL. */ |
| 617 | void* /* pthread_cond_t* */ associated_cv; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 618 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 619 | /* If VgTs_Sleeping, this is when we should wake up, measured in |
| 620 | milliseconds as supplied by VG_(read_millisecond_counter). |
| 621 | |
| 622 | If VgTs_WaitCV, this indicates the time at which |
| 623 | pthread_cond_timedwait should wake up. If == 0xFFFFFFFF, |
| 624 | this means infinitely far in the future, viz, |
| 625 | pthread_cond_wait. */ |
| 626 | UInt awaken_at; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 627 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 628 | /* If VgTs_WaitJoiner, return value, as generated by joinees. */ |
| 629 | void* joinee_retval; |
| 630 | |
| 631 | /* If VgTs_WaitJoinee, place to copy the return value to, and |
| 632 | the identity of the thread we're waiting for. */ |
| 633 | void** joiner_thread_return; |
| 634 | ThreadId joiner_jee_tid; |
| 635 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 636 | /* Whether or not detached. */ |
| 637 | Bool detached; |
| 638 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 639 | /* Cancelability state and type. */ |
| 640 | Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */ |
| 641 | Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */ |
| 642 | |
| 643 | /* Pointer to fn to call to do cancellation. Indicates whether |
| 644 | or not cancellation is pending. If NULL, not pending. Else |
| 645 | should be &thread_exit_wrapper(), indicating that |
| 646 | cancallation is pending. */ |
| 647 | void (*cancel_pend)(void*); |
| 648 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 649 | /* The cleanup stack. */ |
| 650 | Int custack_used; |
| 651 | CleanupEntry custack[VG_N_CLEANUPSTACK]; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 652 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 653 | /* thread-specific data */ |
| 654 | void* specifics[VG_N_THREAD_KEYS]; |
| 655 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 656 | /* This thread's blocked-signals mask. Semantics is that for a |
| 657 | signal to be delivered to this thread, the signal must not be |
| 658 | blocked by either the process-wide signal mask nor by this |
| 659 | one. So, if this thread is prepared to handle any signal that |
| 660 | the process as a whole is prepared to handle, this mask should |
| 661 | be made empty -- and that it is its default, starting |
| 662 | state. */ |
| 663 | vki_ksigset_t sig_mask; |
| 664 | |
| 665 | /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG, |
| 666 | is the set of signals for which we are sigwait()ing. */ |
| 667 | vki_ksigset_t sigs_waited_for; |
| 668 | |
sewardj | 9a2224b | 2002-06-19 10:17:40 +0000 | [diff] [blame] | 669 | /* Counts the number of times a signal handler for this thread |
| 670 | has returned. This makes it easy to implement pause(), by |
| 671 | polling this value, of course interspersed with nanosleeps, |
| 672 | and waiting till it changes. */ |
| 673 | UInt n_signals_returned; |
| 674 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 675 | /* Stacks. When a thread slot is freed, we don't deallocate its |
| 676 | stack; we just leave it lying around for the next use of the |
| 677 | slot. If the next use of the slot requires a larger stack, |
| 678 | only then is the old one deallocated and a new one |
| 679 | allocated. |
| 680 | |
| 681 | For the main thread (threadid == 0), this mechanism doesn't |
| 682 | apply. We don't know the size of the stack since we didn't |
| 683 | allocate it, and furthermore we never reallocate it. */ |
| 684 | |
| 685 | /* The allocated size of this thread's stack (permanently zero |
| 686 | if this is ThreadId == 0, since we didn't allocate its stack) */ |
| 687 | UInt stack_size; |
| 688 | |
| 689 | /* Address of the lowest word in this thread's stack. NULL means |
| 690 | not allocated yet. |
| 691 | */ |
| 692 | Addr stack_base; |
| 693 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 694 | /* Address of the highest legitimate word in this stack. This is |
| 695 | used for error messages only -- not critical for execution |
| 696 | correctness. Is is set for all stacks, specifically including |
| 697 | ThreadId == 0 (the main thread). */ |
| 698 | Addr stack_highest_word; |
| 699 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 700 | /* Saved machine context. */ |
| 701 | UInt m_eax; |
| 702 | UInt m_ebx; |
| 703 | UInt m_ecx; |
| 704 | UInt m_edx; |
| 705 | UInt m_esi; |
| 706 | UInt m_edi; |
| 707 | UInt m_ebp; |
| 708 | UInt m_esp; |
| 709 | UInt m_eflags; |
| 710 | UInt m_eip; |
| 711 | UInt m_fpu[VG_SIZE_OF_FPUSTATE_W]; |
| 712 | |
| 713 | UInt sh_eax; |
| 714 | UInt sh_ebx; |
| 715 | UInt sh_ecx; |
| 716 | UInt sh_edx; |
| 717 | UInt sh_esi; |
| 718 | UInt sh_edi; |
| 719 | UInt sh_ebp; |
| 720 | UInt sh_esp; |
| 721 | UInt sh_eflags; |
| 722 | } |
| 723 | ThreadState; |
| 724 | |
| 725 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 726 | /* The thread table. */ |
| 727 | extern ThreadState VG_(threads)[VG_N_THREADS]; |
| 728 | |
| 729 | /* Check that tid is in range and denotes a non-Empty thread. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 730 | extern Bool VG_(is_valid_tid) ( ThreadId tid ); |
| 731 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 732 | /* Check that tid is in range. */ |
| 733 | extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid ); |
| 734 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 735 | /* Copy the specified thread's state into VG_(baseBlock) in |
| 736 | preparation for running it. */ |
| 737 | extern void VG_(load_thread_state)( ThreadId ); |
| 738 | |
| 739 | /* Save the specified thread's state back in VG_(baseBlock), and fill |
| 740 | VG_(baseBlock) with junk, for sanity-check reasons. */ |
| 741 | extern void VG_(save_thread_state)( ThreadId ); |
| 742 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 743 | /* And for the currently running one, if valid. */ |
| 744 | extern ThreadState* VG_(get_current_thread_state) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 745 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 746 | /* Similarly ... */ |
| 747 | extern ThreadId VG_(get_current_tid) ( void ); |
| 748 | |
| 749 | /* Which thread is this address in the stack of, if any? Used for |
| 750 | error message generation. */ |
| 751 | extern ThreadId VG_(identify_stack_addr)( Addr a ); |
| 752 | |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 753 | /* Nuke all threads except tid. */ |
| 754 | extern void VG_(nuke_all_threads_except) ( ThreadId me ); |
| 755 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 756 | |
| 757 | /* Return codes from the scheduler. */ |
| 758 | typedef |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 759 | enum { |
| 760 | VgSrc_Deadlock, /* no runnable threads and no prospect of any |
| 761 | even if we wait for a long time */ |
| 762 | VgSrc_ExitSyscall, /* client called exit(). This is the normal |
| 763 | route out. */ |
| 764 | VgSrc_BbsDone /* In a debugging run, the specified number of |
| 765 | bbs has been completed. */ |
| 766 | } |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 767 | VgSchedReturnCode; |
| 768 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 769 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 770 | /* The scheduler. */ |
| 771 | extern VgSchedReturnCode VG_(scheduler) ( void ); |
| 772 | |
| 773 | extern void VG_(scheduler_init) ( void ); |
| 774 | |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 775 | extern void VG_(pp_sched_status) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 776 | |
| 777 | /* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */ |
| 778 | extern jmp_buf VG_(scheduler_jmpbuf); |
sewardj | 872051c | 2002-07-13 12:12:56 +0000 | [diff] [blame^] | 779 | /* This says whether scheduler_jmpbuf is actually valid. Needed so |
| 780 | that our signal handler doesn't longjmp when the buffer isn't |
| 781 | actually valid. */ |
| 782 | extern Bool VG_(scheduler_jmpbuf_valid); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 783 | /* ... and if so, here's the signal which caused it to do so. */ |
| 784 | extern Int VG_(longjmpd_on_signal); |
| 785 | |
| 786 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 787 | /* Possible places where the main stack might be based. We check that |
| 788 | the initial stack, which we can't move, is allocated here. |
| 789 | VG_(scheduler_init) checks this. Andrea Archelangi's 2.4 kernels |
| 790 | have been rumoured to start stacks at 0x80000000, so that too is |
| 791 | considered. |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 792 | */ |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 793 | #define VG_STARTUP_STACK_BASE_1 (Addr)0xC0000000 |
| 794 | #define VG_STARTUP_STACK_BASE_2 (Addr)0x80000000 |
| 795 | #define VG_STARTUP_STACK_SMALLERTHAN 0x100000 /* 1024k */ |
| 796 | |
| 797 | #define VG_STACK_MATCHES_BASE(zzstack, zzbase) \ |
| 798 | ( \ |
| 799 | ((zzstack) & ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN)) \ |
| 800 | == \ |
| 801 | ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN) \ |
| 802 | ) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 803 | |
| 804 | |
| 805 | /* The red-zone size which we put at the bottom (highest address) of |
| 806 | thread stacks, for paranoia reasons. This can be arbitrary, and |
| 807 | doesn't really need to be set at compile time. */ |
| 808 | #define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4 |
| 809 | |
| 810 | #define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \ |
| 811 | (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD) |
| 812 | |
| 813 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 814 | /* Write a value to the client's %EDX (request return value register) |
| 815 | and set the shadow to indicate it is defined. */ |
| 816 | #define SET_EDX(zztid, zzval) \ |
| 817 | do { VG_(threads)[zztid].m_edx = (zzval); \ |
| 818 | VG_(threads)[zztid].sh_edx = VGM_WORD_VALID; \ |
| 819 | } while (0) |
| 820 | |
| 821 | #define SET_EAX(zztid, zzval) \ |
| 822 | do { VG_(threads)[zztid].m_eax = (zzval); \ |
| 823 | VG_(threads)[zztid].sh_eax = VGM_WORD_VALID; \ |
| 824 | } while (0) |
| 825 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 826 | |
| 827 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 828 | Exports of vg_signals.c |
| 829 | ------------------------------------------------------------------ */ |
| 830 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 831 | extern void VG_(sigstartup_actions) ( void ); |
| 832 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 833 | extern Bool VG_(deliver_signals) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 834 | extern void VG_(unblock_host_signal) ( Int sigNo ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 835 | extern void VG_(handle_SCSS_change) ( Bool force_update ); |
| 836 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 837 | |
| 838 | /* Fake system calls for signal handling. */ |
sewardj | 2342c97 | 2002-05-22 23:34:20 +0000 | [diff] [blame] | 839 | extern void VG_(do__NR_sigaltstack) ( ThreadId tid ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 840 | extern void VG_(do__NR_sigaction) ( ThreadId tid ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 841 | extern void VG_(do__NR_sigprocmask) ( ThreadId tid, |
| 842 | Int how, |
| 843 | vki_ksigset_t* set, |
| 844 | vki_ksigset_t* oldset ); |
| 845 | extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid, |
| 846 | Int how, |
| 847 | vki_ksigset_t* set, |
| 848 | vki_ksigset_t* oldset ); |
| 849 | extern void VG_(send_signal_to_thread) ( ThreadId thread, |
| 850 | Int signo ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 851 | |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 852 | extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set ); |
| 853 | |
| 854 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 855 | /* Modify the current thread's state once we have detected it is |
| 856 | returning from a signal handler. */ |
sewardj | 77e466c | 2002-04-14 02:29:29 +0000 | [diff] [blame] | 857 | extern Bool VG_(signal_returns) ( ThreadId ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 858 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 859 | /* Handy utilities to block/restore all host signals. */ |
| 860 | extern void VG_(block_all_host_signals) |
| 861 | ( /* OUT */ vki_ksigset_t* saved_mask ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 862 | extern void VG_(restore_all_host_signals) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 863 | ( /* IN */ vki_ksigset_t* saved_mask ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 864 | |
| 865 | /* --------------------------------------------------------------------- |
| 866 | Exports of vg_mylibc.c |
| 867 | ------------------------------------------------------------------ */ |
| 868 | |
| 869 | |
sewardj | fbe18b9 | 2002-05-10 00:46:59 +0000 | [diff] [blame] | 870 | #if !defined(NULL) |
| 871 | # define NULL ((void*)0) |
| 872 | #endif |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 873 | |
| 874 | extern void VG_(exit)( Int status ) |
| 875 | __attribute__ ((__noreturn__)); |
| 876 | |
| 877 | extern void VG_(printf) ( const char *format, ... ); |
| 878 | /* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */ |
| 879 | |
| 880 | extern void VG_(sprintf) ( Char* buf, Char *format, ... ); |
| 881 | |
| 882 | extern void VG_(vprintf) ( void(*send)(Char), |
| 883 | const Char *format, va_list vargs ); |
| 884 | |
| 885 | extern Bool VG_(isspace) ( Char c ); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 886 | extern Bool VG_(isdigit) ( Char c ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 887 | |
| 888 | extern Int VG_(strlen) ( const Char* str ); |
| 889 | |
| 890 | extern Long VG_(atoll) ( Char* str ); |
sewardj | a70ca3f | 2002-05-30 01:22:20 +0000 | [diff] [blame] | 891 | extern Long VG_(atoll36) ( Char* str ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 892 | |
| 893 | extern Char* VG_(strcat) ( Char* dest, const Char* src ); |
| 894 | extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n ); |
| 895 | extern Char* VG_(strpbrk) ( const Char* s, const Char* accept ); |
| 896 | |
| 897 | extern Char* VG_(strcpy) ( Char* dest, const Char* src ); |
| 898 | |
| 899 | extern Int VG_(strcmp) ( const Char* s1, const Char* s2 ); |
| 900 | extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ); |
| 901 | |
| 902 | extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax ); |
| 903 | extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax ); |
| 904 | |
| 905 | extern Char* VG_(strstr) ( const Char* haystack, Char* needle ); |
| 906 | extern Char* VG_(strchr) ( const Char* s, Char c ); |
| 907 | extern Char* VG_(strdup) ( ArenaId aid, const Char* s); |
| 908 | |
| 909 | extern Char* VG_(getenv) ( Char* name ); |
| 910 | extern Int VG_(getpid) ( void ); |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 911 | |
| 912 | extern void VG_(start_rdtsc_calibration) ( void ); |
| 913 | extern void VG_(end_rdtsc_calibration) ( void ); |
| 914 | extern UInt VG_(read_millisecond_timer) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 915 | |
| 916 | |
| 917 | extern Char VG_(toupper) ( Char c ); |
| 918 | |
| 919 | extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest ); |
| 920 | |
| 921 | extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest ); |
| 922 | |
| 923 | extern Bool VG_(stringMatch) ( Char* pat, Char* str ); |
| 924 | |
| 925 | |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 926 | #define VG__STRING(__str) #__str |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 927 | |
| 928 | /* Asserts are permanently enabled. Hurrah! */ |
| 929 | #define vg_assert(expr) \ |
| 930 | ((void) ((expr) ? 0 : \ |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 931 | (VG_(assert_fail) (VG__STRING(expr), \ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 932 | __FILE__, __LINE__, \ |
| 933 | __PRETTY_FUNCTION__), 0))) |
| 934 | |
| 935 | extern void VG_(assert_fail) ( Char* expr, Char* file, |
| 936 | Int line, Char* fn ) |
| 937 | __attribute__ ((__noreturn__)); |
| 938 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 939 | /* Reading and writing files. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 940 | extern Int VG_(open_read) ( Char* pathname ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 941 | extern Int VG_(open_write) ( Char* pathname ); |
| 942 | extern Int VG_(create_and_write) ( Char* pathname ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 943 | extern void VG_(close) ( Int fd ); |
| 944 | extern Int VG_(read) ( Int fd, void* buf, Int count); |
| 945 | extern Int VG_(write) ( Int fd, void* buf, Int count); |
sewardj | b358620 | 2002-05-09 17:38:13 +0000 | [diff] [blame] | 946 | extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 947 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 948 | extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); |
| 949 | |
| 950 | extern Int VG_(select)( Int n, |
| 951 | vki_fd_set* readfds, |
| 952 | vki_fd_set* writefds, |
| 953 | vki_fd_set* exceptfds, |
| 954 | struct vki_timeval * timeout ); |
| 955 | extern Int VG_(nanosleep)( const struct vki_timespec *req, |
| 956 | struct vki_timespec *rem ); |
| 957 | |
| 958 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 959 | /* mmap-ery ... */ |
| 960 | extern void* VG_(mmap)( void* start, UInt length, |
| 961 | UInt prot, UInt flags, UInt fd, UInt offset ); |
| 962 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 963 | extern Int VG_(munmap)( void* start, Int length ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 964 | |
sewardj | b358620 | 2002-05-09 17:38:13 +0000 | [diff] [blame] | 965 | extern void* VG_(brk) ( void* end_data_segment ); |
| 966 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 967 | |
| 968 | /* Print a (panic) message, and abort. */ |
| 969 | extern void VG_(panic) ( Char* str ) |
| 970 | __attribute__ ((__noreturn__)); |
| 971 | |
| 972 | /* Get memory by anonymous mmap. */ |
sewardj | e904795 | 2002-06-05 20:28:33 +0000 | [diff] [blame] | 973 | extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who ); |
sewardj | e6a2524 | 2002-04-21 22:03:07 +0000 | [diff] [blame] | 974 | |
| 975 | /* Crude stand-in for the glibc system() call. */ |
| 976 | extern Int VG_(system) ( Char* cmd ); |
| 977 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 978 | |
| 979 | /* Signal stuff. Note that these use the vk_ (kernel) structure |
| 980 | definitions, which are different in places from those that glibc |
| 981 | defines. Since we're operating right at the kernel interface, |
| 982 | glibc's view of the world is entirely irrelevant. */ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 983 | |
| 984 | /* --- Signal set ops --- */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 985 | extern Int VG_(ksigfillset)( vki_ksigset_t* set ); |
| 986 | extern Int VG_(ksigemptyset)( vki_ksigset_t* set ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 987 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 988 | extern Bool VG_(kisfullsigset)( vki_ksigset_t* set ); |
| 989 | extern Bool VG_(kisemptysigset)( vki_ksigset_t* set ); |
| 990 | |
| 991 | extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum ); |
| 992 | extern Int VG_(ksigdelset)( vki_ksigset_t* set, Int signum ); |
| 993 | extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum ); |
| 994 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 995 | extern void VG_(ksigaddset_from_set)( vki_ksigset_t* dst, |
| 996 | vki_ksigset_t* src ); |
| 997 | extern void VG_(ksigdelset_from_set)( vki_ksigset_t* dst, |
| 998 | vki_ksigset_t* src ); |
| 999 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1000 | /* --- Mess with the kernel's sig state --- */ |
| 1001 | extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set, |
| 1002 | vki_ksigset_t* oldset ); |
| 1003 | extern Int VG_(ksigaction) ( Int signum, |
| 1004 | const vki_ksigaction* act, |
| 1005 | vki_ksigaction* oldact ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1006 | |
| 1007 | extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int)); |
| 1008 | |
| 1009 | extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss ); |
| 1010 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1011 | extern Int VG_(kill)( Int pid, Int signo ); |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 1012 | extern Int VG_(sigpending) ( vki_ksigset_t* set ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1013 | |
| 1014 | |
| 1015 | /* --------------------------------------------------------------------- |
| 1016 | Definitions for the JITter (vg_translate.c, vg_to_ucode.c, |
| 1017 | vg_from_ucode.c). |
| 1018 | ------------------------------------------------------------------ */ |
| 1019 | |
| 1020 | /* Tags which describe what operands are. */ |
| 1021 | typedef |
| 1022 | enum { TempReg=0, ArchReg=1, RealReg=2, |
| 1023 | SpillNo=3, Literal=4, Lit16=5, |
| 1024 | NoValue=6 } |
| 1025 | Tag; |
| 1026 | |
| 1027 | |
| 1028 | /* Microinstruction opcodes. */ |
| 1029 | typedef |
| 1030 | enum { |
| 1031 | NOP, |
| 1032 | GET, |
| 1033 | PUT, |
| 1034 | LOAD, |
| 1035 | STORE, |
| 1036 | MOV, |
| 1037 | CMOV, /* Used for cmpxchg and cmov */ |
| 1038 | WIDEN, |
| 1039 | JMP, |
| 1040 | |
| 1041 | /* Read/write the %EFLAGS register into a TempReg. */ |
| 1042 | GETF, PUTF, |
| 1043 | |
| 1044 | ADD, ADC, AND, OR, XOR, SUB, SBB, |
| 1045 | SHL, SHR, SAR, ROL, ROR, RCL, RCR, |
| 1046 | NOT, NEG, INC, DEC, BSWAP, |
| 1047 | CC2VAL, |
| 1048 | |
| 1049 | /* Not strictly needed, but useful for making better |
| 1050 | translations of address calculations. */ |
| 1051 | LEA1, /* reg2 := const + reg1 */ |
| 1052 | LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */ |
| 1053 | |
| 1054 | /* not for translating x86 calls -- only to call helpers */ |
| 1055 | CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences |
| 1056 | for CALLM. */ |
| 1057 | PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */ |
| 1058 | CALLM, /* call to a machine-code helper */ |
| 1059 | |
| 1060 | /* Hack for translating string (REP-) insns. Jump to literal if |
| 1061 | TempReg/RealReg is zero. */ |
| 1062 | JIFZ, |
| 1063 | |
| 1064 | /* FPU ops which read/write mem or don't touch mem at all. */ |
| 1065 | FPU_R, |
| 1066 | FPU_W, |
| 1067 | FPU, |
| 1068 | |
| 1069 | /* Advance the simulated %eip by some small (< 128) number. */ |
| 1070 | INCEIP, |
| 1071 | |
| 1072 | /* uinstrs which are not needed for mere translation of x86 code, |
| 1073 | only for instrumentation of it. */ |
| 1074 | LOADV, |
| 1075 | STOREV, |
| 1076 | GETV, |
| 1077 | PUTV, |
| 1078 | TESTV, |
| 1079 | SETV, |
| 1080 | /* Get/set the v-bit (and it is only one bit) for the simulated |
| 1081 | %eflags register. */ |
| 1082 | GETVF, |
| 1083 | PUTVF, |
| 1084 | |
| 1085 | /* Do a unary or binary tag op. Only for post-instrumented |
| 1086 | code. For TAG1, first and only arg is a TempReg, and is both |
| 1087 | arg and result reg. For TAG2, first arg is src, second is |
| 1088 | dst, in the normal way; both are TempRegs. In both cases, |
| 1089 | 3rd arg is a RiCHelper with a Lit16 tag. This indicates |
| 1090 | which tag op to do. */ |
| 1091 | TAG1, |
| 1092 | TAG2 |
| 1093 | } |
| 1094 | Opcode; |
| 1095 | |
| 1096 | |
| 1097 | /* Condition codes, observing the Intel encoding. CondAlways is an |
| 1098 | extra. */ |
| 1099 | typedef |
| 1100 | enum { |
| 1101 | CondO = 0, /* overflow */ |
| 1102 | CondNO = 1, /* no overflow */ |
| 1103 | CondB = 2, /* below */ |
| 1104 | CondNB = 3, /* not below */ |
| 1105 | CondZ = 4, /* zero */ |
| 1106 | CondNZ = 5, /* not zero */ |
| 1107 | CondBE = 6, /* below or equal */ |
| 1108 | CondNBE = 7, /* not below or equal */ |
| 1109 | CondS = 8, /* negative */ |
| 1110 | ConsNS = 9, /* not negative */ |
| 1111 | CondP = 10, /* parity even */ |
| 1112 | CondNP = 11, /* not parity even */ |
| 1113 | CondL = 12, /* jump less */ |
| 1114 | CondNL = 13, /* not less */ |
| 1115 | CondLE = 14, /* less or equal */ |
| 1116 | CondNLE = 15, /* not less or equal */ |
| 1117 | CondAlways = 16 /* Jump always */ |
| 1118 | } |
| 1119 | Condcode; |
| 1120 | |
| 1121 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1122 | /* Descriptions of additional properties of *unconditional* jumps. */ |
| 1123 | typedef |
| 1124 | enum { |
| 1125 | JmpBoring=0, /* boring unconditional jump */ |
| 1126 | JmpCall=1, /* jump due to an x86 call insn */ |
| 1127 | JmpRet=2, /* jump due to an x86 ret insn */ |
| 1128 | JmpSyscall=3, /* do a system call, then jump */ |
| 1129 | JmpClientReq=4 /* do a client request, then jump */ |
| 1130 | } |
| 1131 | JmpKind; |
| 1132 | |
| 1133 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1134 | /* Flags. User-level code can only read/write O(verflow), S(ign), |
| 1135 | Z(ero), A(ux-carry), C(arry), P(arity), and may also write |
| 1136 | D(irection). That's a total of 7 flags. A FlagSet is a bitset, |
| 1137 | thusly: |
| 1138 | 76543210 |
| 1139 | DOSZACP |
| 1140 | and bit 7 must always be zero since it is unused. |
| 1141 | */ |
| 1142 | typedef UChar FlagSet; |
| 1143 | |
| 1144 | #define FlagD (1<<6) |
| 1145 | #define FlagO (1<<5) |
| 1146 | #define FlagS (1<<4) |
| 1147 | #define FlagZ (1<<3) |
| 1148 | #define FlagA (1<<2) |
| 1149 | #define FlagC (1<<1) |
| 1150 | #define FlagP (1<<0) |
| 1151 | |
| 1152 | #define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP) |
| 1153 | #define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP) |
| 1154 | #define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP) |
| 1155 | #define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP) |
| 1156 | #define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP) |
| 1157 | #define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP) |
sewardj | 4a7456e | 2002-03-24 13:52:19 +0000 | [diff] [blame] | 1158 | #define FlagsZCP ( FlagZ | FlagC | FlagP) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1159 | #define FlagsOC (FlagO | FlagC ) |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 1160 | #define FlagsAC ( FlagA | FlagC ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1161 | |
| 1162 | #define FlagsALL (FlagsOSZACP | FlagD) |
| 1163 | #define FlagsEmpty (FlagSet)0 |
| 1164 | |
| 1165 | #define VG_IS_FLAG_SUBSET(set1,set2) \ |
| 1166 | (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) ) |
| 1167 | |
| 1168 | #define VG_UNION_FLAG_SETS(set1,set2) \ |
| 1169 | ( ((FlagSet)set1) | ((FlagSet)set2) ) |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | /* A Micro (u)-instruction. */ |
| 1174 | typedef |
| 1175 | struct { |
| 1176 | /* word 1 */ |
| 1177 | UInt lit32; /* 32-bit literal */ |
| 1178 | |
| 1179 | /* word 2 */ |
| 1180 | UShort val1; /* first operand */ |
| 1181 | UShort val2; /* second operand */ |
| 1182 | |
| 1183 | /* word 3 */ |
| 1184 | UShort val3; /* third operand */ |
| 1185 | UChar opcode; /* opcode */ |
| 1186 | UChar size; /* data transfer size */ |
| 1187 | |
| 1188 | /* word 4 */ |
| 1189 | FlagSet flags_r; /* :: FlagSet */ |
| 1190 | FlagSet flags_w; /* :: FlagSet */ |
| 1191 | UChar tag1:4; /* first operand tag */ |
| 1192 | UChar tag2:4; /* second operand tag */ |
| 1193 | UChar tag3:4; /* third operand tag */ |
| 1194 | UChar extra4b:4; /* Spare field, used by WIDEN for src |
| 1195 | -size, and by LEA2 for scale |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1196 | (1,2,4 or 8), and by unconditional JMPs for |
| 1197 | orig x86 instr size if --cachesim=yes */ |
| 1198 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1199 | |
| 1200 | /* word 5 */ |
| 1201 | UChar cond; /* condition, for jumps */ |
| 1202 | Bool smc_check:1; /* do a smc test, if writes memory. */ |
| 1203 | Bool signed_widen:1; /* signed or unsigned WIDEN ? */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1204 | JmpKind jmpkind:3; /* additional properties of unconditional JMP */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1205 | } |
| 1206 | UInstr; |
| 1207 | |
| 1208 | |
| 1209 | /* Expandable arrays of uinstrs. */ |
| 1210 | typedef |
| 1211 | struct { |
| 1212 | Int used; |
| 1213 | Int size; |
| 1214 | UInstr* instrs; |
| 1215 | Int nextTemp; |
| 1216 | } |
| 1217 | UCodeBlock; |
| 1218 | |
| 1219 | /* Refer to `the last instruction stuffed in', including as an |
| 1220 | lvalue. */ |
| 1221 | #define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1] |
| 1222 | |
| 1223 | /* An invalid temporary number :-) */ |
| 1224 | #define INVALID_TEMPREG 999999999 |
| 1225 | |
| 1226 | |
| 1227 | /* --------------------------------------------------------------------- |
| 1228 | Exports of vg_demangle.c |
| 1229 | ------------------------------------------------------------------ */ |
| 1230 | |
| 1231 | extern void VG_(demangle) ( Char* orig, Char* result, Int result_size ); |
| 1232 | |
| 1233 | |
| 1234 | /* --------------------------------------------------------------------- |
| 1235 | Exports of vg_from_ucode.c |
| 1236 | ------------------------------------------------------------------ */ |
| 1237 | |
| 1238 | extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes ); |
| 1239 | |
| 1240 | |
| 1241 | /* --------------------------------------------------------------------- |
| 1242 | Exports of vg_to_ucode.c |
| 1243 | ------------------------------------------------------------------ */ |
| 1244 | |
| 1245 | extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 ); |
| 1246 | extern Char* VG_(nameOfIntReg) ( Int size, Int reg ); |
| 1247 | extern Char VG_(nameOfIntSize) ( Int size ); |
| 1248 | extern UInt VG_(extend_s_8to32) ( UInt x ); |
| 1249 | extern Int VG_(getNewTemp) ( UCodeBlock* cb ); |
| 1250 | extern Int VG_(getNewShadow) ( UCodeBlock* cb ); |
| 1251 | |
| 1252 | #define SHADOW(tempreg) ((tempreg)+1) |
| 1253 | |
| 1254 | |
| 1255 | /* --------------------------------------------------------------------- |
| 1256 | Exports of vg_translate.c |
| 1257 | ------------------------------------------------------------------ */ |
| 1258 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1259 | extern void VG_(translate) ( ThreadState* tst, |
| 1260 | Addr orig_addr, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1261 | UInt* orig_size, |
| 1262 | Addr* trans_addr, |
| 1263 | UInt* trans_size ); |
| 1264 | |
| 1265 | extern void VG_(emptyUInstr) ( UInstr* u ); |
| 1266 | extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz ); |
| 1267 | extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz, |
| 1268 | Tag tag1, UInt val1 ); |
| 1269 | extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz, |
| 1270 | Tag tag1, UInt val1, |
| 1271 | Tag tag2, UInt val2 ); |
| 1272 | extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz, |
| 1273 | Tag tag1, UInt val1, |
| 1274 | Tag tag2, UInt val2, |
| 1275 | Tag tag3, UInt val3 ); |
| 1276 | extern void VG_(setFlagRW) ( UInstr* u, |
| 1277 | FlagSet fr, FlagSet fw ); |
| 1278 | |
| 1279 | extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 ); |
| 1280 | extern Bool VG_(anyFlagUse) ( UInstr* u ); |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | extern void VG_(ppUInstr) ( Int instrNo, UInstr* u ); |
| 1285 | extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title ); |
| 1286 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1287 | extern UCodeBlock* VG_(allocCodeBlock) ( void ); |
| 1288 | extern void VG_(freeCodeBlock) ( UCodeBlock* cb ); |
| 1289 | extern void VG_(copyUInstr) ( UCodeBlock* cb, UInstr* instr ); |
| 1290 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1291 | extern Char* VG_(nameCondcode) ( Condcode cond ); |
| 1292 | extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u ); |
| 1293 | extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb ); |
| 1294 | extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc ); |
| 1295 | extern Int VG_(rankToRealRegNo) ( Int rank ); |
| 1296 | |
| 1297 | extern void* VG_(jitmalloc) ( Int nbytes ); |
| 1298 | extern void VG_(jitfree) ( void* ptr ); |
| 1299 | |
| 1300 | |
| 1301 | /* --------------------------------------------------------------------- |
| 1302 | Exports of vg_execontext.c. |
| 1303 | ------------------------------------------------------------------ */ |
| 1304 | |
| 1305 | /* Records the PC and a bit of the call chain. The first 4 %eip |
| 1306 | values are used in comparisons do remove duplicate errors, and for |
| 1307 | comparing against suppression specifications. The rest are purely |
| 1308 | informational (but often important). */ |
| 1309 | |
| 1310 | typedef |
| 1311 | struct _ExeContextRec { |
| 1312 | struct _ExeContextRec * next; |
| 1313 | /* The size of this array is VG_(clo_backtrace_size); at least |
| 1314 | 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip, |
| 1315 | [1] is its caller, [2] is the caller of [1], etc. */ |
| 1316 | Addr eips[0]; |
| 1317 | } |
| 1318 | ExeContext; |
| 1319 | |
| 1320 | |
| 1321 | /* Initialise the ExeContext storage mechanism. */ |
| 1322 | extern void VG_(init_ExeContext_storage) ( void ); |
| 1323 | |
| 1324 | /* Print stats (informational only). */ |
| 1325 | extern void VG_(show_ExeContext_stats) ( void ); |
| 1326 | |
| 1327 | |
| 1328 | /* Take a snapshot of the client's stack. Search our collection of |
| 1329 | ExeContexts to see if we already have it, and if not, allocate a |
| 1330 | new one. Either way, return a pointer to the context. */ |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1331 | extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame, |
| 1332 | Addr eip, Addr ebp ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1333 | |
| 1334 | /* Print an ExeContext. */ |
| 1335 | extern void VG_(pp_ExeContext) ( ExeContext* ); |
| 1336 | |
| 1337 | /* Compare two ExeContexts, just comparing the top two callers. */ |
| 1338 | extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 ); |
| 1339 | |
| 1340 | /* Compare two ExeContexts, just comparing the top four callers. */ |
| 1341 | extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 ); |
| 1342 | |
| 1343 | /* Compare two ExeContexts, comparing all callers. */ |
| 1344 | extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 ); |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | /* --------------------------------------------------------------------- |
| 1349 | Exports of vg_errcontext.c. |
| 1350 | ------------------------------------------------------------------ */ |
| 1351 | |
| 1352 | extern void VG_(load_suppressions) ( void ); |
| 1353 | extern void VG_(show_all_errors) ( void ); |
| 1354 | extern void VG_(record_value_error) ( Int size ); |
sewardj | aabd5ad | 2002-04-19 15:43:37 +0000 | [diff] [blame] | 1355 | extern void VG_(record_free_error) ( ThreadState* tst, Addr a ); |
| 1356 | extern void VG_(record_freemismatch_error) ( ThreadState* tst, Addr a ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1357 | extern void VG_(record_address_error) ( Addr a, Int size, |
| 1358 | Bool isWrite ); |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1359 | |
| 1360 | extern void VG_(record_jump_error) ( ThreadState* tst, Addr a ); |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1361 | |
| 1362 | extern void VG_(record_param_err) ( ThreadState* tst, |
| 1363 | Addr a, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1364 | Bool isWriteLack, |
| 1365 | Char* msg ); |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1366 | extern void VG_(record_user_err) ( ThreadState* tst, |
| 1367 | Addr a, Bool isWriteLack ); |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 1368 | extern void VG_(record_pthread_err) ( ThreadId tid, Char* msg ); |
| 1369 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1370 | |
| 1371 | |
| 1372 | /* The classification of a faulting address. */ |
| 1373 | typedef |
sewardj | b581a13 | 2002-05-08 00:32:50 +0000 | [diff] [blame] | 1374 | enum { Undescribed, /* as-yet unclassified */ |
| 1375 | Stack, |
| 1376 | Unknown, /* classification yielded nothing useful */ |
| 1377 | Freed, Mallocd, |
| 1378 | UserG, UserS } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1379 | AddrKind; |
| 1380 | |
| 1381 | /* Records info about a faulting address. */ |
| 1382 | typedef |
| 1383 | struct { |
| 1384 | /* ALL */ |
| 1385 | AddrKind akind; |
| 1386 | /* Freed, Mallocd */ |
| 1387 | Int blksize; |
| 1388 | /* Freed, Mallocd */ |
| 1389 | Int rwoffset; |
| 1390 | /* Freed, Mallocd */ |
| 1391 | ExeContext* lastchange; |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1392 | /* Stack */ |
| 1393 | ThreadId stack_tid; |
sewardj | b581a13 | 2002-05-08 00:32:50 +0000 | [diff] [blame] | 1394 | /* True if is just-below %esp -- could be a gcc bug. */ |
| 1395 | Bool maybe_gcc; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1396 | } |
| 1397 | AddrInfo; |
| 1398 | |
| 1399 | |
| 1400 | /* --------------------------------------------------------------------- |
| 1401 | Exports of vg_clientperms.c |
| 1402 | ------------------------------------------------------------------ */ |
| 1403 | |
| 1404 | extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai ); |
| 1405 | |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1406 | extern UInt VG_(handle_client_request) ( ThreadState* tst, UInt* arg_block ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1407 | |
| 1408 | extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void ); |
| 1409 | |
| 1410 | extern void VG_(show_client_block_stats) ( void ); |
| 1411 | |
| 1412 | |
| 1413 | /* --------------------------------------------------------------------- |
| 1414 | Exports of vg_procselfmaps.c |
| 1415 | ------------------------------------------------------------------ */ |
| 1416 | |
| 1417 | extern |
| 1418 | void VG_(read_procselfmaps) ( |
| 1419 | void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* ) |
| 1420 | ); |
| 1421 | |
| 1422 | |
| 1423 | /* --------------------------------------------------------------------- |
| 1424 | Exports of vg_symtab2.c |
| 1425 | ------------------------------------------------------------------ */ |
| 1426 | |
| 1427 | /* We assume the executable is loaded here ... can't really find |
| 1428 | out. There is a hacky sanity check in vg_init_memory_audit() |
| 1429 | which should trip up most stupidities. |
| 1430 | */ |
| 1431 | #define VG_ASSUMED_EXE_BASE (Addr)0x8048000 |
| 1432 | |
| 1433 | extern void VG_(read_symbols) ( void ); |
| 1434 | extern void VG_(mini_stack_dump) ( ExeContext* ec ); |
| 1435 | extern void VG_(what_obj_and_fun_is_this) |
| 1436 | ( Addr a, |
| 1437 | Char* obj_buf, Int n_obj_buf, |
| 1438 | Char* fun_buf, Int n_fun_buf ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1439 | extern Bool VG_(what_line_is_this) ( Addr a, |
| 1440 | UChar* filename, Int n_filename, |
| 1441 | UInt* lineno ); |
| 1442 | extern Bool VG_(what_fn_is_this) ( Bool no_demangle, Addr a, |
| 1443 | Char* fn_name, Int n_fn_name); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1444 | |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1445 | extern Bool VG_(symtab_notify_munmap) ( Addr start, UInt length ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1446 | |
| 1447 | |
| 1448 | /* --------------------------------------------------------------------- |
| 1449 | Exports of vg_clientmalloc.c |
| 1450 | ------------------------------------------------------------------ */ |
| 1451 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1452 | typedef |
| 1453 | enum { |
| 1454 | Vg_AllocMalloc = 0, |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1455 | Vg_AllocNew = 1, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1456 | Vg_AllocNewVec = 2 |
| 1457 | } |
| 1458 | VgAllocKind; |
| 1459 | |
| 1460 | /* Description of a malloc'd chunk. */ |
| 1461 | typedef |
| 1462 | struct _ShadowChunk { |
| 1463 | struct _ShadowChunk* next; |
| 1464 | ExeContext* where; /* where malloc'd/free'd */ |
| 1465 | UInt size : 30; /* size requested. */ |
| 1466 | VgAllocKind allockind : 2; /* which wrapper did the allocation */ |
| 1467 | Addr data; /* ptr to actual block. */ |
| 1468 | } |
| 1469 | ShadowChunk; |
| 1470 | |
| 1471 | extern void VG_(clientmalloc_done) ( void ); |
| 1472 | extern void VG_(describe_addr) ( Addr a, AddrInfo* ai ); |
| 1473 | extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows ); |
| 1474 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1475 | /* These are called from the scheduler, when it intercepts a user |
| 1476 | request. */ |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1477 | extern void* VG_(client_malloc) ( ThreadState* tst, |
| 1478 | UInt size, VgAllocKind kind ); |
| 1479 | extern void* VG_(client_memalign) ( ThreadState* tst, |
| 1480 | UInt align, UInt size ); |
| 1481 | extern void VG_(client_free) ( ThreadState* tst, |
| 1482 | void* ptrV, VgAllocKind kind ); |
| 1483 | extern void* VG_(client_calloc) ( ThreadState* tst, |
| 1484 | UInt nmemb, UInt size1 ); |
| 1485 | extern void* VG_(client_realloc) ( ThreadState* tst, |
| 1486 | void* ptrV, UInt size_new ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1487 | |
| 1488 | |
| 1489 | /* --------------------------------------------------------------------- |
| 1490 | Exports of vg_main.c |
| 1491 | ------------------------------------------------------------------ */ |
| 1492 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1493 | /* A structure used as an intermediary when passing the simulated |
| 1494 | CPU's state to some assembly fragments, particularly system calls. |
| 1495 | Stuff is copied from baseBlock to here, the assembly magic runs, |
| 1496 | and then the inverse copy is done. */ |
| 1497 | |
| 1498 | extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */ |
| 1499 | + 1 /* %eflags */ |
| 1500 | + 1 /* %eip */ |
| 1501 | + VG_SIZE_OF_FPUSTATE_W /* FPU state */ |
| 1502 | ]; |
| 1503 | |
| 1504 | /* Handy fns for doing the copy back and forth. */ |
| 1505 | extern void VG_(copy_baseBlock_to_m_state_static) ( void ); |
| 1506 | extern void VG_(copy_m_state_static_to_baseBlock) ( void ); |
| 1507 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1508 | /* Called when some unhandleable client behaviour is detected. |
| 1509 | Prints a msg and aborts. */ |
| 1510 | extern void VG_(unimplemented) ( Char* msg ); |
sewardj | cfc39b2 | 2002-05-08 01:58:18 +0000 | [diff] [blame] | 1511 | extern void VG_(nvidia_moan) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1512 | |
| 1513 | /* The stack on which Valgrind runs. We can't use the same stack as the |
| 1514 | simulatee -- that's an important design decision. */ |
| 1515 | extern UInt VG_(stack)[10000]; |
| 1516 | |
| 1517 | /* Similarly, we have to ask for signals to be delivered on an |
| 1518 | alternative stack, since it is possible, although unlikely, that |
| 1519 | we'll have to run client code from inside the Valgrind-installed |
| 1520 | signal handler. If this happens it will be done by |
| 1521 | vg_deliver_signal_immediately(). */ |
| 1522 | extern UInt VG_(sigstack)[10000]; |
| 1523 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1524 | /* Holds client's %esp at the point we gained control. From this the |
| 1525 | client's argc, argv and envp are deduced. */ |
| 1526 | extern Addr VG_(esp_at_startup); |
| 1527 | extern Int VG_(client_argc); |
| 1528 | extern Char** VG_(client_argv); |
| 1529 | extern Char** VG_(client_envp); |
| 1530 | |
| 1531 | /* Remove valgrind.so from a LD_PRELOAD=... string so child processes |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1532 | don't get traced into. Also mess up $libdir/valgrind so that our |
| 1533 | libpthread.so disappears from view. */ |
| 1534 | void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str, |
| 1535 | Char* ld_library_path_str ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1536 | |
| 1537 | /* Something of a function looking for a home ... start up GDB. This |
| 1538 | is called from VG_(swizzle_esp_then_start_GDB) and so runs on the |
| 1539 | *client's* stack. This is necessary to give GDB the illusion that |
| 1540 | the client program really was running on the real cpu. */ |
| 1541 | extern void VG_(start_GDB_whilst_on_client_stack) ( void ); |
| 1542 | |
| 1543 | /* Spew out vast amounts of junk during JITting? */ |
| 1544 | extern Bool VG_(disassemble); |
| 1545 | |
| 1546 | /* 64-bit counter for the number of basic blocks done. */ |
| 1547 | extern ULong VG_(bbs_done); |
| 1548 | /* 64-bit counter for the number of bbs to go before a debug exit. */ |
| 1549 | extern ULong VG_(bbs_to_go); |
| 1550 | |
| 1551 | /* Counts downwards in vg_run_innerloop. */ |
| 1552 | extern UInt VG_(dispatch_ctr); |
| 1553 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1554 | /* Is the client running on the simulated CPU or the real one? */ |
| 1555 | extern Bool VG_(running_on_simd_CPU); /* Initially False */ |
| 1556 | |
| 1557 | /* The current LRU epoch. */ |
| 1558 | extern UInt VG_(current_epoch); |
| 1559 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1560 | /* This is the ThreadId of the last thread the scheduler ran. */ |
| 1561 | extern ThreadId VG_(last_run_tid); |
| 1562 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1563 | |
| 1564 | /* --- Counters, for informational purposes only. --- */ |
| 1565 | |
| 1566 | /* Number of lookups which miss the fast tt helper. */ |
| 1567 | extern UInt VG_(tt_fast_misses); |
| 1568 | |
| 1569 | /* Counts for LRU informational messages. */ |
| 1570 | |
| 1571 | /* Number and total o/t size of new translations this epoch. */ |
| 1572 | extern UInt VG_(this_epoch_in_count); |
| 1573 | extern UInt VG_(this_epoch_in_osize); |
| 1574 | extern UInt VG_(this_epoch_in_tsize); |
| 1575 | /* Number and total o/t size of discarded translations this epoch. */ |
| 1576 | extern UInt VG_(this_epoch_out_count); |
| 1577 | extern UInt VG_(this_epoch_out_osize); |
| 1578 | extern UInt VG_(this_epoch_out_tsize); |
| 1579 | /* Number and total o/t size of translations overall. */ |
| 1580 | extern UInt VG_(overall_in_count); |
| 1581 | extern UInt VG_(overall_in_osize); |
| 1582 | extern UInt VG_(overall_in_tsize); |
| 1583 | /* Number and total o/t size of discards overall. */ |
| 1584 | extern UInt VG_(overall_out_count); |
| 1585 | extern UInt VG_(overall_out_osize); |
| 1586 | extern UInt VG_(overall_out_tsize); |
| 1587 | |
| 1588 | /* The number of LRU-clearings of TT/TC. */ |
| 1589 | extern UInt VG_(number_of_lrus); |
| 1590 | |
| 1591 | /* Counts pertaining to the register allocator. */ |
| 1592 | |
| 1593 | /* total number of uinstrs input to reg-alloc */ |
| 1594 | extern UInt VG_(uinstrs_prealloc); |
| 1595 | |
| 1596 | /* total number of uinstrs added due to spill code */ |
| 1597 | extern UInt VG_(uinstrs_spill); |
| 1598 | |
| 1599 | /* number of bbs requiring spill code */ |
| 1600 | extern UInt VG_(translations_needing_spill); |
| 1601 | |
| 1602 | /* total of register ranks over all translations */ |
| 1603 | extern UInt VG_(total_reg_rank); |
| 1604 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1605 | /* Counts pertaining to internal sanity checking. */ |
| 1606 | extern UInt VG_(sanity_fast_count); |
| 1607 | extern UInt VG_(sanity_slow_count); |
| 1608 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1609 | /* Counts pertaining to the scheduler. */ |
| 1610 | extern UInt VG_(num_scheduling_events_MINOR); |
| 1611 | extern UInt VG_(num_scheduling_events_MAJOR); |
| 1612 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1613 | |
| 1614 | /* --------------------------------------------------------------------- |
| 1615 | Exports of vg_memory.c |
| 1616 | ------------------------------------------------------------------ */ |
| 1617 | |
| 1618 | extern void VGM_(init_memory_audit) ( void ); |
| 1619 | extern Addr VGM_(curr_dataseg_end); |
| 1620 | extern void VG_(show_reg_tags) ( void ); |
| 1621 | extern void VG_(detect_memory_leaks) ( void ); |
| 1622 | extern void VG_(done_prof_mem) ( void ); |
| 1623 | |
| 1624 | /* Set permissions for an address range. Not speed-critical. */ |
| 1625 | extern void VGM_(make_noaccess) ( Addr a, UInt len ); |
| 1626 | extern void VGM_(make_writable) ( Addr a, UInt len ); |
| 1627 | extern void VGM_(make_readable) ( Addr a, UInt len ); |
| 1628 | /* Use with care! (read: use for shmat only) */ |
| 1629 | extern void VGM_(make_readwritable) ( Addr a, UInt len ); |
| 1630 | extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst, |
| 1631 | UInt len ); |
| 1632 | |
| 1633 | /* Check permissions for an address range. Not speed-critical. */ |
| 1634 | extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr ); |
| 1635 | extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr ); |
| 1636 | extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr ); |
| 1637 | |
sewardj | 0c3b53f | 2002-05-01 01:58:35 +0000 | [diff] [blame] | 1638 | /* Sanity checks which may be done at any time. The scheduler decides |
| 1639 | when. */ |
| 1640 | extern void VG_(do_sanity_checks) ( Bool force_expensive ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1641 | /* Very cheap ... */ |
| 1642 | extern Bool VG_(first_and_last_secondaries_look_plausible) ( void ); |
| 1643 | |
| 1644 | /* These functions are called from generated code. */ |
| 1645 | extern void VG_(helperc_STOREV4) ( UInt, Addr ); |
| 1646 | extern void VG_(helperc_STOREV2) ( UInt, Addr ); |
| 1647 | extern void VG_(helperc_STOREV1) ( UInt, Addr ); |
| 1648 | |
| 1649 | extern UInt VG_(helperc_LOADV1) ( Addr ); |
| 1650 | extern UInt VG_(helperc_LOADV2) ( Addr ); |
| 1651 | extern UInt VG_(helperc_LOADV4) ( Addr ); |
| 1652 | |
| 1653 | extern void VGM_(handle_esp_assignment) ( Addr new_espA ); |
| 1654 | extern void VGM_(fpu_write_check) ( Addr addr, Int size ); |
| 1655 | extern void VGM_(fpu_read_check) ( Addr addr, Int size ); |
| 1656 | |
| 1657 | /* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address |
| 1658 | space and pass the addresses and values of all addressible, |
| 1659 | defined, aligned words to notify_word. This is the basis for the |
| 1660 | leak detector. Returns the number of calls made to notify_word. */ |
| 1661 | UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) ); |
| 1662 | |
| 1663 | /* Is this address within some small distance below %ESP? Used only |
| 1664 | for the --workaround-gcc296-bugs kludge. */ |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1665 | extern Bool VG_(is_just_below_ESP)( Addr esp, Addr aa ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1666 | |
| 1667 | /* Nasty kludgery to deal with applications which switch stacks, |
| 1668 | like netscape. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1669 | #define VG_PLAUSIBLE_STACK_SIZE 8000000 |
| 1670 | |
sewardj | c3bd5f5 | 2002-05-01 03:24:23 +0000 | [diff] [blame] | 1671 | /* Needed by the pthreads implementation. */ |
| 1672 | #define VGM_WORD_VALID 0 |
| 1673 | #define VGM_WORD_INVALID 0xFFFFFFFF |
| 1674 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1675 | |
| 1676 | /* --------------------------------------------------------------------- |
| 1677 | Exports of vg_syscall_mem.c |
| 1678 | ------------------------------------------------------------------ */ |
| 1679 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1680 | extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1681 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1682 | extern void VG_(check_known_blocking_syscall) ( ThreadId tid, |
| 1683 | Int syscallno, |
| 1684 | Int* /*IN*/ res ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1685 | |
| 1686 | extern Bool VG_(is_kerror) ( Int res ); |
| 1687 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1688 | #define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \ |
| 1689 | VG_(load_thread_state)(thread_id); \ |
| 1690 | VG_(copy_baseBlock_to_m_state_static)(); \ |
| 1691 | VG_(do_syscall)(); \ |
| 1692 | VG_(copy_m_state_static_to_baseBlock)(); \ |
| 1693 | VG_(save_thread_state)(thread_id); \ |
| 1694 | VG_(threads)[thread_id].sh_eax = VGM_WORD_VALID; \ |
| 1695 | result_lvalue = VG_(threads)[thread_id].m_eax; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1696 | |
| 1697 | |
| 1698 | /* --------------------------------------------------------------------- |
| 1699 | Exports of vg_transtab.c |
| 1700 | ------------------------------------------------------------------ */ |
| 1701 | |
| 1702 | /* An entry in the translation table (TT). */ |
| 1703 | typedef |
| 1704 | struct { |
| 1705 | /* +0 */ Addr orig_addr; |
| 1706 | /* +4 */ Addr trans_addr; |
| 1707 | /* +8 */ UInt mru_epoch; |
| 1708 | /* +12 */ UShort orig_size; |
| 1709 | /* +14 */ UShort trans_size; |
| 1710 | } |
| 1711 | TTEntry; |
| 1712 | |
| 1713 | /* The number of basic blocks in an epoch (one age-step). */ |
| 1714 | #define VG_BBS_PER_EPOCH 20000 |
| 1715 | |
| 1716 | extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used ); |
| 1717 | extern void VG_(maybe_do_lru_pass) ( void ); |
| 1718 | extern void VG_(flush_transtab) ( void ); |
| 1719 | extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size ); |
| 1720 | extern void VG_(add_to_trans_tab) ( TTEntry* tte ); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1721 | extern void VG_(invalidate_translations) ( Addr start, UInt range ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1722 | |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1723 | extern void VG_(init_tt_tc) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1724 | |
| 1725 | extern void VG_(sanity_check_tc_tt) ( void ); |
| 1726 | extern Addr VG_(search_transtab) ( Addr original_addr ); |
| 1727 | |
| 1728 | extern void VG_(invalidate_tt_fast)( void ); |
| 1729 | |
| 1730 | |
| 1731 | /* --------------------------------------------------------------------- |
| 1732 | Exports of vg_vtagops.c |
| 1733 | ------------------------------------------------------------------ */ |
| 1734 | |
| 1735 | /* Lists the names of value-tag operations used in instrumented |
| 1736 | code. These are the third argument to TAG1 and TAG2 uinsns. */ |
| 1737 | |
| 1738 | typedef |
| 1739 | enum { |
| 1740 | /* Unary. */ |
| 1741 | VgT_PCast40, VgT_PCast20, VgT_PCast10, |
| 1742 | VgT_PCast01, VgT_PCast02, VgT_PCast04, |
| 1743 | |
| 1744 | VgT_PCast14, VgT_PCast12, VgT_PCast11, |
| 1745 | |
| 1746 | VgT_Left4, VgT_Left2, VgT_Left1, |
| 1747 | |
| 1748 | VgT_SWiden14, VgT_SWiden24, VgT_SWiden12, |
| 1749 | VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12, |
| 1750 | |
| 1751 | /* Binary; 1st is rd; 2nd is rd+wr */ |
| 1752 | VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0, |
| 1753 | VgT_DifD4, VgT_DifD2, VgT_DifD1, |
| 1754 | |
| 1755 | VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ, |
| 1756 | VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ, |
| 1757 | VgT_DebugFn |
| 1758 | } |
| 1759 | VgTagOp; |
| 1760 | |
| 1761 | extern Char* VG_(nameOfTagOp) ( VgTagOp ); |
| 1762 | extern UInt VG_(DebugFn) ( UInt a1, UInt a2 ); |
| 1763 | |
| 1764 | |
| 1765 | /* --------------------------------------------------------------------- |
| 1766 | Exports of vg_syscall.S |
| 1767 | ------------------------------------------------------------------ */ |
| 1768 | |
| 1769 | extern void VG_(do_syscall) ( void ); |
| 1770 | |
| 1771 | |
| 1772 | /* --------------------------------------------------------------------- |
| 1773 | Exports of vg_startup.S |
| 1774 | ------------------------------------------------------------------ */ |
| 1775 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1776 | extern void VG_(switch_to_real_CPU) ( void ); |
| 1777 | |
sewardj | 3580542 | 2002-04-21 13:05:34 +0000 | [diff] [blame] | 1778 | extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error, |
| 1779 | Addr m_esp_at_error, |
| 1780 | Addr m_ebp_at_error ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1781 | |
| 1782 | |
| 1783 | /* --------------------------------------------------------------------- |
| 1784 | Exports of vg_dispatch.S |
| 1785 | ------------------------------------------------------------------ */ |
| 1786 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1787 | /* Run a thread for a (very short) while, until some event happens |
| 1788 | which means we need to defer to the scheduler. */ |
| 1789 | extern UInt VG_(run_innerloop) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1790 | |
| 1791 | |
| 1792 | /* --------------------------------------------------------------------- |
| 1793 | Exports of vg_helpers.S |
| 1794 | ------------------------------------------------------------------ */ |
| 1795 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1796 | /* Mul, div, etc, -- we don't codegen these directly. */ |
| 1797 | extern void VG_(helper_idiv_64_32); |
| 1798 | extern void VG_(helper_div_64_32); |
| 1799 | extern void VG_(helper_idiv_32_16); |
| 1800 | extern void VG_(helper_div_32_16); |
| 1801 | extern void VG_(helper_idiv_16_8); |
| 1802 | extern void VG_(helper_div_16_8); |
| 1803 | |
| 1804 | extern void VG_(helper_imul_32_64); |
| 1805 | extern void VG_(helper_mul_32_64); |
| 1806 | extern void VG_(helper_imul_16_32); |
| 1807 | extern void VG_(helper_mul_16_32); |
| 1808 | extern void VG_(helper_imul_8_16); |
| 1809 | extern void VG_(helper_mul_8_16); |
| 1810 | |
| 1811 | extern void VG_(helper_CLD); |
| 1812 | extern void VG_(helper_STD); |
| 1813 | extern void VG_(helper_get_dirflag); |
| 1814 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 1815 | extern void VG_(helper_CLC); |
| 1816 | extern void VG_(helper_STC); |
| 1817 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1818 | extern void VG_(helper_shldl); |
| 1819 | extern void VG_(helper_shldw); |
| 1820 | extern void VG_(helper_shrdl); |
| 1821 | extern void VG_(helper_shrdw); |
| 1822 | |
| 1823 | extern void VG_(helper_RDTSC); |
| 1824 | extern void VG_(helper_CPUID); |
| 1825 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1826 | extern void VG_(helper_bsf); |
| 1827 | extern void VG_(helper_bsr); |
| 1828 | |
| 1829 | extern void VG_(helper_fstsw_AX); |
| 1830 | extern void VG_(helper_SAHF); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 1831 | extern void VG_(helper_DAS); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 1832 | extern void VG_(helper_DAA); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1833 | |
| 1834 | extern void VG_(helper_value_check4_fail); |
| 1835 | extern void VG_(helper_value_check2_fail); |
| 1836 | extern void VG_(helper_value_check1_fail); |
| 1837 | extern void VG_(helper_value_check0_fail); |
| 1838 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1839 | /* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */ |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 1840 | extern void VG_(signalreturn_bogusRA)( void ); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1841 | |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 1842 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1843 | /* --------------------------------------------------------------------- |
| 1844 | Exports of vg_cachesim.c |
| 1845 | ------------------------------------------------------------------ */ |
| 1846 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 1847 | extern Int VG_(log2) ( Int x ); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 1848 | |
sewardj | 07133bf | 2002-06-13 10:25:56 +0000 | [diff] [blame] | 1849 | extern UCodeBlock* VG_(cachesim_instrument) ( UCodeBlock* cb_in, |
| 1850 | Addr orig_addr ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1851 | |
| 1852 | typedef struct _iCC iCC; |
| 1853 | typedef struct _idCC idCC; |
| 1854 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 1855 | extern void VG_(init_cachesim) ( void ); |
| 1856 | extern void VG_(do_cachesim_results)( Int client_argc, Char** client_argv ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1857 | |
| 1858 | extern void VG_(cachesim_log_non_mem_instr)( iCC* cc ); |
| 1859 | extern void VG_(cachesim_log_mem_instr) ( idCC* cc, Addr data_addr ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1860 | |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1861 | extern void VG_(cachesim_notify_discard) ( TTEntry* tte ); |
| 1862 | |
| 1863 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1864 | /* --------------------------------------------------------------------- |
| 1865 | The state of the simulated CPU. |
| 1866 | ------------------------------------------------------------------ */ |
| 1867 | |
| 1868 | /* This is the Intel register encoding. */ |
| 1869 | #define R_EAX 0 |
| 1870 | #define R_ECX 1 |
| 1871 | #define R_EDX 2 |
| 1872 | #define R_EBX 3 |
| 1873 | #define R_ESP 4 |
| 1874 | #define R_EBP 5 |
| 1875 | #define R_ESI 6 |
| 1876 | #define R_EDI 7 |
| 1877 | |
| 1878 | #define R_AL (0+R_EAX) |
| 1879 | #define R_CL (0+R_ECX) |
| 1880 | #define R_DL (0+R_EDX) |
| 1881 | #define R_BL (0+R_EBX) |
| 1882 | #define R_AH (4+R_EAX) |
| 1883 | #define R_CH (4+R_ECX) |
| 1884 | #define R_DH (4+R_EDX) |
| 1885 | #define R_BH (4+R_EBX) |
| 1886 | |
| 1887 | |
| 1888 | /* --------------------------------------------------------------------- |
| 1889 | Offsets into baseBlock for everything which needs to referred to |
| 1890 | from generated code. The order of these decls does not imply |
| 1891 | what the order of the actual offsets is. The latter is important |
| 1892 | and is set up in vg_main.c. |
| 1893 | ------------------------------------------------------------------ */ |
| 1894 | |
| 1895 | /* An array of words. In generated code, %ebp always points to the |
| 1896 | start of this array. Useful stuff, like the simulated CPU state, |
| 1897 | and the addresses of helper functions, can then be found by |
| 1898 | indexing off %ebp. The following declares variables which, at |
| 1899 | startup time, are given values denoting offsets into baseBlock. |
| 1900 | These offsets are in *words* from the start of baseBlock. */ |
| 1901 | |
| 1902 | #define VG_BASEBLOCK_WORDS 200 |
| 1903 | |
| 1904 | extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; |
| 1905 | |
| 1906 | |
| 1907 | /* ----------------------------------------------------- |
| 1908 | Read-write parts of baseBlock. |
| 1909 | -------------------------------------------------- */ |
| 1910 | |
| 1911 | /* State of the simulated CPU. */ |
| 1912 | extern Int VGOFF_(m_eax); |
| 1913 | extern Int VGOFF_(m_ecx); |
| 1914 | extern Int VGOFF_(m_edx); |
| 1915 | extern Int VGOFF_(m_ebx); |
| 1916 | extern Int VGOFF_(m_esp); |
| 1917 | extern Int VGOFF_(m_ebp); |
| 1918 | extern Int VGOFF_(m_esi); |
| 1919 | extern Int VGOFF_(m_edi); |
| 1920 | extern Int VGOFF_(m_eflags); |
| 1921 | extern Int VGOFF_(m_fpustate); |
| 1922 | extern Int VGOFF_(m_eip); |
| 1923 | |
| 1924 | /* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */ |
| 1925 | extern Int VGOFF_(spillslots); |
| 1926 | |
| 1927 | /* Records the valid bits for the 8 integer regs & flags reg. */ |
| 1928 | extern Int VGOFF_(sh_eax); |
| 1929 | extern Int VGOFF_(sh_ecx); |
| 1930 | extern Int VGOFF_(sh_edx); |
| 1931 | extern Int VGOFF_(sh_ebx); |
| 1932 | extern Int VGOFF_(sh_esp); |
| 1933 | extern Int VGOFF_(sh_ebp); |
| 1934 | extern Int VGOFF_(sh_esi); |
| 1935 | extern Int VGOFF_(sh_edi); |
| 1936 | extern Int VGOFF_(sh_eflags); |
| 1937 | |
| 1938 | |
| 1939 | /* ----------------------------------------------------- |
| 1940 | Read-only parts of baseBlock. |
| 1941 | -------------------------------------------------- */ |
| 1942 | |
| 1943 | /* Offsets of addresses of helper functions. A "helper" function is |
| 1944 | one which is called from generated code. */ |
| 1945 | |
| 1946 | extern Int VGOFF_(helper_idiv_64_32); |
| 1947 | extern Int VGOFF_(helper_div_64_32); |
| 1948 | extern Int VGOFF_(helper_idiv_32_16); |
| 1949 | extern Int VGOFF_(helper_div_32_16); |
| 1950 | extern Int VGOFF_(helper_idiv_16_8); |
| 1951 | extern Int VGOFF_(helper_div_16_8); |
| 1952 | |
| 1953 | extern Int VGOFF_(helper_imul_32_64); |
| 1954 | extern Int VGOFF_(helper_mul_32_64); |
| 1955 | extern Int VGOFF_(helper_imul_16_32); |
| 1956 | extern Int VGOFF_(helper_mul_16_32); |
| 1957 | extern Int VGOFF_(helper_imul_8_16); |
| 1958 | extern Int VGOFF_(helper_mul_8_16); |
| 1959 | |
| 1960 | extern Int VGOFF_(helper_CLD); |
| 1961 | extern Int VGOFF_(helper_STD); |
| 1962 | extern Int VGOFF_(helper_get_dirflag); |
| 1963 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 1964 | extern Int VGOFF_(helper_CLC); |
| 1965 | extern Int VGOFF_(helper_STC); |
| 1966 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1967 | extern Int VGOFF_(helper_shldl); |
| 1968 | extern Int VGOFF_(helper_shldw); |
| 1969 | extern Int VGOFF_(helper_shrdl); |
| 1970 | extern Int VGOFF_(helper_shrdw); |
| 1971 | |
| 1972 | extern Int VGOFF_(helper_RDTSC); |
| 1973 | extern Int VGOFF_(helper_CPUID); |
| 1974 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1975 | extern Int VGOFF_(helper_bsf); |
| 1976 | extern Int VGOFF_(helper_bsr); |
| 1977 | |
| 1978 | extern Int VGOFF_(helper_fstsw_AX); |
| 1979 | extern Int VGOFF_(helper_SAHF); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 1980 | extern Int VGOFF_(helper_DAS); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 1981 | extern Int VGOFF_(helper_DAA); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1982 | |
| 1983 | extern Int VGOFF_(helper_value_check4_fail); |
| 1984 | extern Int VGOFF_(helper_value_check2_fail); |
| 1985 | extern Int VGOFF_(helper_value_check1_fail); |
| 1986 | extern Int VGOFF_(helper_value_check0_fail); |
| 1987 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1988 | extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */ |
| 1989 | extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */ |
| 1990 | extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */ |
| 1991 | |
| 1992 | extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */ |
| 1993 | extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */ |
| 1994 | extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */ |
| 1995 | |
| 1996 | extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */ |
| 1997 | extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */ |
| 1998 | extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */ |
| 1999 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 2000 | extern Int VGOFF_(cachesim_log_non_mem_instr); |
| 2001 | extern Int VGOFF_(cachesim_log_mem_instr); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 2002 | |
| 2003 | #endif /* ndef __VG_INCLUDE_H */ |
| 2004 | |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 2005 | |
| 2006 | /* --------------------------------------------------------------------- |
| 2007 | Finally - autoconf-generated settings |
| 2008 | ------------------------------------------------------------------ */ |
| 2009 | |
| 2010 | #include "config.h" |
| 2011 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 2012 | /*--------------------------------------------------------------------*/ |
| 2013 | /*--- end vg_include.h ---*/ |
| 2014 | /*--------------------------------------------------------------------*/ |