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