sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3 | /*--- A header file for all private parts of Valgrind's core. ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 4 | /*--- Include no other! ---*/ |
| 5 | /*--- vg_include.h ---*/ |
| 6 | /*--------------------------------------------------------------------*/ |
| 7 | |
| 8 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | This file is part of Valgrind, an extensible x86 protected-mode |
| 10 | emulator for monitoring program execution on x86-Unixes. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 30 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #ifndef __VG_INCLUDE_H |
| 34 | #define __VG_INCLUDE_H |
| 35 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 36 | /* --------------------------------------------------------------------- |
sewardj | 2d94c11 | 2002-06-03 01:25:54 +0000 | [diff] [blame] | 37 | Where to send bug reports to. |
| 38 | ------------------------------------------------------------------ */ |
| 39 | |
| 40 | #define VG_EMAIL_ADDR "jseward@acm.org" |
| 41 | |
| 42 | |
| 43 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 44 | Build options and table sizes. You should be able to change these |
| 45 | options or sizes, recompile, and still have a working system. |
| 46 | ------------------------------------------------------------------ */ |
| 47 | |
| 48 | #include "vg_constants.h" |
| 49 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 50 | /* All stuff visible to core and skins goes in vg_skin.h. Things visible |
| 51 | * to core but private to skins go here. */ |
| 52 | #include "vg_skin.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | |
| 54 | /* Total number of spill slots available for allocation, if a TempReg |
| 55 | doesn't make it into a RealReg. Just bomb the entire system if |
| 56 | this value is too small; we don't expect it will ever get |
| 57 | particularly high. */ |
| 58 | #define VG_MAX_SPILLSLOTS 24 |
| 59 | |
| 60 | |
| 61 | /* Constants for the slow translation lookup cache. */ |
| 62 | #define VG_TRANSTAB_SLOW_BITS 11 |
| 63 | #define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS) |
| 64 | #define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1) |
| 65 | |
| 66 | /* Size of a buffer used for creating messages. */ |
| 67 | #define M_VG_MSGBUF 10000 |
| 68 | |
| 69 | /* Size of a smallish table used to read /proc/self/map entries. */ |
sewardj | ebc8233 | 2002-04-24 14:44:23 +0000 | [diff] [blame] | 70 | #define M_PROCMAP_BUF 50000 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 71 | |
| 72 | /* Max length of pathname to a .so/executable file. */ |
| 73 | #define M_VG_LIBNAMESTR 100 |
| 74 | |
| 75 | /* Max length of a text fragment used to construct error messages. */ |
| 76 | #define M_VG_ERRTXT 512 |
| 77 | |
| 78 | /* Max length of the string copied from env var VG_ARGS at startup. */ |
| 79 | #define M_VG_CMDLINE_STRLEN 1000 |
| 80 | |
| 81 | /* Max number of options for Valgrind which we can handle. */ |
| 82 | #define M_VG_CMDLINE_OPTS 100 |
| 83 | |
| 84 | /* After this many different unsuppressed errors have been observed, |
| 85 | be more conservative about collecting new ones. */ |
| 86 | #define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50 |
| 87 | |
| 88 | /* After this many different unsuppressed errors have been observed, |
| 89 | stop collecting errors at all, and tell the user their program is |
| 90 | evidently a steaming pile of camel dung. */ |
sewardj | 1bebcbf | 2002-04-24 21:24:18 +0000 | [diff] [blame] | 91 | #define M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN 300 |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 92 | |
| 93 | /* After this many total errors have been observed, stop collecting |
| 94 | errors at all. Counterpart to M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN. */ |
sewardj | 1bebcbf | 2002-04-24 21:24:18 +0000 | [diff] [blame] | 95 | #define M_VG_COLLECT_NO_ERRORS_AFTER_FOUND 30000 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 97 | /* The maximum number of calls we're prepared to save in a |
| 98 | backtrace. */ |
| 99 | #define VG_DEEPEST_BACKTRACE 50 |
| 100 | |
| 101 | /* Number of lists in which we keep track of malloc'd but not free'd |
| 102 | blocks. Should be prime. */ |
| 103 | #define VG_N_MALLOCLISTS 997 |
| 104 | |
| 105 | /* Number of lists in which we keep track of ExeContexts. Should be |
| 106 | prime. */ |
| 107 | #define VG_N_EC_LISTS /*997*/ 4999 |
| 108 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 109 | /* Defines the thread-scheduling timeslice, in terms of the number of |
| 110 | basic blocks we attempt to run each thread for. Smaller values |
| 111 | give finer interleaving but much increased scheduling overheads. */ |
sewardj | 4505b9e | 2002-05-28 11:27:31 +0000 | [diff] [blame] | 112 | #define VG_SCHEDULING_QUANTUM 50000 |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 113 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 114 | /* Number of file descriptors that can simultaneously be waited on for |
| 115 | I/O to complete. Perhaps this should be the same as VG_N_THREADS |
| 116 | (surely a thread can't wait on more than one fd at once?. Who |
| 117 | knows.) */ |
| 118 | #define VG_N_WAITING_FDS 10 |
| 119 | |
sewardj | bf290b9 | 2002-05-01 02:28:01 +0000 | [diff] [blame] | 120 | /* Stack size for a thread. We try and check that they do not go |
| 121 | beyond it. */ |
sewardj | f0b0645 | 2002-06-04 08:38:04 +0000 | [diff] [blame] | 122 | #define VG_PTHREAD_STACK_SIZE (1 << 20) |
sewardj | bf290b9 | 2002-05-01 02:28:01 +0000 | [diff] [blame] | 123 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 124 | /* Number of entries in the semaphore-remapping table. */ |
| 125 | #define VG_N_SEMAPHORES 50 |
| 126 | |
| 127 | /* Number of entries in the rwlock-remapping table. */ |
sewardj | 89745a5 | 2002-09-27 01:04:29 +0000 | [diff] [blame] | 128 | #define VG_N_RWLOCKS 500 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 129 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 130 | /* Number of entries in each thread's cleanup stack. */ |
| 131 | #define VG_N_CLEANUPSTACK 8 |
| 132 | |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 133 | /* Number of entries in each thread's fork-handler stack. */ |
| 134 | #define VG_N_FORKHANDLERSTACK 2 |
| 135 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 136 | /* Max number of callers for context in a suppression. */ |
| 137 | #define VG_N_SUPP_CALLERS 4 |
| 138 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 139 | |
| 140 | /* --------------------------------------------------------------------- |
| 141 | Basic types |
| 142 | ------------------------------------------------------------------ */ |
| 143 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 144 | /* Just pray that gcc's constant folding works properly ... */ |
| 145 | #define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \ |
| 146 | ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \ |
| 147 | | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0)) |
| 148 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 149 | /* --------------------------------------------------------------------- |
| 150 | Command-line-settable options |
| 151 | ------------------------------------------------------------------ */ |
| 152 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 153 | #define VG_CLO_MAX_SFILES 10 |
| 154 | |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 155 | /* Should we stop collecting errors if too many appear? default: YES */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 156 | extern Bool VG_(clo_error_limit); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 157 | /* Enquire about whether to attach to GDB at errors? default: NO */ |
| 158 | extern Bool VG_(clo_GDB_attach); |
| 159 | /* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */ |
| 160 | extern Int VG_(sanity_level); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 161 | /* Automatically attempt to demangle C++ names? default: YES */ |
| 162 | extern Bool VG_(clo_demangle); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 163 | /* Round malloc sizes upwards to integral number of words? default: |
| 164 | NO */ |
| 165 | extern Bool VG_(clo_sloppy_malloc); |
sewardj | 246d466 | 2002-06-14 10:17:05 +0000 | [diff] [blame] | 166 | /* Minimum alignment in functions that don't specify alignment explicitly. |
| 167 | default: 0, i.e. use default of the machine (== 4) */ |
| 168 | extern Int VG_(clo_alignment); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 169 | /* Simulate child processes? default: NO */ |
| 170 | extern Bool VG_(clo_trace_children); |
| 171 | /* The file id on which we send all messages. default: 2 (stderr). */ |
| 172 | extern Int VG_(clo_logfile_fd); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 173 | |
| 174 | /* The number of suppression files specified. */ |
| 175 | extern Int VG_(clo_n_suppressions); |
| 176 | /* The names of the suppression files. */ |
| 177 | extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
| 178 | |
| 179 | /* Single stepping? default: NO */ |
| 180 | extern Bool VG_(clo_single_step); |
| 181 | /* Code improvement? default: YES */ |
| 182 | extern Bool VG_(clo_optimise); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 183 | /* DEBUG: print generated code? default: 00000 ( == NO ) */ |
| 184 | extern Bool VG_(clo_trace_codegen); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 185 | /* DEBUG: print system calls? default: NO */ |
| 186 | extern Bool VG_(clo_trace_syscalls); |
| 187 | /* DEBUG: print signal details? default: NO */ |
| 188 | extern Bool VG_(clo_trace_signals); |
| 189 | /* DEBUG: print symtab details? default: NO */ |
| 190 | extern Bool VG_(clo_trace_symtab); |
| 191 | /* DEBUG: print malloc details? default: NO */ |
| 192 | extern Bool VG_(clo_trace_malloc); |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 193 | /* DEBUG: print thread scheduling events? default: NO */ |
| 194 | extern Bool VG_(clo_trace_sched); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 195 | /* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1 |
| 196 | (some), 2 (all) */ |
| 197 | extern Int VG_(clo_trace_pthread_level); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 198 | /* Stop after this many basic blocks. default: Infinity. */ |
| 199 | extern ULong VG_(clo_stop_after); |
| 200 | /* Display gory details for the k'th most popular error. default: |
| 201 | Infinity. */ |
| 202 | extern Int VG_(clo_dump_error); |
| 203 | /* Number of parents of a backtrace. Default: 8. */ |
| 204 | extern Int VG_(clo_backtrace_size); |
sewardj | 3984b85 | 2002-05-12 03:00:17 +0000 | [diff] [blame] | 205 | /* Engage miscellaneous wierd hacks needed for some progs. */ |
sewardj | 8d365b5 | 2002-05-12 10:52:16 +0000 | [diff] [blame] | 206 | extern Char* VG_(clo_weird_hacks); |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 207 | /* Should we run __libc_freeres at exit? Sometimes causes crashes. |
| 208 | Default: YES. Note this is subservient to VG_(needs).libc_freeres; |
| 209 | if the latter says False, then the setting of VG_(clo_weird_hacks) |
| 210 | is ignored. Ie if a skin says no, I don't want this to run, that |
| 211 | cannot be overridden from the command line. */ |
| 212 | extern Bool VG_(clo_run_libc_freeres); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 213 | |
| 214 | |
| 215 | /* --------------------------------------------------------------------- |
| 216 | Debugging and profiling stuff |
| 217 | ------------------------------------------------------------------ */ |
| 218 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 219 | /* Change to 1 to get more accurate but more expensive core profiling. */ |
| 220 | #if 0 |
| 221 | # define VGP_ACCURATE_PROFILING |
| 222 | #endif |
| 223 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 224 | /* Create a logfile into which messages can be dumped. */ |
| 225 | extern void VG_(startup_logging) ( void ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 226 | extern void VG_(shutdown_logging)( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 227 | |
| 228 | extern void VGP_(init_profiling) ( void ); |
| 229 | extern void VGP_(done_profiling) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 230 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 231 | #undef VGP_PUSHCC |
| 232 | #undef VGP_POPCC |
| 233 | #define VGP_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x) |
| 234 | #define VGP_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 235 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 236 | /* Use this for ones that happen a lot and thus we don't want to put in |
| 237 | all the time, eg. for %esp assignment. */ |
| 238 | #ifdef VGP_ACCURATE_PROFILING |
| 239 | # define VGP_MAYBE_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x) |
| 240 | # define VGP_MAYBE_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 241 | #else |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 242 | # define VGP_MAYBE_PUSHCC(x) |
| 243 | # define VGP_MAYBE_POPCC(x) |
| 244 | #endif |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 245 | |
| 246 | |
| 247 | /* --------------------------------------------------------------------- |
| 248 | Exports of vg_malloc2.c |
| 249 | ------------------------------------------------------------------ */ |
| 250 | |
| 251 | /* Allocation arenas. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 252 | CORE is for the core's general use. |
| 253 | SKIN is for the skin to use (and the only one it uses). |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 254 | SYMTAB is for Valgrind's symbol table storage. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 255 | JITTER is for small storage during translation. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 256 | CLIENT is for the client's mallocs/frees. |
| 257 | DEMANGLE is for the C++ demangler. |
| 258 | EXECTXT is for storing ExeContexts. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 259 | ERRORS is for storing CoreErrors. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 260 | TRANSIENT is for very short-term use. It should be empty |
| 261 | in between uses. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 262 | When adding a new arena, remember also to add it to ensure_mm_init(). |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 263 | */ |
| 264 | typedef Int ArenaId; |
| 265 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 266 | #define VG_N_ARENAS 9 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 267 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 268 | #define VG_AR_CORE 0 /* :: ArenaId */ |
| 269 | #define VG_AR_SKIN 1 /* :: ArenaId */ |
| 270 | #define VG_AR_SYMTAB 2 /* :: ArenaId */ |
| 271 | #define VG_AR_JITTER 3 /* :: ArenaId */ |
| 272 | #define VG_AR_CLIENT 4 /* :: ArenaId */ |
| 273 | #define VG_AR_DEMANGLE 5 /* :: ArenaId */ |
| 274 | #define VG_AR_EXECTXT 6 /* :: ArenaId */ |
| 275 | #define VG_AR_ERRORS 7 /* :: ArenaId */ |
| 276 | #define VG_AR_TRANSIENT 8 /* :: ArenaId */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 277 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 278 | extern void* VG_(arena_malloc) ( ArenaId arena, Int nbytes ); |
| 279 | extern void VG_(arena_free) ( ArenaId arena, void* ptr ); |
| 280 | extern void* VG_(arena_calloc) ( ArenaId arena, Int nmemb, Int nbytes ); |
| 281 | extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment, |
| 282 | Int size ); |
| 283 | extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 284 | Int req_pszB ); |
| 285 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 286 | extern void VG_(mallocSanityCheckAll) ( void ); |
| 287 | |
| 288 | extern void VG_(show_all_arena_stats) ( void ); |
| 289 | extern Bool VG_(is_empty_arena) ( ArenaId aid ); |
| 290 | |
| 291 | |
| 292 | /* The red-zone size for the client. This can be arbitrary, but |
| 293 | unfortunately must be set at compile time. */ |
| 294 | #define VG_AR_CLIENT_REDZONE_SZW 4 |
| 295 | |
| 296 | #define VG_AR_CLIENT_REDZONE_SZB \ |
| 297 | (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD) |
| 298 | |
| 299 | |
| 300 | /* --------------------------------------------------------------------- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 301 | Exports of vg_clientfuncs.c |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 302 | ------------------------------------------------------------------ */ |
| 303 | |
| 304 | /* This doesn't export code or data that valgrind.so needs to link |
| 305 | against. However, the scheduler does need to know the following |
| 306 | request codes. A few, publically-visible, request codes are also |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 307 | defined in valgrind.h, and similar headers for some skins. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 308 | |
| 309 | #define VG_USERREQ__MALLOC 0x2001 |
| 310 | #define VG_USERREQ__BUILTIN_NEW 0x2002 |
| 311 | #define VG_USERREQ__BUILTIN_VEC_NEW 0x2003 |
| 312 | |
| 313 | #define VG_USERREQ__FREE 0x2004 |
| 314 | #define VG_USERREQ__BUILTIN_DELETE 0x2005 |
| 315 | #define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006 |
| 316 | |
| 317 | #define VG_USERREQ__CALLOC 0x2007 |
| 318 | #define VG_USERREQ__REALLOC 0x2008 |
| 319 | #define VG_USERREQ__MEMALIGN 0x2009 |
| 320 | |
| 321 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 322 | /* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn |
| 323 | MUST NOT return -- ever. Eventually it will do either __QUIT or |
| 324 | __WAIT_JOINER. */ |
| 325 | #define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001 |
| 326 | |
| 327 | /* ( no-args ): calling thread disappears from the system forever. |
| 328 | Reclaim resources. */ |
| 329 | #define VG_USERREQ__QUIT 0x3002 |
| 330 | |
| 331 | /* ( void* ): calling thread waits for joiner and returns the void* to |
| 332 | it. */ |
| 333 | #define VG_USERREQ__WAIT_JOINER 0x3003 |
| 334 | |
| 335 | /* ( ThreadId, void** ): wait to join a thread. */ |
| 336 | #define VG_USERREQ__PTHREAD_JOIN 0x3004 |
| 337 | |
| 338 | /* Set cancellation state and type for this thread. */ |
| 339 | #define VG_USERREQ__SET_CANCELSTATE 0x3005 |
| 340 | #define VG_USERREQ__SET_CANCELTYPE 0x3006 |
| 341 | |
| 342 | /* ( no-args ): Test if we are at a cancellation point. */ |
| 343 | #define VG_USERREQ__TESTCANCEL 0x3007 |
| 344 | |
| 345 | /* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call |
| 346 | with this arg to indicate that a cancel is now pending for the |
| 347 | specified thread. */ |
| 348 | #define VG_USERREQ__SET_CANCELPEND 0x3008 |
| 349 | |
| 350 | /* Set/get detach state for this thread. */ |
| 351 | #define VG_USERREQ__SET_OR_GET_DETACH 0x3009 |
| 352 | |
| 353 | #define VG_USERREQ__PTHREAD_GET_THREADID 0x300B |
| 354 | #define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C |
| 355 | #define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D |
| 356 | #define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E |
| 357 | #define VG_USERREQ__PTHREAD_COND_WAIT 0x300F |
| 358 | #define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010 |
| 359 | #define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011 |
| 360 | #define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012 |
| 361 | #define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013 |
| 362 | #define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014 |
| 363 | #define VG_USERREQ__PTHREAD_SETSPECIFIC 0x3015 |
| 364 | #define VG_USERREQ__PTHREAD_GETSPECIFIC 0x3016 |
| 365 | #define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017 |
| 366 | #define VG_USERREQ__PTHREAD_SIGMASK 0x3018 |
| 367 | #define VG_USERREQ__SIGWAIT 0x3019 |
| 368 | #define VG_USERREQ__PTHREAD_KILL 0x301A |
| 369 | #define VG_USERREQ__PTHREAD_YIELD 0x301B |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 370 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 371 | #define VG_USERREQ__CLEANUP_PUSH 0x3020 |
| 372 | #define VG_USERREQ__CLEANUP_POP 0x3021 |
sewardj | 870497a | 2002-05-29 01:06:47 +0000 | [diff] [blame] | 373 | #define VG_USERREQ__GET_KEY_D_AND_S 0x3022 |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 374 | |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 375 | #define VG_USERREQ__NUKE_OTHER_THREADS 0x3023 |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 376 | |
| 377 | /* Ask how many signal handler returns have happened to this |
| 378 | thread. */ |
sewardj | 9a2224b | 2002-06-19 10:17:40 +0000 | [diff] [blame] | 379 | #define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024 |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 380 | |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 381 | /* Get/set entries for a thread's pthread_atfork stack. */ |
| 382 | #define VG_USERREQ__SET_FHSTACK_USED 0x3025 |
| 383 | #define VG_USERREQ__GET_FHSTACK_USED 0x3026 |
| 384 | #define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027 |
| 385 | #define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028 |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 386 | |
sewardj | 1fe7b00 | 2002-07-16 01:43:15 +0000 | [diff] [blame] | 387 | /* Denote the finish of VG_(__libc_freeres_wrapper). */ |
| 388 | #define VG_USERREQ__LIBC_FREERES_DONE 0x3029 |
| 389 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 390 | /* Cosmetic ... */ |
| 391 | #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101 |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 392 | /* Log a pthread error from client-space. Cosmetic. */ |
| 393 | #define VG_USERREQ__PTHREAD_ERROR 0x3102 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 394 | |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 395 | /* |
| 396 | In vg_constants.h: |
| 397 | #define VG_USERREQ__SIGNAL_RETURNS 0x4001 |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 398 | */ |
| 399 | |
sewardj | 1fe7b00 | 2002-07-16 01:43:15 +0000 | [diff] [blame] | 400 | /* The scheduler does need to know the address of it so it can be |
| 401 | called at program exit. */ |
| 402 | extern void VG_(__libc_freeres_wrapper)( void ); |
| 403 | |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 404 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 405 | /* --------------------------------------------------------------------- |
| 406 | Constants pertaining to the simulated CPU state, VG_(baseBlock), |
| 407 | which need to go here to avoid ugly circularities. |
| 408 | ------------------------------------------------------------------ */ |
| 409 | |
| 410 | /* How big is the saved FPU state? */ |
| 411 | #define VG_SIZE_OF_FPUSTATE 108 |
| 412 | /* ... and in words ... */ |
| 413 | #define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4) |
| 414 | |
| 415 | |
| 416 | /* --------------------------------------------------------------------- |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 417 | Exports of vg_ldt.c |
| 418 | ------------------------------------------------------------------ */ |
| 419 | |
| 420 | /* This is the hardware-format for a segment descriptor, ie what the |
| 421 | x86 actually deals with. It is 8 bytes long. It's ugly. */ |
| 422 | |
| 423 | typedef struct _LDT_ENTRY { |
| 424 | union { |
| 425 | struct { |
| 426 | UShort LimitLow; |
| 427 | UShort BaseLow; |
| 428 | unsigned BaseMid : 8; |
| 429 | unsigned Type : 5; |
| 430 | unsigned Dpl : 2; |
| 431 | unsigned Pres : 1; |
| 432 | unsigned LimitHi : 4; |
| 433 | unsigned Sys : 1; |
| 434 | unsigned Reserved_0 : 1; |
| 435 | unsigned Default_Big : 1; |
| 436 | unsigned Granularity : 1; |
| 437 | unsigned BaseHi : 8; |
| 438 | } Bits; |
| 439 | struct { |
| 440 | UInt word1; |
| 441 | UInt word2; |
| 442 | } Words; |
| 443 | } |
| 444 | LdtEnt; |
| 445 | } VgLdtEntry; |
| 446 | |
| 447 | /* Maximum number of LDT entries supported (by the x86). */ |
| 448 | #define VG_M_LDT_ENTRIES 8192 |
| 449 | /* The size of each LDT entry == sizeof(VgLdtEntry) */ |
| 450 | #define VG_LDT_ENTRY_SIZE 8 |
| 451 | |
| 452 | /* Alloc & copy, and dealloc. */ |
| 453 | extern VgLdtEntry* |
| 454 | VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt ); |
| 455 | extern void |
| 456 | VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt ); |
| 457 | |
| 458 | /* Simulate the modify_ldt syscall. */ |
| 459 | extern Int VG_(sys_modify_ldt) ( ThreadId tid, |
| 460 | Int func, void* ptr, UInt bytecount ); |
| 461 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 462 | /* Called from generated code. Given a segment selector and a virtual |
| 463 | address, return a linear address, and do limit checks too. */ |
| 464 | extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr ); |
| 465 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 466 | |
| 467 | /* --------------------------------------------------------------------- |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 468 | Exports of vg_scheduler.c |
| 469 | ------------------------------------------------------------------ */ |
| 470 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 471 | typedef |
| 472 | enum { |
| 473 | VgTs_Empty, /* this slot is not in use */ |
| 474 | VgTs_Runnable, /* waiting to be scheduled */ |
| 475 | VgTs_WaitJoiner, /* waiting for someone to do join on me */ |
| 476 | VgTs_WaitJoinee, /* waiting for the thread I did join on */ |
| 477 | VgTs_WaitFD, /* waiting for I/O completion on a fd */ |
| 478 | VgTs_WaitMX, /* waiting on a mutex */ |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 479 | VgTs_WaitCV, /* waiting on a condition variable */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 480 | VgTs_WaitSIG, /* waiting due to sigwait() */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 481 | VgTs_Sleeping /* sleeping for a while */ |
| 482 | } |
| 483 | ThreadStatus; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 484 | |
| 485 | /* An entry in a threads's cleanup stack. */ |
| 486 | typedef |
| 487 | struct { |
| 488 | void (*fn)(void*); |
| 489 | void* arg; |
| 490 | } |
| 491 | CleanupEntry; |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 492 | |
| 493 | /* An entry in a thread's fork-handler stack. */ |
| 494 | typedef |
| 495 | struct { |
| 496 | void (*prepare)(void); |
| 497 | void (*parent)(void); |
| 498 | void (*child)(void); |
| 499 | } |
| 500 | ForkHandlerEntry; |
| 501 | |
| 502 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 503 | struct _ThreadState { |
| 504 | /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED. |
| 505 | The thread identity is simply the index in vg_threads[]. |
| 506 | ThreadId == 1 is the root thread and has the special property |
| 507 | that we don't try and allocate or deallocate its stack. For |
| 508 | convenience of generating error message, we also put the |
| 509 | ThreadId in this tid field, but be aware that it should |
| 510 | ALWAYS == the index in vg_threads[]. */ |
| 511 | ThreadId tid; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 512 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 513 | /* Current scheduling status. |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 514 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 515 | Complications: whenever this is set to VgTs_WaitMX, you |
| 516 | should also set .m_edx to whatever the required return value |
| 517 | is for pthread_mutex_lock / pthread_cond_timedwait for when |
| 518 | the mutex finally gets unblocked. */ |
| 519 | ThreadStatus status; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 520 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 521 | /* When .status == WaitMX, points to the mutex I am waiting for. |
| 522 | When .status == WaitCV, points to the mutex associated with |
| 523 | the condition variable indicated by the .associated_cv field. |
| 524 | In all other cases, should be NULL. */ |
| 525 | void* /*pthread_mutex_t* */ associated_mx; |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 526 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 527 | /* When .status == WaitCV, points to the condition variable I am |
| 528 | waiting for. In all other cases, should be NULL. */ |
| 529 | void* /*pthread_cond_t* */ associated_cv; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 530 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 531 | /* If VgTs_Sleeping, this is when we should wake up, measured in |
| 532 | milliseconds as supplied by VG_(read_millisecond_counter). |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 533 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 534 | If VgTs_WaitCV, this indicates the time at which |
| 535 | pthread_cond_timedwait should wake up. If == 0xFFFFFFFF, |
| 536 | this means infinitely far in the future, viz, |
| 537 | pthread_cond_wait. */ |
| 538 | UInt awaken_at; |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 539 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 540 | /* If VgTs_WaitJoiner, return value, as generated by joinees. */ |
| 541 | void* joinee_retval; |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 542 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 543 | /* If VgTs_WaitJoinee, place to copy the return value to, and |
| 544 | the identity of the thread we're waiting for. */ |
| 545 | void** joiner_thread_return; |
| 546 | ThreadId joiner_jee_tid; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 547 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 548 | /* Whether or not detached. */ |
| 549 | Bool detached; |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 550 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 551 | /* Cancelability state and type. */ |
| 552 | Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */ |
| 553 | Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */ |
| 554 | |
| 555 | /* Pointer to fn to call to do cancellation. Indicates whether |
| 556 | or not cancellation is pending. If NULL, not pending. Else |
| 557 | should be &thread_exit_wrapper(), indicating that |
| 558 | cancallation is pending. */ |
| 559 | void (*cancel_pend)(void*); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 560 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 561 | /* The cleanup stack. */ |
| 562 | Int custack_used; |
| 563 | CleanupEntry custack[VG_N_CLEANUPSTACK]; |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 564 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 565 | /* thread-specific data */ |
| 566 | void* specifics[VG_N_THREAD_KEYS]; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 567 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 568 | /* This thread's blocked-signals mask. Semantics is that for a |
| 569 | signal to be delivered to this thread, the signal must not be |
| 570 | blocked by either the process-wide signal mask nor by this |
| 571 | one. So, if this thread is prepared to handle any signal that |
| 572 | the process as a whole is prepared to handle, this mask should |
| 573 | be made empty -- and that it is its default, starting |
| 574 | state. */ |
| 575 | vki_ksigset_t sig_mask; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 576 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 577 | /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG, |
| 578 | is the set of signals for which we are sigwait()ing. */ |
| 579 | vki_ksigset_t sigs_waited_for; |
sewardj | 9a2224b | 2002-06-19 10:17:40 +0000 | [diff] [blame] | 580 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 581 | /* Counts the number of times a signal handler for this thread |
| 582 | has returned. This makes it easy to implement pause(), by |
| 583 | polling this value, of course interspersed with nanosleeps, |
| 584 | and waiting till it changes. */ |
| 585 | UInt n_signals_returned; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 586 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 587 | /* Stacks. When a thread slot is freed, we don't deallocate its |
| 588 | stack; we just leave it lying around for the next use of the |
| 589 | slot. If the next use of the slot requires a larger stack, |
| 590 | only then is the old one deallocated and a new one |
| 591 | allocated. |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 592 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 593 | For the main thread (threadid == 0), this mechanism doesn't |
| 594 | apply. We don't know the size of the stack since we didn't |
| 595 | allocate it, and furthermore we never reallocate it. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 596 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 597 | /* The allocated size of this thread's stack (permanently zero |
| 598 | if this is ThreadId == 0, since we didn't allocate its stack) */ |
| 599 | UInt stack_size; |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 600 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 601 | /* Address of the lowest word in this thread's stack. NULL means |
| 602 | not allocated yet. |
| 603 | */ |
| 604 | Addr stack_base; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 605 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 606 | /* Address of the highest legitimate word in this stack. This is |
| 607 | used for error messages only -- not critical for execution |
| 608 | correctness. Is is set for all stacks, specifically including |
| 609 | ThreadId == 0 (the main thread). */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 610 | Addr stack_highest_word; |
| 611 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 612 | /* Pointer to this thread's Local (Segment) Descriptor Table. |
| 613 | Starts out as NULL, indicating there is no table, and we hope to |
| 614 | keep it that way. If the thread does __NR_modify_ldt to create |
| 615 | entries, we allocate a 8192-entry table at that point. This is |
| 616 | a straight copy of the Linux kernel's scheme. Don't forget to |
| 617 | deallocate this at thread exit. */ |
| 618 | VgLdtEntry* ldt; |
| 619 | |
| 620 | /* Saved machine context. Note the FPU state, %EIP and segment |
| 621 | registers are not shadowed. |
| 622 | |
| 623 | Although the segment registers are 16 bits long, storage |
| 624 | management here, in VG_(baseBlock) and in VG_(m_state_static) is |
| 625 | simplified if we pretend they are 32 bits. */ |
| 626 | UInt m_cs; |
| 627 | UInt m_ss; |
| 628 | UInt m_ds; |
| 629 | UInt m_es; |
| 630 | UInt m_fs; |
| 631 | UInt m_gs; |
| 632 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 633 | UInt m_eax; |
| 634 | UInt m_ebx; |
| 635 | UInt m_ecx; |
| 636 | UInt m_edx; |
| 637 | UInt m_esi; |
| 638 | UInt m_edi; |
| 639 | UInt m_ebp; |
| 640 | UInt m_esp; |
| 641 | UInt m_eflags; |
| 642 | UInt m_eip; |
| 643 | UInt m_fpu[VG_SIZE_OF_FPUSTATE_W]; |
| 644 | |
| 645 | UInt sh_eax; |
| 646 | UInt sh_ebx; |
| 647 | UInt sh_ecx; |
| 648 | UInt sh_edx; |
| 649 | UInt sh_esi; |
| 650 | UInt sh_edi; |
| 651 | UInt sh_ebp; |
| 652 | UInt sh_esp; |
| 653 | UInt sh_eflags; |
| 654 | }; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 655 | |
| 656 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 657 | /* The thread table. */ |
| 658 | extern ThreadState VG_(threads)[VG_N_THREADS]; |
| 659 | |
| 660 | /* Check that tid is in range and denotes a non-Empty thread. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 661 | extern Bool VG_(is_valid_tid) ( ThreadId tid ); |
| 662 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 663 | /* Check that tid is in range. */ |
| 664 | extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid ); |
| 665 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 666 | /* Copy the specified thread's state into VG_(baseBlock) in |
| 667 | preparation for running it. */ |
| 668 | extern void VG_(load_thread_state)( ThreadId ); |
| 669 | |
| 670 | /* Save the specified thread's state back in VG_(baseBlock), and fill |
| 671 | VG_(baseBlock) with junk, for sanity-check reasons. */ |
| 672 | extern void VG_(save_thread_state)( ThreadId ); |
| 673 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 674 | /* And for the currently running one, if valid. */ |
| 675 | extern ThreadState* VG_(get_current_thread_state) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 676 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 677 | /* Similarly ... */ |
| 678 | extern ThreadId VG_(get_current_tid) ( void ); |
| 679 | |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 680 | /* Nuke all threads except tid. */ |
| 681 | extern void VG_(nuke_all_threads_except) ( ThreadId me ); |
| 682 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 683 | |
| 684 | /* Return codes from the scheduler. */ |
| 685 | typedef |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 686 | enum { |
| 687 | VgSrc_Deadlock, /* no runnable threads and no prospect of any |
| 688 | even if we wait for a long time */ |
| 689 | VgSrc_ExitSyscall, /* client called exit(). This is the normal |
| 690 | route out. */ |
| 691 | VgSrc_BbsDone /* In a debugging run, the specified number of |
| 692 | bbs has been completed. */ |
| 693 | } |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 694 | VgSchedReturnCode; |
| 695 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 696 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 697 | /* The scheduler. */ |
| 698 | extern VgSchedReturnCode VG_(scheduler) ( void ); |
| 699 | |
| 700 | extern void VG_(scheduler_init) ( void ); |
| 701 | |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 702 | extern void VG_(pp_sched_status) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 703 | |
| 704 | /* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */ |
| 705 | extern jmp_buf VG_(scheduler_jmpbuf); |
sewardj | 872051c | 2002-07-13 12:12:56 +0000 | [diff] [blame] | 706 | /* This says whether scheduler_jmpbuf is actually valid. Needed so |
| 707 | that our signal handler doesn't longjmp when the buffer isn't |
| 708 | actually valid. */ |
| 709 | extern Bool VG_(scheduler_jmpbuf_valid); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 710 | /* ... and if so, here's the signal which caused it to do so. */ |
| 711 | extern Int VG_(longjmpd_on_signal); |
| 712 | |
| 713 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 714 | /* Possible places where the main stack might be based. We check that |
| 715 | the initial stack, which we can't move, is allocated here. |
| 716 | VG_(scheduler_init) checks this. Andrea Archelangi's 2.4 kernels |
| 717 | have been rumoured to start stacks at 0x80000000, so that too is |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 718 | considered. It seems systems with longer uptimes tend to to use |
| 719 | stacks which start at 0x40000000 sometimes. JRS 2002-Aug-21: I |
| 720 | also have reports of stacks starting at 0xE0000000.*/ |
| 721 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 722 | #define VG_STARTUP_STACK_BASE_1 (Addr)0xC0000000 |
| 723 | #define VG_STARTUP_STACK_BASE_2 (Addr)0x80000000 |
daywalker | a256220 | 2002-07-15 19:39:51 +0000 | [diff] [blame] | 724 | #define VG_STARTUP_STACK_BASE_3 (Addr)0x40000000 |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 725 | #define VG_STARTUP_STACK_BASE_4 (Addr)0xE0000000 |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 726 | #define VG_STARTUP_STACK_SMALLERTHAN 0x100000 /* 1024k */ |
| 727 | |
| 728 | #define VG_STACK_MATCHES_BASE(zzstack, zzbase) \ |
| 729 | ( \ |
| 730 | ((zzstack) & ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN)) \ |
| 731 | == \ |
| 732 | ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN) \ |
| 733 | ) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 734 | |
| 735 | |
| 736 | /* The red-zone size which we put at the bottom (highest address) of |
| 737 | thread stacks, for paranoia reasons. This can be arbitrary, and |
| 738 | doesn't really need to be set at compile time. */ |
| 739 | #define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4 |
| 740 | |
| 741 | #define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \ |
| 742 | (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD) |
| 743 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 744 | /* Junk to fill up a thread's shadow regs with when shadow regs aren't |
| 745 | * being used. */ |
| 746 | #define VG_UNUSED_SHADOW_REG_VALUE 0x27182818 |
| 747 | |
| 748 | /* What we set a shadow register to when written by SET_EAX and similar |
| 749 | * things. */ |
| 750 | extern UInt VG_(written_shadow_reg); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 751 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 752 | /* Write a value to the client's %EDX (request return value register) |
| 753 | and set the shadow to indicate it is defined. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 754 | #define SET_EDX(zztid, zzval) \ |
| 755 | do { VG_(threads)[zztid].m_edx = (zzval); \ |
| 756 | VG_(threads)[zztid].sh_edx = VG_(written_shadow_reg); \ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 757 | } while (0) |
| 758 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 759 | #define SET_EAX(zztid, zzval) \ |
| 760 | do { VG_(threads)[zztid].m_eax = (zzval); \ |
| 761 | VG_(threads)[zztid].sh_eax = VG_(written_shadow_reg); \ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 762 | } while (0) |
| 763 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 764 | |
| 765 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 766 | Exports of vg_signals.c |
| 767 | ------------------------------------------------------------------ */ |
| 768 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 769 | extern void VG_(sigstartup_actions) ( void ); |
| 770 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 771 | extern Bool VG_(deliver_signals) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 772 | extern void VG_(unblock_host_signal) ( Int sigNo ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 773 | extern void VG_(handle_SCSS_change) ( Bool force_update ); |
| 774 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 775 | |
| 776 | /* Fake system calls for signal handling. */ |
sewardj | 2342c97 | 2002-05-22 23:34:20 +0000 | [diff] [blame] | 777 | extern void VG_(do__NR_sigaltstack) ( ThreadId tid ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 778 | extern void VG_(do__NR_sigaction) ( ThreadId tid ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 779 | extern void VG_(do__NR_sigprocmask) ( ThreadId tid, |
| 780 | Int how, |
| 781 | vki_ksigset_t* set, |
| 782 | vki_ksigset_t* oldset ); |
| 783 | extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid, |
| 784 | Int how, |
| 785 | vki_ksigset_t* set, |
| 786 | vki_ksigset_t* oldset ); |
| 787 | extern void VG_(send_signal_to_thread) ( ThreadId thread, |
| 788 | Int signo ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 789 | |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 790 | extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set ); |
| 791 | |
| 792 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 793 | /* Modify the current thread's state once we have detected it is |
| 794 | returning from a signal handler. */ |
sewardj | 77e466c | 2002-04-14 02:29:29 +0000 | [diff] [blame] | 795 | extern Bool VG_(signal_returns) ( ThreadId ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 796 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 797 | /* Handy utilities to block/restore all host signals. */ |
| 798 | extern void VG_(block_all_host_signals) |
| 799 | ( /* OUT */ vki_ksigset_t* saved_mask ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 800 | extern void VG_(restore_all_host_signals) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 801 | ( /* IN */ vki_ksigset_t* saved_mask ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 802 | |
| 803 | /* --------------------------------------------------------------------- |
| 804 | Exports of vg_mylibc.c |
| 805 | ------------------------------------------------------------------ */ |
| 806 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 807 | #define vg_assert(expr) \ |
| 808 | ((void) ((expr) ? 0 : \ |
| 809 | (VG_(core_assert_fail) (VG__STRING(expr), \ |
| 810 | __FILE__, __LINE__, \ |
| 811 | __PRETTY_FUNCTION__), 0))) |
| 812 | __attribute__ ((__noreturn__)) |
| 813 | extern void VG_(core_assert_fail) ( Char* expr, Char* file, |
| 814 | Int line, Char* fn ); |
| 815 | __attribute__ ((__noreturn__)) |
| 816 | extern void VG_(core_panic) ( Char* str ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 817 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 818 | /* VG_(brk) not public so skins cannot screw with curr_dataseg_end */ |
| 819 | extern void* VG_(brk) ( void* end_data_segment ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 820 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 821 | /* Skins use VG_(strdup)() which doesn't expose ArenaId */ |
| 822 | extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 823 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 824 | /* Skins shouldn't need these...(?) */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 825 | extern void VG_(start_rdtsc_calibration) ( void ); |
| 826 | extern void VG_(end_rdtsc_calibration) ( void ); |
| 827 | extern UInt VG_(read_millisecond_timer) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 828 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 829 | extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 830 | extern Int VG_(select)( Int n, |
| 831 | vki_fd_set* readfds, |
| 832 | vki_fd_set* writefds, |
| 833 | vki_fd_set* exceptfds, |
| 834 | struct vki_timeval * timeout ); |
| 835 | extern Int VG_(nanosleep)( const struct vki_timespec *req, |
| 836 | struct vki_timespec *rem ); |
| 837 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 838 | /* --------------------------------------------------------------------- |
| 839 | Definitions for the JITter (vg_translate.c, vg_to_ucode.c, |
| 840 | vg_from_ucode.c). |
| 841 | ------------------------------------------------------------------ */ |
| 842 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 843 | #define VG_IS_FLAG_SUBSET(set1,set2) \ |
| 844 | (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) ) |
| 845 | |
| 846 | #define VG_UNION_FLAG_SETS(set1,set2) \ |
| 847 | ( ((FlagSet)set1) | ((FlagSet)set2) ) |
| 848 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 849 | /* --------------------------------------------------------------------- |
| 850 | Exports of vg_demangle.c |
| 851 | ------------------------------------------------------------------ */ |
| 852 | |
| 853 | extern void VG_(demangle) ( Char* orig, Char* result, Int result_size ); |
| 854 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 855 | /* --------------------------------------------------------------------- |
| 856 | Exports of vg_from_ucode.c |
| 857 | ------------------------------------------------------------------ */ |
| 858 | |
| 859 | extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes ); |
| 860 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 861 | extern void VG_(print_ccall_stats) ( void ); |
| 862 | extern void VG_(print_UInstr_histogram) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 863 | |
| 864 | /* --------------------------------------------------------------------- |
| 865 | Exports of vg_to_ucode.c |
| 866 | ------------------------------------------------------------------ */ |
| 867 | |
| 868 | extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 869 | |
| 870 | /* --------------------------------------------------------------------- |
| 871 | Exports of vg_translate.c |
| 872 | ------------------------------------------------------------------ */ |
| 873 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 874 | extern void VG_(translate) ( ThreadState* tst, |
| 875 | Addr orig_addr, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 876 | UInt* orig_size, |
| 877 | Addr* trans_addr, |
| 878 | UInt* trans_size ); |
| 879 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 880 | extern Char* VG_(nameCondcode) ( Condcode cond ); |
| 881 | extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness, |
| 882 | UInstr* u ); |
| 883 | extern void VG_(saneUCodeBlock) ( UCodeBlock* cb ); |
| 884 | extern Bool VG_(saneUCodeBlockCalls) ( UCodeBlock* cb ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 885 | |
| 886 | /* --------------------------------------------------------------------- |
| 887 | Exports of vg_execontext.c. |
| 888 | ------------------------------------------------------------------ */ |
| 889 | |
| 890 | /* Records the PC and a bit of the call chain. The first 4 %eip |
| 891 | values are used in comparisons do remove duplicate errors, and for |
| 892 | comparing against suppression specifications. The rest are purely |
| 893 | informational (but often important). */ |
| 894 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 895 | struct _ExeContext { |
| 896 | struct _ExeContext * next; |
| 897 | /* Variable-length array. The size is VG_(clo_backtrace_size); at |
| 898 | least 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip, |
| 899 | [1] is its caller, [2] is the caller of [1], etc. */ |
| 900 | Addr eips[0]; |
| 901 | }; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 902 | |
| 903 | |
| 904 | /* Initialise the ExeContext storage mechanism. */ |
| 905 | extern void VG_(init_ExeContext_storage) ( void ); |
| 906 | |
| 907 | /* Print stats (informational only). */ |
| 908 | extern void VG_(show_ExeContext_stats) ( void ); |
| 909 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 910 | /* Like VG_(get_ExeContext), but with a slightly different type */ |
| 911 | extern ExeContext* VG_(get_ExeContext2) ( Addr eip, Addr ebp, |
| 912 | Addr ebp_min, Addr ebp_max ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 913 | |
| 914 | |
| 915 | /* --------------------------------------------------------------------- |
| 916 | Exports of vg_errcontext.c. |
| 917 | ------------------------------------------------------------------ */ |
| 918 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 919 | /* Note: it is imperative this doesn't overlap with (0..) at all, as skins |
| 920 | * effectively extend it by defining their own enums in the (0..) range. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 921 | typedef |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 922 | enum { |
| 923 | PThreadSupp = -1, /* Matches PThreadErr */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 924 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 925 | CoreSuppKind; |
| 926 | |
| 927 | /* For each caller specified for a suppression, record the nature of |
| 928 | the caller name. Not of interest to skins. */ |
| 929 | typedef |
| 930 | enum { |
| 931 | ObjName, /* Name is of an shared object file. */ |
| 932 | FunName /* Name is of a function. */ |
| 933 | } |
| 934 | SuppLocTy; |
| 935 | |
| 936 | /* Suppressions. Skin part `SkinSupp' (which is all skins have to deal |
| 937 | with) is in vg_skin.h */ |
| 938 | typedef |
| 939 | struct _CoreSupp { |
| 940 | struct _CoreSupp* next; |
| 941 | /* The number of times this error has been suppressed. */ |
| 942 | Int count; |
| 943 | /* The name by which the suppression is referred to. */ |
| 944 | Char* sname; |
| 945 | /* First two (name of fn where err occurs, and immediate caller) |
| 946 | * are mandatory; extra two are optional. */ |
| 947 | SuppLocTy caller_ty[VG_N_SUPP_CALLERS]; |
| 948 | Char* caller [VG_N_SUPP_CALLERS]; |
| 949 | /* The skin-specific part */ |
| 950 | SkinSupp skin_supp; |
| 951 | } |
| 952 | CoreSupp; |
| 953 | |
| 954 | /* Note: it is imperative this doesn't overlap with (0..) at all, as skins |
| 955 | * effectively extend it by defining their own enums in the (0..) range. */ |
| 956 | typedef |
| 957 | enum { |
| 958 | PThreadErr = -1, /* Pthreading error */ |
| 959 | } |
| 960 | CoreErrorKind; |
| 961 | |
| 962 | /* Errors. Skin part `SkinError' (which is all skins have to deal |
| 963 | with) is in vg_skin.h */ |
| 964 | typedef |
| 965 | struct _CoreErrContext { |
| 966 | struct _CoreErrContext* next; |
| 967 | /* NULL if unsuppressed; or ptr to suppression record. */ |
| 968 | CoreSupp* supp; |
| 969 | Int count; |
| 970 | ExeContext* where; |
| 971 | ThreadId tid; |
| 972 | /* These record %EIP, %ESP and %EBP at the error point. They |
| 973 | are only used to make GDB-attaching convenient; there is no |
| 974 | other purpose; specifically they are not used to do |
| 975 | comparisons between errors. */ |
| 976 | UInt m_eip; |
| 977 | UInt m_esp; |
| 978 | UInt m_ebp; |
| 979 | /* The skin-specific part */ |
| 980 | SkinError skin_err; |
| 981 | } |
| 982 | CoreError; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 983 | |
| 984 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 985 | extern void VG_(load_suppressions) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 986 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 987 | extern void VG_(record_pthread_error) ( ThreadId tid, Char* msg ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 988 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 989 | extern void VG_(show_all_errors) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 990 | |
| 991 | /* --------------------------------------------------------------------- |
| 992 | Exports of vg_procselfmaps.c |
| 993 | ------------------------------------------------------------------ */ |
| 994 | |
| 995 | extern |
| 996 | void VG_(read_procselfmaps) ( |
| 997 | void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* ) |
| 998 | ); |
| 999 | |
| 1000 | |
| 1001 | /* --------------------------------------------------------------------- |
| 1002 | Exports of vg_symtab2.c |
| 1003 | ------------------------------------------------------------------ */ |
| 1004 | |
| 1005 | /* We assume the executable is loaded here ... can't really find |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1006 | out. There is a hacky sanity check in VG_(init_memory)() |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1007 | which should trip up most stupidities. |
| 1008 | */ |
| 1009 | #define VG_ASSUMED_EXE_BASE (Addr)0x8048000 |
| 1010 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1011 | extern void VG_(maybe_read_symbols) ( void ); |
| 1012 | extern void VG_(read_symtab_callback) ( Addr start, UInt size, |
| 1013 | Char rr, Char ww, Char xx, |
| 1014 | UInt foffset, UChar* filename ); |
| 1015 | extern void VG_(maybe_unload_symbols) ( Addr start, UInt length ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1016 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1017 | extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname ); |
| 1018 | extern void VG_(mini_stack_dump) ( ExeContext* ec ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1019 | |
| 1020 | |
| 1021 | /* --------------------------------------------------------------------- |
| 1022 | Exports of vg_clientmalloc.c |
| 1023 | ------------------------------------------------------------------ */ |
| 1024 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1025 | extern void VG_(client_malloc_init)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1026 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1027 | /* These are called from the scheduler, when it intercepts a user |
| 1028 | request. */ |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 1029 | extern void* VG_(client_malloc) ( ThreadState* tst, |
| 1030 | UInt size, VgAllocKind kind ); |
| 1031 | extern void* VG_(client_memalign) ( ThreadState* tst, |
| 1032 | UInt align, UInt size ); |
| 1033 | extern void VG_(client_free) ( ThreadState* tst, |
| 1034 | void* ptrV, VgAllocKind kind ); |
| 1035 | extern void* VG_(client_calloc) ( ThreadState* tst, |
| 1036 | UInt nmemb, UInt size1 ); |
| 1037 | extern void* VG_(client_realloc) ( ThreadState* tst, |
| 1038 | void* ptrV, UInt size_new ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1039 | |
| 1040 | |
| 1041 | /* --------------------------------------------------------------------- |
| 1042 | Exports of vg_main.c |
| 1043 | ------------------------------------------------------------------ */ |
| 1044 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1045 | /* Sanity checks which may be done at any time. The scheduler decides when. */ |
| 1046 | extern void VG_(do_sanity_checks) ( Bool force_expensive ); |
| 1047 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1048 | /* A structure used as an intermediary when passing the simulated |
| 1049 | CPU's state to some assembly fragments, particularly system calls. |
| 1050 | Stuff is copied from baseBlock to here, the assembly magic runs, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1051 | and then the inverse copy is done. |
| 1052 | */ |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1053 | extern UInt VG_(m_state_static) [6 /* segment regs, Intel order */ |
| 1054 | + 8 /* int regs, in Intel order */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1055 | + 1 /* %eflags */ |
| 1056 | + 1 /* %eip */ |
| 1057 | + VG_SIZE_OF_FPUSTATE_W /* FPU state */ |
| 1058 | ]; |
| 1059 | |
| 1060 | /* Handy fns for doing the copy back and forth. */ |
| 1061 | extern void VG_(copy_baseBlock_to_m_state_static) ( void ); |
| 1062 | extern void VG_(copy_m_state_static_to_baseBlock) ( void ); |
| 1063 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1064 | /* Called when some unhandleable client behaviour is detected. |
| 1065 | Prints a msg and aborts. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1066 | extern void VG_(unimplemented) ( Char* msg ) |
| 1067 | __attribute__((__noreturn__)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1068 | |
| 1069 | /* The stack on which Valgrind runs. We can't use the same stack as the |
| 1070 | simulatee -- that's an important design decision. */ |
| 1071 | extern UInt VG_(stack)[10000]; |
| 1072 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1073 | /* Similarly, we have to ask for signals to be delivered on an alternative |
| 1074 | stack, since it is possible, although unlikely, that we'll have to run |
| 1075 | client code from inside the Valgrind-installed signal handler. If this |
| 1076 | happens it will be done by vg_deliver_signal_immediately(). */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1077 | extern UInt VG_(sigstack)[10000]; |
| 1078 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1079 | /* Holds client's %esp at the point we gained control. From this the |
| 1080 | client's argc, argv and envp are deduced. */ |
| 1081 | extern Addr VG_(esp_at_startup); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1082 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1083 | /* Remove valgrind.so and skin's .so from a LD_PRELOAD=... string so child |
| 1084 | processes don't get traced into. Also mess up $libdir/valgrind so that |
| 1085 | our libpthread.so disappears from view. */ |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1086 | void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str, |
| 1087 | Char* ld_library_path_str ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1088 | |
| 1089 | /* Something of a function looking for a home ... start up GDB. This |
| 1090 | is called from VG_(swizzle_esp_then_start_GDB) and so runs on the |
| 1091 | *client's* stack. This is necessary to give GDB the illusion that |
| 1092 | the client program really was running on the real cpu. */ |
| 1093 | extern void VG_(start_GDB_whilst_on_client_stack) ( void ); |
| 1094 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1095 | /* 64-bit counter for the number of basic blocks done. */ |
| 1096 | extern ULong VG_(bbs_done); |
| 1097 | /* 64-bit counter for the number of bbs to go before a debug exit. */ |
| 1098 | extern ULong VG_(bbs_to_go); |
| 1099 | |
| 1100 | /* Counts downwards in vg_run_innerloop. */ |
| 1101 | extern UInt VG_(dispatch_ctr); |
| 1102 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1103 | /* Is the client running on the simulated CPU or the real one? */ |
| 1104 | extern Bool VG_(running_on_simd_CPU); /* Initially False */ |
| 1105 | |
| 1106 | /* The current LRU epoch. */ |
| 1107 | extern UInt VG_(current_epoch); |
| 1108 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1109 | /* This is the ThreadId of the last thread the scheduler ran. */ |
| 1110 | extern ThreadId VG_(last_run_tid); |
| 1111 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1112 | /* This is the argument to __NR_exit() supplied by the first thread to |
| 1113 | call that syscall. We eventually pass that to __NR_exit() for |
| 1114 | real. */ |
| 1115 | extern UInt VG_(exitcode); |
| 1116 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1117 | |
| 1118 | /* --- Counters, for informational purposes only. --- */ |
| 1119 | |
| 1120 | /* Number of lookups which miss the fast tt helper. */ |
| 1121 | extern UInt VG_(tt_fast_misses); |
| 1122 | |
| 1123 | /* Counts for LRU informational messages. */ |
| 1124 | |
| 1125 | /* Number and total o/t size of new translations this epoch. */ |
| 1126 | extern UInt VG_(this_epoch_in_count); |
| 1127 | extern UInt VG_(this_epoch_in_osize); |
| 1128 | extern UInt VG_(this_epoch_in_tsize); |
| 1129 | /* Number and total o/t size of discarded translations this epoch. */ |
| 1130 | extern UInt VG_(this_epoch_out_count); |
| 1131 | extern UInt VG_(this_epoch_out_osize); |
| 1132 | extern UInt VG_(this_epoch_out_tsize); |
| 1133 | /* Number and total o/t size of translations overall. */ |
| 1134 | extern UInt VG_(overall_in_count); |
| 1135 | extern UInt VG_(overall_in_osize); |
| 1136 | extern UInt VG_(overall_in_tsize); |
| 1137 | /* Number and total o/t size of discards overall. */ |
| 1138 | extern UInt VG_(overall_out_count); |
| 1139 | extern UInt VG_(overall_out_osize); |
| 1140 | extern UInt VG_(overall_out_tsize); |
| 1141 | |
| 1142 | /* The number of LRU-clearings of TT/TC. */ |
| 1143 | extern UInt VG_(number_of_lrus); |
| 1144 | |
| 1145 | /* Counts pertaining to the register allocator. */ |
| 1146 | |
| 1147 | /* total number of uinstrs input to reg-alloc */ |
| 1148 | extern UInt VG_(uinstrs_prealloc); |
| 1149 | |
| 1150 | /* total number of uinstrs added due to spill code */ |
| 1151 | extern UInt VG_(uinstrs_spill); |
| 1152 | |
| 1153 | /* number of bbs requiring spill code */ |
| 1154 | extern UInt VG_(translations_needing_spill); |
| 1155 | |
| 1156 | /* total of register ranks over all translations */ |
| 1157 | extern UInt VG_(total_reg_rank); |
| 1158 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1159 | /* Counts pertaining to internal sanity checking. */ |
| 1160 | extern UInt VG_(sanity_fast_count); |
| 1161 | extern UInt VG_(sanity_slow_count); |
| 1162 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1163 | /* Counts pertaining to the scheduler. */ |
| 1164 | extern UInt VG_(num_scheduling_events_MINOR); |
| 1165 | extern UInt VG_(num_scheduling_events_MAJOR); |
| 1166 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1167 | |
| 1168 | /* --------------------------------------------------------------------- |
| 1169 | Exports of vg_memory.c |
| 1170 | ------------------------------------------------------------------ */ |
| 1171 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1172 | extern void VG_(init_memory) ( void ); |
| 1173 | extern void VG_(new_exe_segment) ( Addr a, UInt len ); |
| 1174 | extern void VG_(remove_if_exe_segment) ( Addr a, UInt len ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1175 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1176 | /* Called from generated code. */ |
| 1177 | extern void VG_(handle_esp_assignment) ( Addr new_espA ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1178 | |
| 1179 | /* Nasty kludgery to deal with applications which switch stacks, |
| 1180 | like netscape. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1181 | #define VG_PLAUSIBLE_STACK_SIZE 8000000 |
| 1182 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1183 | /* --------------------------------------------------------------------- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1184 | Exports of vg_syscalls.c |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1185 | ------------------------------------------------------------------ */ |
| 1186 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1187 | extern void VG_(init_dataseg_end_for_brk) ( void ); |
| 1188 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1189 | extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1190 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1191 | extern void* VG_(pre_known_blocking_syscall) ( ThreadId tid, Int syscallno ); |
| 1192 | extern void VG_(post_known_blocking_syscall)( ThreadId tid, Int syscallno, |
| 1193 | void* pre_res, Int res ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1194 | |
| 1195 | extern Bool VG_(is_kerror) ( Int res ); |
| 1196 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1197 | #define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \ |
| 1198 | VG_(load_thread_state)(thread_id); \ |
| 1199 | VG_(copy_baseBlock_to_m_state_static)(); \ |
| 1200 | VG_(do_syscall)(); \ |
| 1201 | VG_(copy_m_state_static_to_baseBlock)(); \ |
| 1202 | VG_(save_thread_state)(thread_id); \ |
| 1203 | VG_(threads)[thread_id].sh_eax = VG_(written_shadow_reg);\ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1204 | result_lvalue = VG_(threads)[thread_id].m_eax; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1205 | |
| 1206 | |
| 1207 | /* --------------------------------------------------------------------- |
| 1208 | Exports of vg_transtab.c |
| 1209 | ------------------------------------------------------------------ */ |
| 1210 | |
| 1211 | /* An entry in the translation table (TT). */ |
| 1212 | typedef |
| 1213 | struct { |
| 1214 | /* +0 */ Addr orig_addr; |
| 1215 | /* +4 */ Addr trans_addr; |
| 1216 | /* +8 */ UInt mru_epoch; |
| 1217 | /* +12 */ UShort orig_size; |
| 1218 | /* +14 */ UShort trans_size; |
| 1219 | } |
| 1220 | TTEntry; |
| 1221 | |
| 1222 | /* The number of basic blocks in an epoch (one age-step). */ |
| 1223 | #define VG_BBS_PER_EPOCH 20000 |
| 1224 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1225 | /* The fast-cache for tt-lookup. */ |
| 1226 | extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE]; |
| 1227 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1228 | extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used ); |
| 1229 | extern void VG_(maybe_do_lru_pass) ( void ); |
| 1230 | extern void VG_(flush_transtab) ( void ); |
| 1231 | extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size ); |
| 1232 | extern void VG_(add_to_trans_tab) ( TTEntry* tte ); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1233 | extern void VG_(invalidate_translations) ( Addr start, UInt range ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1234 | |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1235 | extern void VG_(init_tt_tc) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1236 | |
| 1237 | extern void VG_(sanity_check_tc_tt) ( void ); |
| 1238 | extern Addr VG_(search_transtab) ( Addr original_addr ); |
| 1239 | |
| 1240 | extern void VG_(invalidate_tt_fast)( void ); |
| 1241 | |
| 1242 | |
| 1243 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1244 | Exports of vg_syscall.S |
| 1245 | ------------------------------------------------------------------ */ |
| 1246 | |
| 1247 | extern void VG_(do_syscall) ( void ); |
| 1248 | |
| 1249 | |
| 1250 | /* --------------------------------------------------------------------- |
| 1251 | Exports of vg_startup.S |
| 1252 | ------------------------------------------------------------------ */ |
| 1253 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1254 | extern void VG_(switch_to_real_CPU) ( void ); |
| 1255 | |
sewardj | 3580542 | 2002-04-21 13:05:34 +0000 | [diff] [blame] | 1256 | extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error, |
| 1257 | Addr m_esp_at_error, |
| 1258 | Addr m_ebp_at_error ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1259 | |
| 1260 | |
| 1261 | /* --------------------------------------------------------------------- |
| 1262 | Exports of vg_dispatch.S |
| 1263 | ------------------------------------------------------------------ */ |
| 1264 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1265 | /* Run a thread for a (very short) while, until some event happens |
| 1266 | which means we need to defer to the scheduler. */ |
| 1267 | extern UInt VG_(run_innerloop) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1268 | |
| 1269 | |
| 1270 | /* --------------------------------------------------------------------- |
| 1271 | Exports of vg_helpers.S |
| 1272 | ------------------------------------------------------------------ */ |
| 1273 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1274 | /* Mul, div, etc, -- we don't codegen these directly. */ |
| 1275 | extern void VG_(helper_idiv_64_32); |
| 1276 | extern void VG_(helper_div_64_32); |
| 1277 | extern void VG_(helper_idiv_32_16); |
| 1278 | extern void VG_(helper_div_32_16); |
| 1279 | extern void VG_(helper_idiv_16_8); |
| 1280 | extern void VG_(helper_div_16_8); |
| 1281 | |
| 1282 | extern void VG_(helper_imul_32_64); |
| 1283 | extern void VG_(helper_mul_32_64); |
| 1284 | extern void VG_(helper_imul_16_32); |
| 1285 | extern void VG_(helper_mul_16_32); |
| 1286 | extern void VG_(helper_imul_8_16); |
| 1287 | extern void VG_(helper_mul_8_16); |
| 1288 | |
| 1289 | extern void VG_(helper_CLD); |
| 1290 | extern void VG_(helper_STD); |
| 1291 | extern void VG_(helper_get_dirflag); |
| 1292 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 1293 | extern void VG_(helper_CLC); |
| 1294 | extern void VG_(helper_STC); |
| 1295 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1296 | extern void VG_(helper_shldl); |
| 1297 | extern void VG_(helper_shldw); |
| 1298 | extern void VG_(helper_shrdl); |
| 1299 | extern void VG_(helper_shrdw); |
| 1300 | |
| 1301 | extern void VG_(helper_RDTSC); |
| 1302 | extern void VG_(helper_CPUID); |
| 1303 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1304 | extern void VG_(helper_bsf); |
| 1305 | extern void VG_(helper_bsr); |
| 1306 | |
| 1307 | extern void VG_(helper_fstsw_AX); |
| 1308 | extern void VG_(helper_SAHF); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 1309 | extern void VG_(helper_DAS); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 1310 | extern void VG_(helper_DAA); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1311 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1312 | /* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */ |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 1313 | extern void VG_(signalreturn_bogusRA)( void ); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1314 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1315 | /* --------------------------------------------------------------------- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1316 | Things relating to the used skin |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1317 | ------------------------------------------------------------------ */ |
| 1318 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1319 | #define VG_TRACK(fn, args...) \ |
| 1320 | do { \ |
| 1321 | if (VG_(track_events).fn) \ |
| 1322 | VG_(track_events).fn(args); \ |
| 1323 | } while (0) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1324 | |
| 1325 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1326 | /* --------------------------------------------------------------------- |
| 1327 | The state of the simulated CPU. |
| 1328 | ------------------------------------------------------------------ */ |
| 1329 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1330 | /* --------------------------------------------------------------------- |
| 1331 | Offsets into baseBlock for everything which needs to referred to |
| 1332 | from generated code. The order of these decls does not imply |
| 1333 | what the order of the actual offsets is. The latter is important |
| 1334 | and is set up in vg_main.c. |
| 1335 | ------------------------------------------------------------------ */ |
| 1336 | |
| 1337 | /* An array of words. In generated code, %ebp always points to the |
| 1338 | start of this array. Useful stuff, like the simulated CPU state, |
| 1339 | and the addresses of helper functions, can then be found by |
| 1340 | indexing off %ebp. The following declares variables which, at |
| 1341 | startup time, are given values denoting offsets into baseBlock. |
| 1342 | These offsets are in *words* from the start of baseBlock. */ |
| 1343 | |
| 1344 | #define VG_BASEBLOCK_WORDS 200 |
| 1345 | |
| 1346 | extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; |
| 1347 | |
| 1348 | |
| 1349 | /* ----------------------------------------------------- |
| 1350 | Read-write parts of baseBlock. |
| 1351 | -------------------------------------------------- */ |
| 1352 | |
| 1353 | /* State of the simulated CPU. */ |
| 1354 | extern Int VGOFF_(m_eax); |
| 1355 | extern Int VGOFF_(m_ecx); |
| 1356 | extern Int VGOFF_(m_edx); |
| 1357 | extern Int VGOFF_(m_ebx); |
| 1358 | extern Int VGOFF_(m_esp); |
| 1359 | extern Int VGOFF_(m_ebp); |
| 1360 | extern Int VGOFF_(m_esi); |
| 1361 | extern Int VGOFF_(m_edi); |
| 1362 | extern Int VGOFF_(m_eflags); |
| 1363 | extern Int VGOFF_(m_fpustate); |
| 1364 | extern Int VGOFF_(m_eip); |
| 1365 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1366 | extern Int VGOFF_(m_cs); |
| 1367 | extern Int VGOFF_(m_ss); |
| 1368 | extern Int VGOFF_(m_ds); |
| 1369 | extern Int VGOFF_(m_es); |
| 1370 | extern Int VGOFF_(m_fs); |
| 1371 | extern Int VGOFF_(m_gs); |
| 1372 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1373 | /* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */ |
| 1374 | extern Int VGOFF_(spillslots); |
| 1375 | |
| 1376 | /* Records the valid bits for the 8 integer regs & flags reg. */ |
| 1377 | extern Int VGOFF_(sh_eax); |
| 1378 | extern Int VGOFF_(sh_ecx); |
| 1379 | extern Int VGOFF_(sh_edx); |
| 1380 | extern Int VGOFF_(sh_ebx); |
| 1381 | extern Int VGOFF_(sh_esp); |
| 1382 | extern Int VGOFF_(sh_ebp); |
| 1383 | extern Int VGOFF_(sh_esi); |
| 1384 | extern Int VGOFF_(sh_edi); |
| 1385 | extern Int VGOFF_(sh_eflags); |
| 1386 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1387 | /* ----------------------------------------------------- |
| 1388 | Read-only parts of baseBlock. |
| 1389 | -------------------------------------------------- */ |
| 1390 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1391 | /* This thread's LDT pointer. */ |
| 1392 | extern Int VGOFF_(ldt); |
| 1393 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1394 | /* Offsets of addresses of helper functions. A "helper" function is |
| 1395 | one which is called from generated code. */ |
| 1396 | |
| 1397 | extern Int VGOFF_(helper_idiv_64_32); |
| 1398 | extern Int VGOFF_(helper_div_64_32); |
| 1399 | extern Int VGOFF_(helper_idiv_32_16); |
| 1400 | extern Int VGOFF_(helper_div_32_16); |
| 1401 | extern Int VGOFF_(helper_idiv_16_8); |
| 1402 | extern Int VGOFF_(helper_div_16_8); |
| 1403 | |
| 1404 | extern Int VGOFF_(helper_imul_32_64); |
| 1405 | extern Int VGOFF_(helper_mul_32_64); |
| 1406 | extern Int VGOFF_(helper_imul_16_32); |
| 1407 | extern Int VGOFF_(helper_mul_16_32); |
| 1408 | extern Int VGOFF_(helper_imul_8_16); |
| 1409 | extern Int VGOFF_(helper_mul_8_16); |
| 1410 | |
| 1411 | extern Int VGOFF_(helper_CLD); |
| 1412 | extern Int VGOFF_(helper_STD); |
| 1413 | extern Int VGOFF_(helper_get_dirflag); |
| 1414 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 1415 | extern Int VGOFF_(helper_CLC); |
| 1416 | extern Int VGOFF_(helper_STC); |
| 1417 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1418 | extern Int VGOFF_(helper_shldl); |
| 1419 | extern Int VGOFF_(helper_shldw); |
| 1420 | extern Int VGOFF_(helper_shrdl); |
| 1421 | extern Int VGOFF_(helper_shrdw); |
| 1422 | |
| 1423 | extern Int VGOFF_(helper_RDTSC); |
| 1424 | extern Int VGOFF_(helper_CPUID); |
| 1425 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1426 | extern Int VGOFF_(helper_bsf); |
| 1427 | extern Int VGOFF_(helper_bsr); |
| 1428 | |
| 1429 | extern Int VGOFF_(helper_fstsw_AX); |
| 1430 | extern Int VGOFF_(helper_SAHF); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 1431 | extern Int VGOFF_(helper_DAS); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 1432 | extern Int VGOFF_(helper_DAA); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1433 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1434 | extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1435 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1436 | /* For storing extension-specific helpers, determined at runtime. The addr |
| 1437 | * and offset arrays together form a (addr, offset) map that allows a |
| 1438 | * helper's baseBlock offset to be computed from its address. It's done |
| 1439 | * like this so CCALL_M_Ns and other helper calls can use the function |
| 1440 | * address rather than having to much around with offsets. */ |
| 1441 | extern UInt VG_(n_compact_helpers); |
| 1442 | extern UInt VG_(n_noncompact_helpers); |
| 1443 | |
| 1444 | extern Addr VG_(compact_helper_addrs) []; |
| 1445 | extern Int VG_(compact_helper_offsets)[]; |
| 1446 | |
| 1447 | extern Addr VG_(noncompact_helper_addrs) []; |
| 1448 | extern Int VG_(noncompact_helper_offsets)[]; |
| 1449 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1450 | |
| 1451 | #endif /* ndef __VG_INCLUDE_H */ |
| 1452 | |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1453 | |
| 1454 | /* --------------------------------------------------------------------- |
| 1455 | Finally - autoconf-generated settings |
| 1456 | ------------------------------------------------------------------ */ |
| 1457 | |
| 1458 | #include "config.h" |
| 1459 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1460 | /*--------------------------------------------------------------------*/ |
| 1461 | /*--- end vg_include.h ---*/ |
| 1462 | /*--------------------------------------------------------------------*/ |