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