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 | |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 12 | Copyright (C) 2000-2003 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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.) */ |
njn | 9a07c22 | 2003-06-29 10:18:48 +0000 | [diff] [blame] | 119 | #define VG_N_WAITING_FDS 20 |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 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. */ |
sewardj | 61821c0 | 2003-05-04 13:02:10 +0000 | [diff] [blame] | 132 | #define VG_N_CLEANUPSTACK 16 |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 133 | |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 134 | /* Number of entries in each thread's fork-handler stack. */ |
sewardj | 4700f04 | 2003-07-26 17:49:58 +0000 | [diff] [blame] | 135 | #define VG_N_FORKHANDLERSTACK 4 |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 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 | |
njn | 6eba4ef | 2003-05-01 08:06:41 +0000 | [diff] [blame] | 140 | /* Valgrind's stack sizes, in words */ |
| 141 | #define VG_STACK_SIZE_W 10000 |
| 142 | #define VG_SIGSTACK_SIZE_W 10000 |
njn | 12a5714 | 2003-04-30 20:49:10 +0000 | [diff] [blame] | 143 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 144 | |
| 145 | /* --------------------------------------------------------------------- |
| 146 | Basic types |
| 147 | ------------------------------------------------------------------ */ |
| 148 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 149 | /* Just pray that gcc's constant folding works properly ... */ |
| 150 | #define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \ |
| 151 | ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \ |
| 152 | | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0)) |
| 153 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 154 | /* --------------------------------------------------------------------- |
| 155 | Command-line-settable options |
| 156 | ------------------------------------------------------------------ */ |
| 157 | |
sewardj | 4f094a7 | 2002-11-05 23:37:35 +0000 | [diff] [blame] | 158 | /* Default destination port to be used in logging over a network, if |
| 159 | none specified. */ |
| 160 | #define VG_CLO_DEFAULT_LOGPORT 1500 |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 161 | |
| 162 | /* The max number of suppression files. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 163 | #define VG_CLO_MAX_SFILES 10 |
| 164 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 165 | /* Describes where logging output is to be sent. */ |
| 166 | typedef |
| 167 | enum { |
| 168 | VgLogTo_Fd, |
| 169 | VgLogTo_File, |
| 170 | VgLogTo_Socket |
| 171 | } VgLogTo; |
| 172 | |
| 173 | |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 174 | /* Should we stop collecting errors if too many appear? default: YES */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 175 | extern Bool VG_(clo_error_limit); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 176 | /* Enquire about whether to attach to GDB at errors? default: NO */ |
| 177 | extern Bool VG_(clo_GDB_attach); |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 178 | /* The path to GDB? default: whatever ./configure found */ |
| 179 | extern Char* VG_(clo_GDB_path); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 180 | /* Enquire about generating a suppression for each error? default: NO */ |
| 181 | extern Bool VG_(clo_gen_suppressions); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 182 | /* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */ |
| 183 | extern Int VG_(sanity_level); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 184 | /* Automatically attempt to demangle C++ names? default: YES */ |
| 185 | extern Bool VG_(clo_demangle); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 186 | /* Simulate child processes? default: NO */ |
| 187 | extern Bool VG_(clo_trace_children); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 188 | |
| 189 | /* Where logging output is to be sent to. |
| 190 | |
| 191 | When log_to == VgLogTo_Fd, clo_logfile_fd holds the file id, and is |
| 192 | taken from the command line. clo_logfile_name is irrelevant. |
| 193 | |
| 194 | When log_to == VgLogTo_File, clo_logfile_name holds the logfile |
| 195 | name, and is taken from the command line. clo_logfile_fd is then |
| 196 | made to hold the relevant file id, by opening clo_logfile_name |
| 197 | (concatenated with the process ID) for writing. |
| 198 | |
| 199 | When log_to == VgLogTo_Socket, clo_logfile_name holds the |
| 200 | hostname:portnumber pair, and is taken from the command line. |
| 201 | clo_logfile_fd is then made to hold the relevant file handle, by |
| 202 | opening a connection to said hostname:portnumber pair. |
| 203 | |
| 204 | Global default is to set log_to == VgLogTo_Fd and logfile_fd == 2 |
| 205 | (stderr). */ |
| 206 | extern VgLogTo VG_(clo_log_to); |
| 207 | extern Int VG_(clo_logfile_fd); |
| 208 | extern Char* VG_(clo_logfile_name); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 209 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 210 | /* The file descriptor to read for input. default: 0 == stdin */ |
| 211 | extern Int VG_(clo_input_fd); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 212 | /* The number of suppression files specified. */ |
| 213 | extern Int VG_(clo_n_suppressions); |
| 214 | /* The names of the suppression files. */ |
| 215 | extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
| 216 | |
| 217 | /* Single stepping? default: NO */ |
| 218 | extern Bool VG_(clo_single_step); |
| 219 | /* Code improvement? default: YES */ |
| 220 | extern Bool VG_(clo_optimise); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 221 | /* DEBUG: print generated code? default: 00000 ( == NO ) */ |
| 222 | extern Bool VG_(clo_trace_codegen); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 223 | /* DEBUG: print system calls? default: NO */ |
| 224 | extern Bool VG_(clo_trace_syscalls); |
| 225 | /* DEBUG: print signal details? default: NO */ |
| 226 | extern Bool VG_(clo_trace_signals); |
| 227 | /* DEBUG: print symtab details? default: NO */ |
| 228 | extern Bool VG_(clo_trace_symtab); |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 229 | /* DEBUG: print thread scheduling events? default: NO */ |
| 230 | extern Bool VG_(clo_trace_sched); |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 231 | /* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1 |
| 232 | (some), 2 (all) */ |
| 233 | extern Int VG_(clo_trace_pthread_level); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 234 | /* Stop after this many basic blocks. default: Infinity. */ |
| 235 | extern ULong VG_(clo_stop_after); |
| 236 | /* Display gory details for the k'th most popular error. default: |
| 237 | Infinity. */ |
| 238 | extern Int VG_(clo_dump_error); |
| 239 | /* Number of parents of a backtrace. Default: 8. */ |
| 240 | extern Int VG_(clo_backtrace_size); |
daywalker | 7e73e5f | 2003-07-04 16:18:15 +0000 | [diff] [blame] | 241 | /* Engage miscellaneous weird hacks needed for some progs. */ |
sewardj | 8d365b5 | 2002-05-12 10:52:16 +0000 | [diff] [blame] | 242 | extern Char* VG_(clo_weird_hacks); |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 243 | /* Should we run __libc_freeres at exit? Sometimes causes crashes. |
| 244 | Default: YES. Note this is subservient to VG_(needs).libc_freeres; |
| 245 | if the latter says False, then the setting of VG_(clo_weird_hacks) |
| 246 | is ignored. Ie if a skin says no, I don't want this to run, that |
| 247 | cannot be overridden from the command line. */ |
| 248 | extern Bool VG_(clo_run_libc_freeres); |
sewardj | b5ff83e | 2002-12-01 19:40:49 +0000 | [diff] [blame] | 249 | /* Use the basic-block chaining optimisation? Default: YES */ |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 250 | extern Bool VG_(clo_chain_bb); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 251 | |
| 252 | |
| 253 | /* --------------------------------------------------------------------- |
| 254 | Debugging and profiling stuff |
| 255 | ------------------------------------------------------------------ */ |
| 256 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 257 | /* Create a logfile into which messages can be dumped. */ |
| 258 | extern void VG_(startup_logging) ( void ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 259 | extern void VG_(shutdown_logging)( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 260 | |
| 261 | extern void VGP_(init_profiling) ( void ); |
| 262 | extern void VGP_(done_profiling) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 263 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 264 | #undef VGP_PUSHCC |
| 265 | #undef VGP_POPCC |
| 266 | #define VGP_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x) |
| 267 | #define VGP_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 268 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 269 | /* --------------------------------------------------------------------- |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 270 | Skin-related types |
| 271 | ------------------------------------------------------------------ */ |
| 272 | /* These structs are not exposed to skins to mitigate possibility of |
| 273 | binary-incompatibilities when the core/skin interface changes. Instead, |
| 274 | set functions are provided (see include/vg_skin.h). */ |
| 275 | typedef |
| 276 | struct { |
| 277 | Char* name; |
| 278 | Char* version; |
| 279 | Char* description; |
| 280 | Char* copyright_author; |
| 281 | Char* bug_reports_to; |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 282 | UInt avg_translation_sizeB; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 283 | } |
| 284 | VgDetails; |
| 285 | |
| 286 | extern VgDetails VG_(details); |
| 287 | |
| 288 | /* If new fields are added to this type, update: |
| 289 | * - vg_main.c:initialisation of VG_(needs) |
| 290 | * - vg_main.c:sanity_check_needs() |
| 291 | * |
| 292 | * If the name of this type or any of its fields change, update: |
| 293 | * - dependent comments (just search for "VG_(needs)"). |
| 294 | */ |
| 295 | typedef |
| 296 | struct { |
| 297 | Bool libc_freeres; |
| 298 | Bool core_errors; |
| 299 | |
| 300 | Bool skin_errors; |
| 301 | Bool basic_block_discards; |
| 302 | Bool shadow_regs; |
| 303 | Bool command_line_options; |
| 304 | Bool client_requests; |
| 305 | Bool extended_UCode; |
| 306 | Bool syscall_wrapper; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 307 | Bool sanity_checks; |
| 308 | Bool data_syms; |
| 309 | } |
| 310 | VgNeeds; |
| 311 | |
| 312 | extern VgNeeds VG_(needs); |
| 313 | |
| 314 | /* Events happening in core to track. To be notified, assign a function |
| 315 | to the function pointer. To ignore an event, don't do anything |
| 316 | (default assignment is to NULL in which case the call is skipped). */ |
| 317 | typedef |
| 318 | struct { |
| 319 | /* Memory events */ |
| 320 | void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx ); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 321 | void (*new_mem_stack_signal) ( Addr a, UInt len ); |
| 322 | void (*new_mem_brk) ( Addr a, UInt len ); |
| 323 | void (*new_mem_mmap) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx ); |
| 324 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 325 | void (*copy_mem_remap) ( Addr from, Addr to, UInt len ); |
| 326 | void (*change_mem_mprotect) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx ); |
| 327 | void (*die_mem_stack_signal) ( Addr a, UInt len ); |
| 328 | void (*die_mem_brk) ( Addr a, UInt len ); |
| 329 | void (*die_mem_munmap) ( Addr a, UInt len ); |
| 330 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 331 | void (*new_mem_stack_4) ( Addr new_ESP ); |
| 332 | void (*new_mem_stack_8) ( Addr new_ESP ); |
| 333 | void (*new_mem_stack_12) ( Addr new_ESP ); |
| 334 | void (*new_mem_stack_16) ( Addr new_ESP ); |
| 335 | void (*new_mem_stack_32) ( Addr new_ESP ); |
| 336 | void (*new_mem_stack) ( Addr a, UInt len ); |
| 337 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 338 | void (*die_mem_stack_4) ( Addr die_ESP ); |
| 339 | void (*die_mem_stack_8) ( Addr die_ESP ); |
| 340 | void (*die_mem_stack_12) ( Addr die_ESP ); |
| 341 | void (*die_mem_stack_16) ( Addr die_ESP ); |
| 342 | void (*die_mem_stack_32) ( Addr die_ESP ); |
| 343 | void (*die_mem_stack) ( Addr a, UInt len ); |
| 344 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 345 | void (*ban_mem_stack) ( Addr a, UInt len ); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 346 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 347 | void (*pre_mem_read) ( CorePart part, ThreadId tid, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 348 | Char* s, Addr a, UInt size ); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 349 | void (*pre_mem_read_asciiz) ( CorePart part, ThreadId tid, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 350 | Char* s, Addr a ); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 351 | void (*pre_mem_write) ( CorePart part, ThreadId tid, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 352 | Char* s, Addr a, UInt size ); |
| 353 | /* Not implemented yet -- have to add in lots of places, which is a |
| 354 | pain. Won't bother unless/until there's a need. */ |
| 355 | /* void (*post_mem_read) ( ThreadState* tst, Char* s, |
| 356 | Addr a, UInt size ); */ |
| 357 | void (*post_mem_write) ( Addr a, UInt size ); |
| 358 | |
| 359 | |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 360 | /* Register events */ |
| 361 | void (*post_regs_write_init) ( void ); |
| 362 | void (*post_reg_write_syscall_return) ( ThreadId tid, UInt reg ); |
| 363 | void (*post_reg_write_deliver_signal) ( ThreadId tid, UInt reg ); |
| 364 | void (*post_reg_write_pthread_return) ( ThreadId tid, UInt reg ); |
| 365 | void (*post_reg_write_clientreq_return) ( ThreadId tid, UInt reg ); |
| 366 | void (*post_reg_write_clientcall_return) ( ThreadId tid, UInt reg, |
| 367 | Addr f ); |
| 368 | |
| 369 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 370 | /* Scheduler events (not exhaustive) */ |
| 371 | void (*thread_run) ( ThreadId tid ); |
| 372 | |
| 373 | |
| 374 | /* Thread events (not exhaustive) */ |
| 375 | void (*post_thread_create) ( ThreadId tid, ThreadId child ); |
| 376 | void (*post_thread_join) ( ThreadId joiner, ThreadId joinee ); |
| 377 | |
| 378 | |
| 379 | /* Mutex events (not exhaustive) */ |
| 380 | void (*pre_mutex_lock) ( ThreadId tid, |
| 381 | void* /*pthread_mutex_t* */ mutex ); |
| 382 | void (*post_mutex_lock) ( ThreadId tid, |
| 383 | void* /*pthread_mutex_t* */ mutex ); |
| 384 | void (*post_mutex_unlock) ( ThreadId tid, |
| 385 | void* /*pthread_mutex_t* */ mutex ); |
| 386 | |
njn | fdc28af | 2003-02-24 10:36:48 +0000 | [diff] [blame] | 387 | /* Signal events (not exhaustive) */ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 388 | void (* pre_deliver_signal) ( ThreadId tid, Int sigNo, Bool alt_stack ); |
njn | fdc28af | 2003-02-24 10:36:48 +0000 | [diff] [blame] | 389 | void (*post_deliver_signal) ( ThreadId tid, Int sigNo ); |
| 390 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 391 | |
njn | fdc28af | 2003-02-24 10:36:48 +0000 | [diff] [blame] | 392 | /* Others... condition variable... */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 393 | /* ... */ |
| 394 | } |
| 395 | VgTrackEvents; |
| 396 | |
| 397 | extern VgTrackEvents VG_(track_events); |
| 398 | |
| 399 | |
| 400 | /* --------------------------------------------------------------------- |
| 401 | Exports of vg_needs.c |
| 402 | ------------------------------------------------------------------ */ |
| 403 | |
| 404 | void VG_(sanity_check_needs)(void); |
| 405 | |
| 406 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 407 | Exports of vg_malloc2.c |
| 408 | ------------------------------------------------------------------ */ |
| 409 | |
| 410 | /* Allocation arenas. |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 411 | |
| 412 | CORE for the core's general use. |
| 413 | SKIN for the skin to use (and the only one it uses). |
| 414 | SYMTAB for Valgrind's symbol table storage. |
| 415 | JITTER for small storage during translation. |
| 416 | CLIENT for the client's mallocs/frees, if the skin replaces glibc's |
| 417 | malloc() et al -- redzone size is chosen by the skin. |
| 418 | DEMANGLE for the C++ demangler. |
| 419 | EXECTXT for storing ExeContexts. |
| 420 | ERRORS for storing CoreErrors. |
| 421 | TRANSIENT for very short-term use. It should be empty in between uses. |
| 422 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 423 | 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] | 424 | */ |
| 425 | typedef Int ArenaId; |
| 426 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 427 | #define VG_N_ARENAS 9 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 428 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 429 | #define VG_AR_CORE 0 |
| 430 | #define VG_AR_SKIN 1 |
| 431 | #define VG_AR_SYMTAB 2 |
| 432 | #define VG_AR_JITTER 3 |
| 433 | #define VG_AR_CLIENT 4 |
| 434 | #define VG_AR_DEMANGLE 5 |
| 435 | #define VG_AR_EXECTXT 6 |
| 436 | #define VG_AR_ERRORS 7 |
| 437 | #define VG_AR_TRANSIENT 8 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 438 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 439 | extern void* VG_(arena_malloc) ( ArenaId arena, Int nbytes ); |
| 440 | extern void VG_(arena_free) ( ArenaId arena, void* ptr ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 441 | extern void* VG_(arena_calloc) ( ArenaId arena, Int alignment, |
| 442 | Int nmemb, Int nbytes ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 443 | extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment, |
| 444 | Int size ); |
| 445 | extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 446 | Int req_pszB ); |
| 447 | |
njn | 8a6b6c0 | 2003-04-22 22:45:55 +0000 | [diff] [blame] | 448 | extern Int VG_(arena_payload_szB) ( ArenaId aid, void* payload ); |
| 449 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 450 | extern void VG_(mallocSanityCheckAll) ( void ); |
| 451 | |
| 452 | extern void VG_(show_all_arena_stats) ( void ); |
| 453 | extern Bool VG_(is_empty_arena) ( ArenaId aid ); |
| 454 | |
sewardj | ecf8e10 | 2003-07-12 12:11:39 +0000 | [diff] [blame] | 455 | /* Returns True if aa is inside any block mmap'd /dev/zero |
| 456 | by our low-level memory manager. */ |
| 457 | extern Bool VG_(is_inside_segment_mmapd_by_low_level_MM)( Addr aa ); |
| 458 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 459 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 460 | /* --------------------------------------------------------------------- |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 461 | Exports of vg_intercept.c |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 462 | ------------------------------------------------------------------ */ |
| 463 | |
| 464 | /* This doesn't export code or data that valgrind.so needs to link |
| 465 | against. However, the scheduler does need to know the following |
| 466 | request codes. A few, publically-visible, request codes are also |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 467 | defined in valgrind.h, and similar headers for some skins. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 468 | |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 469 | #define VG_USERREQ__MALLOC 0x2001 |
| 470 | #define VG_USERREQ__FREE 0x2002 |
| 471 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 472 | /* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn |
| 473 | MUST NOT return -- ever. Eventually it will do either __QUIT or |
| 474 | __WAIT_JOINER. */ |
| 475 | #define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001 |
| 476 | |
| 477 | /* ( no-args ): calling thread disappears from the system forever. |
| 478 | Reclaim resources. */ |
| 479 | #define VG_USERREQ__QUIT 0x3002 |
| 480 | |
| 481 | /* ( void* ): calling thread waits for joiner and returns the void* to |
| 482 | it. */ |
| 483 | #define VG_USERREQ__WAIT_JOINER 0x3003 |
| 484 | |
| 485 | /* ( ThreadId, void** ): wait to join a thread. */ |
| 486 | #define VG_USERREQ__PTHREAD_JOIN 0x3004 |
| 487 | |
| 488 | /* Set cancellation state and type for this thread. */ |
| 489 | #define VG_USERREQ__SET_CANCELSTATE 0x3005 |
| 490 | #define VG_USERREQ__SET_CANCELTYPE 0x3006 |
| 491 | |
| 492 | /* ( no-args ): Test if we are at a cancellation point. */ |
| 493 | #define VG_USERREQ__TESTCANCEL 0x3007 |
| 494 | |
| 495 | /* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call |
| 496 | with this arg to indicate that a cancel is now pending for the |
| 497 | specified thread. */ |
| 498 | #define VG_USERREQ__SET_CANCELPEND 0x3008 |
| 499 | |
| 500 | /* Set/get detach state for this thread. */ |
| 501 | #define VG_USERREQ__SET_OR_GET_DETACH 0x3009 |
| 502 | |
| 503 | #define VG_USERREQ__PTHREAD_GET_THREADID 0x300B |
| 504 | #define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C |
| 505 | #define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D |
| 506 | #define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E |
| 507 | #define VG_USERREQ__PTHREAD_COND_WAIT 0x300F |
| 508 | #define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010 |
| 509 | #define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011 |
| 510 | #define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012 |
| 511 | #define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013 |
| 512 | #define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014 |
sewardj | 00a66b1 | 2002-10-12 16:42:35 +0000 | [diff] [blame] | 513 | #define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015 |
| 514 | #define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 515 | #define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017 |
| 516 | #define VG_USERREQ__PTHREAD_SIGMASK 0x3018 |
| 517 | #define VG_USERREQ__SIGWAIT 0x3019 |
| 518 | #define VG_USERREQ__PTHREAD_KILL 0x301A |
| 519 | #define VG_USERREQ__PTHREAD_YIELD 0x301B |
sewardj | 00a66b1 | 2002-10-12 16:42:35 +0000 | [diff] [blame] | 520 | #define VG_USERREQ__PTHREAD_KEY_VALIDATE 0x301C |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 521 | |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 522 | #define VG_USERREQ__CLEANUP_PUSH 0x3020 |
| 523 | #define VG_USERREQ__CLEANUP_POP 0x3021 |
sewardj | 870497a | 2002-05-29 01:06:47 +0000 | [diff] [blame] | 524 | #define VG_USERREQ__GET_KEY_D_AND_S 0x3022 |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 525 | |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 526 | #define VG_USERREQ__NUKE_OTHER_THREADS 0x3023 |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 527 | |
| 528 | /* Ask how many signal handler returns have happened to this |
| 529 | thread. */ |
sewardj | 9a2224b | 2002-06-19 10:17:40 +0000 | [diff] [blame] | 530 | #define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024 |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 531 | |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 532 | /* Get/set entries for a thread's pthread_atfork stack. */ |
| 533 | #define VG_USERREQ__SET_FHSTACK_USED 0x3025 |
| 534 | #define VG_USERREQ__GET_FHSTACK_USED 0x3026 |
| 535 | #define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027 |
| 536 | #define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028 |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 537 | |
sewardj | 1fe7b00 | 2002-07-16 01:43:15 +0000 | [diff] [blame] | 538 | /* Denote the finish of VG_(__libc_freeres_wrapper). */ |
| 539 | #define VG_USERREQ__LIBC_FREERES_DONE 0x3029 |
| 540 | |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 541 | /* Cosmetic ... */ |
| 542 | #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101 |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 543 | /* Log a pthread error from client-space. Cosmetic. */ |
| 544 | #define VG_USERREQ__PTHREAD_ERROR 0x3102 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 545 | |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 546 | /* |
| 547 | In vg_constants.h: |
| 548 | #define VG_USERREQ__SIGNAL_RETURNS 0x4001 |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 549 | */ |
| 550 | |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 551 | |
sewardj | 1fe7b00 | 2002-07-16 01:43:15 +0000 | [diff] [blame] | 552 | /* The scheduler does need to know the address of it so it can be |
| 553 | called at program exit. */ |
| 554 | extern void VG_(__libc_freeres_wrapper)( void ); |
| 555 | |
sewardj | 11f0bb4 | 2003-04-26 20:11:15 +0000 | [diff] [blame] | 556 | extern void VGR_(wait_for_fd_to_be_readable_or_erring) ( int fd ); |
| 557 | extern void VGR_(wait_for_fd_to_be_writable_or_erring) ( int fd ); |
| 558 | |
| 559 | extern int VGR_(recv)(int s, void *buf, unsigned int/*size_t*/ len, |
| 560 | int flags); |
| 561 | |
| 562 | extern int VGR_(accept)(int s, /*struct sockaddr*/ void *addr, |
| 563 | /*socklen_t*/ void *addrlen); |
| 564 | |
| 565 | |
| 566 | extern int VGR_(select) ( int n, |
| 567 | /*fd_set*/ void *rfds, |
| 568 | /*fd_set*/ void *wfds, |
| 569 | /*fd_set*/ void *xfds, |
| 570 | /*struct timeval*/ void *timeout ); |
| 571 | |
| 572 | extern int VGR_(msgsnd)(int msgid, |
| 573 | const void *msgp, |
| 574 | /*size_t*/ unsigned int msgsz, |
| 575 | int msgflg); |
| 576 | |
| 577 | extern int VGR_(msgrcv)( int msqid, |
| 578 | void* msgp, |
| 579 | /*size_t*/ unsigned int msgsz, |
| 580 | long msgtyp, |
| 581 | int msgflg ); |
| 582 | |
| 583 | extern int VGR_(readv)(int fd, |
| 584 | const /*struct iovec*/ void *iovV, |
| 585 | int count); |
| 586 | |
| 587 | extern int VGR_(writev)(int fd, |
| 588 | const /*struct iovec*/ void *iovV, |
| 589 | int count); |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 590 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 591 | /* --------------------------------------------------------------------- |
| 592 | Constants pertaining to the simulated CPU state, VG_(baseBlock), |
| 593 | which need to go here to avoid ugly circularities. |
| 594 | ------------------------------------------------------------------ */ |
| 595 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 596 | /* How big is the saved SSE/SSE2 state? Note that this subsumes the |
| 597 | FPU state. On machines without SSE, we just save/restore the FPU |
| 598 | state into the first part of this area. */ |
| 599 | /* A general comment about SSE save/restore: It appears that the 7th |
| 600 | word (which is the MXCSR) has to be &ed with 0x0000FFBF in order |
| 601 | that restoring from it later does not cause a GP fault (which is |
| 602 | delivered as a segfault). I guess this will have to be done |
| 603 | any time we do fxsave :-( 7th word means word offset 6 or byte |
| 604 | offset 24 from the start address of the save area. |
| 605 | */ |
| 606 | #define VG_SIZE_OF_SSESTATE 512 |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 607 | /* ... and in words ... */ |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 608 | #define VG_SIZE_OF_SSESTATE_W ((VG_SIZE_OF_SSESTATE+3)/4) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 609 | |
| 610 | |
| 611 | /* --------------------------------------------------------------------- |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 612 | Exports of vg_defaults.c |
| 613 | ------------------------------------------------------------------ */ |
| 614 | |
| 615 | extern Bool VG_(sk_malloc_called_by_scheduler); |
| 616 | |
| 617 | |
| 618 | /* --------------------------------------------------------------------- |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 619 | Exports of vg_ldt.c |
| 620 | ------------------------------------------------------------------ */ |
| 621 | |
| 622 | /* This is the hardware-format for a segment descriptor, ie what the |
| 623 | x86 actually deals with. It is 8 bytes long. It's ugly. */ |
| 624 | |
| 625 | typedef struct _LDT_ENTRY { |
| 626 | union { |
| 627 | struct { |
| 628 | UShort LimitLow; |
| 629 | UShort BaseLow; |
| 630 | unsigned BaseMid : 8; |
| 631 | unsigned Type : 5; |
| 632 | unsigned Dpl : 2; |
| 633 | unsigned Pres : 1; |
| 634 | unsigned LimitHi : 4; |
| 635 | unsigned Sys : 1; |
| 636 | unsigned Reserved_0 : 1; |
| 637 | unsigned Default_Big : 1; |
| 638 | unsigned Granularity : 1; |
| 639 | unsigned BaseHi : 8; |
| 640 | } Bits; |
| 641 | struct { |
| 642 | UInt word1; |
| 643 | UInt word2; |
| 644 | } Words; |
| 645 | } |
| 646 | LdtEnt; |
| 647 | } VgLdtEntry; |
| 648 | |
| 649 | /* Maximum number of LDT entries supported (by the x86). */ |
| 650 | #define VG_M_LDT_ENTRIES 8192 |
| 651 | /* The size of each LDT entry == sizeof(VgLdtEntry) */ |
| 652 | #define VG_LDT_ENTRY_SIZE 8 |
| 653 | |
| 654 | /* Alloc & copy, and dealloc. */ |
| 655 | extern VgLdtEntry* |
| 656 | VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt ); |
| 657 | extern void |
| 658 | VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt ); |
| 659 | |
| 660 | /* Simulate the modify_ldt syscall. */ |
| 661 | extern Int VG_(sys_modify_ldt) ( ThreadId tid, |
| 662 | Int func, void* ptr, UInt bytecount ); |
| 663 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 664 | /* Called from generated code. Given a segment selector and a virtual |
| 665 | address, return a linear address, and do limit checks too. */ |
| 666 | extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr ); |
| 667 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 668 | |
| 669 | /* --------------------------------------------------------------------- |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 670 | Exports of vg_scheduler.c |
| 671 | ------------------------------------------------------------------ */ |
| 672 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 673 | typedef |
| 674 | enum { |
| 675 | VgTs_Empty, /* this slot is not in use */ |
| 676 | VgTs_Runnable, /* waiting to be scheduled */ |
| 677 | VgTs_WaitJoiner, /* waiting for someone to do join on me */ |
| 678 | VgTs_WaitJoinee, /* waiting for the thread I did join on */ |
| 679 | VgTs_WaitFD, /* waiting for I/O completion on a fd */ |
| 680 | VgTs_WaitMX, /* waiting on a mutex */ |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 681 | VgTs_WaitCV, /* waiting on a condition variable */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 682 | VgTs_WaitSIG, /* waiting due to sigwait() */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 683 | VgTs_Sleeping /* sleeping for a while */ |
| 684 | } |
| 685 | ThreadStatus; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 686 | |
| 687 | /* An entry in a threads's cleanup stack. */ |
| 688 | typedef |
| 689 | struct { |
| 690 | void (*fn)(void*); |
| 691 | void* arg; |
| 692 | } |
| 693 | CleanupEntry; |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 694 | |
| 695 | /* An entry in a thread's fork-handler stack. */ |
| 696 | typedef |
| 697 | struct { |
| 698 | void (*prepare)(void); |
| 699 | void (*parent)(void); |
| 700 | void (*child)(void); |
| 701 | } |
| 702 | ForkHandlerEntry; |
| 703 | |
| 704 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 705 | typedef |
| 706 | struct _ThreadState { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 707 | /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED. |
| 708 | The thread identity is simply the index in vg_threads[]. |
| 709 | ThreadId == 1 is the root thread and has the special property |
| 710 | that we don't try and allocate or deallocate its stack. For |
| 711 | convenience of generating error message, we also put the |
| 712 | ThreadId in this tid field, but be aware that it should |
| 713 | ALWAYS == the index in vg_threads[]. */ |
| 714 | ThreadId tid; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 715 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 716 | /* Current scheduling status. |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 717 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 718 | Complications: whenever this is set to VgTs_WaitMX, you |
| 719 | should also set .m_edx to whatever the required return value |
| 720 | is for pthread_mutex_lock / pthread_cond_timedwait for when |
| 721 | the mutex finally gets unblocked. */ |
| 722 | ThreadStatus status; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 723 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 724 | /* When .status == WaitMX, points to the mutex I am waiting for. |
| 725 | When .status == WaitCV, points to the mutex associated with |
| 726 | the condition variable indicated by the .associated_cv field. |
| 727 | In all other cases, should be NULL. */ |
| 728 | void* /*pthread_mutex_t* */ associated_mx; |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 729 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 730 | /* When .status == WaitCV, points to the condition variable I am |
| 731 | waiting for. In all other cases, should be NULL. */ |
| 732 | void* /*pthread_cond_t* */ associated_cv; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 733 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 734 | /* If VgTs_Sleeping, this is when we should wake up, measured in |
njn | 6c84655 | 2003-09-16 07:41:43 +0000 | [diff] [blame] | 735 | milliseconds as supplied by VG_(read_millisecond_timer). |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 736 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 737 | If VgTs_WaitCV, this indicates the time at which |
| 738 | pthread_cond_timedwait should wake up. If == 0xFFFFFFFF, |
| 739 | this means infinitely far in the future, viz, |
| 740 | pthread_cond_wait. */ |
| 741 | UInt awaken_at; |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 742 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 743 | /* If VgTs_WaitJoiner, return value, as generated by joinees. */ |
| 744 | void* joinee_retval; |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 745 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 746 | /* If VgTs_WaitJoinee, place to copy the return value to, and |
| 747 | the identity of the thread we're waiting for. */ |
| 748 | void** joiner_thread_return; |
| 749 | ThreadId joiner_jee_tid; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 750 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 751 | /* Whether or not detached. */ |
| 752 | Bool detached; |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 753 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 754 | /* Cancelability state and type. */ |
| 755 | Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */ |
| 756 | Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */ |
| 757 | |
| 758 | /* Pointer to fn to call to do cancellation. Indicates whether |
| 759 | or not cancellation is pending. If NULL, not pending. Else |
| 760 | should be &thread_exit_wrapper(), indicating that |
| 761 | cancallation is pending. */ |
| 762 | void (*cancel_pend)(void*); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 763 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 764 | /* The cleanup stack. */ |
| 765 | Int custack_used; |
| 766 | CleanupEntry custack[VG_N_CLEANUPSTACK]; |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 767 | |
sewardj | 00a66b1 | 2002-10-12 16:42:35 +0000 | [diff] [blame] | 768 | /* A pointer to the thread's-specific-data. This is handled almost |
| 769 | entirely from vg_libpthread.c. We just provide hooks to get and |
| 770 | set this ptr. This is either NULL, indicating the thread has |
| 771 | read/written none of its specifics so far, OR points to a |
| 772 | void*[VG_N_THREAD_KEYS], allocated and deallocated in |
| 773 | vg_libpthread.c. */ |
| 774 | void** specifics_ptr; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 775 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 776 | /* This thread's blocked-signals mask. Semantics is that for a |
| 777 | signal to be delivered to this thread, the signal must not be |
| 778 | blocked by either the process-wide signal mask nor by this |
| 779 | one. So, if this thread is prepared to handle any signal that |
| 780 | the process as a whole is prepared to handle, this mask should |
| 781 | be made empty -- and that it is its default, starting |
| 782 | state. */ |
| 783 | vki_ksigset_t sig_mask; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 784 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 785 | /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG, |
| 786 | is the set of signals for which we are sigwait()ing. */ |
| 787 | vki_ksigset_t sigs_waited_for; |
sewardj | 9a2224b | 2002-06-19 10:17:40 +0000 | [diff] [blame] | 788 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 789 | /* Counts the number of times a signal handler for this thread |
| 790 | has returned. This makes it easy to implement pause(), by |
| 791 | polling this value, of course interspersed with nanosleeps, |
| 792 | and waiting till it changes. */ |
| 793 | UInt n_signals_returned; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 794 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 795 | /* Stacks. When a thread slot is freed, we don't deallocate its |
| 796 | stack; we just leave it lying around for the next use of the |
| 797 | slot. If the next use of the slot requires a larger stack, |
| 798 | only then is the old one deallocated and a new one |
| 799 | allocated. |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 800 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 801 | For the main thread (threadid == 0), this mechanism doesn't |
| 802 | apply. We don't know the size of the stack since we didn't |
| 803 | allocate it, and furthermore we never reallocate it. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 804 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 805 | /* The allocated size of this thread's stack (permanently zero |
| 806 | if this is ThreadId == 0, since we didn't allocate its stack) */ |
| 807 | UInt stack_size; |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 808 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 809 | /* Address of the lowest word in this thread's stack. NULL means |
| 810 | not allocated yet. |
| 811 | */ |
| 812 | Addr stack_base; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 813 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 814 | /* Address of the highest legitimate word in this stack. This is |
| 815 | used for error messages only -- not critical for execution |
| 816 | correctness. Is is set for all stacks, specifically including |
| 817 | ThreadId == 0 (the main thread). */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 818 | Addr stack_highest_word; |
| 819 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 820 | /* Pointer to this thread's Local (Segment) Descriptor Table. |
| 821 | Starts out as NULL, indicating there is no table, and we hope to |
| 822 | keep it that way. If the thread does __NR_modify_ldt to create |
| 823 | entries, we allocate a 8192-entry table at that point. This is |
| 824 | a straight copy of the Linux kernel's scheme. Don't forget to |
| 825 | deallocate this at thread exit. */ |
| 826 | VgLdtEntry* ldt; |
| 827 | |
| 828 | /* Saved machine context. Note the FPU state, %EIP and segment |
| 829 | registers are not shadowed. |
| 830 | |
| 831 | Although the segment registers are 16 bits long, storage |
| 832 | management here, in VG_(baseBlock) and in VG_(m_state_static) is |
| 833 | simplified if we pretend they are 32 bits. */ |
| 834 | UInt m_cs; |
| 835 | UInt m_ss; |
| 836 | UInt m_ds; |
| 837 | UInt m_es; |
| 838 | UInt m_fs; |
| 839 | UInt m_gs; |
| 840 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 841 | UInt m_eax; |
| 842 | UInt m_ebx; |
| 843 | UInt m_ecx; |
| 844 | UInt m_edx; |
| 845 | UInt m_esi; |
| 846 | UInt m_edi; |
| 847 | UInt m_ebp; |
| 848 | UInt m_esp; |
| 849 | UInt m_eflags; |
| 850 | UInt m_eip; |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 851 | |
| 852 | /* The SSE/FPU state. This array does not (necessarily) have the |
| 853 | required 16-byte alignment required to get stuff in/out by |
| 854 | fxsave/fxrestore. So we have to do it "by hand". |
| 855 | */ |
| 856 | UInt m_sse[VG_SIZE_OF_SSESTATE_W]; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 857 | |
| 858 | UInt sh_eax; |
| 859 | UInt sh_ebx; |
| 860 | UInt sh_ecx; |
| 861 | UInt sh_edx; |
| 862 | UInt sh_esi; |
| 863 | UInt sh_edi; |
| 864 | UInt sh_ebp; |
| 865 | UInt sh_esp; |
| 866 | UInt sh_eflags; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 867 | } |
| 868 | ThreadState; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 869 | |
| 870 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 871 | /* The thread table. */ |
| 872 | extern ThreadState VG_(threads)[VG_N_THREADS]; |
| 873 | |
| 874 | /* Check that tid is in range and denotes a non-Empty thread. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 875 | extern Bool VG_(is_valid_tid) ( ThreadId tid ); |
| 876 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 877 | /* Check that tid is in range. */ |
| 878 | extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid ); |
| 879 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 880 | /* Determine if 'tid' is that of the current running thread (Nb: returns |
| 881 | False if no thread is currently running. */ |
| 882 | extern Bool VG_(is_running_thread)(ThreadId tid); |
| 883 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 884 | /* Copy the specified thread's state into VG_(baseBlock) in |
| 885 | preparation for running it. */ |
| 886 | extern void VG_(load_thread_state)( ThreadId ); |
| 887 | |
| 888 | /* Save the specified thread's state back in VG_(baseBlock), and fill |
| 889 | VG_(baseBlock) with junk, for sanity-check reasons. */ |
| 890 | extern void VG_(save_thread_state)( ThreadId ); |
| 891 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 892 | /* And for the currently running one, if valid. */ |
| 893 | extern ThreadState* VG_(get_current_thread_state) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 894 | |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 895 | /* Similarly ... */ |
| 896 | extern ThreadId VG_(get_current_tid) ( void ); |
| 897 | |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 898 | /* Nuke all threads except tid. */ |
| 899 | extern void VG_(nuke_all_threads_except) ( ThreadId me ); |
| 900 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 901 | |
| 902 | /* Return codes from the scheduler. */ |
| 903 | typedef |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 904 | enum { |
| 905 | VgSrc_Deadlock, /* no runnable threads and no prospect of any |
| 906 | even if we wait for a long time */ |
| 907 | VgSrc_ExitSyscall, /* client called exit(). This is the normal |
| 908 | route out. */ |
| 909 | VgSrc_BbsDone /* In a debugging run, the specified number of |
| 910 | bbs has been completed. */ |
| 911 | } |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 912 | VgSchedReturnCode; |
| 913 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 914 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 915 | /* The scheduler. */ |
| 916 | extern VgSchedReturnCode VG_(scheduler) ( void ); |
| 917 | |
| 918 | extern void VG_(scheduler_init) ( void ); |
| 919 | |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 920 | extern void VG_(pp_sched_status) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 921 | |
| 922 | /* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */ |
| 923 | extern jmp_buf VG_(scheduler_jmpbuf); |
sewardj | 872051c | 2002-07-13 12:12:56 +0000 | [diff] [blame] | 924 | /* This says whether scheduler_jmpbuf is actually valid. Needed so |
| 925 | that our signal handler doesn't longjmp when the buffer isn't |
| 926 | actually valid. */ |
| 927 | extern Bool VG_(scheduler_jmpbuf_valid); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 928 | /* ... and if so, here's the signal which caused it to do so. */ |
| 929 | extern Int VG_(longjmpd_on_signal); |
| 930 | |
| 931 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 932 | /* The red-zone size which we put at the bottom (highest address) of |
| 933 | thread stacks, for paranoia reasons. This can be arbitrary, and |
| 934 | doesn't really need to be set at compile time. */ |
| 935 | #define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4 |
| 936 | |
| 937 | #define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \ |
| 938 | (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD) |
| 939 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 940 | /* Junk to fill up a thread's shadow regs with when shadow regs aren't |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 941 | being used. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 942 | #define VG_UNUSED_SHADOW_REG_VALUE 0x27182818 |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 943 | /* For sanity checking: if this ends up in a thread's shadow regs when |
| 944 | shadow regs aren't being used, something went wrong. */ |
| 945 | #define VG_USED_SHADOW_REG_VALUE 0x31415927 |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 946 | |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 947 | /* Write a value to a client's thread register, and shadow (if necessary) */ |
| 948 | #define SET_THREAD_REG( zztid, zzval, zzreg, zzREG, zzevent, zzargs... ) \ |
| 949 | do { VG_(threads)[zztid].m_##zzreg = (zzval); \ |
| 950 | VG_TRACK( zzevent, zztid, R_##zzREG, ##zzargs ); \ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 951 | } while (0) |
| 952 | |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 953 | #define SET_SYSCALL_RETVAL(zztid, zzval) \ |
| 954 | SET_THREAD_REG(zztid, zzval, eax, EAX, post_reg_write_syscall_return) |
| 955 | |
| 956 | #define SET_SIGNAL_EDX(zztid, zzval) \ |
| 957 | SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_deliver_signal) |
| 958 | |
| 959 | #define SET_SIGNAL_ESP(zztid, zzval) \ |
| 960 | SET_THREAD_REG(zztid, zzval, esp, ESP, post_reg_write_deliver_signal) |
| 961 | |
| 962 | #define SET_CLREQ_RETVAL(zztid, zzval) \ |
| 963 | SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_clientreq_return) |
| 964 | |
| 965 | #define SET_CLCALL_RETVAL(zztid, zzval, f) \ |
| 966 | SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_clientcall_return, f) |
| 967 | |
| 968 | #define SET_PTHREQ_ESP(zztid, zzval) \ |
| 969 | SET_THREAD_REG(zztid, zzval, esp, ESP, post_reg_write_pthread_return) |
| 970 | |
| 971 | #define SET_PTHREQ_RETVAL(zztid, zzval) \ |
| 972 | SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_pthread_return) |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 973 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 974 | |
sewardj | d8acdf2 | 2002-11-13 21:57:52 +0000 | [diff] [blame] | 975 | /* This is or'd into a pthread mutex's __m_kind field if it is used |
| 976 | before Valgrind is up and running (prehistory). This is used so |
| 977 | that if some early code (like the dynamic linker) takes a lock |
| 978 | before Valgrind starts and then releases it afterwards, we can work |
| 979 | out what's happening. */ |
| 980 | #define VG_PTHREAD_PREHISTORY 0x80000000 |
| 981 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 982 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 983 | Exports of vg_signals.c |
| 984 | ------------------------------------------------------------------ */ |
| 985 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 986 | extern void VG_(sigstartup_actions) ( void ); |
sewardj | 839299f | 2003-06-14 11:57:59 +0000 | [diff] [blame] | 987 | extern void VG_(sigshutdown_actions) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 988 | |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 989 | extern Bool VG_(deliver_signals) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 990 | extern void VG_(unblock_host_signal) ( Int sigNo ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 991 | extern void VG_(handle_SCSS_change) ( Bool force_update ); |
| 992 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 993 | |
| 994 | /* Fake system calls for signal handling. */ |
sewardj | 2342c97 | 2002-05-22 23:34:20 +0000 | [diff] [blame] | 995 | extern void VG_(do__NR_sigaltstack) ( ThreadId tid ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 996 | extern void VG_(do__NR_sigaction) ( ThreadId tid ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 997 | extern void VG_(do__NR_sigprocmask) ( ThreadId tid, |
| 998 | Int how, |
| 999 | vki_ksigset_t* set, |
| 1000 | vki_ksigset_t* oldset ); |
| 1001 | extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid, |
| 1002 | Int how, |
| 1003 | vki_ksigset_t* set, |
| 1004 | vki_ksigset_t* oldset ); |
| 1005 | extern void VG_(send_signal_to_thread) ( ThreadId thread, |
| 1006 | Int signo ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1007 | |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 1008 | extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set ); |
| 1009 | |
| 1010 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1011 | /* Modify the current thread's state once we have detected it is |
| 1012 | returning from a signal handler. */ |
sewardj | 77e466c | 2002-04-14 02:29:29 +0000 | [diff] [blame] | 1013 | extern Bool VG_(signal_returns) ( ThreadId ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1014 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1015 | /* Handy utilities to block/restore all host signals. */ |
| 1016 | extern void VG_(block_all_host_signals) |
| 1017 | ( /* OUT */ vki_ksigset_t* saved_mask ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1018 | extern void VG_(restore_all_host_signals) |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1019 | ( /* IN */ vki_ksigset_t* saved_mask ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1020 | |
| 1021 | /* --------------------------------------------------------------------- |
| 1022 | Exports of vg_mylibc.c |
| 1023 | ------------------------------------------------------------------ */ |
| 1024 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1025 | #define vg_assert(expr) \ |
| 1026 | ((void) ((expr) ? 0 : \ |
| 1027 | (VG_(core_assert_fail) (VG__STRING(expr), \ |
| 1028 | __FILE__, __LINE__, \ |
| 1029 | __PRETTY_FUNCTION__), 0))) |
| 1030 | __attribute__ ((__noreturn__)) |
daywalker | 3222e0a | 2003-09-18 01:39:50 +0000 | [diff] [blame^] | 1031 | extern void VG_(core_assert_fail) ( const Char* expr, const Char* file, |
| 1032 | Int line, const Char* fn ); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1033 | __attribute__ ((__noreturn__)) |
| 1034 | extern void VG_(core_panic) ( Char* str ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1035 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1036 | /* VG_(brk) not public so skins cannot screw with curr_dataseg_end */ |
| 1037 | extern void* VG_(brk) ( void* end_data_segment ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1038 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1039 | /* Skins use VG_(strdup)() which doesn't expose ArenaId */ |
| 1040 | extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1041 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1042 | /* Skins shouldn't need these...(?) */ |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1043 | extern void VG_(start_rdtsc_calibration) ( void ); |
| 1044 | extern void VG_(end_rdtsc_calibration) ( void ); |
| 1045 | extern UInt VG_(read_millisecond_timer) ( void ); |
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 Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1048 | extern Int VG_(select)( Int n, |
| 1049 | vki_fd_set* readfds, |
| 1050 | vki_fd_set* writefds, |
| 1051 | vki_fd_set* exceptfds, |
| 1052 | struct vki_timeval * timeout ); |
| 1053 | extern Int VG_(nanosleep)( const struct vki_timespec *req, |
| 1054 | struct vki_timespec *rem ); |
| 1055 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1056 | extern Int VG_(write_socket)( Int sd, void *msg, Int count ); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1057 | |
| 1058 | /* --- Connecting over the network --- */ |
| 1059 | extern Int VG_(connect_via_socket)( UChar* str ); |
| 1060 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1061 | |
| 1062 | /* --------------------------------------------------------------------- |
| 1063 | Exports of vg_message.c |
| 1064 | ------------------------------------------------------------------ */ |
| 1065 | |
| 1066 | /* Low-level -- send bytes directly to the message sink. Do not |
| 1067 | use. */ |
| 1068 | extern void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes ); |
| 1069 | |
| 1070 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1071 | /* --------------------------------------------------------------------- |
| 1072 | Definitions for the JITter (vg_translate.c, vg_to_ucode.c, |
| 1073 | vg_from_ucode.c). |
| 1074 | ------------------------------------------------------------------ */ |
| 1075 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1076 | #define VG_IS_FLAG_SUBSET(set1,set2) \ |
| 1077 | (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) ) |
| 1078 | |
| 1079 | #define VG_UNION_FLAG_SETS(set1,set2) \ |
| 1080 | ( ((FlagSet)set1) | ((FlagSet)set2) ) |
| 1081 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1082 | /* --------------------------------------------------------------------- |
| 1083 | Exports of vg_demangle.c |
| 1084 | ------------------------------------------------------------------ */ |
| 1085 | |
| 1086 | extern void VG_(demangle) ( Char* orig, Char* result, Int result_size ); |
| 1087 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1088 | /* --------------------------------------------------------------------- |
| 1089 | Exports of vg_from_ucode.c |
| 1090 | ------------------------------------------------------------------ */ |
| 1091 | |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1092 | extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes, UShort jumps[VG_MAX_JUMPS] ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1093 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1094 | extern void VG_(print_ccall_stats) ( void ); |
| 1095 | extern void VG_(print_UInstr_histogram) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1096 | |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1097 | extern void VG_(unchain_jumpsite) ( Addr jumpsite ); |
| 1098 | extern Addr VG_(get_jmp_dest) ( Addr jumpsite ); |
| 1099 | extern Bool VG_(is_unchained_jumpsite) ( Addr jumpsite ); |
| 1100 | extern Bool VG_(is_chained_jumpsite) ( Addr jumpsite ); |
| 1101 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1102 | /* --------------------------------------------------------------------- |
| 1103 | Exports of vg_to_ucode.c |
| 1104 | ------------------------------------------------------------------ */ |
| 1105 | |
| 1106 | extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1107 | |
| 1108 | /* --------------------------------------------------------------------- |
| 1109 | Exports of vg_translate.c |
| 1110 | ------------------------------------------------------------------ */ |
| 1111 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1112 | /* Expandable arrays of uinstrs. */ |
| 1113 | struct _UCodeBlock { |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1114 | Addr orig_eip; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1115 | Int used; |
| 1116 | Int size; |
| 1117 | UInstr* instrs; |
| 1118 | Int nextTemp; |
| 1119 | }; |
| 1120 | |
| 1121 | extern UCodeBlock* VG_(alloc_UCodeBlock) ( void ); |
| 1122 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 1123 | extern void VG_(translate) ( ThreadId tid, |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 1124 | Addr orig_addr, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1125 | UInt* orig_size, |
| 1126 | Addr* trans_addr, |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1127 | UInt* trans_size, |
| 1128 | UShort jumps[VG_MAX_JUMPS]); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1129 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1130 | extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness, |
| 1131 | UInstr* u ); |
| 1132 | extern void VG_(saneUCodeBlock) ( UCodeBlock* cb ); |
| 1133 | extern Bool VG_(saneUCodeBlockCalls) ( UCodeBlock* cb ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1134 | |
sewardj | b5ff83e | 2002-12-01 19:40:49 +0000 | [diff] [blame] | 1135 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1136 | /* --------------------------------------------------------------------- |
| 1137 | Exports of vg_execontext.c. |
| 1138 | ------------------------------------------------------------------ */ |
| 1139 | |
| 1140 | /* Records the PC and a bit of the call chain. The first 4 %eip |
| 1141 | values are used in comparisons do remove duplicate errors, and for |
| 1142 | comparing against suppression specifications. The rest are purely |
| 1143 | informational (but often important). */ |
| 1144 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1145 | struct _ExeContext { |
| 1146 | struct _ExeContext * next; |
| 1147 | /* Variable-length array. The size is VG_(clo_backtrace_size); at |
njn | 6c84655 | 2003-09-16 07:41:43 +0000 | [diff] [blame] | 1148 | least 1, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1149 | [1] is its caller, [2] is the caller of [1], etc. */ |
| 1150 | Addr eips[0]; |
| 1151 | }; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1152 | |
| 1153 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1154 | /* Print stats (informational only). */ |
| 1155 | extern void VG_(show_ExeContext_stats) ( void ); |
| 1156 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1157 | /* Like VG_(get_ExeContext), but with a slightly different type */ |
| 1158 | extern ExeContext* VG_(get_ExeContext2) ( Addr eip, Addr ebp, |
| 1159 | Addr ebp_min, Addr ebp_max ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1160 | |
| 1161 | |
| 1162 | /* --------------------------------------------------------------------- |
| 1163 | Exports of vg_errcontext.c. |
| 1164 | ------------------------------------------------------------------ */ |
| 1165 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1166 | /* Note: it is imperative this doesn't overlap with (0..) at all, as skins |
| 1167 | * effectively extend it by defining their own enums in the (0..) range. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1168 | typedef |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1169 | enum { |
| 1170 | PThreadSupp = -1, /* Matches PThreadErr */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1171 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1172 | CoreSuppKind; |
| 1173 | |
| 1174 | /* For each caller specified for a suppression, record the nature of |
| 1175 | the caller name. Not of interest to skins. */ |
| 1176 | typedef |
| 1177 | enum { |
| 1178 | ObjName, /* Name is of an shared object file. */ |
| 1179 | FunName /* Name is of a function. */ |
| 1180 | } |
| 1181 | SuppLocTy; |
| 1182 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1183 | /* Suppressions. Skins can get/set skin-relevant parts with functions |
| 1184 | declared in include/vg_skin.h. Extensible via the 'extra' field. |
| 1185 | Skins can use a normal enum (with element values in the normal range |
| 1186 | (0..)) for `skind'. */ |
| 1187 | struct _Supp { |
| 1188 | struct _Supp* next; |
| 1189 | /* The number of times this error has been suppressed. */ |
| 1190 | Int count; |
| 1191 | /* The name by which the suppression is referred to. */ |
| 1192 | Char* sname; |
| 1193 | /* First two (name of fn where err occurs, and immediate caller) |
| 1194 | * are mandatory; extra two are optional. */ |
| 1195 | SuppLocTy caller_ty[VG_N_SUPP_CALLERS]; |
| 1196 | Char* caller [VG_N_SUPP_CALLERS]; |
| 1197 | |
| 1198 | /* The skin-specific part */ |
| 1199 | /* What kind of suppression. Must use the range (0..) */ |
| 1200 | SuppKind skind; |
| 1201 | /* String -- use is optional. NULL by default. */ |
| 1202 | Char* string; |
| 1203 | /* Anything else -- use is optional. NULL by default. */ |
| 1204 | void* extra; |
| 1205 | }; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1206 | |
| 1207 | /* Note: it is imperative this doesn't overlap with (0..) at all, as skins |
| 1208 | * effectively extend it by defining their own enums in the (0..) range. */ |
| 1209 | typedef |
| 1210 | enum { |
| 1211 | PThreadErr = -1, /* Pthreading error */ |
| 1212 | } |
| 1213 | CoreErrorKind; |
| 1214 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1215 | /* Errors. Extensible (via the 'extra' field). Skins can use a normal |
| 1216 | enum (with element values in the normal range (0..)) for `ekind'. |
| 1217 | Functions for getting/setting the skin-relevant fields are in |
| 1218 | include/vg_skin.h. |
| 1219 | |
| 1220 | When errors are found and recorded with VG_(maybe_record_error)(), all |
| 1221 | the skin must do is pass in the four parameters; core will |
| 1222 | allocate/initialise the error record. |
| 1223 | */ |
| 1224 | struct _Error { |
| 1225 | struct _Error* next; |
| 1226 | /* NULL if unsuppressed; or ptr to suppression record. */ |
| 1227 | Supp* supp; |
| 1228 | Int count; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1229 | ThreadId tid; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1230 | |
| 1231 | /* The skin-specific part */ |
njn | ae17bec | 2003-01-28 19:59:38 +0000 | [diff] [blame] | 1232 | /* Initialised by core */ |
| 1233 | ExeContext* where; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1234 | /* Used by ALL. Must be in the range (0..) */ |
| 1235 | Int ekind; |
| 1236 | /* Used frequently */ |
| 1237 | Addr addr; |
| 1238 | /* Used frequently */ |
| 1239 | Char* string; |
| 1240 | /* For any skin-specific extras */ |
| 1241 | void* extra; |
| 1242 | }; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1243 | |
| 1244 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1245 | extern void VG_(load_suppressions) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1246 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1247 | extern void VG_(record_pthread_error) ( ThreadId tid, Char* msg ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1248 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1249 | extern void VG_(show_all_errors) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1250 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1251 | extern Bool VG_(is_action_requested) ( Char* action, Bool* clo ); |
| 1252 | |
| 1253 | extern void VG_(gen_suppression) ( Error* err ); |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 1254 | |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 1255 | extern UInt VG_(n_errs_found); |
| 1256 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1257 | /* --------------------------------------------------------------------- |
| 1258 | Exports of vg_procselfmaps.c |
| 1259 | ------------------------------------------------------------------ */ |
| 1260 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1261 | /* Reads /proc/self/maps into a static buffer. */ |
| 1262 | void VG_(read_procselfmaps_contents) ( void ); |
| 1263 | |
| 1264 | /* Parses /proc/self/maps, calling `record_mapping' for each entry. If |
| 1265 | `read_from_file' is True, /proc/self/maps is read directly, otherwise |
| 1266 | it's read from the buffer filled by VG_(read_procselfmaps_contents)(). */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1267 | extern |
| 1268 | void VG_(read_procselfmaps) ( |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1269 | void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* ), |
| 1270 | Bool read_from_file |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1271 | ); |
| 1272 | |
| 1273 | |
| 1274 | /* --------------------------------------------------------------------- |
| 1275 | Exports of vg_symtab2.c |
| 1276 | ------------------------------------------------------------------ */ |
| 1277 | |
daywalker | 3222e0a | 2003-09-18 01:39:50 +0000 | [diff] [blame^] | 1278 | extern void VG_(mini_stack_dump) ( Addr eips[], UInt n_eips ); |
| 1279 | extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf); |
sewardj | 8a77ffb | 2003-07-10 23:31:27 +0000 | [diff] [blame] | 1280 | extern void VG_(read_symbols) ( void ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1281 | extern void VG_(read_symtab_callback) ( Addr start, UInt size, |
| 1282 | Char rr, Char ww, Char xx, |
| 1283 | UInt foffset, UChar* filename ); |
sewardj | 8a77ffb | 2003-07-10 23:31:27 +0000 | [diff] [blame] | 1284 | extern void VG_(unload_symbols) ( Addr start, UInt length ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1285 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1286 | extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname ); |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 1287 | extern Int VG_(setup_code_redirect_table) ( void ); |
| 1288 | |
| 1289 | typedef |
| 1290 | struct { |
| 1291 | Addr entry_pt_orig; |
| 1292 | Addr entry_pt_subst; |
| 1293 | } |
| 1294 | CodeRedirect; |
| 1295 | |
| 1296 | #define VG_N_CODE_REDIRECTS 10 |
| 1297 | extern CodeRedirect VG_(code_redirect_table)[VG_N_CODE_REDIRECTS]; |
| 1298 | /* Table is terminated by a NULL entry_pt_orig field. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1299 | |
| 1300 | |
| 1301 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1302 | Exports of vg_main.c |
| 1303 | ------------------------------------------------------------------ */ |
| 1304 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1305 | /* Is this a SSE/SSE2-capable CPU? If so, we had better save/restore |
| 1306 | the SSE state all over the place. This is set up very early, in |
| 1307 | vg_startup.S. We have to determine it early since we can't even |
| 1308 | correctly snapshot the startup machine state without it. */ |
| 1309 | extern Bool VG_(have_ssestate); |
| 1310 | |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1311 | /* Tell the logging mechanism whether we are logging to a file |
| 1312 | descriptor or a socket descriptor. */ |
| 1313 | extern Bool VG_(logging_to_filedes); |
| 1314 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1315 | /* Sanity checks which may be done at any time. The scheduler decides when. */ |
| 1316 | extern void VG_(do_sanity_checks) ( Bool force_expensive ); |
| 1317 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1318 | /* A structure used as an intermediary when passing the simulated |
| 1319 | CPU's state to some assembly fragments, particularly system calls. |
| 1320 | Stuff is copied from baseBlock to here, the assembly magic runs, |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1321 | and then the inverse copy is done. Alignment: the SSE state must |
| 1322 | be 16-byte aligned. We ask for the whole struct to be 16-byte |
| 1323 | aligned, and the SSE state starts at the 6+8+1+1th == 16th word, |
| 1324 | so it too must be 16-byte aligned. Consequence: change this struct |
| 1325 | only _very carefully_ ! See also above comment re masking MXCSR. |
| 1326 | */ |
| 1327 | __attribute__ ((aligned (16))) |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1328 | extern UInt VG_(m_state_static) [6 /* segment regs, Intel order */ |
| 1329 | + 8 /* int regs, in Intel order */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1330 | + 1 /* %eflags */ |
| 1331 | + 1 /* %eip */ |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1332 | + VG_SIZE_OF_SSESTATE_W /* SSE state */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1333 | ]; |
| 1334 | |
| 1335 | /* Handy fns for doing the copy back and forth. */ |
| 1336 | extern void VG_(copy_baseBlock_to_m_state_static) ( void ); |
| 1337 | extern void VG_(copy_m_state_static_to_baseBlock) ( void ); |
| 1338 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 1339 | /* Determine if %esp adjustment must be noted */ |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 1340 | extern Bool VG_(need_to_handle_esp_assignment) ( void ); |
| 1341 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1342 | /* Called when some unhandleable client behaviour is detected. |
| 1343 | Prints a msg and aborts. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1344 | extern void VG_(unimplemented) ( Char* msg ) |
| 1345 | __attribute__((__noreturn__)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1346 | |
| 1347 | /* The stack on which Valgrind runs. We can't use the same stack as the |
| 1348 | simulatee -- that's an important design decision. */ |
njn | 6eba4ef | 2003-05-01 08:06:41 +0000 | [diff] [blame] | 1349 | extern UInt VG_(stack)[VG_STACK_SIZE_W]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1350 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1351 | /* Similarly, we have to ask for signals to be delivered on an alternative |
| 1352 | stack, since it is possible, although unlikely, that we'll have to run |
| 1353 | client code from inside the Valgrind-installed signal handler. If this |
| 1354 | happens it will be done by vg_deliver_signal_immediately(). */ |
njn | 6eba4ef | 2003-05-01 08:06:41 +0000 | [diff] [blame] | 1355 | extern UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1356 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1357 | /* Holds client's %esp at the point we gained control. From this the |
| 1358 | client's argc, argv and envp are deduced. */ |
| 1359 | extern Addr VG_(esp_at_startup); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1360 | |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 1361 | /* Indicates presence, and holds address of client's sysinfo page, a |
| 1362 | feature of some modern kernels used to provide vsyscalls, etc. */ |
| 1363 | extern Bool VG_(sysinfo_page_exists); |
| 1364 | extern Addr VG_(sysinfo_page_addr); |
| 1365 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1366 | /* Remove valgrind.so and skin's .so from a LD_PRELOAD=... string so child |
| 1367 | processes don't get traced into. Also mess up $libdir/valgrind so that |
| 1368 | our libpthread.so disappears from view. */ |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1369 | void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str, |
| 1370 | Char* ld_library_path_str ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1371 | |
| 1372 | /* Something of a function looking for a home ... start up GDB. This |
| 1373 | is called from VG_(swizzle_esp_then_start_GDB) and so runs on the |
| 1374 | *client's* stack. This is necessary to give GDB the illusion that |
| 1375 | the client program really was running on the real cpu. */ |
| 1376 | extern void VG_(start_GDB_whilst_on_client_stack) ( void ); |
| 1377 | |
njn | 4155712 | 2002-10-14 09:25:37 +0000 | [diff] [blame] | 1378 | /* VG_(bbs_done) in include/vg_skin.h */ |
| 1379 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1380 | /* 64-bit counter for the number of bbs to go before a debug exit. */ |
| 1381 | extern ULong VG_(bbs_to_go); |
| 1382 | |
| 1383 | /* Counts downwards in vg_run_innerloop. */ |
| 1384 | extern UInt VG_(dispatch_ctr); |
| 1385 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1386 | /* Is the client running on the simulated CPU or the real one? */ |
| 1387 | extern Bool VG_(running_on_simd_CPU); /* Initially False */ |
| 1388 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1389 | /* This is the ThreadId of the last thread the scheduler ran. */ |
| 1390 | extern ThreadId VG_(last_run_tid); |
| 1391 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1392 | /* This is the argument to __NR_exit() supplied by the first thread to |
| 1393 | call that syscall. We eventually pass that to __NR_exit() for |
| 1394 | real. */ |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 1395 | extern Int VG_(exitcode); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1396 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1397 | |
| 1398 | /* --- Counters, for informational purposes only. --- */ |
| 1399 | |
| 1400 | /* Number of lookups which miss the fast tt helper. */ |
| 1401 | extern UInt VG_(tt_fast_misses); |
| 1402 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1403 | /* Counts for TT/TC informational messages. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1404 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1405 | /* Number and total o/t size of translations overall. */ |
| 1406 | extern UInt VG_(overall_in_count); |
| 1407 | extern UInt VG_(overall_in_osize); |
| 1408 | extern UInt VG_(overall_in_tsize); |
| 1409 | /* Number and total o/t size of discards overall. */ |
| 1410 | extern UInt VG_(overall_out_count); |
| 1411 | extern UInt VG_(overall_out_osize); |
| 1412 | extern UInt VG_(overall_out_tsize); |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1413 | /* The number of discards of TT/TC. */ |
| 1414 | extern UInt VG_(number_of_tc_discards); |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1415 | /* Counts of chain and unchain operations done. */ |
| 1416 | extern UInt VG_(bb_enchain_count); |
| 1417 | extern UInt VG_(bb_dechain_count); |
| 1418 | /* Number of unchained jumps performed. */ |
| 1419 | extern UInt VG_(unchained_jumps_done); |
| 1420 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1421 | |
| 1422 | /* Counts pertaining to the register allocator. */ |
| 1423 | |
| 1424 | /* total number of uinstrs input to reg-alloc */ |
| 1425 | extern UInt VG_(uinstrs_prealloc); |
| 1426 | |
| 1427 | /* total number of uinstrs added due to spill code */ |
| 1428 | extern UInt VG_(uinstrs_spill); |
| 1429 | |
| 1430 | /* number of bbs requiring spill code */ |
| 1431 | extern UInt VG_(translations_needing_spill); |
| 1432 | |
| 1433 | /* total of register ranks over all translations */ |
| 1434 | extern UInt VG_(total_reg_rank); |
| 1435 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1436 | /* Counts pertaining to internal sanity checking. */ |
| 1437 | extern UInt VG_(sanity_fast_count); |
| 1438 | extern UInt VG_(sanity_slow_count); |
| 1439 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1440 | /* Counts pertaining to the scheduler. */ |
| 1441 | extern UInt VG_(num_scheduling_events_MINOR); |
| 1442 | extern UInt VG_(num_scheduling_events_MAJOR); |
| 1443 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1444 | /* Insert and extract the D flag from eflags */ |
| 1445 | UInt VG_(insertDflag)(UInt eflags, Int d); |
| 1446 | Int VG_(extractDflag)(UInt eflags); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1447 | |
sewardj | 49e630d | 2003-04-23 21:18:52 +0000 | [diff] [blame] | 1448 | /* start address and size of the initial stack */ |
| 1449 | extern Addr VG_(foundstack_start); |
| 1450 | extern UInt VG_(foundstack_size); |
| 1451 | |
| 1452 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1453 | /* --------------------------------------------------------------------- |
| 1454 | Exports of vg_memory.c |
| 1455 | ------------------------------------------------------------------ */ |
| 1456 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1457 | extern void VG_(init_memory) ( void ); |
| 1458 | extern void VG_(new_exe_segment) ( Addr a, UInt len ); |
| 1459 | extern void VG_(remove_if_exe_segment) ( Addr a, UInt len ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1460 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 1461 | extern __attribute__((regparm(1))) |
| 1462 | void VG_(unknown_esp_update) ( Addr new_ESP ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1463 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1464 | /* --------------------------------------------------------------------- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1465 | Exports of vg_syscalls.c |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1466 | ------------------------------------------------------------------ */ |
| 1467 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1468 | extern void VG_(init_dataseg_end_for_brk) ( void ); |
| 1469 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1470 | extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1471 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1472 | extern void* VG_(pre_known_blocking_syscall) ( ThreadId tid, Int syscallno ); |
| 1473 | extern void VG_(post_known_blocking_syscall)( ThreadId tid, Int syscallno, |
| 1474 | void* pre_res, Int res ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1475 | |
| 1476 | extern Bool VG_(is_kerror) ( Int res ); |
| 1477 | |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 1478 | #define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \ |
| 1479 | VG_(load_thread_state)(thread_id); \ |
| 1480 | VG_(copy_baseBlock_to_m_state_static)(); \ |
| 1481 | VG_(do_syscall)(); \ |
| 1482 | VG_(copy_m_state_static_to_baseBlock)(); \ |
| 1483 | VG_(save_thread_state)(thread_id); \ |
| 1484 | result_lvalue = VG_(threads)[thread_id].m_eax; \ |
| 1485 | VG_TRACK( post_reg_write_syscall_return, thread_id, R_EAX ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1486 | |
| 1487 | |
| 1488 | /* --------------------------------------------------------------------- |
| 1489 | Exports of vg_transtab.c |
| 1490 | ------------------------------------------------------------------ */ |
| 1491 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1492 | /* The fast-cache for tt-lookup. */ |
| 1493 | extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE]; |
| 1494 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1495 | extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used ); |
sewardj | 6c3769f | 2002-11-29 01:02:45 +0000 | [diff] [blame] | 1496 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1497 | extern void VG_(add_to_trans_tab) ( Addr orig_addr, Int orig_size, |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1498 | Addr trans_addr, Int trans_size, |
| 1499 | UShort jumps[VG_MAX_JUMPS]); |
sewardj | 6c3769f | 2002-11-29 01:02:45 +0000 | [diff] [blame] | 1500 | |
sewardj | 97ad552 | 2003-05-04 12:32:56 +0000 | [diff] [blame] | 1501 | extern void VG_(invalidate_translations) ( Addr start, UInt range, Bool unchain_blocks ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1502 | |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1503 | extern void VG_(init_tt_tc) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1504 | |
| 1505 | extern void VG_(sanity_check_tc_tt) ( void ); |
| 1506 | extern Addr VG_(search_transtab) ( Addr original_addr ); |
| 1507 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1508 | |
| 1509 | |
| 1510 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1511 | Exports of vg_syscall.S |
| 1512 | ------------------------------------------------------------------ */ |
| 1513 | |
| 1514 | extern void VG_(do_syscall) ( void ); |
| 1515 | |
| 1516 | |
| 1517 | /* --------------------------------------------------------------------- |
| 1518 | Exports of vg_startup.S |
| 1519 | ------------------------------------------------------------------ */ |
| 1520 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1521 | extern void VG_(switch_to_real_CPU) ( void ); |
| 1522 | |
sewardj | 3580542 | 2002-04-21 13:05:34 +0000 | [diff] [blame] | 1523 | extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error, |
| 1524 | Addr m_esp_at_error, |
| 1525 | Addr m_ebp_at_error ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1526 | |
| 1527 | |
| 1528 | /* --------------------------------------------------------------------- |
| 1529 | Exports of vg_dispatch.S |
| 1530 | ------------------------------------------------------------------ */ |
| 1531 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1532 | /* Run a thread for a (very short) while, until some event happens |
| 1533 | which means we need to defer to the scheduler. */ |
| 1534 | extern UInt VG_(run_innerloop) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1535 | |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1536 | /* The patching routing called when a BB wants to chain itself to |
| 1537 | another. */ |
| 1538 | extern UInt VG_(patch_me); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1539 | |
| 1540 | /* --------------------------------------------------------------------- |
| 1541 | Exports of vg_helpers.S |
| 1542 | ------------------------------------------------------------------ */ |
| 1543 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1544 | /* Mul, div, etc, -- we don't codegen these directly. */ |
| 1545 | extern void VG_(helper_idiv_64_32); |
| 1546 | extern void VG_(helper_div_64_32); |
| 1547 | extern void VG_(helper_idiv_32_16); |
| 1548 | extern void VG_(helper_div_32_16); |
| 1549 | extern void VG_(helper_idiv_16_8); |
| 1550 | extern void VG_(helper_div_16_8); |
| 1551 | |
| 1552 | extern void VG_(helper_imul_32_64); |
| 1553 | extern void VG_(helper_mul_32_64); |
| 1554 | extern void VG_(helper_imul_16_32); |
| 1555 | extern void VG_(helper_mul_16_32); |
| 1556 | extern void VG_(helper_imul_8_16); |
| 1557 | extern void VG_(helper_mul_8_16); |
| 1558 | |
| 1559 | extern void VG_(helper_CLD); |
| 1560 | extern void VG_(helper_STD); |
| 1561 | extern void VG_(helper_get_dirflag); |
| 1562 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 1563 | extern void VG_(helper_CLC); |
| 1564 | extern void VG_(helper_STC); |
| 1565 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1566 | extern void VG_(helper_shldl); |
| 1567 | extern void VG_(helper_shldw); |
| 1568 | extern void VG_(helper_shrdl); |
| 1569 | extern void VG_(helper_shrdw); |
| 1570 | |
| 1571 | extern void VG_(helper_RDTSC); |
| 1572 | extern void VG_(helper_CPUID); |
| 1573 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1574 | extern void VG_(helper_bsf); |
| 1575 | extern void VG_(helper_bsr); |
| 1576 | |
| 1577 | extern void VG_(helper_fstsw_AX); |
| 1578 | extern void VG_(helper_SAHF); |
njn | d6251f1 | 2003-06-03 13:38:51 +0000 | [diff] [blame] | 1579 | extern void VG_(helper_LAHF); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 1580 | extern void VG_(helper_DAS); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 1581 | extern void VG_(helper_DAA); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1582 | |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 1583 | extern void VG_(helper_undefined_instruction); |
| 1584 | |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1585 | /* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */ |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 1586 | extern void VG_(signalreturn_bogusRA)( void ); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1587 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1588 | /* --------------------------------------------------------------------- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1589 | Things relating to the used skin |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1590 | ------------------------------------------------------------------ */ |
| 1591 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1592 | #define VG_TRACK(fn, args...) \ |
| 1593 | do { \ |
| 1594 | if (VG_(track_events).fn) \ |
| 1595 | VG_(track_events).fn(args); \ |
| 1596 | } while (0) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1597 | |
| 1598 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1599 | /* --------------------------------------------------------------------- |
| 1600 | The state of the simulated CPU. |
| 1601 | ------------------------------------------------------------------ */ |
| 1602 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1603 | /* --------------------------------------------------------------------- |
| 1604 | Offsets into baseBlock for everything which needs to referred to |
| 1605 | from generated code. The order of these decls does not imply |
| 1606 | what the order of the actual offsets is. The latter is important |
| 1607 | and is set up in vg_main.c. |
| 1608 | ------------------------------------------------------------------ */ |
| 1609 | |
| 1610 | /* An array of words. In generated code, %ebp always points to the |
| 1611 | start of this array. Useful stuff, like the simulated CPU state, |
| 1612 | and the addresses of helper functions, can then be found by |
| 1613 | indexing off %ebp. The following declares variables which, at |
| 1614 | startup time, are given values denoting offsets into baseBlock. |
| 1615 | These offsets are in *words* from the start of baseBlock. */ |
| 1616 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1617 | #define VG_BASEBLOCK_WORDS 400 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1618 | |
| 1619 | extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; |
| 1620 | |
| 1621 | |
| 1622 | /* ----------------------------------------------------- |
| 1623 | Read-write parts of baseBlock. |
| 1624 | -------------------------------------------------- */ |
| 1625 | |
| 1626 | /* State of the simulated CPU. */ |
| 1627 | extern Int VGOFF_(m_eax); |
| 1628 | extern Int VGOFF_(m_ecx); |
| 1629 | extern Int VGOFF_(m_edx); |
| 1630 | extern Int VGOFF_(m_ebx); |
| 1631 | extern Int VGOFF_(m_esp); |
| 1632 | extern Int VGOFF_(m_ebp); |
| 1633 | extern Int VGOFF_(m_esi); |
| 1634 | extern Int VGOFF_(m_edi); |
| 1635 | extern Int VGOFF_(m_eflags); |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1636 | extern Int VGOFF_(m_ssestate); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1637 | extern Int VGOFF_(m_eip); |
| 1638 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1639 | extern Int VGOFF_(m_dflag); /* D flag is handled specially */ |
| 1640 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1641 | extern Int VGOFF_(m_cs); |
| 1642 | extern Int VGOFF_(m_ss); |
| 1643 | extern Int VGOFF_(m_ds); |
| 1644 | extern Int VGOFF_(m_es); |
| 1645 | extern Int VGOFF_(m_fs); |
| 1646 | extern Int VGOFF_(m_gs); |
| 1647 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1648 | /* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */ |
| 1649 | extern Int VGOFF_(spillslots); |
| 1650 | |
| 1651 | /* Records the valid bits for the 8 integer regs & flags reg. */ |
| 1652 | extern Int VGOFF_(sh_eax); |
| 1653 | extern Int VGOFF_(sh_ecx); |
| 1654 | extern Int VGOFF_(sh_edx); |
| 1655 | extern Int VGOFF_(sh_ebx); |
| 1656 | extern Int VGOFF_(sh_esp); |
| 1657 | extern Int VGOFF_(sh_ebp); |
| 1658 | extern Int VGOFF_(sh_esi); |
| 1659 | extern Int VGOFF_(sh_edi); |
| 1660 | extern Int VGOFF_(sh_eflags); |
| 1661 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1662 | /* ----------------------------------------------------- |
| 1663 | Read-only parts of baseBlock. |
| 1664 | -------------------------------------------------- */ |
| 1665 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1666 | /* This thread's LDT pointer. */ |
| 1667 | extern Int VGOFF_(ldt); |
| 1668 | |
njn | 211b6ad | 2003-02-03 12:33:31 +0000 | [diff] [blame] | 1669 | /* Nb: Most helper offsets are in include/vg_skin.h, for use by skins */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1670 | |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 1671 | extern Int VGOFF_(helper_undefined_instruction); |
| 1672 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1673 | /* For storing extension-specific helpers, determined at runtime. The addr |
| 1674 | * and offset arrays together form a (addr, offset) map that allows a |
| 1675 | * helper's baseBlock offset to be computed from its address. It's done |
| 1676 | * like this so CCALL_M_Ns and other helper calls can use the function |
| 1677 | * address rather than having to much around with offsets. */ |
| 1678 | extern UInt VG_(n_compact_helpers); |
| 1679 | extern UInt VG_(n_noncompact_helpers); |
| 1680 | |
| 1681 | extern Addr VG_(compact_helper_addrs) []; |
| 1682 | extern Int VG_(compact_helper_offsets)[]; |
| 1683 | |
| 1684 | extern Addr VG_(noncompact_helper_addrs) []; |
| 1685 | extern Int VG_(noncompact_helper_offsets)[]; |
| 1686 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1687 | #endif /* ndef __VG_INCLUDE_H */ |
| 1688 | |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1689 | |
| 1690 | /* --------------------------------------------------------------------- |
| 1691 | Finally - autoconf-generated settings |
| 1692 | ------------------------------------------------------------------ */ |
| 1693 | |
| 1694 | #include "config.h" |
| 1695 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1696 | /*--------------------------------------------------------------------*/ |
| 1697 | /*--- end vg_include.h ---*/ |
| 1698 | /*--------------------------------------------------------------------*/ |