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