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 | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 40 | #include <setjmp.h> // for jmp_buf |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 41 | |
njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 42 | #include "pub_core_mallocfree.h" // for type 'ArenaId' |
| 43 | #include "pub_core_scheduler.h" // for types 'ThreadState', 'ThreadArchState' |
njn | 4f6e370 | 2005-05-16 20:50:52 +0000 | [diff] [blame] | 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 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 52 | /* Useful macros */ |
| 53 | /* a - alignment - must be a power of 2 */ |
tom | de2ec26 | 2005-03-29 12:16:10 +0000 | [diff] [blame] | 54 | #define ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1)) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 55 | #define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a)) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 56 | #define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE) |
| 57 | #define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 58 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 59 | |
nethercote | 80013e9 | 2004-09-05 20:39:51 +0000 | [diff] [blame] | 60 | /* --------------------------------------------------------------------- |
| 61 | Environment variables |
| 62 | ------------------------------------------------------------------ */ |
| 63 | |
| 64 | /* The directory we look for all our auxillary files in */ |
| 65 | #define VALGRINDLIB "VALGRINDLIB" |
| 66 | |
| 67 | /* Additional command-line arguments; they are overridden by actual |
| 68 | command-line option. Each argument is separated by spaces. There |
| 69 | is no quoting mechanism. |
| 70 | */ |
| 71 | #define VALGRINDOPTS "VALGRIND_OPTS" |
| 72 | |
| 73 | /* If this variable is present in the environment, then valgrind will |
| 74 | not parse the command line for options at all; all options come |
| 75 | from this variable. Arguments are terminated by ^A (\001). There |
| 76 | is no quoting mechanism. |
| 77 | |
| 78 | This variable is not expected to be set by anything other than |
| 79 | Valgrind itself, as part of its handling of execve with |
| 80 | --trace-children=yes. This variable should not be present in the |
| 81 | client environment. |
| 82 | */ |
| 83 | #define VALGRINDCLO "_VALGRIND_CLO" |
| 84 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 85 | |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 86 | /* Application-visible file descriptor limits */ |
| 87 | extern Int VG_(fd_soft_limit); |
| 88 | extern Int VG_(fd_hard_limit); |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 89 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 90 | /* --------------------------------------------------------------------- |
nethercote | 85cdd34 | 2004-08-01 22:36:40 +0000 | [diff] [blame] | 91 | Profiling stuff |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 92 | ------------------------------------------------------------------ */ |
| 93 | |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 94 | extern void VG_(init_profiling) ( void ); |
| 95 | extern void VG_(done_profiling) ( void ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 97 | #undef VGP_PUSHCC |
| 98 | #undef VGP_POPCC |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 99 | #define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x) |
| 100 | #define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 101 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 102 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 103 | /* --------------------------------------------------------------------- |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 104 | Exports of vg_intercept.c |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 105 | ------------------------------------------------------------------ */ |
| 106 | |
njn | a91498f | 2005-05-11 22:32:39 +0000 | [diff] [blame] | 107 | /* These are the internal client request codes. The publically-visible |
| 108 | request codes are also defined in valgrind.h, and similar headers for |
| 109 | some tools. */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 110 | |
njn | a91498f | 2005-05-11 22:32:39 +0000 | [diff] [blame] | 111 | /* Get the tool's malloc-wrapping functions */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 112 | #define VG_USERREQ__GET_MALLOCFUNCS 0x3030 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 113 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 114 | /* Internal equivalent of VALGRIND_PRINTF . */ |
| 115 | #define VG_USERREQ__INTERNAL_PRINTF 0x3103 |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 116 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 117 | /* Denote the finish of __libc_freeres_wrapper(). |
| 118 | A synonym for exit. */ |
| 119 | #define VG_USERREQ__LIBC_FREERES_DONE 0x3029 |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 120 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 121 | /* Intercept prefix stuff. See |
| 122 | coregrind/m_replace_malloc/vg_replace_malloc.c for details. |
| 123 | Unfortunately the "_vgi_" literal is also hardcoded in that file, so if |
| 124 | you change this one you must also change the other one. */ |
sewardj | 9ee81f5 | 2005-04-02 17:38:59 +0000 | [diff] [blame] | 125 | #define VG_INTERCEPT_PREFIX "_vgi_" |
| 126 | #define VG_INTERCEPT_PREFIX_LEN 5 |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 127 | |
sewardj | 9ee81f5 | 2005-04-02 17:38:59 +0000 | [diff] [blame] | 128 | /* Not sure what these are for. Todo: clarify */ |
| 129 | #define VG_WRAPPER_PREFIX "_vgw_" |
| 130 | #define VG_WRAPPER_PREFIX_LEN 5 |
| 131 | #define VG_WRAPPER(name) _vgw_##name |
| 132 | #define VG_WRAPPER_ALIAS(name) "_vgw_" #name |
rjwalsh | e4e779d | 2004-04-16 23:02:29 +0000 | [diff] [blame] | 133 | |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 134 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 135 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 136 | Exports of vg_mylibc.c |
| 137 | ------------------------------------------------------------------ */ |
| 138 | |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 139 | // Useful for making failing stubs, when certain things haven't yet been |
| 140 | // implemented. |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 141 | #define I_die_here \ |
sewardj | 0ab10c4 | 2005-05-12 08:26:36 +0000 | [diff] [blame] | 142 | VG_(assert_fail) (/*isCore*//*BOGUS*/True, \ |
| 143 | "Unimplemented functionality", \ |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 144 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 145 | "valgrind", VG_BUGS_TO, "") |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 146 | |
njn | 50ae1a7 | 2005-04-08 23:28:23 +0000 | [diff] [blame] | 147 | #define vg_assert(expr) \ |
| 148 | ((void) ((expr) ? 0 : \ |
| 149 | (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \ |
| 150 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 151 | ""), \ |
| 152 | 0))) |
| 153 | |
| 154 | #define vg_assert2(expr, format, args...) \ |
| 155 | ((void) ((expr) ? 0 : \ |
| 156 | (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \ |
| 157 | __FILE__, __LINE__, __PRETTY_FUNCTION__, \ |
| 158 | format, ##args), \ |
| 159 | 0))) |
| 160 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 161 | __attribute__ ((__noreturn__)) |
| 162 | extern void VG_(core_panic) ( Char* str ); |
thughes | 5876d55 | 2004-09-26 18:44:06 +0000 | [diff] [blame] | 163 | __attribute__ ((__noreturn__)) |
njn | db13c4f | 2005-06-01 00:00:46 +0000 | [diff] [blame^] | 164 | extern void VG_(core_panic_at) ( Char* str, Addr ip, Addr sp, Addr fp ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 165 | |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 166 | /* Called when some unhandleable client behaviour is detected. |
| 167 | Prints a msg and aborts. */ |
| 168 | extern void VG_(unimplemented) ( Char* msg ) |
| 169 | __attribute__((__noreturn__)); |
| 170 | |
| 171 | /* Tell the logging mechanism whether we are logging to a file |
| 172 | descriptor or a socket descriptor. */ |
| 173 | extern Bool VG_(logging_to_socket); |
| 174 | |
nethercote | 05675c8 | 2004-08-04 10:37:49 +0000 | [diff] [blame] | 175 | /* Tools use VG_(strdup)() which doesn't expose ArenaId */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 176 | extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 177 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 178 | extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 179 | extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 180 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 181 | /* system/mman.h */ |
njn | 7df470b | 2005-05-29 18:46:38 +0000 | [diff] [blame] | 182 | extern void* VG_(mmap) ( void* start, SizeT length, UInt prot, UInt flags, |
| 183 | UInt sf_flags, UInt fd, OffT offset ); |
| 184 | extern void* VG_(mmap_native)( void* start, SizeT length, UInt prot, UInt flags, |
| 185 | UInt fd, OffT offset ); |
| 186 | extern Int VG_(munmap) ( void* start, SizeT length ); |
| 187 | extern Int VG_(mprotect) ( void *start, SizeT length, UInt prot ); |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 188 | extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 189 | |
| 190 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 191 | /* Move an fd into the Valgrind-safe range */ |
| 192 | Int VG_(safe_fd)(Int oldfd); |
| 193 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 194 | extern Int VG_(write_socket)( Int sd, void *msg, Int count ); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 195 | |
| 196 | /* --- Connecting over the network --- */ |
| 197 | extern Int VG_(connect_via_socket)( UChar* str ); |
| 198 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 199 | /* Environment manipulations */ |
nethercote | 60a96c5 | 2004-08-03 13:08:31 +0000 | [diff] [blame] | 200 | extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname, |
| 201 | const Char *val ); |
| 202 | extern void VG_(env_unsetenv) ( Char **env, const Char *varname ); |
| 203 | extern void VG_(env_remove_valgrind_env_stuff) ( Char** env ); |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 204 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 205 | extern void VG_(nanosleep)(struct vki_timespec *); |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 206 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 207 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 208 | Exports of vg_syscall.S |
| 209 | ------------------------------------------------------------------ */ |
| 210 | |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 211 | // We use a full prototype rather than "..." here to ensure that all |
| 212 | // arguments get converted to a UWord appropriately. Not doing so can |
| 213 | // cause problems when passing 32-bit integers on 64-bit platforms, because |
| 214 | // the top 32-bits might not be zeroed appropriately, eg. as would happen |
| 215 | // with the 6th arg on AMD64 which is passed on the stack. |
njn | f4aeaea | 2004-11-29 17:33:31 +0000 | [diff] [blame] | 216 | extern Word VG_(do_syscall) ( UInt, UWord, UWord, UWord, UWord, UWord, UWord ); |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 217 | |
| 218 | // Macros make life easier. |
| 219 | #define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0,0) |
| 220 | #define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),0,0,0,0,0) |
| 221 | #define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),0,0,0,0) |
| 222 | #define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(c),0,0,0) |
| 223 | #define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),(c),(d),0,0) |
| 224 | #define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),(c),(d),(e),0) |
| 225 | #define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),(c),(d),(e),(f)) |
| 226 | |
fitzhardinge | 4f10ada | 2004-06-03 10:00:42 +0000 | [diff] [blame] | 227 | extern void VG_(sigreturn)(void); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 228 | |
| 229 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 230 | Exports of vg_helpers.S |
| 231 | ------------------------------------------------------------------ */ |
| 232 | |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 233 | /* Information about trampoline code (for signal return and syscalls) */ |
| 234 | extern const Char VG_(trampoline_code_start); |
| 235 | extern const Int VG_(trampoline_code_length); |
| 236 | extern const Int VG_(tramp_sigreturn_offset); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 237 | extern const Int VG_(tramp_rt_sigreturn_offset); |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 238 | extern const Int VG_(tramp_syscall_offset); |
tom | ee0bcbf | 2005-05-02 10:28:42 +0000 | [diff] [blame] | 239 | extern const Int VG_(tramp_gettimeofday_offset); |
| 240 | extern const Int VG_(tramp_time_offset); |
njn | 3c00878 | 2005-05-31 22:15:14 +0000 | [diff] [blame] | 241 | |
nethercote | c06e213 | 2004-09-03 13:45:29 +0000 | [diff] [blame] | 242 | // --------------------------------------------------------------------- |
| 243 | // Architecture-specific things defined in eg. x86/*.c |
| 244 | // --------------------------------------------------------------------- |
| 245 | |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 246 | // Returns the architecture and subarchitecture, or indicates |
| 247 | // that this subarchitecture is unable to run Valgrind |
| 248 | // Returns False to indicate we cannot proceed further. |
sewardj | 51ac087 | 2004-12-21 01:20:49 +0000 | [diff] [blame] | 249 | extern Bool VGA_(getArchAndSubArch)( /*OUT*/VexArch*, |
| 250 | /*OUT*/VexSubArch* ); |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 251 | // Accessors for the ThreadArchState |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 252 | #define INSTR_PTR(regs) ((regs).vex.VGA_INSTR_PTR) |
| 253 | #define STACK_PTR(regs) ((regs).vex.VGA_STACK_PTR) |
| 254 | #define FRAME_PTR(regs) ((regs).vex.VGA_FRAME_PTR) |
| 255 | #define CLREQ_ARGS(regs) ((regs).vex.VGA_CLREQ_ARGS) |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 256 | #define CLREQ_RET(regs) ((regs).vex.VGA_CLREQ_RET) |
njn | 16de557 | 2004-11-27 14:27:21 +0000 | [diff] [blame] | 257 | // Offsets for the Vex state |
njn | 35172bc | 2005-03-26 00:04:03 +0000 | [diff] [blame] | 258 | #define O_STACK_PTR (offsetof(VexGuestArchState, VGA_STACK_PTR)) |
| 259 | #define O_FRAME_PTR (offsetof(VexGuestArchState, VGA_FRAME_PTR)) |
| 260 | #define O_CLREQ_RET (offsetof(VexGuestArchState, VGA_CLREQ_RET)) |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 261 | |
| 262 | |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 263 | // Setting up the initial thread (1) state |
| 264 | extern void |
| 265 | VGA_(init_thread1state) ( Addr client_eip, |
| 266 | Addr esp_at_startup, |
| 267 | /*MOD*/ ThreadArchState* arch ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 268 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 269 | // OS/Platform-specific thread clear (after thread exit) |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 270 | extern void VGO_(os_state_clear)(ThreadState *); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 271 | |
| 272 | // OS/Platform-specific thread init (at scheduler init time) |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 273 | extern void VGO_(os_state_init)(ThreadState *); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 274 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 275 | // Run a thread from beginning to end. |
| 276 | extern VgSchedReturnCode VGO_(thread_wrapper)(Word /*ThreadId*/ tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 277 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 278 | // Call here to exit the entire Valgrind system. |
| 279 | extern void VGO_(terminate_NORETURN)(ThreadId tid, VgSchedReturnCode src); |
| 280 | |
| 281 | // Allocates a stack for the first thread, then runs it, |
| 282 | // as if the thread had been set up by clone() |
| 283 | extern void VGP_(main_thread_wrapper_NORETURN)(ThreadId tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 284 | |
| 285 | // Return how many bytes of a thread's Valgrind stack are unused |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 286 | extern SSizeT VGA_(stack_unused)(ThreadId tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 287 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 288 | // wait until all other threads are dead |
| 289 | extern void VGA_(reap_threads)(ThreadId self); |
| 290 | |
| 291 | // handle an arch-specific client request |
| 292 | extern Bool VGA_(client_request)(ThreadId tid, UWord *args); |
| 293 | |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 294 | // Pointercheck |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 295 | extern Bool VGA_(setup_pointercheck) ( Addr client_base, Addr client_end ); |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 296 | |
| 297 | // For attaching the debugger |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 298 | extern Int VGA_(ptrace_setregs_from_tst) ( Int pid, ThreadArchState* arch ); |
nethercote | fedd810 | 2004-09-13 15:19:34 +0000 | [diff] [blame] | 299 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 300 | // Used by leakcheck |
| 301 | extern void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr)); |
| 302 | |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 303 | // Set up the libc freeres wrapper |
| 304 | extern void VGA_(intercept_libc_freeres_wrapper)(Addr); |
| 305 | |
| 306 | // Clean up the client by calling before the final reports |
| 307 | extern void VGA_(final_tidyup)(ThreadId tid); |
| 308 | |
| 309 | // Arch-specific client requests |
| 310 | extern Bool VGA_(client_requests)(ThreadId tid, UWord *args); |
| 311 | |
nethercote | 9b3c765 | 2004-10-19 13:18:00 +0000 | [diff] [blame] | 312 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 313 | ///* --------------------------------------------------------------------- |
| 314 | // Thread modelling |
| 315 | // ------------------------------------------------------------------ */ |
| 316 | //extern void VG_(tm_thread_create) (ThreadId creator, ThreadId tid, Bool detached); |
| 317 | //extern void VG_(tm_thread_exit) (ThreadId tid); |
| 318 | //extern Bool VG_(tm_thread_exists) (ThreadId tid); |
| 319 | //extern void VG_(tm_thread_detach) (ThreadId tid); |
| 320 | //extern void VG_(tm_thread_join) (ThreadId joiner, ThreadId joinee); |
| 321 | //extern void VG_(tm_thread_switchto)(ThreadId tid); |
| 322 | // |
| 323 | //extern void VG_(tm_mutex_init) (ThreadId tid, Addr mutexp); |
| 324 | //extern void VG_(tm_mutex_destroy)(ThreadId tid, Addr mutexp); |
| 325 | //extern void VG_(tm_mutex_trylock)(ThreadId tid, Addr mutexp); |
| 326 | //extern void VG_(tm_mutex_giveup) (ThreadId tid, Addr mutexp); |
| 327 | //extern void VG_(tm_mutex_acquire)(ThreadId tid, Addr mutexp); |
| 328 | //extern void VG_(tm_mutex_tryunlock)(ThreadId tid, Addr mutexp); |
| 329 | //extern void VG_(tm_mutex_unlock) (ThreadId tid, Addr mutexp); |
| 330 | //extern Bool VG_(tm_mutex_exists) (Addr mutexp); |
| 331 | // |
| 332 | //extern UInt VG_(tm_error_update_extra) (Error *err); |
| 333 | //extern Bool VG_(tm_error_equal) (VgRes res, Error *e1, Error *e2); |
| 334 | //extern void VG_(tm_error_print) (Error *err); |
| 335 | // |
| 336 | //extern void VG_(tm_init) (); |
| 337 | // |
| 338 | //extern void VG_(tm_cond_init) (ThreadId tid, Addr condp); |
| 339 | //extern void VG_(tm_cond_destroy) (ThreadId tid, Addr condp); |
| 340 | //extern void VG_(tm_cond_wait) (ThreadId tid, Addr condp, Addr mutexp); |
| 341 | //extern void VG_(tm_cond_wakeup) (ThreadId tid, Addr condp, Addr mutexp); |
| 342 | //extern void VG_(tm_cond_signal) (ThreadId tid, Addr condp); |
| 343 | // |
| 344 | ///* ----- pthreads ----- */ |
| 345 | //extern void VG_(pthread_init) (); |
| 346 | //extern void VG_(pthread_startfunc_wrapper)(Addr wrapper); |
| 347 | // |
| 348 | //struct vg_pthread_newthread_data { |
| 349 | // void *(*startfunc)(void *arg); |
| 350 | // void *arg; |
| 351 | //}; |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 352 | |
| 353 | /* --------------------------------------------------------------------- |
| 354 | Finally - autoconf-generated settings |
| 355 | ------------------------------------------------------------------ */ |
| 356 | |
| 357 | #include "config.h" |
| 358 | |
nethercote | c06e213 | 2004-09-03 13:45:29 +0000 | [diff] [blame] | 359 | #endif /* ndef __CORE_H */ |
| 360 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 361 | /*--------------------------------------------------------------------*/ |
nethercote | 109d0df | 2004-09-02 08:10:13 +0000 | [diff] [blame] | 362 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 363 | /*--------------------------------------------------------------------*/ |