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