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