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 | 1334313 | 2004-09-02 15:49:09 +0000 | [diff] [blame] | 35 | #include "tool.h" // tool stuff |
nethercote | bb4222b | 2004-09-10 17:42:11 +0000 | [diff] [blame] | 36 | #include "core_arch.h" // arch-specific stuff, eg. x86/core_arch.h |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 37 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 38 | #include "core_os.h" // OS-specific stuff, eg. linux/core_os.h |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 39 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 40 | #include "pub_core_mallocfree.h" // for type 'ArenaId' |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 41 | #include "pub_core_stacktrace.h" // for type 'StackTrace' |
| 42 | |
njn | 4f6e370 | 2005-05-16 20:50:52 +0000 | [diff] [blame] | 43 | #include <setjmp.h> /* for jmp_buf */ |
| 44 | |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 45 | /* --------------------------------------------------------------------- |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 46 | Global macros. |
nethercote | 7be4725 | 2004-09-02 16:02:58 +0000 | [diff] [blame] | 47 | ------------------------------------------------------------------ */ |
| 48 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 49 | /* Max length of a text fragment used to construct error messages. */ |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 50 | #define VG_ERRTXT_LEN 4096 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 51 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 52 | /* The maximum number of calls we're prepared to save in a |
| 53 | backtrace. */ |
| 54 | #define VG_DEEPEST_BACKTRACE 50 |
| 55 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 56 | /* Useful macros */ |
| 57 | /* a - alignment - must be a power of 2 */ |
tom | de2ec26 | 2005-03-29 12:16:10 +0000 | [diff] [blame] | 58 | #define ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1)) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 59 | #define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a)) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 60 | #define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE) |
| 61 | #define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 62 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 63 | |
nethercote | 80013e9 | 2004-09-05 20:39:51 +0000 | [diff] [blame] | 64 | /* --------------------------------------------------------------------- |
| 65 | Environment variables |
| 66 | ------------------------------------------------------------------ */ |
| 67 | |
| 68 | /* The directory we look for all our auxillary files in */ |
| 69 | #define VALGRINDLIB "VALGRINDLIB" |
| 70 | |
| 71 | /* Additional command-line arguments; they are overridden by actual |
| 72 | command-line option. Each argument is separated by spaces. There |
| 73 | is no quoting mechanism. |
| 74 | */ |
| 75 | #define VALGRINDOPTS "VALGRIND_OPTS" |
| 76 | |
| 77 | /* If this variable is present in the environment, then valgrind will |
| 78 | not parse the command line for options at all; all options come |
| 79 | from this variable. Arguments are terminated by ^A (\001). There |
| 80 | is no quoting mechanism. |
| 81 | |
| 82 | This variable is not expected to be set by anything other than |
| 83 | Valgrind itself, as part of its handling of execve with |
| 84 | --trace-children=yes. This variable should not be present in the |
| 85 | client environment. |
| 86 | */ |
| 87 | #define VALGRINDCLO "_VALGRIND_CLO" |
| 88 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 89 | |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 90 | /* Application-visible file descriptor limits */ |
| 91 | extern Int VG_(fd_soft_limit); |
| 92 | extern Int VG_(fd_hard_limit); |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 93 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 94 | /* --------------------------------------------------------------------- |
nethercote | 85cdd34 | 2004-08-01 22:36:40 +0000 | [diff] [blame] | 95 | Profiling stuff |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | ------------------------------------------------------------------ */ |
| 97 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 98 | extern void VG_(init_profiling) ( void ); |
| 99 | extern void VG_(done_profiling) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 100 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 101 | #undef VGP_PUSHCC |
| 102 | #undef VGP_POPCC |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 103 | #define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x) |
| 104 | #define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 105 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 106 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 107 | /* --------------------------------------------------------------------- |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 108 | Exports of vg_intercept.c |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 109 | ------------------------------------------------------------------ */ |
| 110 | |
njn | a91498f | 2005-05-11 22:32:39 +0000 | [diff] [blame] | 111 | /* These are the internal client request codes. The publically-visible |
| 112 | request codes are also defined in valgrind.h, and similar headers for |
| 113 | some tools. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 114 | |
njn | a91498f | 2005-05-11 22:32:39 +0000 | [diff] [blame] | 115 | /* Get the tool's malloc-wrapping functions */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 116 | #define VG_USERREQ__GET_MALLOCFUNCS 0x3030 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 117 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 118 | /* Internal equivalent of VALGRIND_PRINTF . */ |
| 119 | #define VG_USERREQ__INTERNAL_PRINTF 0x3103 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 120 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 121 | /* Denote the finish of __libc_freeres_wrapper(). |
| 122 | A synonym for exit. */ |
| 123 | #define VG_USERREQ__LIBC_FREERES_DONE 0x3029 |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 124 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 125 | /* Intercept prefix stuff. See |
| 126 | coregrind/m_replace_malloc/vg_replace_malloc.c for details. |
| 127 | Unfortunately the "_vgi_" literal is also hardcoded in that file, so if |
| 128 | you change this one you must also change the other one. */ |
sewardj | 9ee81f5 | 2005-04-02 17:38:59 +0000 | [diff] [blame] | 129 | #define VG_INTERCEPT_PREFIX "_vgi_" |
| 130 | #define VG_INTERCEPT_PREFIX_LEN 5 |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 131 | |
sewardj | 9ee81f5 | 2005-04-02 17:38:59 +0000 | [diff] [blame] | 132 | /* Not sure what these are for. Todo: clarify */ |
| 133 | #define VG_WRAPPER_PREFIX "_vgw_" |
| 134 | #define VG_WRAPPER_PREFIX_LEN 5 |
| 135 | #define VG_WRAPPER(name) _vgw_##name |
| 136 | #define VG_WRAPPER_ALIAS(name) "_vgw_" #name |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 137 | |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 138 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 139 | /* --------------------------------------------------------------------- |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 140 | Exports of vg_scheduler.c |
| 141 | ------------------------------------------------------------------ */ |
| 142 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 143 | /* |
| 144 | Thread state machine: |
| 145 | |
| 146 | Empty -> Init -> Runnable <=> WaitSys/Yielding |
| 147 | ^ | |
| 148 | \---- Zombie -----/ |
| 149 | */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 150 | typedef |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 151 | enum ThreadStatus { |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 152 | VgTs_Empty, /* this slot is not in use */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 153 | VgTs_Init, /* just allocated */ |
| 154 | VgTs_Runnable, /* ready to run */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 155 | VgTs_WaitSys, /* waiting for a syscall to complete */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 156 | VgTs_Yielding, /* temporarily yielding the CPU */ |
| 157 | VgTs_Zombie, /* transient state just before exiting */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 158 | } |
| 159 | ThreadStatus; |
sewardj | 8ad94e1 | 2002-05-29 00:10:20 +0000 | [diff] [blame] | 160 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 161 | /* Return codes from the scheduler. */ |
thughes | 11975ff | 2004-06-12 12:58:22 +0000 | [diff] [blame] | 162 | typedef |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 163 | enum { |
| 164 | VgSrc_None, /* not exiting yet */ |
| 165 | VgSrc_ExitSyscall, /* client called exit(). This is the normal |
| 166 | route out. */ |
| 167 | VgSrc_FatalSig /* Killed by the default action of a fatal |
| 168 | signal */ |
thughes | 11975ff | 2004-06-12 12:58:22 +0000 | [diff] [blame] | 169 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 170 | VgSchedReturnCode; |
thughes | 11975ff | 2004-06-12 12:58:22 +0000 | [diff] [blame] | 171 | |
njn | 77e8ac1 | 2005-05-16 21:16:44 +0000 | [diff] [blame] | 172 | |
| 173 | #if defined(VGA_x86) |
| 174 | typedef VexGuestX86State VexGuestArchState; |
tom | bb42223 | 2005-05-16 23:16:25 +0000 | [diff] [blame] | 175 | #elif defined(VGA_amd64) |
njn | 77e8ac1 | 2005-05-16 21:16:44 +0000 | [diff] [blame] | 176 | typedef VexGuestAMD64State VexGuestArchState; |
| 177 | #elif defined(VGA_arm) |
| 178 | typedef VexGuestARMState VexGuestArchState; |
| 179 | #else |
| 180 | # error Unknown architecture |
| 181 | #endif |
| 182 | |
| 183 | |
| 184 | typedef |
| 185 | struct { |
| 186 | /* --- BEGIN vex-mandated guest state --- */ |
| 187 | |
| 188 | /* Saved machine context. */ |
| 189 | VexGuestArchState vex; |
| 190 | |
| 191 | /* Saved shadow context. */ |
| 192 | VexGuestArchState vex_shadow; |
| 193 | |
| 194 | /* Spill area. */ |
| 195 | UChar vex_spill[LibVEX_N_SPILL_BYTES]; |
| 196 | |
| 197 | /* --- END vex-mandated guest state --- */ |
| 198 | } |
| 199 | ThreadArchState; |
| 200 | |
| 201 | |
njn | 1b72800 | 2005-05-17 21:10:11 +0000 | [diff] [blame] | 202 | typedef struct { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 203 | /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED. |
| 204 | The thread identity is simply the index in vg_threads[]. |
| 205 | ThreadId == 1 is the root thread and has the special property |
| 206 | that we don't try and allocate or deallocate its stack. For |
| 207 | convenience of generating error message, we also put the |
| 208 | ThreadId in this tid field, but be aware that it should |
| 209 | ALWAYS == the index in vg_threads[]. */ |
| 210 | ThreadId tid; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 211 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 212 | /* Current scheduling status. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 213 | ThreadStatus status; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 214 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 215 | /* This is set if the thread is in the process of exiting for any |
| 216 | reason. The precise details of the exit are in the OS-specific |
| 217 | state. */ |
| 218 | VgSchedReturnCode exitreason; |
sewardj | 3b5d886 | 2002-04-20 13:53:23 +0000 | [diff] [blame] | 219 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 220 | /* Architecture-specific thread state. */ |
| 221 | ThreadArchState arch; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 222 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 223 | /* This thread's blocked-signals mask. Semantics is that for a |
| 224 | signal to be delivered to this thread, the signal must not be |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 225 | blocked by this signal mask. If more than one thread accepts a |
| 226 | signal, then it will be delivered to one at random. If all |
| 227 | threads block the signal, it will remain pending until either a |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 228 | thread unblocks it or someone uses sigwaitsig/sigtimedwait. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 229 | vki_sigset_t sig_mask; |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 230 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 231 | /* tmp_sig_mask is usually the same as sig_mask, and is kept in |
| 232 | sync whenever sig_mask is changed. The only time they have |
| 233 | different values is during the execution of a sigsuspend, where |
| 234 | tmp_sig_mask is the temporary mask which sigsuspend installs. |
| 235 | It is only consulted to compute the signal mask applied to a |
| 236 | signal handler. */ |
| 237 | vki_sigset_t tmp_sig_mask; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 238 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 239 | /* A little signal queue for signals we can't get the kernel to |
| 240 | queue for us. This is only allocated as needed, since it should |
| 241 | be rare. */ |
| 242 | struct SigQueue *sig_queue; |
| 243 | |
| 244 | /* Syscall the Thread is currently running; -1 if none. Should only |
| 245 | be set while Thread is in VgTs_WaitSys. */ |
| 246 | Int syscallno; |
| 247 | |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 248 | /* Client stacks. When a thread slot is freed, we don't deallocate its |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 249 | stack; we just leave it lying around for the next use of the |
| 250 | slot. If the next use of the slot requires a larger stack, |
| 251 | only then is the old one deallocated and a new one |
| 252 | allocated. |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 253 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 254 | For the main thread (threadid == 0), this mechanism doesn't |
| 255 | apply. We don't know the size of the stack since we didn't |
| 256 | allocate it, and furthermore we never reallocate it. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 257 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 258 | /* The allocated size of this thread's stack (permanently zero |
| 259 | if this is ThreadId == 0, since we didn't allocate its stack) */ |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 260 | SizeT client_stack_szB; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 261 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 262 | /* Address of the highest legitimate word in this stack. This is |
| 263 | used for error messages only -- not critical for execution |
| 264 | correctness. Is is set for all stacks, specifically including |
| 265 | ThreadId == 0 (the main thread). */ |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 266 | Addr client_stack_highest_word; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 267 | |
fitzhardinge | 98c4dc0 | 2004-03-16 08:27:29 +0000 | [diff] [blame] | 268 | /* Alternate signal stack */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 269 | vki_stack_t altstack; |
fitzhardinge | 98c4dc0 | 2004-03-16 08:27:29 +0000 | [diff] [blame] | 270 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 271 | /* OS-specific thread state */ |
| 272 | os_thread_t os_state; |
sewardj | 004e8ca | 2005-02-28 17:27:04 +0000 | [diff] [blame] | 273 | |
| 274 | /* Used in the syscall handlers. Set to True to indicate that the |
| 275 | PRE routine for a syscall has set the syscall result already and |
| 276 | so the syscall does not need to be handed to the kernel. */ |
| 277 | Bool syscall_result_set; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 278 | |
| 279 | /* Per-thread jmp_buf to resume scheduler after a signal */ |
| 280 | Bool sched_jmpbuf_valid; |
| 281 | jmp_buf sched_jmpbuf; |
njn | 1b72800 | 2005-05-17 21:10:11 +0000 | [diff] [blame] | 282 | } |
| 283 | ThreadState; |
| 284 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 285 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 286 | /* The thread table. */ |
| 287 | extern ThreadState VG_(threads)[VG_N_THREADS]; |
| 288 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 289 | /* Allocate a new ThreadState */ |
| 290 | extern ThreadId VG_(alloc_ThreadState)(void); |
| 291 | |
| 292 | /* A thread exits. tid must currently be running. */ |
| 293 | extern void VG_(exit_thread)(ThreadId tid); |
| 294 | |
| 295 | /* Kill a thread. This interrupts whatever a thread is doing, and |
| 296 | makes it exit ASAP. This does not set the exitreason or |
| 297 | exitcode. */ |
| 298 | extern void VG_(kill_thread)(ThreadId tid); |
| 299 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 300 | /* Check that tid is in range and denotes a non-Empty thread. */ |
sewardj | b48e500 | 2002-05-13 00:16:03 +0000 | [diff] [blame] | 301 | extern Bool VG_(is_valid_tid) ( ThreadId tid ); |
| 302 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 303 | /* Get the ThreadState for a particular thread */ |
| 304 | extern ThreadState *VG_(get_ThreadState)(ThreadId tid); |
| 305 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 306 | /* Given an LWP id (ie, real kernel thread id), find the corresponding |
| 307 | ThreadId */ |
| 308 | extern ThreadId VG_(get_lwp_tid)(Int lwpid); |
| 309 | |
| 310 | /* Returns true if a thread is currently running (ie, has the CPU lock) */ |
| 311 | extern Bool VG_(is_running_thread)(ThreadId tid); |
| 312 | |
| 313 | /* Returns true if the thread is in the process of exiting */ |
| 314 | extern Bool VG_(is_exiting)(ThreadId tid); |
| 315 | |
| 316 | /* Return the number of non-dead Threads */ |
| 317 | extern Int VG_(count_living_threads)(void); |
| 318 | |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 319 | /* Nuke all threads except tid. */ |
njn | 1b72800 | 2005-05-17 21:10:11 +0000 | [diff] [blame] | 320 | extern void VG_(nuke_all_threads_except) ( ThreadId me, |
| 321 | VgSchedReturnCode reason ); |
sewardj | ccef2e6 | 2002-05-29 19:26:32 +0000 | [diff] [blame] | 322 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 323 | /* Make a thread the running thread. The thread must previously been |
| 324 | sleeping, and not holding the CPU semaphore. This will set the |
| 325 | thread state to VgTs_Runnable, and the thread will attempt to take |
| 326 | the CPU semaphore. By the time it returns, tid will be the running |
| 327 | thread. */ |
| 328 | extern void VG_(set_running) ( ThreadId tid ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 329 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 330 | /* Set a thread into a sleeping state. Before the call, the thread |
| 331 | must be runnable, and holding the CPU semaphore. When this call |
| 332 | returns, the thread will be set to the specified sleeping state, |
| 333 | and will not be holding the CPU semaphore. Note that another |
| 334 | thread could be running by the time this call returns, so the |
| 335 | caller must be careful not to touch any shared state. It is also |
| 336 | the caller's responsibility to actually block until the thread is |
| 337 | ready to run again. */ |
| 338 | extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 339 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 340 | /* Yield the CPU for a while */ |
| 341 | extern void VG_(vg_yield)(void); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 342 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 343 | // The scheduler. |
| 344 | extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid ); |
| 345 | |
| 346 | // Do everything which needs doing before the process finally ends, |
| 347 | // like printing reports, etc |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame^] | 348 | extern void VG_(shutdown_actions_NORETURN) ( |
| 349 | ThreadId tid, |
| 350 | VgSchedReturnCode tids_schedretcode |
| 351 | ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 352 | |
| 353 | extern void VG_(scheduler_init) ( void ); |
| 354 | |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 355 | extern void VG_(pp_sched_status) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 356 | |
nethercote | 75d2624 | 2004-08-01 22:59:18 +0000 | [diff] [blame] | 357 | // Longjmp back to the scheduler and thus enter the sighandler immediately. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 358 | extern void VG_(resume_scheduler) ( ThreadId tid ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 359 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 360 | /* If true, a fault is Valgrind-internal (ie, a bug) */ |
| 361 | extern Bool VG_(my_fault); |
nethercote | 238a3c3 | 2004-08-09 13:13:31 +0000 | [diff] [blame] | 362 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 363 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 364 | Exports of vg_signals.c |
| 365 | ------------------------------------------------------------------ */ |
| 366 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 367 | /* Highest signal the kernel will let us use */ |
| 368 | extern Int VG_(max_signal); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 369 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 370 | extern void VG_(sigstartup_actions) ( void ); |
| 371 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 372 | /* Poll a thread's set of pending signals, and update the Thread's context to deliver one */ |
| 373 | extern void VG_(poll_signals) ( ThreadId ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 374 | |
| 375 | /* Fake system calls for signal handling. */ |
njn | 502badb | 2005-05-08 02:04:49 +0000 | [diff] [blame] | 376 | extern Int VG_(do_sys_sigaltstack) ( ThreadId tid, vki_stack_t* ss, |
| 377 | vki_stack_t* oss ); |
| 378 | extern Int VG_(do_sys_sigaction) ( Int signo, |
| 379 | const struct vki_sigaction *new_act, |
| 380 | struct vki_sigaction *old_act ); |
| 381 | extern Int VG_(do_sys_sigprocmask) ( ThreadId tid, Int how, |
| 382 | vki_sigset_t* set, |
| 383 | vki_sigset_t* oldset ); |
sewardj | efbfcdf | 2002-06-19 17:35:45 +0000 | [diff] [blame] | 384 | |
njn | 444eba1 | 2005-05-12 03:47:31 +0000 | [diff] [blame] | 385 | extern void VG_(clear_out_queued_signals) |
| 386 | ( ThreadId tid, /* OUT */ vki_sigset_t* saved_mask ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 387 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 388 | extern void VG_(kill_self)(Int sigNo); |
| 389 | |
fitzhardinge | f1beb25 | 2004-03-16 09:49:08 +0000 | [diff] [blame] | 390 | /* These function synthesize a fault, as if the running instruction |
| 391 | had had a fault. These functions do not return - they longjmp back |
| 392 | into the scheduler so the signal can be delivered. */ |
| 393 | extern void VG_(synth_fault) (ThreadId tid); |
| 394 | extern void VG_(synth_fault_mapping)(ThreadId tid, Addr addr); |
| 395 | extern void VG_(synth_fault_perms) (ThreadId tid, Addr addr); |
sewardj | 5e2f001 | 2004-12-13 14:10:34 +0000 | [diff] [blame] | 396 | extern void VG_(synth_sigill) (ThreadId tid, Addr addr); |
fitzhardinge | f1beb25 | 2004-03-16 09:49:08 +0000 | [diff] [blame] | 397 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 398 | /* Extend the stack to cover addr, if possible */ |
| 399 | extern Bool VG_(extend_stack)(Addr addr, UInt maxsize); |
| 400 | |
| 401 | /* Returns True if the signal is OK for the client to use */ |
| 402 | extern Bool VG_(client_signal_OK)(Int sigNo); |
| 403 | |
| 404 | /* Forces the client's signal handler to SIG_DFL - generally just |
| 405 | before using that signal to kill the process. */ |
| 406 | extern void VG_(set_default_handler)(Int sig); |
| 407 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 408 | /* --------------------------------------------------------------------- |
| 409 | Exports of vg_mylibc.c |
| 410 | ------------------------------------------------------------------ */ |
| 411 | |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 412 | // Useful for making failing stubs, when certain things haven't yet been |
| 413 | // implemented. |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 414 | #define I_die_here \ |
sewardj | 0ab10c4 | 2005-05-12 08:26:36 +0000 | [diff] [blame] | 415 | VG_(assert_fail) (/*isCore*//*BOGUS*/True, \ |
| 416 | "Unimplemented functionality", \ |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 417 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 418 | "valgrind", VG_BUGS_TO, "") |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 419 | |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 420 | #define vg_assert(expr) \ |
| 421 | ((void) ((expr) ? 0 : \ |
| 422 | (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \ |
| 423 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 424 | ""), \ |
| 425 | 0))) |
| 426 | |
| 427 | #define vg_assert2(expr, format, args...) \ |
| 428 | ((void) ((expr) ? 0 : \ |
| 429 | (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \ |
| 430 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 431 | format, ##args), \ |
| 432 | 0))) |
| 433 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 434 | __attribute__ ((__noreturn__)) |
| 435 | extern void VG_(core_panic) ( Char* str ); |
thughes | 5876d55 | 2004-09-26 18:44:06 +0000 | [diff] [blame] | 436 | __attribute__ ((__noreturn__)) |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 437 | extern void VG_(core_panic_at) ( Char* str, StackTrace ips ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 438 | |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 439 | /* Tools use VG_(strdup)() which doesn't expose ArenaId */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 440 | extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 441 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 442 | extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 443 | extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 444 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 445 | /* system/mman.h */ |
njn | 7df470b | 2005-05-29 18:46:38 +0000 | [diff] [blame] | 446 | extern void* VG_(mmap) ( void* start, SizeT length, UInt prot, UInt flags, |
| 447 | UInt sf_flags, UInt fd, OffT offset ); |
| 448 | extern void* VG_(mmap_native)( void* start, SizeT length, UInt prot, UInt flags, |
| 449 | UInt fd, OffT offset ); |
| 450 | extern Int VG_(munmap) ( void* start, SizeT length ); |
| 451 | extern Int VG_(mprotect) ( void *start, SizeT length, UInt prot ); |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 452 | extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 453 | |
| 454 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 455 | /* Move an fd into the Valgrind-safe range */ |
| 456 | Int VG_(safe_fd)(Int oldfd); |
| 457 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 458 | extern Int VG_(write_socket)( Int sd, void *msg, Int count ); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 459 | |
| 460 | /* --- Connecting over the network --- */ |
| 461 | extern Int VG_(connect_via_socket)( UChar* str ); |
| 462 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 463 | /* Environment manipulations */ |
nethercote | 60a96c5 | 2004-08-03 13:08:31 +0000 | [diff] [blame] | 464 | extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname, |
| 465 | const Char *val ); |
| 466 | extern void VG_(env_unsetenv) ( Char **env, const Char *varname ); |
| 467 | extern void VG_(env_remove_valgrind_env_stuff) ( Char** env ); |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 468 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 469 | extern void VG_(nanosleep)(struct vki_timespec *); |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 470 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 471 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 472 | Exports of vg_symtab2.c |
| 473 | ------------------------------------------------------------------ */ |
| 474 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 475 | typedef struct _Segment Segment; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 476 | typedef struct _CodeRedirect CodeRedirect; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 477 | |
| 478 | extern Bool VG_(is_object_file) ( const void *hdr ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 479 | extern SegInfo * VG_(read_seg_symbols) ( Segment *seg ); |
njn | 36ef6ba | 2005-05-14 18:42:26 +0000 | [diff] [blame] | 480 | extern void VG_(seginfo_incref) ( SegInfo * ); |
| 481 | extern void VG_(seginfo_decref) ( SegInfo *, Addr a ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 482 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 483 | extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname ); |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 484 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 485 | extern Addr VG_(reverse_search_one_symtab) ( const SegInfo* si, const Char* name ); |
| 486 | |
sewardj | 3516553 | 2005-04-30 18:47:48 +0000 | [diff] [blame] | 487 | extern Bool VG_(use_CFI_info) ( /*MOD*/Addr* ipP, |
| 488 | /*MOD*/Addr* spP, |
| 489 | /*MOD*/Addr* fpP, |
| 490 | Addr min_accessible, |
| 491 | Addr max_accessible ); |
| 492 | |
| 493 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 494 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 495 | Exports of vg_main.c |
| 496 | ------------------------------------------------------------------ */ |
| 497 | |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 498 | /* Tell the logging mechanism whether we are logging to a file |
| 499 | descriptor or a socket descriptor. */ |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 500 | extern Bool VG_(logging_to_socket); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 501 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 502 | /* Sanity checks which may be done at any time. The scheduler decides when. */ |
nethercote | 885dd91 | 2004-08-03 23:14:00 +0000 | [diff] [blame] | 503 | extern void VG_(sanity_check_general) ( Bool force_expensive ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 504 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 505 | /* Address space */ |
| 506 | extern Addr VG_(client_base); /* client address space limits */ |
| 507 | extern Addr VG_(client_end); |
| 508 | extern Addr VG_(client_mapbase); /* base of mappings */ |
| 509 | extern Addr VG_(clstk_base); /* client stack range */ |
| 510 | extern Addr VG_(clstk_end); |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 511 | extern Addr VG_(client_trampoline_code); |
| 512 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 513 | extern Addr VG_(brk_base); /* start of brk */ |
| 514 | extern Addr VG_(brk_limit); /* current brk */ |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 515 | extern Addr VG_(shadow_base); /* tool's shadow memory */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 516 | extern Addr VG_(shadow_end); |
| 517 | extern Addr VG_(valgrind_base); /* valgrind's address range */ |
nethercote | 820bd8c | 2004-09-07 23:04:49 +0000 | [diff] [blame] | 518 | 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] | 519 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 520 | extern struct vki_rlimit VG_(client_rlimit_data); /* client's original rlimit data */ |
| 521 | extern struct vki_rlimit VG_(client_rlimit_stack); /* client's original rlimit stack */ |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 522 | |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 523 | /* client executable file descriptor */ |
| 524 | extern Int VG_(clexecfd); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 525 | |
nethercote | f6a1d50 | 2004-08-09 12:21:57 +0000 | [diff] [blame] | 526 | // Help set up the child used when doing execve() with --trace-children=yes |
| 527 | Char* VG_(build_child_VALGRINDCLO) ( Char* exename ); |
| 528 | Char* VG_(build_child_exename) ( void ); |
| 529 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 530 | /* Called when some unhandleable client behaviour is detected. |
| 531 | Prints a msg and aborts. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 532 | extern void VG_(unimplemented) ( Char* msg ) |
| 533 | __attribute__((__noreturn__)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 534 | |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 535 | /* Something of a function looking for a home ... start up debugger. */ |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 536 | extern void VG_(start_debugger) ( ThreadId tid ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 537 | |
sewardj | 4ccf707 | 2004-11-28 16:58:05 +0000 | [diff] [blame] | 538 | /* Stats ... */ |
nethercote | 844e712 | 2004-08-02 15:27:22 +0000 | [diff] [blame] | 539 | extern void VG_(print_scheduler_stats) ( void ); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 540 | |
njn | 1f70772 | 2005-03-27 03:17:52 +0000 | [diff] [blame] | 541 | /* 64-bit counter for the number of basic blocks done. */ |
| 542 | extern ULong VG_(bbs_done); |
| 543 | |
nethercote | 2e05c33 | 2004-09-06 16:43:37 +0000 | [diff] [blame] | 544 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 545 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 546 | Exports of vg_syscall.S |
| 547 | ------------------------------------------------------------------ */ |
| 548 | |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 549 | // We use a full prototype rather than "..." here to ensure that all |
| 550 | // arguments get converted to a UWord appropriately. Not doing so can |
| 551 | // cause problems when passing 32-bit integers on 64-bit platforms, because |
| 552 | // the top 32-bits might not be zeroed appropriately, eg. as would happen |
| 553 | // with the 6th arg on AMD64 which is passed on the stack. |
njn | f4aeaea | 2004-11-29 17:33:31 +0000 | [diff] [blame] | 554 | extern Word VG_(do_syscall) ( UInt, UWord, UWord, UWord, UWord, UWord, UWord ); |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 555 | |
| 556 | // Macros make life easier. |
| 557 | #define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0,0) |
| 558 | #define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),0,0,0,0,0) |
| 559 | #define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),0,0,0,0) |
| 560 | #define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(c),0,0,0) |
| 561 | #define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),(c),(d),0,0) |
| 562 | #define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),(c),(d),(e),0) |
| 563 | #define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),(c),(d),(e),(f)) |
| 564 | |
fitzhardinge | 4f10ada | 2004-06-03 10:00:42 +0000 | [diff] [blame] | 565 | extern void VG_(sigreturn)(void); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 566 | |
| 567 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 568 | Exports of vg_helpers.S |
| 569 | ------------------------------------------------------------------ */ |
| 570 | |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 571 | /* Information about trampoline code (for signal return and syscalls) */ |
| 572 | extern const Char VG_(trampoline_code_start); |
| 573 | extern const Int VG_(trampoline_code_length); |
| 574 | extern const Int VG_(tramp_sigreturn_offset); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 575 | extern const Int VG_(tramp_rt_sigreturn_offset); |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 576 | extern const Int VG_(tramp_syscall_offset); |
tom | ee0bcbf | 2005-05-02 10:28:42 +0000 | [diff] [blame] | 577 | extern const Int VG_(tramp_gettimeofday_offset); |
| 578 | extern const Int VG_(tramp_time_offset); |
sewardj | 20917d8 | 2002-05-28 01:36:45 +0000 | [diff] [blame] | 579 | |
nethercote | c06e213 | 2004-09-03 13:45:29 +0000 | [diff] [blame] | 580 | // --------------------------------------------------------------------- |
| 581 | // Architecture-specific things defined in eg. x86/*.c |
| 582 | // --------------------------------------------------------------------- |
| 583 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 584 | // Returns the architecture and subarchitecture, or indicates |
| 585 | // that this subarchitecture is unable to run Valgrind |
| 586 | // Returns False to indicate we cannot proceed further. |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 587 | extern Bool VGA_(getArchAndSubArch)( /*OUT*/VexArch*, |
| 588 | /*OUT*/VexSubArch* ); |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 589 | // Accessors for the ThreadArchState |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 590 | #define INSTR_PTR(regs) ((regs).vex.VGA_INSTR_PTR) |
| 591 | #define STACK_PTR(regs) ((regs).vex.VGA_STACK_PTR) |
| 592 | #define FRAME_PTR(regs) ((regs).vex.VGA_FRAME_PTR) |
| 593 | #define CLREQ_ARGS(regs) ((regs).vex.VGA_CLREQ_ARGS) |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 594 | #define CLREQ_RET(regs) ((regs).vex.VGA_CLREQ_RET) |
njn | 16de557 | 2004-11-27 14:27:21 +0000 | [diff] [blame] | 595 | // Offsets for the Vex state |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 596 | #define O_STACK_PTR (offsetof(VexGuestArchState, VGA_STACK_PTR)) |
| 597 | #define O_FRAME_PTR (offsetof(VexGuestArchState, VGA_FRAME_PTR)) |
| 598 | #define O_CLREQ_RET (offsetof(VexGuestArchState, VGA_CLREQ_RET)) |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 599 | |
| 600 | |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 601 | // Setting up the initial thread (1) state |
| 602 | extern void |
| 603 | VGA_(init_thread1state) ( Addr client_eip, |
| 604 | Addr esp_at_startup, |
| 605 | /*MOD*/ ThreadArchState* arch ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 606 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 607 | // OS/Platform-specific thread clear (after thread exit) |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame^] | 608 | extern void VGO_(os_state_clear)(ThreadState *); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 609 | |
| 610 | // OS/Platform-specific thread init (at scheduler init time) |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame^] | 611 | extern void VGO_(os_state_init)(ThreadState *); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 612 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame^] | 613 | // Run a thread from beginning to end. |
| 614 | extern VgSchedReturnCode VGO_(thread_wrapper)(Word /*ThreadId*/ tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 615 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame^] | 616 | // Call here to exit the entire Valgrind system. |
| 617 | extern void VGO_(terminate_NORETURN)(ThreadId tid, VgSchedReturnCode src); |
| 618 | |
| 619 | // Allocates a stack for the first thread, then runs it, |
| 620 | // as if the thread had been set up by clone() |
| 621 | extern void VGP_(main_thread_wrapper_NORETURN)(ThreadId tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 622 | |
| 623 | // Return how many bytes of a thread's Valgrind stack are unused |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame^] | 624 | extern SSizeT VGA_(stack_unused)(ThreadId tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 625 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 626 | // wait until all other threads are dead |
| 627 | extern void VGA_(reap_threads)(ThreadId self); |
| 628 | |
| 629 | // handle an arch-specific client request |
| 630 | extern Bool VGA_(client_request)(ThreadId tid, UWord *args); |
| 631 | |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 632 | // Pointercheck |
| 633 | extern Bool VGA_(setup_pointercheck) ( void ); |
| 634 | |
| 635 | // For attaching the debugger |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 636 | extern Int VGA_(ptrace_setregs_from_tst) ( Int pid, ThreadArchState* arch ); |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 637 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 638 | // Used by leakcheck |
| 639 | extern void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr)); |
| 640 | |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 641 | // Set up the libc freeres wrapper |
| 642 | extern void VGA_(intercept_libc_freeres_wrapper)(Addr); |
| 643 | |
| 644 | // Clean up the client by calling before the final reports |
| 645 | extern void VGA_(final_tidyup)(ThreadId tid); |
| 646 | |
| 647 | // Arch-specific client requests |
| 648 | extern Bool VGA_(client_requests)(ThreadId tid, UWord *args); |
| 649 | |
nethercote | 9b3c765 | 2004-10-19 13:18:00 +0000 | [diff] [blame] | 650 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 651 | ///* --------------------------------------------------------------------- |
| 652 | // Thread modelling |
| 653 | // ------------------------------------------------------------------ */ |
| 654 | //extern void VG_(tm_thread_create) (ThreadId creator, ThreadId tid, Bool detached); |
| 655 | //extern void VG_(tm_thread_exit) (ThreadId tid); |
| 656 | //extern Bool VG_(tm_thread_exists) (ThreadId tid); |
| 657 | //extern void VG_(tm_thread_detach) (ThreadId tid); |
| 658 | //extern void VG_(tm_thread_join) (ThreadId joiner, ThreadId joinee); |
| 659 | //extern void VG_(tm_thread_switchto)(ThreadId tid); |
| 660 | // |
| 661 | //extern void VG_(tm_mutex_init) (ThreadId tid, Addr mutexp); |
| 662 | //extern void VG_(tm_mutex_destroy)(ThreadId tid, Addr mutexp); |
| 663 | //extern void VG_(tm_mutex_trylock)(ThreadId tid, Addr mutexp); |
| 664 | //extern void VG_(tm_mutex_giveup) (ThreadId tid, Addr mutexp); |
| 665 | //extern void VG_(tm_mutex_acquire)(ThreadId tid, Addr mutexp); |
| 666 | //extern void VG_(tm_mutex_tryunlock)(ThreadId tid, Addr mutexp); |
| 667 | //extern void VG_(tm_mutex_unlock) (ThreadId tid, Addr mutexp); |
| 668 | //extern Bool VG_(tm_mutex_exists) (Addr mutexp); |
| 669 | // |
| 670 | //extern UInt VG_(tm_error_update_extra) (Error *err); |
| 671 | //extern Bool VG_(tm_error_equal) (VgRes res, Error *e1, Error *e2); |
| 672 | //extern void VG_(tm_error_print) (Error *err); |
| 673 | // |
| 674 | //extern void VG_(tm_init) (); |
| 675 | // |
| 676 | //extern void VG_(tm_cond_init) (ThreadId tid, Addr condp); |
| 677 | //extern void VG_(tm_cond_destroy) (ThreadId tid, Addr condp); |
| 678 | //extern void VG_(tm_cond_wait) (ThreadId tid, Addr condp, Addr mutexp); |
| 679 | //extern void VG_(tm_cond_wakeup) (ThreadId tid, Addr condp, Addr mutexp); |
| 680 | //extern void VG_(tm_cond_signal) (ThreadId tid, Addr condp); |
| 681 | // |
| 682 | ///* ----- pthreads ----- */ |
| 683 | //extern void VG_(pthread_init) (); |
| 684 | //extern void VG_(pthread_startfunc_wrapper)(Addr wrapper); |
| 685 | // |
| 686 | //struct vg_pthread_newthread_data { |
| 687 | // void *(*startfunc)(void *arg); |
| 688 | // void *arg; |
| 689 | //}; |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 690 | |
| 691 | /* --------------------------------------------------------------------- |
| 692 | Finally - autoconf-generated settings |
| 693 | ------------------------------------------------------------------ */ |
| 694 | |
| 695 | #include "config.h" |
| 696 | |
nethercote | c06e213 | 2004-09-03 13:45:29 +0000 | [diff] [blame] | 697 | #endif /* ndef __CORE_H */ |
| 698 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 699 | /*--------------------------------------------------------------------*/ |
nethercote | 109d0df | 2004-09-02 08:10:13 +0000 | [diff] [blame] | 700 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 701 | /*--------------------------------------------------------------------*/ |