sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame^] | 3 | /*--- A header file for various private parts of Valgrind's core. ---*/ |
rjwalsh | 7109a8c | 2004-09-02 00:31:02 +0000 | [diff] [blame] | 4 | /*--- core.h ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 8 | This file is part of Valgrind, a dynamic binary instrumentation |
| 9 | framework. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 10 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2005 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 12 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 29 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
rjwalsh | 7109a8c | 2004-09-02 00:31:02 +0000 | [diff] [blame] | 32 | #ifndef __CORE_H |
| 33 | #define __CORE_H |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 34 | |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 35 | /* |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 36 | [This comment is not longer accurate -- we're switching to an easier to |
| 37 | understand module-based approach, with one or two headers per module, |
| 38 | rather than having monolithic headers as described. --njn 07-May-2005] |
| 39 | |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 40 | Header hierarchy: |
| 41 | |
| 42 | - core C files include core.h |
| 43 | - core asm files include core_asm.h |
| 44 | - tool C files include tool.h |
| 45 | - tool asm files include tool_asm.h |
| 46 | |
| 47 | - The hierarchy of the header files themselves is based around the |
| 48 | following rules: |
| 49 | |
| 50 | - core headers include tool headers |
| 51 | - generic headers include arch/OS/platform headers |
| 52 | - C headers include asm headers |
| 53 | |
| 54 | This gives the following hierarchy (only showing 'arch' headers, not |
nethercote | 80cca43 | 2004-09-02 16:25:49 +0000 | [diff] [blame] | 55 | 'os' or 'platform' headers), where arrows indicate inclusion, and |
| 56 | $VG_ARCH==x86: |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 57 | |
nethercote | 80cca43 | 2004-09-02 16:25:49 +0000 | [diff] [blame] | 58 | |
| 59 | (include/x86/tool_arch_asm.h?) <----- coregrind/x86/core_arch_asm.h |
| 60 | ^ ^ ^ ^ |
| 61 | / \ / \ |
| 62 | / \ / \ |
| 63 | / \ / \ |
| 64 | include/tool_asm.h <-\---- coregrind/core_asm.h \ |
| 65 | ^ \ ^ \ |
| 66 | \ include/x86/tool_arch.h <--------coregrind/x86/core_arch.h |
| 67 | \ ^ \ ^ |
| 68 | \ / \ / |
| 69 | \ / \ / |
| 70 | \ / \ / |
| 71 | include/tool.h <------------ coregrind/core.h |
| 72 | |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 73 | |
| 74 | Note that core.h contains the *declarations* of arch-specific functions |
| 75 | and variables, which can be used by the core_arch.h file of any |
| 76 | architecture. (The functions/variables are *defined* within arch/.) |
| 77 | However, arch-specific macros and types cannot go into core.h, because |
| 78 | there is no separation between declaration and definition for |
| 79 | macros/types, so they instead go into $VG_ARCH/core_arch.h. |
nethercote | 80cca43 | 2004-09-02 16:25:49 +0000 | [diff] [blame] | 80 | |
| 81 | The tool-specific headers are all in include/ so they can be seen by any |
| 82 | external tools. |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 83 | */ |
| 84 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 85 | /* For system call numbers __NR_... */ |
nethercote | f94fe2f | 2004-09-10 14:23:59 +0000 | [diff] [blame] | 86 | #include "vki_unistd.h" |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 87 | |
nethercote | 1334313 | 2004-09-02 15:49:09 +0000 | [diff] [blame] | 88 | #include "core_asm.h" // asm stuff |
| 89 | #include "tool.h" // tool stuff |
nethercote | bb4222b | 2004-09-10 17:42:11 +0000 | [diff] [blame] | 90 | #include "core_arch.h" // arch-specific stuff, eg. x86/core_arch.h |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 91 | |
| 92 | // Ugly: this is needed by linux/core_os.h |
| 93 | typedef struct _ThreadState ThreadState; |
| 94 | |
nethercote | bb4222b | 2004-09-10 17:42:11 +0000 | [diff] [blame] | 95 | #include "core_platform.h" // platform-specific stuff, |
| 96 | // eg. x86-linux/core_platform.h |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 97 | #include "core_os.h" // OS-specific stuff, eg. linux/core_os.h |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 98 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame^] | 99 | #include "pub_core_mallocfree.h" // for type 'ArenaId' |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 100 | #include "pub_core_stacktrace.h" // for type 'StackTrace' |
| 101 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 102 | #include "valgrind.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 103 | |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 104 | /* --------------------------------------------------------------------- |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 105 | Global macros. |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 106 | ------------------------------------------------------------------ */ |
| 107 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 108 | /* Max length of a text fragment used to construct error messages. */ |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 109 | #define VG_ERRTXT_LEN 4096 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 110 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 111 | /* The maximum number of calls we're prepared to save in a |
| 112 | backtrace. */ |
| 113 | #define VG_DEEPEST_BACKTRACE 50 |
| 114 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 115 | /* Useful macros */ |
| 116 | /* a - alignment - must be a power of 2 */ |
tom | de2ec26 | 2005-03-29 12:16:10 +0000 | [diff] [blame] | 117 | #define ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1)) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 118 | #define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a)) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 119 | #define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE) |
| 120 | #define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 121 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 122 | |
nethercote | 80013e9 | 2004-09-05 20:39:51 +0000 | [diff] [blame] | 123 | /* --------------------------------------------------------------------- |
| 124 | Environment variables |
| 125 | ------------------------------------------------------------------ */ |
| 126 | |
| 127 | /* The directory we look for all our auxillary files in */ |
| 128 | #define VALGRINDLIB "VALGRINDLIB" |
| 129 | |
| 130 | /* Additional command-line arguments; they are overridden by actual |
| 131 | command-line option. Each argument is separated by spaces. There |
| 132 | is no quoting mechanism. |
| 133 | */ |
| 134 | #define VALGRINDOPTS "VALGRIND_OPTS" |
| 135 | |
| 136 | /* If this variable is present in the environment, then valgrind will |
| 137 | not parse the command line for options at all; all options come |
| 138 | from this variable. Arguments are terminated by ^A (\001). There |
| 139 | is no quoting mechanism. |
| 140 | |
| 141 | This variable is not expected to be set by anything other than |
| 142 | Valgrind itself, as part of its handling of execve with |
| 143 | --trace-children=yes. This variable should not be present in the |
| 144 | client environment. |
| 145 | */ |
| 146 | #define VALGRINDCLO "_VALGRIND_CLO" |
| 147 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 148 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 149 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 150 | Command-line-settable options |
| 151 | ------------------------------------------------------------------ */ |
| 152 | |
sewardj | 4f094a7 | 2002-11-05 23:37:35 +0000 | [diff] [blame] | 153 | /* Default destination port to be used in logging over a network, if |
| 154 | none specified. */ |
| 155 | #define VG_CLO_DEFAULT_LOGPORT 1500 |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 156 | |
| 157 | /* The max number of suppression files. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 158 | #define VG_CLO_MAX_SFILES 10 |
| 159 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 160 | /* Describes where logging output is to be sent. */ |
| 161 | typedef |
| 162 | enum { |
| 163 | VgLogTo_Fd, |
| 164 | VgLogTo_File, |
sewardj | 603d410 | 2005-01-11 14:01:02 +0000 | [diff] [blame] | 165 | VgLogTo_FileExactly, |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 166 | VgLogTo_Socket |
| 167 | } VgLogTo; |
| 168 | |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 169 | /* Application-visible file descriptor limits */ |
| 170 | extern Int VG_(fd_soft_limit); |
| 171 | extern Int VG_(fd_hard_limit); |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 172 | |
sewardj | 8b635a4 | 2004-11-22 19:01:47 +0000 | [diff] [blame] | 173 | /* Vex iropt control */ |
| 174 | extern VexControl VG_(clo_vex_control); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 175 | /* Should we stop collecting errors if too many appear? default: YES */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 176 | extern Bool VG_(clo_error_limit); |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 177 | /* Enquire about whether to attach to a debugger at errors? default: NO */ |
| 178 | extern Bool VG_(clo_db_attach); |
| 179 | /* The debugger command? default: whatever gdb ./configure found */ |
| 180 | extern Char* VG_(clo_db_command); |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 181 | /* Generating a suppression for each error? default: 0 (NO) |
| 182 | Other values: 1 (yes, but ask user), 2 (yes, don't ask user) */ |
| 183 | extern Int VG_(clo_gen_suppressions); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 184 | /* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */ |
nethercote | 27fec90 | 2004-06-16 21:26:32 +0000 | [diff] [blame] | 185 | extern Int VG_(clo_sanity_level); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 186 | /* Automatically attempt to demangle C++ names? default: YES */ |
| 187 | extern Bool VG_(clo_demangle); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 188 | /* Simulate child processes? default: NO */ |
| 189 | extern Bool VG_(clo_trace_children); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 190 | |
| 191 | /* Where logging output is to be sent to. |
| 192 | |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 193 | When log_to == VgLogTo_Fd, clo_log_fd holds the file id, and is |
| 194 | taken from the command line. clo_log_name is irrelevant. |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 195 | |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 196 | When log_to == VgLogTo_File, clo_log_name holds the log-file |
| 197 | name, and is taken from the command line. clo_log_fd is then |
| 198 | made to hold the relevant file id, by opening clo_log_name |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 199 | (concatenated with the process ID) for writing. |
| 200 | |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 201 | When log_to == VgLogTo_Socket, clo_log_name holds the |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 202 | hostname:portnumber pair, and is taken from the command line. |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 203 | clo_log_fd is then made to hold the relevant file handle, by |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 204 | opening a connection to said hostname:portnumber pair. |
| 205 | |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 206 | Global default is to set log_to == VgLogTo_Fd and log_fd == 2 |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 207 | (stderr). */ |
| 208 | extern VgLogTo VG_(clo_log_to); |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 209 | extern Int VG_(clo_log_fd); |
| 210 | extern Char* VG_(clo_log_name); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 211 | |
thughes | 6233a38 | 2004-08-21 11:10:44 +0000 | [diff] [blame] | 212 | /* Add timestamps to log messages? default: NO */ |
| 213 | extern Bool VG_(clo_time_stamp); |
| 214 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 215 | /* The file descriptor to read for input. default: 0 == stdin */ |
| 216 | extern Int VG_(clo_input_fd); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 217 | /* The number of suppression files specified. */ |
| 218 | extern Int VG_(clo_n_suppressions); |
| 219 | /* The names of the suppression files. */ |
| 220 | extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
| 221 | |
sewardj | c771b29 | 2004-11-30 18:55:21 +0000 | [diff] [blame] | 222 | /* DEBUG: print generated code? default: 00000000 ( == NO ) */ |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 223 | extern Bool VG_(clo_trace_flags); |
| 224 | /* DEBUG: do bb profiling? default: 00000000 ( == NO ) */ |
| 225 | extern Bool VG_(clo_profile_flags); |
sewardj | c771b29 | 2004-11-30 18:55:21 +0000 | [diff] [blame] | 226 | /* DEBUG: if tracing codegen, be quiet until after this bb ( 0 ) */ |
| 227 | extern Int VG_(clo_trace_notbelow); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 228 | /* DEBUG: print system calls? default: NO */ |
| 229 | extern Bool VG_(clo_trace_syscalls); |
| 230 | /* DEBUG: print signal details? default: NO */ |
| 231 | extern Bool VG_(clo_trace_signals); |
| 232 | /* DEBUG: print symtab details? default: NO */ |
| 233 | extern Bool VG_(clo_trace_symtab); |
sewardj | ce058b0 | 2005-05-01 08:55:38 +0000 | [diff] [blame] | 234 | /* DEBUG: print call-frame-info details? default: NO */ |
| 235 | extern Bool VG_(clo_trace_cfi); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 236 | /* DEBUG: print redirection details? default: NO */ |
| 237 | extern Bool VG_(clo_trace_redir); |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 238 | /* DEBUG: print thread scheduling events? default: NO */ |
| 239 | extern Bool VG_(clo_trace_sched); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 240 | /* DEBUG: print pthreads calls? default: NO */ |
| 241 | extern Bool VG_(clo_trace_pthreads); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 250 | /* Track open file descriptors? */ |
| 251 | extern Bool VG_(clo_track_fds); |
| 252 | |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 253 | /* Should we run __libc_freeres at exit? Sometimes causes crashes. |
| 254 | Default: YES. Note this is subservient to VG_(needs).libc_freeres; |
| 255 | if the latter says False, then the setting of VG_(clo_weird_hacks) |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 256 | is ignored. Ie if a tool says no, I don't want this to run, that |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 257 | cannot be overridden from the command line. */ |
| 258 | extern Bool VG_(clo_run_libc_freeres); |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame] | 259 | /* Generate branch-prediction hints? */ |
| 260 | extern Bool VG_(clo_branchpred); |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 261 | /* Continue stack traces below main()? Default: NO */ |
| 262 | extern Bool VG_(clo_show_below_main); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 263 | /* Test each client pointer dereference to check it's within the |
| 264 | client address space bounds */ |
| 265 | extern Bool VG_(clo_pointercheck); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 266 | /* Model the pthread library */ |
| 267 | extern Bool VG_(clo_model_pthreads); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 268 | |
sewardj | 062f355 | 2005-01-06 16:13:40 +0000 | [diff] [blame] | 269 | /* HACK: Use hacked version of clone for Quadrics Elan3 drivers */ |
| 270 | extern Bool VG_(clo_support_elan3); |
| 271 | |
sewardj | b1131a8 | 2005-03-19 15:12:21 +0000 | [diff] [blame] | 272 | /* Should we show VEX emulation warnings? Default: NO */ |
| 273 | extern Bool VG_(clo_show_emwarns); |
| 274 | |
sewardj | 97724e5 | 2005-04-02 23:40:59 +0000 | [diff] [blame] | 275 | /* How much does the stack pointer have to change before tools |
| 276 | consider a stack switch to have happened? Default: 2000000 bytes */ |
| 277 | extern Int VG_(clo_max_stackframe); |
| 278 | |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 279 | /* Set up the libc freeres wrapper */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 280 | extern void VGA_(intercept_libc_freeres_wrapper)(Addr); |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 281 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 282 | // Clean up the client by calling before the final reports |
| 283 | extern void VGA_(final_tidyup)(ThreadId tid); |
| 284 | |
| 285 | // Arch-specific client requests |
| 286 | extern Bool VGA_(client_requests)(ThreadId tid, UWord *args); |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 287 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 288 | /* --------------------------------------------------------------------- |
nethercote | 85cdd34 | 2004-08-01 22:36:40 +0000 | [diff] [blame] | 289 | Profiling stuff |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 290 | ------------------------------------------------------------------ */ |
| 291 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 292 | extern void VG_(init_profiling) ( void ); |
| 293 | extern void VG_(done_profiling) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 294 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 295 | #undef VGP_PUSHCC |
| 296 | #undef VGP_POPCC |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 297 | #define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x) |
| 298 | #define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 299 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 300 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 301 | /* --------------------------------------------------------------------- |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 302 | Tool-related types |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 303 | ------------------------------------------------------------------ */ |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 304 | /* These structs are not exposed to tools to mitigate possibility of |
| 305 | binary-incompatibilities when the core/tool interface changes. Instead, |
nethercote | 4606320 | 2004-09-02 08:51:43 +0000 | [diff] [blame] | 306 | set functions are provided (see include/tool.h). */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 307 | typedef |
| 308 | struct { |
| 309 | Char* name; |
| 310 | Char* version; |
| 311 | Char* description; |
| 312 | Char* copyright_author; |
| 313 | Char* bug_reports_to; |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 314 | UInt avg_translation_sizeB; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 315 | } |
| 316 | VgDetails; |
| 317 | |
| 318 | extern VgDetails VG_(details); |
| 319 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 320 | typedef |
| 321 | struct { |
| 322 | Bool libc_freeres; |
| 323 | Bool core_errors; |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 324 | Bool tool_errors; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 325 | Bool basic_block_discards; |
njn | abb14ad | 2004-11-24 16:57:16 +0000 | [diff] [blame] | 326 | Bool no_longer_used_1; // for backwards compatibility |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 327 | Bool command_line_options; |
| 328 | Bool client_requests; |
njn | 37624a7 | 2004-11-22 20:37:42 +0000 | [diff] [blame] | 329 | Bool no_longer_used_0; // for backwards compatibility |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 330 | Bool syscall_wrapper; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 331 | Bool sanity_checks; |
| 332 | Bool data_syms; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 333 | Bool shadow_memory; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 334 | } |
| 335 | VgNeeds; |
| 336 | |
| 337 | extern VgNeeds VG_(needs); |
| 338 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 339 | typedef struct { |
| 340 | // --------------------------------------------- |
| 341 | // 'Needs' and related functions |
| 342 | // --------------------------------------------- |
| 343 | // Basic functions |
| 344 | void (*tool_pre_clo_init) (void); |
| 345 | void (*tool_post_clo_init)(void); |
| 346 | IRBB* (*tool_instrument) (IRBB*, VexGuestLayout*, IRType, IRType); |
| 347 | void (*tool_fini) (Int); |
| 348 | |
| 349 | // VG_(needs).core_errors |
| 350 | // (none) |
| 351 | |
| 352 | // VG_(needs).tool_errors |
| 353 | Bool (*tool_eq_Error) (VgRes, Error*, Error*); |
| 354 | void (*tool_pp_Error) (Error*); |
| 355 | UInt (*tool_update_extra) (Error*); |
| 356 | Bool (*tool_recognised_suppression) (Char*, Supp*); |
| 357 | Bool (*tool_read_extra_suppression_info) (Int, Char*, Int, Supp*); |
| 358 | Bool (*tool_error_matches_suppression) (Error*, Supp*); |
| 359 | Char* (*tool_get_error_name) (Error*); |
| 360 | void (*tool_print_extra_suppression_info)(Error*); |
| 361 | |
| 362 | // VG_(needs).basic_block_discards |
| 363 | void (*tool_discard_basic_block_info)(Addr, SizeT); |
| 364 | |
| 365 | // VG_(needs).command_line_options |
| 366 | Bool (*tool_process_cmd_line_option)(Char*); |
| 367 | void (*tool_print_usage) (void); |
| 368 | void (*tool_print_debug_usage) (void); |
| 369 | |
| 370 | // VG_(needs).client_requests |
| 371 | Bool (*tool_handle_client_request)(ThreadId, UWord*, UWord*); |
| 372 | |
| 373 | // VG_(needs).syscall_wrapper |
| 374 | void (*tool_pre_syscall) (ThreadId, UInt); |
| 375 | void (*tool_post_syscall)(ThreadId, UInt, Int); |
| 376 | |
| 377 | // VG_(needs).sanity_checks |
| 378 | Bool (*tool_cheap_sanity_check)(void); |
| 379 | Bool (*tool_expensive_sanity_check)(void); |
| 380 | |
| 381 | // --------------------------------------------- |
| 382 | // Event tracking functions |
| 383 | // --------------------------------------------- |
| 384 | void (*track_new_mem_startup) (Addr, SizeT, Bool, Bool, Bool); |
| 385 | void (*track_new_mem_stack_signal)(Addr, SizeT); |
| 386 | void (*track_new_mem_brk) (Addr, SizeT); |
| 387 | void (*track_new_mem_mmap) (Addr, SizeT, Bool, Bool, Bool); |
| 388 | |
| 389 | void (*track_copy_mem_remap) (Addr, Addr, SizeT); |
| 390 | void (*track_change_mem_mprotect) (Addr, SizeT, Bool, Bool, Bool); |
| 391 | void (*track_die_mem_stack_signal)(Addr, SizeT); |
| 392 | void (*track_die_mem_brk) (Addr, SizeT); |
| 393 | void (*track_die_mem_munmap) (Addr, SizeT); |
| 394 | |
| 395 | VGA_REGPARM(1) void (*track_new_mem_stack_4) (Addr); |
| 396 | VGA_REGPARM(1) void (*track_new_mem_stack_8) (Addr); |
| 397 | VGA_REGPARM(1) void (*track_new_mem_stack_12)(Addr); |
| 398 | VGA_REGPARM(1) void (*track_new_mem_stack_16)(Addr); |
| 399 | VGA_REGPARM(1) void (*track_new_mem_stack_32)(Addr); |
| 400 | void (*track_new_mem_stack)(Addr, SizeT); |
| 401 | |
| 402 | VGA_REGPARM(1) void (*track_die_mem_stack_4) (Addr); |
| 403 | VGA_REGPARM(1) void (*track_die_mem_stack_8) (Addr); |
| 404 | VGA_REGPARM(1) void (*track_die_mem_stack_12)(Addr); |
| 405 | VGA_REGPARM(1) void (*track_die_mem_stack_16)(Addr); |
| 406 | VGA_REGPARM(1) void (*track_die_mem_stack_32)(Addr); |
| 407 | void (*track_die_mem_stack)(Addr, SizeT); |
| 408 | |
| 409 | void (*track_ban_mem_stack)(Addr, SizeT); |
| 410 | |
| 411 | void (*track_pre_mem_read) (CorePart, ThreadId, Char*, Addr, SizeT); |
| 412 | void (*track_pre_mem_read_asciiz)(CorePart, ThreadId, Char*, Addr); |
| 413 | void (*track_pre_mem_write) (CorePart, ThreadId, Char*, Addr, SizeT); |
| 414 | void (*track_post_mem_write) (CorePart, ThreadId, Addr, SizeT); |
| 415 | |
| 416 | void (*track_pre_reg_read) (CorePart, ThreadId, Char*, OffT, SizeT); |
| 417 | void (*track_post_reg_write)(CorePart, ThreadId, OffT, SizeT); |
| 418 | void (*track_post_reg_write_clientcall_return)(ThreadId, OffT, SizeT, Addr); |
| 419 | |
| 420 | void (*track_thread_run)(ThreadId); |
| 421 | |
| 422 | void (*track_post_thread_create)(ThreadId, ThreadId); |
| 423 | void (*track_post_thread_join) (ThreadId, ThreadId); |
| 424 | |
| 425 | void (*track_pre_mutex_lock) (ThreadId, void*); |
| 426 | void (*track_post_mutex_lock) (ThreadId, void*); |
| 427 | void (*track_post_mutex_unlock)(ThreadId, void*); |
| 428 | |
| 429 | void (*track_pre_deliver_signal) (ThreadId, Int sigNo, Bool); |
| 430 | void (*track_post_deliver_signal)(ThreadId, Int sigNo); |
| 431 | |
| 432 | void (*track_init_shadow_page)(Addr); |
| 433 | |
| 434 | // --------------------------------------------- |
| 435 | // malloc/free replacements |
| 436 | // --------------------------------------------- |
| 437 | void* (*malloc_malloc) (ThreadId, SizeT); |
| 438 | void* (*malloc___builtin_new) (ThreadId, SizeT); |
| 439 | void* (*malloc___builtin_vec_new) (ThreadId, SizeT); |
| 440 | void* (*malloc_memalign) (ThreadId, SizeT, SizeT); |
| 441 | void* (*malloc_calloc) (ThreadId, SizeT, SizeT); |
| 442 | void (*malloc_free) (ThreadId, void*); |
| 443 | void (*malloc___builtin_delete) (ThreadId, void*); |
| 444 | void (*malloc___builtin_vec_delete)(ThreadId, void*); |
| 445 | void* (*malloc_realloc) (ThreadId, void*, SizeT); |
| 446 | |
| 447 | } VgToolInterface; |
| 448 | |
| 449 | extern VgToolInterface VG_(tdict); |
| 450 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 451 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 452 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 453 | /* --------------------------------------------------------------------- |
| 454 | Exports of vg_needs.c |
| 455 | ------------------------------------------------------------------ */ |
| 456 | |
| 457 | void VG_(sanity_check_needs)(void); |
| 458 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 459 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 460 | /* --------------------------------------------------------------------- |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 461 | Exports of vg_intercept.c |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 462 | ------------------------------------------------------------------ */ |
| 463 | |
| 464 | /* This doesn't export code or data that valgrind.so needs to link |
| 465 | against. However, the scheduler does need to know the following |
| 466 | request codes. A few, publically-visible, request codes are also |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 467 | defined in valgrind.h, and similar headers for some tools. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 468 | |
njn | d13e5e6 | 2005-03-26 03:50:14 +0000 | [diff] [blame] | 469 | /* Obsolete pthread-related requests */ |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 470 | #define VG_USERREQ__MALLOC 0x2001 |
| 471 | #define VG_USERREQ__FREE 0x2002 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 472 | #define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 473 | #define VG_USERREQ__QUIT 0x3002 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 474 | #define VG_USERREQ__WAIT_JOINER 0x3003 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 475 | #define VG_USERREQ__PTHREAD_JOIN 0x3004 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 476 | #define VG_USERREQ__SET_CANCELSTATE 0x3005 |
| 477 | #define VG_USERREQ__SET_CANCELTYPE 0x3006 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 478 | #define VG_USERREQ__TESTCANCEL 0x3007 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 479 | #define VG_USERREQ__SET_CANCELPEND 0x3008 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 480 | #define VG_USERREQ__SET_OR_GET_DETACH 0x3009 |
thughes | e321d49 | 2004-10-17 15:00:20 +0000 | [diff] [blame] | 481 | #define VG_USERREQ__PTHREAD_GET_THREADID 0x300A |
| 482 | #define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300B |
| 483 | #define VG_USERREQ__PTHREAD_MUTEX_TIMEDLOCK 0x300C |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 484 | #define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D |
| 485 | #define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E |
| 486 | #define VG_USERREQ__PTHREAD_COND_WAIT 0x300F |
| 487 | #define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010 |
| 488 | #define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011 |
| 489 | #define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012 |
| 490 | #define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013 |
| 491 | #define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014 |
sewardj | 00a66b1 | 2002-10-12 16:42:35 +0000 | [diff] [blame] | 492 | #define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015 |
| 493 | #define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016 |
njn | d13e5e6 | 2005-03-26 03:50:14 +0000 | [diff] [blame] | 494 | #define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 495 | #define VG_USERREQ__PTHREAD_SIGMASK 0x3018 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 496 | #define VG_USERREQ__SIGWAIT 0x3019 |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 497 | #define VG_USERREQ__PTHREAD_KILL 0x301A |
| 498 | #define VG_USERREQ__PTHREAD_YIELD 0x301B |
sewardj | 00a66b1 | 2002-10-12 16:42:35 +0000 | [diff] [blame] | 499 | #define VG_USERREQ__PTHREAD_KEY_VALIDATE 0x301C |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 500 | #define VG_USERREQ__CLEANUP_PUSH 0x3020 |
| 501 | #define VG_USERREQ__CLEANUP_POP 0x3021 |
sewardj | 870497a | 2002-05-29 01:06:47 +0000 | [diff] [blame] | 502 | #define VG_USERREQ__GET_KEY_D_AND_S 0x3022 |
sewardj | ef037c7 | 2002-05-30 00:40:03 +0000 | [diff] [blame] | 503 | #define VG_USERREQ__NUKE_OTHER_THREADS 0x3023 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 504 | #define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024 |
sewardj | 2cb0034 | 2002-06-28 01:46:26 +0000 | [diff] [blame] | 505 | #define VG_USERREQ__SET_FHSTACK_USED 0x3025 |
| 506 | #define VG_USERREQ__GET_FHSTACK_USED 0x3026 |
| 507 | #define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027 |
| 508 | #define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028 |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 509 | #define VG_USERREQ__GET_SIGRT_MIN 0x302B |
| 510 | #define VG_USERREQ__GET_SIGRT_MAX 0x302C |
| 511 | #define VG_USERREQ__ALLOC_RTSIG 0x302D |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 512 | #define VG_USERREQ__GET_MALLOCFUNCS 0x3030 |
thughes | daa3456 | 2004-06-27 12:48:53 +0000 | [diff] [blame] | 513 | #define VG_USERREQ__GET_STACK_INFO 0x3033 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 514 | #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101 |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 515 | #define VG_USERREQ__PTHREAD_ERROR 0x3102 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 516 | |
| 517 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 518 | /* Internal equivalent of VALGRIND_PRINTF . */ |
| 519 | #define VG_USERREQ__INTERNAL_PRINTF 0x3103 |
njn | aa3c26b | 2005-03-12 05:32:28 +0000 | [diff] [blame] | 520 | /* Internal equivalent of VALGRIND_PRINTF_BACKTRACE . (no longer used) */ |
| 521 | //#define VG_USERREQ__INTERNAL_PRINTF_BACKTRACE 0x3104 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 522 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 523 | /* Denote the finish of __libc_freeres_wrapper(). |
| 524 | A synonym for exit. */ |
| 525 | #define VG_USERREQ__LIBC_FREERES_DONE 0x3029 |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 526 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame^] | 527 | /* Intercept prefix stuff. See |
| 528 | coregrind/m_replace_malloc/vg_replace_malloc.c for details. |
| 529 | Unfortunately the "_vgi_" literal is also hardcoded in that file, so if |
| 530 | you change this one you must also change the other one. */ |
sewardj | 9ee81f5 | 2005-04-02 17:38:59 +0000 | [diff] [blame] | 531 | #define VG_INTERCEPT_PREFIX "_vgi_" |
| 532 | #define VG_INTERCEPT_PREFIX_LEN 5 |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 533 | |
sewardj | 9ee81f5 | 2005-04-02 17:38:59 +0000 | [diff] [blame] | 534 | /* Not sure what these are for. Todo: clarify */ |
| 535 | #define VG_WRAPPER_PREFIX "_vgw_" |
| 536 | #define VG_WRAPPER_PREFIX_LEN 5 |
| 537 | #define VG_WRAPPER(name) _vgw_##name |
| 538 | #define VG_WRAPPER_ALIAS(name) "_vgw_" #name |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 539 | |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 540 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 541 | struct vg_mallocfunc_info { |
| 542 | /* things vg_replace_malloc.o needs to know about */ |
njn | cf81d55 | 2005-03-31 04:52:26 +0000 | [diff] [blame] | 543 | void* (*tl_malloc) (ThreadId tid, SizeT n); |
| 544 | void* (*tl___builtin_new) (ThreadId tid, SizeT n); |
| 545 | void* (*tl___builtin_vec_new) (ThreadId tid, SizeT n); |
| 546 | void* (*tl_memalign) (ThreadId tid, SizeT align, SizeT n); |
| 547 | void* (*tl_calloc) (ThreadId tid, SizeT nmemb, SizeT n); |
| 548 | void (*tl_free) (ThreadId tid, void* p); |
| 549 | void (*tl___builtin_delete) (ThreadId tid, void* p); |
| 550 | void (*tl___builtin_vec_delete)(ThreadId tid, void* p); |
| 551 | void* (*tl_realloc) (ThreadId tid, void* p, SizeT size); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 552 | |
njn | cf81d55 | 2005-03-31 04:52:26 +0000 | [diff] [blame] | 553 | SizeT (*arena_payload_szB) (ArenaId aid, void* payload); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 554 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 555 | Bool clo_trace_malloc; |
| 556 | }; |
sewardj | 1fe7b00 | 2002-07-16 01:43:15 +0000 | [diff] [blame] | 557 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 558 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 559 | /* --------------------------------------------------------------------- |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 560 | Exports of vg_scheduler.c |
| 561 | ------------------------------------------------------------------ */ |
| 562 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 563 | /* |
| 564 | Thread state machine: |
| 565 | |
| 566 | Empty -> Init -> Runnable <=> WaitSys/Yielding |
| 567 | ^ | |
| 568 | \---- Zombie -----/ |
| 569 | */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 570 | typedef |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 571 | enum ThreadStatus { |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 572 | VgTs_Empty, /* this slot is not in use */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 573 | VgTs_Init, /* just allocated */ |
| 574 | VgTs_Runnable, /* ready to run */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 575 | VgTs_WaitSys, /* waiting for a syscall to complete */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 576 | VgTs_Yielding, /* temporarily yielding the CPU */ |
| 577 | VgTs_Zombie, /* transient state just before exiting */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 578 | } |
| 579 | ThreadStatus; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 580 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 581 | /* Return codes from the scheduler. */ |
thughes | 11975ff | 2004-06-12 12:58:22 +0000 | [diff] [blame] | 582 | typedef |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 583 | enum { |
| 584 | VgSrc_None, /* not exiting yet */ |
| 585 | VgSrc_ExitSyscall, /* client called exit(). This is the normal |
| 586 | route out. */ |
| 587 | VgSrc_FatalSig /* Killed by the default action of a fatal |
| 588 | signal */ |
thughes | 11975ff | 2004-06-12 12:58:22 +0000 | [diff] [blame] | 589 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 590 | VgSchedReturnCode; |
thughes | 11975ff | 2004-06-12 12:58:22 +0000 | [diff] [blame] | 591 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 592 | struct _ThreadState { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 593 | /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED. |
| 594 | The thread identity is simply the index in vg_threads[]. |
| 595 | ThreadId == 1 is the root thread and has the special property |
| 596 | that we don't try and allocate or deallocate its stack. For |
| 597 | convenience of generating error message, we also put the |
| 598 | ThreadId in this tid field, but be aware that it should |
| 599 | ALWAYS == the index in vg_threads[]. */ |
| 600 | ThreadId tid; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 601 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 602 | /* Current scheduling status. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 603 | ThreadStatus status; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 604 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 605 | /* This is set if the thread is in the process of exiting for any |
| 606 | reason. The precise details of the exit are in the OS-specific |
| 607 | state. */ |
| 608 | VgSchedReturnCode exitreason; |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 609 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 610 | /* Architecture-specific thread state. */ |
| 611 | ThreadArchState arch; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 612 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 613 | /* This thread's blocked-signals mask. Semantics is that for a |
| 614 | signal to be delivered to this thread, the signal must not be |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 615 | blocked by this signal mask. If more than one thread accepts a |
| 616 | signal, then it will be delivered to one at random. If all |
| 617 | threads block the signal, it will remain pending until either a |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 618 | thread unblocks it or someone uses sigwaitsig/sigtimedwait. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 619 | vki_sigset_t sig_mask; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 620 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 621 | /* tmp_sig_mask is usually the same as sig_mask, and is kept in |
| 622 | sync whenever sig_mask is changed. The only time they have |
| 623 | different values is during the execution of a sigsuspend, where |
| 624 | tmp_sig_mask is the temporary mask which sigsuspend installs. |
| 625 | It is only consulted to compute the signal mask applied to a |
| 626 | signal handler. */ |
| 627 | vki_sigset_t tmp_sig_mask; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 628 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 629 | /* A little signal queue for signals we can't get the kernel to |
| 630 | queue for us. This is only allocated as needed, since it should |
| 631 | be rare. */ |
| 632 | struct SigQueue *sig_queue; |
| 633 | |
| 634 | /* Syscall the Thread is currently running; -1 if none. Should only |
| 635 | be set while Thread is in VgTs_WaitSys. */ |
| 636 | Int syscallno; |
| 637 | |
| 638 | /* A value the Tool wants to pass from its pre-syscall to its |
| 639 | post-syscall function. */ |
| 640 | void *tool_pre_syscall_value; |
thughes | 8abf392 | 2004-10-16 10:59:49 +0000 | [diff] [blame] | 641 | |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 642 | /* Client stacks. When a thread slot is freed, we don't deallocate its |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 643 | stack; we just leave it lying around for the next use of the |
| 644 | slot. If the next use of the slot requires a larger stack, |
| 645 | only then is the old one deallocated and a new one |
| 646 | allocated. |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 647 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 648 | For the main thread (threadid == 0), this mechanism doesn't |
| 649 | apply. We don't know the size of the stack since we didn't |
| 650 | allocate it, and furthermore we never reallocate it. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 651 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 652 | /* The allocated size of this thread's stack (permanently zero |
| 653 | if this is ThreadId == 0, since we didn't allocate its stack) */ |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 654 | SizeT client_stack_szB; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 655 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 656 | /* Address of the highest legitimate word in this stack. This is |
| 657 | used for error messages only -- not critical for execution |
| 658 | correctness. Is is set for all stacks, specifically including |
| 659 | ThreadId == 0 (the main thread). */ |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 660 | Addr client_stack_highest_word; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 661 | |
fitzhardinge | 98c4dc0 | 2004-03-16 08:27:29 +0000 | [diff] [blame] | 662 | /* Alternate signal stack */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 663 | vki_stack_t altstack; |
fitzhardinge | 98c4dc0 | 2004-03-16 08:27:29 +0000 | [diff] [blame] | 664 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 665 | /* OS-specific thread state */ |
| 666 | os_thread_t os_state; |
sewardj | 004e8ca | 2005-02-28 17:27:04 +0000 | [diff] [blame] | 667 | |
| 668 | /* Used in the syscall handlers. Set to True to indicate that the |
| 669 | PRE routine for a syscall has set the syscall result already and |
| 670 | so the syscall does not need to be handed to the kernel. */ |
| 671 | Bool syscall_result_set; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 672 | |
| 673 | /* Per-thread jmp_buf to resume scheduler after a signal */ |
| 674 | Bool sched_jmpbuf_valid; |
| 675 | jmp_buf sched_jmpbuf; |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 676 | }; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 677 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 678 | /* The thread table. */ |
| 679 | extern ThreadState VG_(threads)[VG_N_THREADS]; |
| 680 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 681 | /* Allocate a new ThreadState */ |
| 682 | extern ThreadId VG_(alloc_ThreadState)(void); |
| 683 | |
| 684 | /* A thread exits. tid must currently be running. */ |
| 685 | extern void VG_(exit_thread)(ThreadId tid); |
| 686 | |
| 687 | /* Kill a thread. This interrupts whatever a thread is doing, and |
| 688 | makes it exit ASAP. This does not set the exitreason or |
| 689 | exitcode. */ |
| 690 | extern void VG_(kill_thread)(ThreadId tid); |
| 691 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 692 | /* Check that tid is in range and denotes a non-Empty thread. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 693 | extern Bool VG_(is_valid_tid) ( ThreadId tid ); |
| 694 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 695 | /* Get the ThreadState for a particular thread */ |
| 696 | extern ThreadState *VG_(get_ThreadState)(ThreadId tid); |
| 697 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 698 | /* Given an LWP id (ie, real kernel thread id), find the corresponding |
| 699 | ThreadId */ |
| 700 | extern ThreadId VG_(get_lwp_tid)(Int lwpid); |
| 701 | |
| 702 | /* Returns true if a thread is currently running (ie, has the CPU lock) */ |
| 703 | extern Bool VG_(is_running_thread)(ThreadId tid); |
| 704 | |
| 705 | /* Returns true if the thread is in the process of exiting */ |
| 706 | extern Bool VG_(is_exiting)(ThreadId tid); |
| 707 | |
| 708 | /* Return the number of non-dead Threads */ |
| 709 | extern Int VG_(count_living_threads)(void); |
| 710 | |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 711 | /* Nuke all threads except tid. */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 712 | extern void VG_(nuke_all_threads_except) ( ThreadId me, VgSchedReturnCode reason ); |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 713 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 714 | /* Make a thread the running thread. The thread must previously been |
| 715 | sleeping, and not holding the CPU semaphore. This will set the |
| 716 | thread state to VgTs_Runnable, and the thread will attempt to take |
| 717 | the CPU semaphore. By the time it returns, tid will be the running |
| 718 | thread. */ |
| 719 | extern void VG_(set_running) ( ThreadId tid ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 720 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 721 | /* Set a thread into a sleeping state. Before the call, the thread |
| 722 | must be runnable, and holding the CPU semaphore. When this call |
| 723 | returns, the thread will be set to the specified sleeping state, |
| 724 | and will not be holding the CPU semaphore. Note that another |
| 725 | thread could be running by the time this call returns, so the |
| 726 | caller must be careful not to touch any shared state. It is also |
| 727 | the caller's responsibility to actually block until the thread is |
| 728 | ready to run again. */ |
| 729 | extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 730 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 731 | /* Yield the CPU for a while */ |
| 732 | extern void VG_(vg_yield)(void); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 733 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 734 | // The scheduler. |
| 735 | extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid ); |
| 736 | |
| 737 | // Do everything which needs doing before the process finally ends, |
| 738 | // like printing reports, etc |
| 739 | extern void VG_(shutdown_actions)(ThreadId tid); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 740 | |
| 741 | extern void VG_(scheduler_init) ( void ); |
| 742 | |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 743 | extern void VG_(pp_sched_status) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 744 | |
nethercote | 75d2624 | 2004-08-01 22:59:18 +0000 | [diff] [blame] | 745 | // Longjmp back to the scheduler and thus enter the sighandler immediately. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 746 | extern void VG_(resume_scheduler) ( ThreadId tid ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 747 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 748 | /* If true, a fault is Valgrind-internal (ie, a bug) */ |
| 749 | extern Bool VG_(my_fault); |
nethercote | 238a3c3 | 2004-08-09 13:13:31 +0000 | [diff] [blame] | 750 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 751 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 752 | Exports of vg_signals.c |
| 753 | ------------------------------------------------------------------ */ |
| 754 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 755 | /* Set the standard set of blocked signals, used wheneever we're not |
| 756 | running a client syscall. */ |
| 757 | extern void VG_(block_signals)(ThreadId tid); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 758 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 759 | /* Highest signal the kernel will let us use */ |
| 760 | extern Int VG_(max_signal); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 761 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 762 | extern void VG_(sigstartup_actions) ( void ); |
| 763 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 764 | extern Bool VG_(is_sig_ign) ( Int sigNo ); |
| 765 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 766 | /* Poll a thread's set of pending signals, and update the Thread's context to deliver one */ |
| 767 | extern void VG_(poll_signals) ( ThreadId ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 768 | |
| 769 | /* Fake system calls for signal handling. */ |
njn | 502badb | 2005-05-08 02:04:49 +0000 | [diff] [blame] | 770 | extern Int VG_(do_sys_sigaltstack) ( ThreadId tid, vki_stack_t* ss, |
| 771 | vki_stack_t* oss ); |
| 772 | extern Int VG_(do_sys_sigaction) ( Int signo, |
| 773 | const struct vki_sigaction *new_act, |
| 774 | struct vki_sigaction *old_act ); |
| 775 | extern Int VG_(do_sys_sigprocmask) ( ThreadId tid, Int how, |
| 776 | vki_sigset_t* set, |
| 777 | vki_sigset_t* oldset ); |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 778 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 779 | /* Handy utilities to block/restore all host signals. */ |
| 780 | extern void VG_(block_all_host_signals) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 781 | ( /* OUT */ vki_sigset_t* saved_mask ); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 782 | extern void VG_(restore_all_host_signals) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 783 | ( /* IN */ vki_sigset_t* saved_mask ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 784 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 785 | extern void VG_(kill_self)(Int sigNo); |
| 786 | |
fitzhardinge | f1beb25 | 2004-03-16 09:49:08 +0000 | [diff] [blame] | 787 | /* These function synthesize a fault, as if the running instruction |
| 788 | had had a fault. These functions do not return - they longjmp back |
| 789 | into the scheduler so the signal can be delivered. */ |
| 790 | extern void VG_(synth_fault) (ThreadId tid); |
| 791 | extern void VG_(synth_fault_mapping)(ThreadId tid, Addr addr); |
| 792 | extern void VG_(synth_fault_perms) (ThreadId tid, Addr addr); |
sewardj | 5e2f001 | 2004-12-13 14:10:34 +0000 | [diff] [blame] | 793 | extern void VG_(synth_sigill) (ThreadId tid, Addr addr); |
fitzhardinge | f1beb25 | 2004-03-16 09:49:08 +0000 | [diff] [blame] | 794 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 795 | /* Extend the stack to cover addr, if possible */ |
| 796 | extern Bool VG_(extend_stack)(Addr addr, UInt maxsize); |
| 797 | |
| 798 | /* Returns True if the signal is OK for the client to use */ |
| 799 | extern Bool VG_(client_signal_OK)(Int sigNo); |
| 800 | |
| 801 | /* Forces the client's signal handler to SIG_DFL - generally just |
| 802 | before using that signal to kill the process. */ |
| 803 | extern void VG_(set_default_handler)(Int sig); |
| 804 | |
| 805 | /* Adjust a client's signal mask to match our internal requirements */ |
| 806 | extern void VG_(sanitize_client_sigmask)(ThreadId tid, vki_sigset_t *mask); |
| 807 | |
| 808 | /* Wait until a thread-related predicate is true */ |
| 809 | extern void VG_(wait_for_threadstate)(Bool (*pred)(void *), void *arg); |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 810 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 811 | /* --------------------------------------------------------------------- |
| 812 | Exports of vg_mylibc.c |
| 813 | ------------------------------------------------------------------ */ |
| 814 | |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 815 | // Useful for making failing stubs, when certain things haven't yet been |
| 816 | // implemented. |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 817 | #define I_die_here \ |
| 818 | VG_(assert_fail) ("Unimplemented functionality", \ |
| 819 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 820 | "valgrind", VG_BUGS_TO, "") |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 821 | |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 822 | #define vg_assert(expr) \ |
| 823 | ((void) ((expr) ? 0 : \ |
| 824 | (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \ |
| 825 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 826 | ""), \ |
| 827 | 0))) |
| 828 | |
| 829 | #define vg_assert2(expr, format, args...) \ |
| 830 | ((void) ((expr) ? 0 : \ |
| 831 | (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \ |
| 832 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 833 | format, ##args), \ |
| 834 | 0))) |
| 835 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 836 | __attribute__ ((__noreturn__)) |
| 837 | extern void VG_(core_panic) ( Char* str ); |
thughes | 5876d55 | 2004-09-26 18:44:06 +0000 | [diff] [blame] | 838 | __attribute__ ((__noreturn__)) |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 839 | extern void VG_(core_panic_at) ( Char* str, StackTrace ips ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 840 | |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 841 | /* Tools use VG_(strdup)() which doesn't expose ArenaId */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 842 | extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 843 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 844 | extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 845 | extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 846 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 847 | /* system/mman.h */ |
nethercote | 8b5f40c | 2004-11-02 13:29:50 +0000 | [diff] [blame] | 848 | extern void* VG_(mmap)( void* start, SizeT length, UInt prot, UInt flags, |
nethercote | 5b9fafd | 2004-11-04 18:39:22 +0000 | [diff] [blame] | 849 | UInt sf_flags, UInt fd, OffT offset ); |
nethercote | 8b5f40c | 2004-11-02 13:29:50 +0000 | [diff] [blame] | 850 | extern Int VG_(munmap)( void* start, SizeT length ); |
| 851 | extern Int VG_(mprotect)( void *start, SizeT length, UInt prot ); |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 852 | extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 853 | |
| 854 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 855 | /* Move an fd into the Valgrind-safe range */ |
| 856 | Int VG_(safe_fd)(Int oldfd); |
| 857 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 858 | extern Int VG_(write_socket)( Int sd, void *msg, Int count ); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 859 | |
| 860 | /* --- Connecting over the network --- */ |
| 861 | extern Int VG_(connect_via_socket)( UChar* str ); |
| 862 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 863 | /* Environment manipulations */ |
nethercote | 60a96c5 | 2004-08-03 13:08:31 +0000 | [diff] [blame] | 864 | extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname, |
| 865 | const Char *val ); |
| 866 | extern void VG_(env_unsetenv) ( Char **env, const Char *varname ); |
| 867 | extern void VG_(env_remove_valgrind_env_stuff) ( Char** env ); |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 868 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 869 | extern void VG_(nanosleep)(struct vki_timespec *); |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 870 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 871 | /* --------------------------------------------------------------------- |
| 872 | Exports of vg_message.c |
| 873 | ------------------------------------------------------------------ */ |
| 874 | |
| 875 | /* Low-level -- send bytes directly to the message sink. Do not |
| 876 | use. */ |
| 877 | extern void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes ); |
| 878 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 879 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 880 | Exports of vg_demangle.c |
| 881 | ------------------------------------------------------------------ */ |
| 882 | |
| 883 | extern void VG_(demangle) ( Char* orig, Char* result, Int result_size ); |
| 884 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 885 | extern void VG_(reloc_abs_jump) ( UChar *jmp ); |
sewardj | 4ccf707 | 2004-11-28 16:58:05 +0000 | [diff] [blame] | 886 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 887 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 888 | Exports of vg_translate.c |
| 889 | ------------------------------------------------------------------ */ |
| 890 | |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 891 | extern |
| 892 | Bool VG_(translate) ( ThreadId tid, |
| 893 | Addr64 orig_addr, |
| 894 | Bool debugging_translation, |
| 895 | Int debugging_verbosity ); |
sewardj | b5ff83e | 2002-12-01 19:40:49 +0000 | [diff] [blame] | 896 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 897 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 898 | Exports of vg_symtab2.c |
| 899 | ------------------------------------------------------------------ */ |
| 900 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 901 | typedef struct _Segment Segment; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 902 | typedef struct _CodeRedirect CodeRedirect; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 903 | |
| 904 | extern Bool VG_(is_object_file) ( const void *hdr ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 905 | extern SegInfo * VG_(read_seg_symbols) ( Segment *seg ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 906 | extern void VG_(symtab_incref) ( SegInfo * ); |
nethercote | 8991d5a | 2004-11-03 17:07:46 +0000 | [diff] [blame] | 907 | extern void VG_(symtab_decref) ( SegInfo *, Addr a ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 908 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 909 | extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname ); |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 910 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 911 | extern Addr VG_(reverse_search_one_symtab) ( const SegInfo* si, const Char* name ); |
| 912 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 913 | /* Set up some default redirects */ |
| 914 | extern void VG_(setup_code_redirect_table) ( void ); |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 915 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 916 | extern Bool VG_(resolve_redir_allsegs)(CodeRedirect *redir); |
| 917 | |
sewardj | 3516553 | 2005-04-30 18:47:48 +0000 | [diff] [blame] | 918 | extern Bool VG_(use_CFI_info) ( /*MOD*/Addr* ipP, |
| 919 | /*MOD*/Addr* spP, |
| 920 | /*MOD*/Addr* fpP, |
| 921 | Addr min_accessible, |
| 922 | Addr max_accessible ); |
| 923 | |
| 924 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 925 | /* --------------------------------------------------------------------- |
| 926 | Exports of vg_redir.c |
| 927 | ------------------------------------------------------------------ */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 928 | /* Redirection machinery */ |
nethercote | 85cdd34 | 2004-08-01 22:36:40 +0000 | [diff] [blame] | 929 | extern Addr VG_(code_redirect) ( Addr orig ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 930 | |
tom | 748a131 | 2005-04-02 15:53:01 +0000 | [diff] [blame] | 931 | extern void VG_(add_redirect_sym_to_addr)(const Char *from_lib, |
| 932 | const Char *from_sym, |
| 933 | Addr to_addr); |
| 934 | extern void VG_(add_redirect_addr_to_addr)(Addr from_addr, Addr to_addr); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 935 | extern void VG_(resolve_seg_redirs)(SegInfo *si); |
| 936 | extern Bool VG_(resolve_redir)(CodeRedirect *redir, const SegInfo *si); |
| 937 | |
| 938 | /* Wrapping machinery */ |
| 939 | enum return_type { |
| 940 | RT_RETURN, |
| 941 | RT_LONGJMP, |
| 942 | RT_EXIT, |
| 943 | }; |
| 944 | |
| 945 | typedef struct _FuncWrapper FuncWrapper; |
| 946 | struct _FuncWrapper { |
| 947 | void *(*before)(va_list args); |
| 948 | void (*after) (void *nonce, enum return_type, Word retval); |
| 949 | }; |
| 950 | |
| 951 | extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper); |
| 952 | extern const FuncWrapper *VG_(is_wrapped)(Addr eip); |
| 953 | extern Bool VG_(is_wrapper_return)(Addr eip); |
| 954 | |
| 955 | /* Primary interface for adding wrappers for client-side functions. */ |
| 956 | extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym, |
| 957 | const FuncWrapper *wrapper); |
| 958 | |
| 959 | extern Bool VG_(is_resolved)(const CodeRedirect *redir); |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 960 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 961 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 962 | Exports of vg_main.c |
| 963 | ------------------------------------------------------------------ */ |
| 964 | |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 965 | /* Tell the logging mechanism whether we are logging to a file |
| 966 | descriptor or a socket descriptor. */ |
| 967 | extern Bool VG_(logging_to_filedes); |
| 968 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 969 | /* Sanity checks which may be done at any time. The scheduler decides when. */ |
nethercote | 885dd91 | 2004-08-03 23:14:00 +0000 | [diff] [blame] | 970 | extern void VG_(sanity_check_general) ( Bool force_expensive ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 971 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 972 | /* Address space */ |
| 973 | extern Addr VG_(client_base); /* client address space limits */ |
| 974 | extern Addr VG_(client_end); |
| 975 | extern Addr VG_(client_mapbase); /* base of mappings */ |
| 976 | extern Addr VG_(clstk_base); /* client stack range */ |
| 977 | extern Addr VG_(clstk_end); |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 978 | extern Addr VG_(client_trampoline_code); |
| 979 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 980 | extern Addr VG_(brk_base); /* start of brk */ |
| 981 | extern Addr VG_(brk_limit); /* current brk */ |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 982 | extern Addr VG_(shadow_base); /* tool's shadow memory */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 983 | extern Addr VG_(shadow_end); |
| 984 | extern Addr VG_(valgrind_base); /* valgrind's address range */ |
nethercote | 820bd8c | 2004-09-07 23:04:49 +0000 | [diff] [blame] | 985 | extern Addr VG_(valgrind_last); // Nb: last byte, rather than one past the end |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 986 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 987 | extern struct vki_rlimit VG_(client_rlimit_data); /* client's original rlimit data */ |
| 988 | extern struct vki_rlimit VG_(client_rlimit_stack); /* client's original rlimit stack */ |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 989 | |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 990 | /* client executable file descriptor */ |
| 991 | extern Int VG_(clexecfd); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 992 | |
nethercote | f6a1d50 | 2004-08-09 12:21:57 +0000 | [diff] [blame] | 993 | // Help set up the child used when doing execve() with --trace-children=yes |
| 994 | Char* VG_(build_child_VALGRINDCLO) ( Char* exename ); |
| 995 | Char* VG_(build_child_exename) ( void ); |
| 996 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 997 | /* The master thread the one which will be responsible for mopping |
| 998 | everything up at exit. Normally it is tid 1, since that's the |
| 999 | first thread created, but it may be something else after a |
| 1000 | fork(). */ |
| 1001 | extern ThreadId VG_(master_tid); |
| 1002 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1003 | /* Called when some unhandleable client behaviour is detected. |
| 1004 | Prints a msg and aborts. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1005 | extern void VG_(unimplemented) ( Char* msg ) |
| 1006 | __attribute__((__noreturn__)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1007 | |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 1008 | /* Something of a function looking for a home ... start up debugger. */ |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1009 | extern void VG_(start_debugger) ( ThreadId tid ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1010 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1011 | /* Counts downwards in vg_run_innerloop. */ |
| 1012 | extern UInt VG_(dispatch_ctr); |
| 1013 | |
sewardj | 4ccf707 | 2004-11-28 16:58:05 +0000 | [diff] [blame] | 1014 | /* Stats ... */ |
nethercote | 844e712 | 2004-08-02 15:27:22 +0000 | [diff] [blame] | 1015 | extern void VG_(print_scheduler_stats) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1016 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 1017 | /* Indicates what arch and subarch we are running on. */ |
| 1018 | extern VexArch VG_(vex_arch); |
| 1019 | extern VexSubArch VG_(vex_subarch); |
| 1020 | |
njn | 1f70772 | 2005-03-27 03:17:52 +0000 | [diff] [blame] | 1021 | /* 64-bit counter for the number of basic blocks done. */ |
| 1022 | extern ULong VG_(bbs_done); |
| 1023 | |
nethercote | 2e05c33 | 2004-09-06 16:43:37 +0000 | [diff] [blame] | 1024 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1025 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1026 | Exports of vg_transtab.c |
| 1027 | ------------------------------------------------------------------ */ |
| 1028 | |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 1029 | /* The fast-cache for tt-lookup, and for finding counters. */ |
| 1030 | extern ULong* VG_(tt_fast) [VG_TT_FAST_SIZE]; |
| 1031 | extern UInt* VG_(tt_fastN)[VG_TT_FAST_SIZE]; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1032 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1033 | |
nethercote | 92e7b7f | 2004-08-07 17:52:25 +0000 | [diff] [blame] | 1034 | extern void VG_(init_tt_tc) ( void ); |
sewardj | 6c3769f | 2002-11-29 01:02:45 +0000 | [diff] [blame] | 1035 | |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 1036 | extern |
| 1037 | void VG_(add_to_trans_tab)( VexGuestExtents* vge, |
| 1038 | Addr64 entry, |
| 1039 | AddrH code, |
| 1040 | UInt code_len ); |
| 1041 | |
| 1042 | extern Bool VG_(search_transtab) ( /*OUT*/AddrH* result, |
| 1043 | Addr64 guest_addr, |
| 1044 | Bool upd_cache ); |
| 1045 | |
| 1046 | extern void VG_(discard_translations) ( Addr64 start, UInt range ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1047 | |
sewardj | 4ccf707 | 2004-11-28 16:58:05 +0000 | [diff] [blame] | 1048 | extern void VG_(sanity_check_tt_tc) ( Char* caller ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1049 | |
nethercote | 92e7b7f | 2004-08-07 17:52:25 +0000 | [diff] [blame] | 1050 | extern void VG_(print_tt_tc_stats) ( void ); |
| 1051 | |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 1052 | extern UInt VG_(get_bbs_translated) ( void ); |
| 1053 | |
| 1054 | extern void VG_(show_BB_profile) ( void ); |
| 1055 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1056 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1057 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1058 | Exports of vg_syscall.S |
| 1059 | ------------------------------------------------------------------ */ |
| 1060 | |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 1061 | // We use a full prototype rather than "..." here to ensure that all |
| 1062 | // arguments get converted to a UWord appropriately. Not doing so can |
| 1063 | // cause problems when passing 32-bit integers on 64-bit platforms, because |
| 1064 | // the top 32-bits might not be zeroed appropriately, eg. as would happen |
| 1065 | // with the 6th arg on AMD64 which is passed on the stack. |
njn | f4aeaea | 2004-11-29 17:33:31 +0000 | [diff] [blame] | 1066 | extern Word VG_(do_syscall) ( UInt, UWord, UWord, UWord, UWord, UWord, UWord ); |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 1067 | |
| 1068 | // Macros make life easier. |
| 1069 | #define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0,0) |
| 1070 | #define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),0,0,0,0,0) |
| 1071 | #define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),0,0,0,0) |
| 1072 | #define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(c),0,0,0) |
| 1073 | #define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),(c),(d),0,0) |
| 1074 | #define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),(c),(d),(e),0) |
| 1075 | #define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),(c),(d),(e),(f)) |
| 1076 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1077 | extern Int VG_(clone) ( Int (*fn)(void *), void *stack, Int flags, void *arg, |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1078 | Int *child_tid, Int *parent_tid, vki_modify_ldt_t * ); |
fitzhardinge | 4f10ada | 2004-06-03 10:00:42 +0000 | [diff] [blame] | 1079 | extern void VG_(sigreturn)(void); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1080 | |
| 1081 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1082 | Exports of vg_dispatch.S |
| 1083 | ------------------------------------------------------------------ */ |
| 1084 | |
njn | d6f157d | 2004-11-30 17:27:21 +0000 | [diff] [blame] | 1085 | /* This subroutine is called from the C world. It is passed |
| 1086 | a pointer to the VEX guest state (arch.vex). It must run code |
| 1087 | from the instruction pointer in the guest state, and exit when |
| 1088 | VG_(dispatch_ctr) reaches zero, or we need to defer to the scheduler. |
| 1089 | The return value must indicate why it returned back to the scheduler. |
| 1090 | It can also be exited if the executing code throws a non-resumable |
| 1091 | signal, for example SIGSEGV, in which case control longjmp()s back past |
| 1092 | here. |
| 1093 | |
| 1094 | This code simply handles the common case fast -- when the translation |
| 1095 | address is found in the translation cache. For anything else, the |
| 1096 | scheduler does the work. |
| 1097 | */ |
sewardj | 0312f51 | 2005-03-30 19:04:29 +0000 | [diff] [blame] | 1098 | extern UWord VG_(run_innerloop) ( void* guest_state ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1099 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1100 | /* --------------------------------------------------------------------- |
| 1101 | Exports of vg_helpers.S |
| 1102 | ------------------------------------------------------------------ */ |
| 1103 | |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 1104 | /* Information about trampoline code (for signal return and syscalls) */ |
| 1105 | extern const Char VG_(trampoline_code_start); |
| 1106 | extern const Int VG_(trampoline_code_length); |
| 1107 | extern const Int VG_(tramp_sigreturn_offset); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1108 | extern const Int VG_(tramp_rt_sigreturn_offset); |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 1109 | extern const Int VG_(tramp_syscall_offset); |
tom | ee0bcbf | 2005-05-02 10:28:42 +0000 | [diff] [blame] | 1110 | extern const Int VG_(tramp_gettimeofday_offset); |
| 1111 | extern const Int VG_(tramp_time_offset); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 1112 | |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1113 | /* --------------------------------------------------------------------- |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 1114 | Things relating to the used tool |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1115 | ------------------------------------------------------------------ */ |
| 1116 | |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1117 | // Note the use of C's comma operator here -- it means that we execute both |
| 1118 | // statements, and the rvalue of the whole thing is the rvalue of the last |
| 1119 | // statement. This lets us say "x = VG_TDICT_CALL(...)" in the required |
| 1120 | // places, while still checking the assertion. |
| 1121 | #define VG_TDICT_CALL(fn, args...) \ |
| 1122 | ( tl_assert2(VG_(tdict).fn, \ |
| 1123 | "you forgot to set VgToolInterface function '" #fn "'"), \ |
| 1124 | VG_(tdict).fn(args) ) |
| 1125 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1126 | #define VG_TRACK(fn, args...) \ |
| 1127 | do { \ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1128 | if (VG_(tdict).track_##fn) \ |
| 1129 | VG_(tdict).track_##fn(args); \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1130 | } while(0) |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1131 | |
nethercote | c06e213 | 2004-09-03 13:45:29 +0000 | [diff] [blame] | 1132 | // --------------------------------------------------------------------- |
| 1133 | // Architecture-specific things defined in eg. x86/*.c |
| 1134 | // --------------------------------------------------------------------- |
| 1135 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 1136 | // Returns the architecture and subarchitecture, or indicates |
| 1137 | // that this subarchitecture is unable to run Valgrind |
| 1138 | // Returns False to indicate we cannot proceed further. |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 1139 | extern Bool VGA_(getArchAndSubArch)( /*OUT*/VexArch*, |
| 1140 | /*OUT*/VexSubArch* ); |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 1141 | // Accessors for the ThreadArchState |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 1142 | #define INSTR_PTR(regs) ((regs).vex.VGA_INSTR_PTR) |
| 1143 | #define STACK_PTR(regs) ((regs).vex.VGA_STACK_PTR) |
| 1144 | #define FRAME_PTR(regs) ((regs).vex.VGA_FRAME_PTR) |
| 1145 | #define CLREQ_ARGS(regs) ((regs).vex.VGA_CLREQ_ARGS) |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 1146 | #define CLREQ_RET(regs) ((regs).vex.VGA_CLREQ_RET) |
njn | 16de557 | 2004-11-27 14:27:21 +0000 | [diff] [blame] | 1147 | // Offsets for the Vex state |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 1148 | #define O_STACK_PTR (offsetof(VexGuestArchState, VGA_STACK_PTR)) |
| 1149 | #define O_FRAME_PTR (offsetof(VexGuestArchState, VGA_FRAME_PTR)) |
| 1150 | #define O_CLREQ_RET (offsetof(VexGuestArchState, VGA_CLREQ_RET)) |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 1151 | |
| 1152 | |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 1153 | // Setting up the initial thread (1) state |
| 1154 | extern void |
| 1155 | VGA_(init_thread1state) ( Addr client_eip, |
| 1156 | Addr esp_at_startup, |
| 1157 | /*MOD*/ ThreadArchState* arch ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1158 | |
nethercote | c009ebe | 2004-09-13 11:05:11 +0000 | [diff] [blame] | 1159 | // Thread stuff |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 1160 | extern void VGA_(cleanup_thread) ( ThreadArchState* ); |
| 1161 | extern void VGA_(setup_child) ( ThreadArchState*, ThreadArchState* ); |
nethercote | f9b5941 | 2004-09-10 15:33:32 +0000 | [diff] [blame] | 1162 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1163 | // OS/Platform-specific thread clear (after thread exit) |
| 1164 | extern void VGA_(os_state_clear)(ThreadState *); |
| 1165 | |
| 1166 | // OS/Platform-specific thread init (at scheduler init time) |
| 1167 | extern void VGA_(os_state_init)(ThreadState *); |
| 1168 | |
| 1169 | // Run a thread from beginning to end. Does not return if tid == VG_(master_tid). |
sewardj | 0c1a596 | 2005-03-22 00:19:55 +0000 | [diff] [blame] | 1170 | void VGA_(thread_wrapper)(Word /*ThreadId*/ tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1171 | |
| 1172 | // Like VGA_(thread_wrapper), but it allocates a stack before calling |
| 1173 | // to VGA_(thread_wrapper) on that stack, as if it had been set up by |
| 1174 | // clone() |
| 1175 | void VGA_(main_thread_wrapper)(ThreadId tid) __attribute__ ((__noreturn__)); |
| 1176 | |
| 1177 | // Return how many bytes of a thread's Valgrind stack are unused |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 1178 | SSizeT VGA_(stack_unused)(ThreadId tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1179 | |
| 1180 | // Terminate the process. Does not return. |
| 1181 | void VGA_(terminate)(ThreadId tid, VgSchedReturnCode src) __attribute__((__noreturn__)); |
| 1182 | |
| 1183 | // wait until all other threads are dead |
| 1184 | extern void VGA_(reap_threads)(ThreadId self); |
| 1185 | |
| 1186 | // handle an arch-specific client request |
| 1187 | extern Bool VGA_(client_request)(ThreadId tid, UWord *args); |
| 1188 | |
nethercote | c009ebe | 2004-09-13 11:05:11 +0000 | [diff] [blame] | 1189 | // Symtab stuff |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 1190 | extern UInt* VGA_(reg_addr_from_tst) ( Int regno, ThreadArchState* ); |
nethercote | cd65604 | 2004-09-11 23:48:22 +0000 | [diff] [blame] | 1191 | |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 1192 | // Pointercheck |
| 1193 | extern Bool VGA_(setup_pointercheck) ( void ); |
| 1194 | |
| 1195 | // For attaching the debugger |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 1196 | extern Int VGA_(ptrace_setregs_from_tst) ( Int pid, ThreadArchState* arch ); |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 1197 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1198 | // Used by leakcheck |
| 1199 | extern void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr)); |
| 1200 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1201 | ////typedef struct _ThreadArchAux ThreadArchAux; |
nethercote | 9b3c765 | 2004-10-19 13:18:00 +0000 | [diff] [blame] | 1202 | |
| 1203 | |
nethercote | 41c75da | 2004-10-18 15:34:14 +0000 | [diff] [blame] | 1204 | // --------------------------------------------------------------------- |
| 1205 | // Platform-specific things defined in eg. x86/*.c |
| 1206 | // --------------------------------------------------------------------- |
nethercote | 775508a | 2004-09-07 22:38:23 +0000 | [diff] [blame] | 1207 | |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 1208 | // Do any platform specific redirects. |
tom | 748a131 | 2005-04-02 15:53:01 +0000 | [diff] [blame] | 1209 | extern void VGP_(setup_redirects)(void); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1210 | |
| 1211 | ///* --------------------------------------------------------------------- |
| 1212 | // Thread modelling |
| 1213 | // ------------------------------------------------------------------ */ |
| 1214 | //extern void VG_(tm_thread_create) (ThreadId creator, ThreadId tid, Bool detached); |
| 1215 | //extern void VG_(tm_thread_exit) (ThreadId tid); |
| 1216 | //extern Bool VG_(tm_thread_exists) (ThreadId tid); |
| 1217 | //extern void VG_(tm_thread_detach) (ThreadId tid); |
| 1218 | //extern void VG_(tm_thread_join) (ThreadId joiner, ThreadId joinee); |
| 1219 | //extern void VG_(tm_thread_switchto)(ThreadId tid); |
| 1220 | // |
| 1221 | //extern void VG_(tm_mutex_init) (ThreadId tid, Addr mutexp); |
| 1222 | //extern void VG_(tm_mutex_destroy)(ThreadId tid, Addr mutexp); |
| 1223 | //extern void VG_(tm_mutex_trylock)(ThreadId tid, Addr mutexp); |
| 1224 | //extern void VG_(tm_mutex_giveup) (ThreadId tid, Addr mutexp); |
| 1225 | //extern void VG_(tm_mutex_acquire)(ThreadId tid, Addr mutexp); |
| 1226 | //extern void VG_(tm_mutex_tryunlock)(ThreadId tid, Addr mutexp); |
| 1227 | //extern void VG_(tm_mutex_unlock) (ThreadId tid, Addr mutexp); |
| 1228 | //extern Bool VG_(tm_mutex_exists) (Addr mutexp); |
| 1229 | // |
| 1230 | //extern UInt VG_(tm_error_update_extra) (Error *err); |
| 1231 | //extern Bool VG_(tm_error_equal) (VgRes res, Error *e1, Error *e2); |
| 1232 | //extern void VG_(tm_error_print) (Error *err); |
| 1233 | // |
| 1234 | //extern void VG_(tm_init) (); |
| 1235 | // |
| 1236 | //extern void VG_(tm_cond_init) (ThreadId tid, Addr condp); |
| 1237 | //extern void VG_(tm_cond_destroy) (ThreadId tid, Addr condp); |
| 1238 | //extern void VG_(tm_cond_wait) (ThreadId tid, Addr condp, Addr mutexp); |
| 1239 | //extern void VG_(tm_cond_wakeup) (ThreadId tid, Addr condp, Addr mutexp); |
| 1240 | //extern void VG_(tm_cond_signal) (ThreadId tid, Addr condp); |
| 1241 | // |
| 1242 | ///* ----- pthreads ----- */ |
| 1243 | //extern void VG_(pthread_init) (); |
| 1244 | //extern void VG_(pthread_startfunc_wrapper)(Addr wrapper); |
| 1245 | // |
| 1246 | //struct vg_pthread_newthread_data { |
| 1247 | // void *(*startfunc)(void *arg); |
| 1248 | // void *arg; |
| 1249 | //}; |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1250 | |
| 1251 | /* --------------------------------------------------------------------- |
| 1252 | Finally - autoconf-generated settings |
| 1253 | ------------------------------------------------------------------ */ |
| 1254 | |
| 1255 | #include "config.h" |
| 1256 | |
nethercote | c06e213 | 2004-09-03 13:45:29 +0000 | [diff] [blame] | 1257 | #endif /* ndef __CORE_H */ |
| 1258 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1259 | /*--------------------------------------------------------------------*/ |
nethercote | 109d0df | 2004-09-02 08:10:13 +0000 | [diff] [blame] | 1260 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1261 | /*--------------------------------------------------------------------*/ |