blob: 59d7932006ac62709cb374a91cf2cf47196a1b8d [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
njn717cde52005-05-10 02:47:21 +00003/*--- A header file for various private parts of Valgrind's core. ---*/
rjwalsh7109a8c2004-09-02 00:31:02 +00004/*--- core.h ---*/
sewardjde4a1d02002-03-22 01:27:54 +00005/*--------------------------------------------------------------------*/
6
7/*
njnb9c427c2004-12-01 14:14:42 +00008 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
sewardjde4a1d02002-03-22 01:27:54 +000010
njn53612422005-03-12 16:22:54 +000011 Copyright (C) 2000-2005 Julian Seward
sewardjde4a1d02002-03-22 01:27:54 +000012 jseward@acm.org
sewardjde4a1d02002-03-22 01:27:54 +000013
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
njn25e49d8e72002-09-23 09:36:25 +000029 The GNU General Public License is contained in the file COPYING.
sewardjde4a1d02002-03-22 01:27:54 +000030*/
31
rjwalsh7109a8c2004-09-02 00:31:02 +000032#ifndef __CORE_H
33#define __CORE_H
sewardjde4a1d02002-03-22 01:27:54 +000034
nethercote13343132004-09-02 15:49:09 +000035#include "tool.h" // tool stuff
nethercotebb4222b2004-09-10 17:42:11 +000036#include "core_arch.h" // arch-specific stuff, eg. x86/core_arch.h
nethercote8ff888f2004-11-17 17:11:45 +000037
38// Ugly: this is needed by linux/core_os.h
39typedef struct _ThreadState ThreadState;
40
nethercotebb4222b2004-09-10 17:42:11 +000041#include "core_platform.h" // platform-specific stuff,
42 // eg. x86-linux/core_platform.h
sewardjb5f6f512005-03-10 23:59:00 +000043#include "core_os.h" // OS-specific stuff, eg. linux/core_os.h
sewardjde4a1d02002-03-22 01:27:54 +000044
njn717cde52005-05-10 02:47:21 +000045#include "pub_core_mallocfree.h" // for type 'ArenaId'
njnd01fef72005-03-25 23:35:48 +000046#include "pub_core_stacktrace.h" // for type 'StackTrace'
47
njn4f6e3702005-05-16 20:50:52 +000048#include <setjmp.h> /* for jmp_buf */
49
nethercote7be47252004-09-02 16:02:58 +000050/* ---------------------------------------------------------------------
njn14319cc2005-03-13 06:26:22 +000051 Global macros.
nethercote7be47252004-09-02 16:02:58 +000052 ------------------------------------------------------------------ */
53
sewardjde4a1d02002-03-22 01:27:54 +000054/* Max length of a text fragment used to construct error messages. */
njn47b209a2005-03-25 23:47:16 +000055#define VG_ERRTXT_LEN 4096
sewardjde4a1d02002-03-22 01:27:54 +000056
sewardjde4a1d02002-03-22 01:27:54 +000057/* The maximum number of calls we're prepared to save in a
58 backtrace. */
59#define VG_DEEPEST_BACKTRACE 50
60
fitzhardinge98abfc72003-12-16 02:05:15 +000061/* Useful macros */
62/* a - alignment - must be a power of 2 */
tomde2ec262005-03-29 12:16:10 +000063#define ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1))
fitzhardinge98abfc72003-12-16 02:05:15 +000064#define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a))
nethercote73b526f2004-10-31 18:48:21 +000065#define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE)
66#define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE)
fitzhardinge98abfc72003-12-16 02:05:15 +000067
sewardj51ac0872004-12-21 01:20:49 +000068
nethercote80013e92004-09-05 20:39:51 +000069/* ---------------------------------------------------------------------
70 Environment variables
71 ------------------------------------------------------------------ */
72
73/* The directory we look for all our auxillary files in */
74#define VALGRINDLIB "VALGRINDLIB"
75
76/* Additional command-line arguments; they are overridden by actual
77 command-line option. Each argument is separated by spaces. There
78 is no quoting mechanism.
79 */
80#define VALGRINDOPTS "VALGRIND_OPTS"
81
82/* If this variable is present in the environment, then valgrind will
83 not parse the command line for options at all; all options come
84 from this variable. Arguments are terminated by ^A (\001). There
85 is no quoting mechanism.
86
87 This variable is not expected to be set by anything other than
88 Valgrind itself, as part of its handling of execve with
89 --trace-children=yes. This variable should not be present in the
90 client environment.
91 */
92#define VALGRINDCLO "_VALGRIND_CLO"
93
fitzhardinge98abfc72003-12-16 02:05:15 +000094
sewardjde4a1d02002-03-22 01:27:54 +000095/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +000096 Command-line-settable options
97 ------------------------------------------------------------------ */
98
sewardj4f094a72002-11-05 23:37:35 +000099/* Default destination port to be used in logging over a network, if
100 none specified. */
101#define VG_CLO_DEFAULT_LOGPORT 1500
sewardj73cf3bc2002-11-03 03:20:15 +0000102
103/* The max number of suppression files. */
sewardjde4a1d02002-03-22 01:27:54 +0000104#define VG_CLO_MAX_SFILES 10
105
thughesad1c9562004-06-26 11:27:52 +0000106/* Application-visible file descriptor limits */
107extern Int VG_(fd_soft_limit);
108extern Int VG_(fd_hard_limit);
fitzhardingef0046f22003-12-18 02:39:22 +0000109
sewardj8b635a42004-11-22 19:01:47 +0000110/* Vex iropt control */
111extern VexControl VG_(clo_vex_control);
sewardj72f98ff2002-06-13 17:23:38 +0000112/* Should we stop collecting errors if too many appear? default: YES */
sewardj2e432902002-06-13 20:44:00 +0000113extern Bool VG_(clo_error_limit);
nethercote04d0fbc2004-01-26 16:48:06 +0000114/* Enquire about whether to attach to a debugger at errors? default: NO */
115extern Bool VG_(clo_db_attach);
116/* The debugger command? default: whatever gdb ./configure found */
117extern Char* VG_(clo_db_command);
sewardjd153fae2005-01-10 17:24:47 +0000118/* Generating a suppression for each error? default: 0 (NO)
119 Other values: 1 (yes, but ask user), 2 (yes, don't ask user) */
120extern Int VG_(clo_gen_suppressions);
sewardjde4a1d02002-03-22 01:27:54 +0000121/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
nethercote27fec902004-06-16 21:26:32 +0000122extern Int VG_(clo_sanity_level);
sewardjde4a1d02002-03-22 01:27:54 +0000123/* Automatically attempt to demangle C++ names? default: YES */
124extern Bool VG_(clo_demangle);
sewardjde4a1d02002-03-22 01:27:54 +0000125/* Simulate child processes? default: NO */
126extern Bool VG_(clo_trace_children);
sewardj4cf05692002-10-27 20:28:29 +0000127
128/* Where logging output is to be sent to.
129
njnbe9b47b2005-05-15 16:22:58 +0000130 With --log-fd (and by default), clo_log_fd holds the file id, and is
131 taken from the command line. (fd 2, stderr, is the default.)
132 clo_log_name is irrelevant.
sewardj4cf05692002-10-27 20:28:29 +0000133
njnbe9b47b2005-05-15 16:22:58 +0000134 With --log-file/--log-file-exactly, clo_log_name holds the log-file
nethercotef8548672004-06-21 12:42:35 +0000135 name, and is taken from the command line. clo_log_fd is then
136 made to hold the relevant file id, by opening clo_log_name
sewardj4cf05692002-10-27 20:28:29 +0000137 (concatenated with the process ID) for writing.
138
njnbe9b47b2005-05-15 16:22:58 +0000139 With --log-socket, clo_log_name holds the hostname:portnumber pair,
140 and is taken from the command line. clo_log_fd is then made to hold
141 the relevant file handle, by opening a connection to that
142 hostname:portnumber pair.
sewardj4cf05692002-10-27 20:28:29 +0000143
nethercotef8548672004-06-21 12:42:35 +0000144 Global default is to set log_to == VgLogTo_Fd and log_fd == 2
sewardj4cf05692002-10-27 20:28:29 +0000145 (stderr). */
nethercotef8548672004-06-21 12:42:35 +0000146extern Int VG_(clo_log_fd);
147extern Char* VG_(clo_log_name);
sewardjde4a1d02002-03-22 01:27:54 +0000148
thughes6233a382004-08-21 11:10:44 +0000149/* Add timestamps to log messages? default: NO */
150extern Bool VG_(clo_time_stamp);
151
sewardj6024b212003-07-13 10:54:33 +0000152/* The file descriptor to read for input. default: 0 == stdin */
153extern Int VG_(clo_input_fd);
sewardjde4a1d02002-03-22 01:27:54 +0000154/* The number of suppression files specified. */
155extern Int VG_(clo_n_suppressions);
156/* The names of the suppression files. */
157extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
158
sewardjc771b292004-11-30 18:55:21 +0000159/* DEBUG: print generated code? default: 00000000 ( == NO ) */
sewardjfa8ec112005-01-19 11:55:34 +0000160extern Bool VG_(clo_trace_flags);
161/* DEBUG: do bb profiling? default: 00000000 ( == NO ) */
162extern Bool VG_(clo_profile_flags);
sewardjc771b292004-11-30 18:55:21 +0000163/* DEBUG: if tracing codegen, be quiet until after this bb ( 0 ) */
164extern Int VG_(clo_trace_notbelow);
sewardjde4a1d02002-03-22 01:27:54 +0000165/* DEBUG: print system calls? default: NO */
166extern Bool VG_(clo_trace_syscalls);
167/* DEBUG: print signal details? default: NO */
168extern Bool VG_(clo_trace_signals);
169/* DEBUG: print symtab details? default: NO */
170extern Bool VG_(clo_trace_symtab);
sewardjce058b02005-05-01 08:55:38 +0000171/* DEBUG: print call-frame-info details? default: NO */
172extern Bool VG_(clo_trace_cfi);
sewardjb5f6f512005-03-10 23:59:00 +0000173/* DEBUG: print redirection details? default: NO */
174extern Bool VG_(clo_trace_redir);
sewardj8937c812002-04-12 20:12:20 +0000175/* DEBUG: print thread scheduling events? default: NO */
176extern Bool VG_(clo_trace_sched);
sewardjb5f6f512005-03-10 23:59:00 +0000177/* DEBUG: print pthreads calls? default: NO */
178extern Bool VG_(clo_trace_pthreads);
sewardjde4a1d02002-03-22 01:27:54 +0000179/* Display gory details for the k'th most popular error. default:
180 Infinity. */
181extern Int VG_(clo_dump_error);
182/* Number of parents of a backtrace. Default: 8. */
183extern Int VG_(clo_backtrace_size);
daywalker7e73e5f2003-07-04 16:18:15 +0000184/* Engage miscellaneous weird hacks needed for some progs. */
sewardj8d365b52002-05-12 10:52:16 +0000185extern Char* VG_(clo_weird_hacks);
jsgf855d93d2003-10-13 22:26:55 +0000186
rjwalshf5f536f2003-11-17 17:45:00 +0000187/* Track open file descriptors? */
188extern Bool VG_(clo_track_fds);
189
sewardj858964b2002-10-05 14:15:43 +0000190/* Should we run __libc_freeres at exit? Sometimes causes crashes.
191 Default: YES. Note this is subservient to VG_(needs).libc_freeres;
192 if the latter says False, then the setting of VG_(clo_weird_hacks)
nethercote996901a2004-08-03 13:29:09 +0000193 is ignored. Ie if a tool says no, I don't want this to run, that
sewardj858964b2002-10-05 14:15:43 +0000194 cannot be overridden from the command line. */
195extern Bool VG_(clo_run_libc_freeres);
fitzhardinge462f4f92003-12-18 02:10:54 +0000196/* Generate branch-prediction hints? */
197extern Bool VG_(clo_branchpred);
nethercote77eba602003-11-13 17:35:04 +0000198/* Continue stack traces below main()? Default: NO */
199extern Bool VG_(clo_show_below_main);
fitzhardinge98abfc72003-12-16 02:05:15 +0000200/* Test each client pointer dereference to check it's within the
201 client address space bounds */
202extern Bool VG_(clo_pointercheck);
sewardjb5f6f512005-03-10 23:59:00 +0000203/* Model the pthread library */
204extern Bool VG_(clo_model_pthreads);
sewardjde4a1d02002-03-22 01:27:54 +0000205
sewardj062f3552005-01-06 16:13:40 +0000206/* HACK: Use hacked version of clone for Quadrics Elan3 drivers */
207extern Bool VG_(clo_support_elan3);
208
sewardjb1131a82005-03-19 15:12:21 +0000209/* Should we show VEX emulation warnings? Default: NO */
210extern Bool VG_(clo_show_emwarns);
211
sewardj97724e52005-04-02 23:40:59 +0000212/* How much does the stack pointer have to change before tools
213 consider a stack switch to have happened? Default: 2000000 bytes */
214extern Int VG_(clo_max_stackframe);
215
rjwalshe4e779d2004-04-16 23:02:29 +0000216/* Set up the libc freeres wrapper */
sewardjb5f6f512005-03-10 23:59:00 +0000217extern void VGA_(intercept_libc_freeres_wrapper)(Addr);
rjwalshe4e779d2004-04-16 23:02:29 +0000218
sewardjb5f6f512005-03-10 23:59:00 +0000219// Clean up the client by calling before the final reports
220extern void VGA_(final_tidyup)(ThreadId tid);
221
222// Arch-specific client requests
223extern Bool VGA_(client_requests)(ThreadId tid, UWord *args);
sewardj51ac0872004-12-21 01:20:49 +0000224
sewardjde4a1d02002-03-22 01:27:54 +0000225/* ---------------------------------------------------------------------
nethercote85cdd342004-08-01 22:36:40 +0000226 Profiling stuff
sewardjde4a1d02002-03-22 01:27:54 +0000227 ------------------------------------------------------------------ */
228
njn31066fd2005-03-26 00:42:02 +0000229extern void VG_(init_profiling) ( void );
230extern void VG_(done_profiling) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000231
njn25e49d8e72002-09-23 09:36:25 +0000232#undef VGP_PUSHCC
233#undef VGP_POPCC
njn31066fd2005-03-26 00:42:02 +0000234#define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x)
235#define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x)
sewardjde4a1d02002-03-22 01:27:54 +0000236
sewardj51ac0872004-12-21 01:20:49 +0000237
sewardjde4a1d02002-03-22 01:27:54 +0000238/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000239 Exports of vg_intercept.c
sewardj2e93c502002-04-12 11:12:52 +0000240 ------------------------------------------------------------------ */
241
njna91498f2005-05-11 22:32:39 +0000242/* These are the internal client request codes. The publically-visible
243 request codes are also defined in valgrind.h, and similar headers for
244 some tools. */
sewardj2e93c502002-04-12 11:12:52 +0000245
njna91498f2005-05-11 22:32:39 +0000246/* Get the tool's malloc-wrapping functions */
fitzhardinge98abfc72003-12-16 02:05:15 +0000247#define VG_USERREQ__GET_MALLOCFUNCS 0x3030
sewardjb5f6f512005-03-10 23:59:00 +0000248
fitzhardinge39de4b42003-10-31 07:12:21 +0000249/* Internal equivalent of VALGRIND_PRINTF . */
250#define VG_USERREQ__INTERNAL_PRINTF 0x3103
sewardj45b4b372002-04-16 22:50:32 +0000251
sewardjb5f6f512005-03-10 23:59:00 +0000252/* Denote the finish of __libc_freeres_wrapper().
253 A synonym for exit. */
254#define VG_USERREQ__LIBC_FREERES_DONE 0x3029
sewardj54cacf02002-04-12 23:24:59 +0000255
njn717cde52005-05-10 02:47:21 +0000256/* Intercept prefix stuff. See
257 coregrind/m_replace_malloc/vg_replace_malloc.c for details.
258 Unfortunately the "_vgi_" literal is also hardcoded in that file, so if
259 you change this one you must also change the other one. */
sewardj9ee81f52005-04-02 17:38:59 +0000260#define VG_INTERCEPT_PREFIX "_vgi_"
261#define VG_INTERCEPT_PREFIX_LEN 5
rjwalshe4e779d2004-04-16 23:02:29 +0000262
sewardj9ee81f52005-04-02 17:38:59 +0000263/* Not sure what these are for. Todo: clarify */
264#define VG_WRAPPER_PREFIX "_vgw_"
265#define VG_WRAPPER_PREFIX_LEN 5
266#define VG_WRAPPER(name) _vgw_##name
267#define VG_WRAPPER_ALIAS(name) "_vgw_" #name
rjwalshe4e779d2004-04-16 23:02:29 +0000268
njn4c791212003-05-02 17:53:54 +0000269
sewardj2e93c502002-04-12 11:12:52 +0000270/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000271 Exports of vg_scheduler.c
272 ------------------------------------------------------------------ */
273
sewardjb5f6f512005-03-10 23:59:00 +0000274/*
275 Thread state machine:
276
277 Empty -> Init -> Runnable <=> WaitSys/Yielding
278 ^ |
279 \---- Zombie -----/
280 */
sewardj2e93c502002-04-12 11:12:52 +0000281typedef
jsgf855d93d2003-10-13 22:26:55 +0000282 enum ThreadStatus {
sewardj2e93c502002-04-12 11:12:52 +0000283 VgTs_Empty, /* this slot is not in use */
sewardjb5f6f512005-03-10 23:59:00 +0000284 VgTs_Init, /* just allocated */
285 VgTs_Runnable, /* ready to run */
jsgf855d93d2003-10-13 22:26:55 +0000286 VgTs_WaitSys, /* waiting for a syscall to complete */
sewardjb5f6f512005-03-10 23:59:00 +0000287 VgTs_Yielding, /* temporarily yielding the CPU */
288 VgTs_Zombie, /* transient state just before exiting */
sewardj2e93c502002-04-12 11:12:52 +0000289 }
290 ThreadStatus;
sewardj8ad94e12002-05-29 00:10:20 +0000291
sewardjb5f6f512005-03-10 23:59:00 +0000292/* Return codes from the scheduler. */
thughes11975ff2004-06-12 12:58:22 +0000293typedef
sewardjb5f6f512005-03-10 23:59:00 +0000294 enum {
295 VgSrc_None, /* not exiting yet */
296 VgSrc_ExitSyscall, /* client called exit(). This is the normal
297 route out. */
298 VgSrc_FatalSig /* Killed by the default action of a fatal
299 signal */
thughes11975ff2004-06-12 12:58:22 +0000300 }
sewardjb5f6f512005-03-10 23:59:00 +0000301 VgSchedReturnCode;
thughes11975ff2004-06-12 12:58:22 +0000302
sewardjb5f6f512005-03-10 23:59:00 +0000303struct _ThreadState {
njn25e49d8e72002-09-23 09:36:25 +0000304 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
305 The thread identity is simply the index in vg_threads[].
306 ThreadId == 1 is the root thread and has the special property
307 that we don't try and allocate or deallocate its stack. For
308 convenience of generating error message, we also put the
309 ThreadId in this tid field, but be aware that it should
310 ALWAYS == the index in vg_threads[]. */
311 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000312
sewardjb5f6f512005-03-10 23:59:00 +0000313 /* Current scheduling status. */
njn25e49d8e72002-09-23 09:36:25 +0000314 ThreadStatus status;
sewardj2e93c502002-04-12 11:12:52 +0000315
sewardjb5f6f512005-03-10 23:59:00 +0000316 /* This is set if the thread is in the process of exiting for any
317 reason. The precise details of the exit are in the OS-specific
318 state. */
319 VgSchedReturnCode exitreason;
sewardj3b5d8862002-04-20 13:53:23 +0000320
sewardjb5f6f512005-03-10 23:59:00 +0000321 /* Architecture-specific thread state. */
322 ThreadArchState arch;
sewardjb48e5002002-05-13 00:16:03 +0000323
njn25e49d8e72002-09-23 09:36:25 +0000324 /* This thread's blocked-signals mask. Semantics is that for a
325 signal to be delivered to this thread, the signal must not be
jsgf855d93d2003-10-13 22:26:55 +0000326 blocked by this signal mask. If more than one thread accepts a
327 signal, then it will be delivered to one at random. If all
328 threads block the signal, it will remain pending until either a
sewardjb5f6f512005-03-10 23:59:00 +0000329 thread unblocks it or someone uses sigwaitsig/sigtimedwait. */
nethercote73b526f2004-10-31 18:48:21 +0000330 vki_sigset_t sig_mask;
sewardjb48e5002002-05-13 00:16:03 +0000331
sewardjb5f6f512005-03-10 23:59:00 +0000332 /* tmp_sig_mask is usually the same as sig_mask, and is kept in
333 sync whenever sig_mask is changed. The only time they have
334 different values is during the execution of a sigsuspend, where
335 tmp_sig_mask is the temporary mask which sigsuspend installs.
336 It is only consulted to compute the signal mask applied to a
337 signal handler. */
338 vki_sigset_t tmp_sig_mask;
sewardj2e93c502002-04-12 11:12:52 +0000339
sewardjb5f6f512005-03-10 23:59:00 +0000340 /* A little signal queue for signals we can't get the kernel to
341 queue for us. This is only allocated as needed, since it should
342 be rare. */
343 struct SigQueue *sig_queue;
344
345 /* Syscall the Thread is currently running; -1 if none. Should only
346 be set while Thread is in VgTs_WaitSys. */
347 Int syscallno;
348
349 /* A value the Tool wants to pass from its pre-syscall to its
350 post-syscall function. */
351 void *tool_pre_syscall_value;
thughes8abf3922004-10-16 10:59:49 +0000352
njn50ba34e2005-04-04 02:41:42 +0000353 /* Client stacks. When a thread slot is freed, we don't deallocate its
njn25e49d8e72002-09-23 09:36:25 +0000354 stack; we just leave it lying around for the next use of the
355 slot. If the next use of the slot requires a larger stack,
356 only then is the old one deallocated and a new one
357 allocated.
sewardj2e93c502002-04-12 11:12:52 +0000358
njn25e49d8e72002-09-23 09:36:25 +0000359 For the main thread (threadid == 0), this mechanism doesn't
360 apply. We don't know the size of the stack since we didn't
361 allocate it, and furthermore we never reallocate it. */
sewardj2e93c502002-04-12 11:12:52 +0000362
njn25e49d8e72002-09-23 09:36:25 +0000363 /* The allocated size of this thread's stack (permanently zero
364 if this is ThreadId == 0, since we didn't allocate its stack) */
njn50ba34e2005-04-04 02:41:42 +0000365 SizeT client_stack_szB;
sewardj2e93c502002-04-12 11:12:52 +0000366
sewardj92a59562002-09-30 00:53:10 +0000367 /* Address of the highest legitimate word in this stack. This is
368 used for error messages only -- not critical for execution
369 correctness. Is is set for all stacks, specifically including
370 ThreadId == 0 (the main thread). */
njn50ba34e2005-04-04 02:41:42 +0000371 Addr client_stack_highest_word;
njn25e49d8e72002-09-23 09:36:25 +0000372
fitzhardinge98c4dc02004-03-16 08:27:29 +0000373 /* Alternate signal stack */
nethercote73b526f2004-10-31 18:48:21 +0000374 vki_stack_t altstack;
fitzhardinge98c4dc02004-03-16 08:27:29 +0000375
sewardjb5f6f512005-03-10 23:59:00 +0000376 /* OS-specific thread state */
377 os_thread_t os_state;
sewardj004e8ca2005-02-28 17:27:04 +0000378
379 /* Used in the syscall handlers. Set to True to indicate that the
380 PRE routine for a syscall has set the syscall result already and
381 so the syscall does not need to be handed to the kernel. */
382 Bool syscall_result_set;
sewardjb5f6f512005-03-10 23:59:00 +0000383
384 /* Per-thread jmp_buf to resume scheduler after a signal */
385 Bool sched_jmpbuf_valid;
386 jmp_buf sched_jmpbuf;
nethercote8ff888f2004-11-17 17:11:45 +0000387};
sewardj2e93c502002-04-12 11:12:52 +0000388
sewardj018f7622002-05-15 21:13:39 +0000389/* The thread table. */
390extern ThreadState VG_(threads)[VG_N_THREADS];
391
sewardjb5f6f512005-03-10 23:59:00 +0000392/* Allocate a new ThreadState */
393extern ThreadId VG_(alloc_ThreadState)(void);
394
395/* A thread exits. tid must currently be running. */
396extern void VG_(exit_thread)(ThreadId tid);
397
398/* Kill a thread. This interrupts whatever a thread is doing, and
399 makes it exit ASAP. This does not set the exitreason or
400 exitcode. */
401extern void VG_(kill_thread)(ThreadId tid);
402
sewardj018f7622002-05-15 21:13:39 +0000403/* Check that tid is in range and denotes a non-Empty thread. */
sewardjb48e5002002-05-13 00:16:03 +0000404extern Bool VG_(is_valid_tid) ( ThreadId tid );
405
jsgf855d93d2003-10-13 22:26:55 +0000406/* Get the ThreadState for a particular thread */
407extern ThreadState *VG_(get_ThreadState)(ThreadId tid);
408
sewardjb5f6f512005-03-10 23:59:00 +0000409/* Given an LWP id (ie, real kernel thread id), find the corresponding
410 ThreadId */
411extern ThreadId VG_(get_lwp_tid)(Int lwpid);
412
413/* Returns true if a thread is currently running (ie, has the CPU lock) */
414extern Bool VG_(is_running_thread)(ThreadId tid);
415
416/* Returns true if the thread is in the process of exiting */
417extern Bool VG_(is_exiting)(ThreadId tid);
418
419/* Return the number of non-dead Threads */
420extern Int VG_(count_living_threads)(void);
421
sewardjccef2e62002-05-29 19:26:32 +0000422/* Nuke all threads except tid. */
sewardjb5f6f512005-03-10 23:59:00 +0000423extern void VG_(nuke_all_threads_except) ( ThreadId me, VgSchedReturnCode reason );
sewardjccef2e62002-05-29 19:26:32 +0000424
sewardjb5f6f512005-03-10 23:59:00 +0000425/* Make a thread the running thread. The thread must previously been
426 sleeping, and not holding the CPU semaphore. This will set the
427 thread state to VgTs_Runnable, and the thread will attempt to take
428 the CPU semaphore. By the time it returns, tid will be the running
429 thread. */
430extern void VG_(set_running) ( ThreadId tid );
jsgf855d93d2003-10-13 22:26:55 +0000431
sewardjb5f6f512005-03-10 23:59:00 +0000432/* Set a thread into a sleeping state. Before the call, the thread
433 must be runnable, and holding the CPU semaphore. When this call
434 returns, the thread will be set to the specified sleeping state,
435 and will not be holding the CPU semaphore. Note that another
436 thread could be running by the time this call returns, so the
437 caller must be careful not to touch any shared state. It is also
438 the caller's responsibility to actually block until the thread is
439 ready to run again. */
440extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state );
sewardj2e93c502002-04-12 11:12:52 +0000441
sewardjb5f6f512005-03-10 23:59:00 +0000442/* Yield the CPU for a while */
443extern void VG_(vg_yield)(void);
sewardj7e87e382002-05-03 19:09:05 +0000444
sewardjb5f6f512005-03-10 23:59:00 +0000445// The scheduler.
446extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid );
447
448// Do everything which needs doing before the process finally ends,
449// like printing reports, etc
450extern void VG_(shutdown_actions)(ThreadId tid);
sewardj2e93c502002-04-12 11:12:52 +0000451
452extern void VG_(scheduler_init) ( void );
453
sewardj15a43e12002-04-17 19:35:12 +0000454extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000455
nethercote75d26242004-08-01 22:59:18 +0000456// Longjmp back to the scheduler and thus enter the sighandler immediately.
sewardjb5f6f512005-03-10 23:59:00 +0000457extern void VG_(resume_scheduler) ( ThreadId tid );
sewardj2e93c502002-04-12 11:12:52 +0000458
sewardjb5f6f512005-03-10 23:59:00 +0000459/* If true, a fault is Valgrind-internal (ie, a bug) */
460extern Bool VG_(my_fault);
nethercote238a3c32004-08-09 13:13:31 +0000461
sewardj2e93c502002-04-12 11:12:52 +0000462/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000463 Exports of vg_signals.c
464 ------------------------------------------------------------------ */
465
sewardjb5f6f512005-03-10 23:59:00 +0000466/* Highest signal the kernel will let us use */
467extern Int VG_(max_signal);
jsgf855d93d2003-10-13 22:26:55 +0000468
sewardjde4a1d02002-03-22 01:27:54 +0000469extern void VG_(sigstartup_actions) ( void );
470
jsgf855d93d2003-10-13 22:26:55 +0000471extern Bool VG_(is_sig_ign) ( Int sigNo );
472
sewardjb5f6f512005-03-10 23:59:00 +0000473/* Poll a thread's set of pending signals, and update the Thread's context to deliver one */
474extern void VG_(poll_signals) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000475
476/* Fake system calls for signal handling. */
njn502badb2005-05-08 02:04:49 +0000477extern Int VG_(do_sys_sigaltstack) ( ThreadId tid, vki_stack_t* ss,
478 vki_stack_t* oss );
479extern Int VG_(do_sys_sigaction) ( Int signo,
480 const struct vki_sigaction *new_act,
481 struct vki_sigaction *old_act );
482extern Int VG_(do_sys_sigprocmask) ( ThreadId tid, Int how,
483 vki_sigset_t* set,
484 vki_sigset_t* oldset );
sewardjefbfcdf2002-06-19 17:35:45 +0000485
njn444eba12005-05-12 03:47:31 +0000486extern void VG_(clear_out_queued_signals)
487 ( ThreadId tid, /* OUT */ vki_sigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000488
jsgf855d93d2003-10-13 22:26:55 +0000489extern void VG_(kill_self)(Int sigNo);
490
fitzhardingef1beb252004-03-16 09:49:08 +0000491/* These function synthesize a fault, as if the running instruction
492 had had a fault. These functions do not return - they longjmp back
493 into the scheduler so the signal can be delivered. */
494extern void VG_(synth_fault) (ThreadId tid);
495extern void VG_(synth_fault_mapping)(ThreadId tid, Addr addr);
496extern void VG_(synth_fault_perms) (ThreadId tid, Addr addr);
sewardj5e2f0012004-12-13 14:10:34 +0000497extern void VG_(synth_sigill) (ThreadId tid, Addr addr);
fitzhardingef1beb252004-03-16 09:49:08 +0000498
sewardjb5f6f512005-03-10 23:59:00 +0000499/* Extend the stack to cover addr, if possible */
500extern Bool VG_(extend_stack)(Addr addr, UInt maxsize);
501
502/* Returns True if the signal is OK for the client to use */
503extern Bool VG_(client_signal_OK)(Int sigNo);
504
505/* Forces the client's signal handler to SIG_DFL - generally just
506 before using that signal to kill the process. */
507extern void VG_(set_default_handler)(Int sig);
508
509/* Adjust a client's signal mask to match our internal requirements */
510extern void VG_(sanitize_client_sigmask)(ThreadId tid, vki_sigset_t *mask);
511
512/* Wait until a thread-related predicate is true */
513extern void VG_(wait_for_threadstate)(Bool (*pred)(void *), void *arg);
sewardj51ac0872004-12-21 01:20:49 +0000514
sewardjde4a1d02002-03-22 01:27:54 +0000515/* ---------------------------------------------------------------------
516 Exports of vg_mylibc.c
517 ------------------------------------------------------------------ */
518
njnca0518d2004-11-26 19:34:36 +0000519// Useful for making failing stubs, when certain things haven't yet been
520// implemented.
njn50ae1a72005-04-08 23:28:23 +0000521#define I_die_here \
sewardj0ab10c42005-05-12 08:26:36 +0000522 VG_(assert_fail) (/*isCore*//*BOGUS*/True, \
523 "Unimplemented functionality", \
njn50ae1a72005-04-08 23:28:23 +0000524 __FILE__, __LINE__, __PRETTY_FUNCTION__, \
525 "valgrind", VG_BUGS_TO, "")
njnca0518d2004-11-26 19:34:36 +0000526
njn50ae1a72005-04-08 23:28:23 +0000527#define vg_assert(expr) \
528 ((void) ((expr) ? 0 : \
529 (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \
530 __FILE__, __LINE__, __PRETTY_FUNCTION__, \
531 ""), \
532 0)))
533
534#define vg_assert2(expr, format, args...) \
535 ((void) ((expr) ? 0 : \
536 (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr), \
537 __FILE__, __LINE__, __PRETTY_FUNCTION__, \
538 format, ##args), \
539 0)))
540
njne427a662002-10-02 11:08:25 +0000541__attribute__ ((__noreturn__))
542extern void VG_(core_panic) ( Char* str );
thughes5876d552004-09-26 18:44:06 +0000543__attribute__ ((__noreturn__))
njnd01fef72005-03-25 23:35:48 +0000544extern void VG_(core_panic_at) ( Char* str, StackTrace ips );
sewardjde4a1d02002-03-22 01:27:54 +0000545
nethercote05675c82004-08-04 10:37:49 +0000546/* Tools use VG_(strdup)() which doesn't expose ArenaId */
njn25e49d8e72002-09-23 09:36:25 +0000547extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
sewardjde4a1d02002-03-22 01:27:54 +0000548
njn25e49d8e72002-09-23 09:36:25 +0000549extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
jsgf855d93d2003-10-13 22:26:55 +0000550extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout);
sewardj2e93c502002-04-12 11:12:52 +0000551
fitzhardinge98abfc72003-12-16 02:05:15 +0000552/* system/mman.h */
nethercote8b5f40c2004-11-02 13:29:50 +0000553extern void* VG_(mmap)( void* start, SizeT length, UInt prot, UInt flags,
nethercote5b9fafd2004-11-04 18:39:22 +0000554 UInt sf_flags, UInt fd, OffT offset );
nethercote8b5f40c2004-11-02 13:29:50 +0000555extern Int VG_(munmap)( void* start, SizeT length );
556extern Int VG_(mprotect)( void *start, SizeT length, UInt prot );
sewardj79048ce2005-02-18 08:28:32 +0000557extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot );
fitzhardinge98abfc72003-12-16 02:05:15 +0000558
559
jsgf855d93d2003-10-13 22:26:55 +0000560/* Move an fd into the Valgrind-safe range */
561Int VG_(safe_fd)(Int oldfd);
562
sewardj570f8902002-11-03 11:44:36 +0000563extern Int VG_(write_socket)( Int sd, void *msg, Int count );
sewardj73cf3bc2002-11-03 03:20:15 +0000564
565/* --- Connecting over the network --- */
566extern Int VG_(connect_via_socket)( UChar* str );
567
fitzhardinge98abfc72003-12-16 02:05:15 +0000568/* Environment manipulations */
nethercote60a96c52004-08-03 13:08:31 +0000569extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname,
570 const Char *val );
571extern void VG_(env_unsetenv) ( Char **env, const Char *varname );
572extern void VG_(env_remove_valgrind_env_stuff) ( Char** env );
sewardj570f8902002-11-03 11:44:36 +0000573
sewardjb5f6f512005-03-10 23:59:00 +0000574extern void VG_(nanosleep)(struct vki_timespec *);
njn2521d322005-05-08 14:45:13 +0000575
sewardj570f8902002-11-03 11:44:36 +0000576/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000577 Exports of vg_symtab2.c
578 ------------------------------------------------------------------ */
579
fitzhardinge98abfc72003-12-16 02:05:15 +0000580typedef struct _Segment Segment;
sewardjb5f6f512005-03-10 23:59:00 +0000581typedef struct _CodeRedirect CodeRedirect;
fitzhardinge98abfc72003-12-16 02:05:15 +0000582
583extern Bool VG_(is_object_file) ( const void *hdr );
fitzhardinge98abfc72003-12-16 02:05:15 +0000584extern SegInfo * VG_(read_seg_symbols) ( Segment *seg );
njn36ef6ba2005-05-14 18:42:26 +0000585extern void VG_(seginfo_incref) ( SegInfo * );
586extern void VG_(seginfo_decref) ( SegInfo *, Addr a );
sewardjde4a1d02002-03-22 01:27:54 +0000587
njn25e49d8e72002-09-23 09:36:25 +0000588extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname );
sewardj25c7c3a2003-07-10 00:17:58 +0000589
sewardjb5f6f512005-03-10 23:59:00 +0000590extern Addr VG_(reverse_search_one_symtab) ( const SegInfo* si, const Char* name );
591
sewardj35165532005-04-30 18:47:48 +0000592extern Bool VG_(use_CFI_info) ( /*MOD*/Addr* ipP,
593 /*MOD*/Addr* spP,
594 /*MOD*/Addr* fpP,
595 Addr min_accessible,
596 Addr max_accessible );
597
598
sewardjb5f6f512005-03-10 23:59:00 +0000599/* ---------------------------------------------------------------------
600 Exports of vg_redir.c
601 ------------------------------------------------------------------ */
njn36b66df2005-05-12 05:13:04 +0000602
fitzhardinge98abfc72003-12-16 02:05:15 +0000603/* Redirection machinery */
nethercote85cdd342004-08-01 22:36:40 +0000604extern Addr VG_(code_redirect) ( Addr orig );
sewardjde4a1d02002-03-22 01:27:54 +0000605
njn36b66df2005-05-12 05:13:04 +0000606/* Set up some default redirects */
607extern void VG_(setup_code_redirect_table) ( void );
608
tom748a1312005-04-02 15:53:01 +0000609extern void VG_(add_redirect_sym_to_addr)(const Char *from_lib,
610 const Char *from_sym,
611 Addr to_addr);
612extern void VG_(add_redirect_addr_to_addr)(Addr from_addr, Addr to_addr);
sewardjb5f6f512005-03-10 23:59:00 +0000613extern void VG_(resolve_seg_redirs)(SegInfo *si);
sewardjb5f6f512005-03-10 23:59:00 +0000614
615/* Wrapping machinery */
616enum return_type {
617 RT_RETURN,
618 RT_LONGJMP,
619 RT_EXIT,
620};
621
622typedef struct _FuncWrapper FuncWrapper;
623struct _FuncWrapper {
624 void *(*before)(va_list args);
625 void (*after) (void *nonce, enum return_type, Word retval);
626};
627
628extern void VG_(wrap_function)(Addr eip, const FuncWrapper *wrapper);
629extern const FuncWrapper *VG_(is_wrapped)(Addr eip);
630extern Bool VG_(is_wrapper_return)(Addr eip);
631
632/* Primary interface for adding wrappers for client-side functions. */
633extern CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sym,
634 const FuncWrapper *wrapper);
635
636extern Bool VG_(is_resolved)(const CodeRedirect *redir);
sewardj51ac0872004-12-21 01:20:49 +0000637
sewardjde4a1d02002-03-22 01:27:54 +0000638/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000639 Exports of vg_main.c
640 ------------------------------------------------------------------ */
641
sewardj73cf3bc2002-11-03 03:20:15 +0000642/* Tell the logging mechanism whether we are logging to a file
643 descriptor or a socket descriptor. */
njnbe9b47b2005-05-15 16:22:58 +0000644extern Bool VG_(logging_to_socket);
sewardj73cf3bc2002-11-03 03:20:15 +0000645
njn25e49d8e72002-09-23 09:36:25 +0000646/* Sanity checks which may be done at any time. The scheduler decides when. */
nethercote885dd912004-08-03 23:14:00 +0000647extern void VG_(sanity_check_general) ( Bool force_expensive );
njn25e49d8e72002-09-23 09:36:25 +0000648
fitzhardinge98abfc72003-12-16 02:05:15 +0000649/* Address space */
650extern Addr VG_(client_base); /* client address space limits */
651extern Addr VG_(client_end);
652extern Addr VG_(client_mapbase); /* base of mappings */
653extern Addr VG_(clstk_base); /* client stack range */
654extern Addr VG_(clstk_end);
fitzhardinge92360792003-12-24 10:11:11 +0000655extern Addr VG_(client_trampoline_code);
656
fitzhardinge98abfc72003-12-16 02:05:15 +0000657extern Addr VG_(brk_base); /* start of brk */
658extern Addr VG_(brk_limit); /* current brk */
nethercote996901a2004-08-03 13:29:09 +0000659extern Addr VG_(shadow_base); /* tool's shadow memory */
fitzhardinge98abfc72003-12-16 02:05:15 +0000660extern Addr VG_(shadow_end);
661extern Addr VG_(valgrind_base); /* valgrind's address range */
nethercote820bd8c2004-09-07 23:04:49 +0000662extern Addr VG_(valgrind_last); // Nb: last byte, rather than one past the end
fitzhardinge98abfc72003-12-16 02:05:15 +0000663
nethercote73b526f2004-10-31 18:48:21 +0000664extern struct vki_rlimit VG_(client_rlimit_data); /* client's original rlimit data */
665extern struct vki_rlimit VG_(client_rlimit_stack); /* client's original rlimit stack */
fitzhardingeb50068f2004-02-24 23:42:55 +0000666
fitzhardingea49f9b52003-12-16 22:26:45 +0000667/* client executable file descriptor */
668extern Int VG_(clexecfd);
fitzhardinge98abfc72003-12-16 02:05:15 +0000669
nethercotef6a1d502004-08-09 12:21:57 +0000670// Help set up the child used when doing execve() with --trace-children=yes
671Char* VG_(build_child_VALGRINDCLO) ( Char* exename );
672Char* VG_(build_child_exename) ( void );
673
sewardjb5f6f512005-03-10 23:59:00 +0000674/* The master thread the one which will be responsible for mopping
675 everything up at exit. Normally it is tid 1, since that's the
676 first thread created, but it may be something else after a
677 fork(). */
678extern ThreadId VG_(master_tid);
679
sewardjde4a1d02002-03-22 01:27:54 +0000680/* Called when some unhandleable client behaviour is detected.
681 Prints a msg and aborts. */
njn25e49d8e72002-09-23 09:36:25 +0000682extern void VG_(unimplemented) ( Char* msg )
683 __attribute__((__noreturn__));
sewardjde4a1d02002-03-22 01:27:54 +0000684
nethercote04d0fbc2004-01-26 16:48:06 +0000685/* Something of a function looking for a home ... start up debugger. */
njnc6168192004-11-29 13:54:10 +0000686extern void VG_(start_debugger) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +0000687
sewardjde4a1d02002-03-22 01:27:54 +0000688/* Counts downwards in vg_run_innerloop. */
689extern UInt VG_(dispatch_ctr);
690
sewardj4ccf7072004-11-28 16:58:05 +0000691/* Stats ... */
nethercote844e7122004-08-02 15:27:22 +0000692extern void VG_(print_scheduler_stats) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000693
njn1f707722005-03-27 03:17:52 +0000694/* 64-bit counter for the number of basic blocks done. */
695extern ULong VG_(bbs_done);
696
nethercote2e05c332004-09-06 16:43:37 +0000697
sewardjde4a1d02002-03-22 01:27:54 +0000698/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000699 Exports of vg_syscall.S
700 ------------------------------------------------------------------ */
701
njnca6fef02004-11-29 16:49:18 +0000702// We use a full prototype rather than "..." here to ensure that all
703// arguments get converted to a UWord appropriately. Not doing so can
704// cause problems when passing 32-bit integers on 64-bit platforms, because
705// the top 32-bits might not be zeroed appropriately, eg. as would happen
706// with the 6th arg on AMD64 which is passed on the stack.
njnf4aeaea2004-11-29 17:33:31 +0000707extern Word VG_(do_syscall) ( UInt, UWord, UWord, UWord, UWord, UWord, UWord );
njnca6fef02004-11-29 16:49:18 +0000708
709// Macros make life easier.
710#define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0,0)
711#define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),0,0,0,0,0)
712#define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),0,0,0,0)
713#define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(c),0,0,0)
714#define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),(c),(d),0,0)
715#define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),(c),(d),(e),0)
716#define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),(c),(d),(e),(f))
717
fitzhardinge4f10ada2004-06-03 10:00:42 +0000718extern void VG_(sigreturn)(void);
sewardjde4a1d02002-03-22 01:27:54 +0000719
720/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000721 Exports of vg_helpers.S
722 ------------------------------------------------------------------ */
723
fitzhardinge92360792003-12-24 10:11:11 +0000724/* Information about trampoline code (for signal return and syscalls) */
725extern const Char VG_(trampoline_code_start);
726extern const Int VG_(trampoline_code_length);
727extern const Int VG_(tramp_sigreturn_offset);
sewardjb5f6f512005-03-10 23:59:00 +0000728extern const Int VG_(tramp_rt_sigreturn_offset);
fitzhardinge92360792003-12-24 10:11:11 +0000729extern const Int VG_(tramp_syscall_offset);
tomee0bcbf2005-05-02 10:28:42 +0000730extern const Int VG_(tramp_gettimeofday_offset);
731extern const Int VG_(tramp_time_offset);
sewardj20917d82002-05-28 01:36:45 +0000732
nethercotec06e2132004-09-03 13:45:29 +0000733// ---------------------------------------------------------------------
734// Architecture-specific things defined in eg. x86/*.c
735// ---------------------------------------------------------------------
736
sewardj51ac0872004-12-21 01:20:49 +0000737// Returns the architecture and subarchitecture, or indicates
738// that this subarchitecture is unable to run Valgrind
739// Returns False to indicate we cannot proceed further.
sewardj51ac0872004-12-21 01:20:49 +0000740extern Bool VGA_(getArchAndSubArch)( /*OUT*/VexArch*,
741 /*OUT*/VexSubArch* );
njncf45fd42004-11-24 16:30:22 +0000742// Accessors for the ThreadArchState
njn35172bc2005-03-26 00:04:03 +0000743#define INSTR_PTR(regs) ((regs).vex.VGA_INSTR_PTR)
744#define STACK_PTR(regs) ((regs).vex.VGA_STACK_PTR)
745#define FRAME_PTR(regs) ((regs).vex.VGA_FRAME_PTR)
746#define CLREQ_ARGS(regs) ((regs).vex.VGA_CLREQ_ARGS)
njn35172bc2005-03-26 00:04:03 +0000747#define CLREQ_RET(regs) ((regs).vex.VGA_CLREQ_RET)
njn16de5572004-11-27 14:27:21 +0000748// Offsets for the Vex state
njn35172bc2005-03-26 00:04:03 +0000749#define O_STACK_PTR (offsetof(VexGuestArchState, VGA_STACK_PTR))
750#define O_FRAME_PTR (offsetof(VexGuestArchState, VGA_FRAME_PTR))
751#define O_CLREQ_RET (offsetof(VexGuestArchState, VGA_CLREQ_RET))
njncf45fd42004-11-24 16:30:22 +0000752
753
sewardj2a99cf62004-11-24 10:44:19 +0000754// Setting up the initial thread (1) state
755extern void
756 VGA_(init_thread1state) ( Addr client_eip,
757 Addr esp_at_startup,
758 /*MOD*/ ThreadArchState* arch );
sewardjde4a1d02002-03-22 01:27:54 +0000759
sewardjb5f6f512005-03-10 23:59:00 +0000760// OS/Platform-specific thread clear (after thread exit)
761extern void VGA_(os_state_clear)(ThreadState *);
762
763// OS/Platform-specific thread init (at scheduler init time)
764extern void VGA_(os_state_init)(ThreadState *);
765
766// Run a thread from beginning to end. Does not return if tid == VG_(master_tid).
sewardj0c1a5962005-03-22 00:19:55 +0000767void VGA_(thread_wrapper)(Word /*ThreadId*/ tid);
sewardjb5f6f512005-03-10 23:59:00 +0000768
769// Like VGA_(thread_wrapper), but it allocates a stack before calling
770// to VGA_(thread_wrapper) on that stack, as if it had been set up by
771// clone()
772void VGA_(main_thread_wrapper)(ThreadId tid) __attribute__ ((__noreturn__));
773
774// Return how many bytes of a thread's Valgrind stack are unused
njn990e90c2005-04-05 02:49:09 +0000775SSizeT VGA_(stack_unused)(ThreadId tid);
sewardjb5f6f512005-03-10 23:59:00 +0000776
sewardjb5f6f512005-03-10 23:59:00 +0000777// wait until all other threads are dead
778extern void VGA_(reap_threads)(ThreadId self);
779
780// handle an arch-specific client request
781extern Bool VGA_(client_request)(ThreadId tid, UWord *args);
782
nethercotefedd8102004-09-13 15:19:34 +0000783// Pointercheck
784extern Bool VGA_(setup_pointercheck) ( void );
785
786// For attaching the debugger
sewardj2a99cf62004-11-24 10:44:19 +0000787extern Int VGA_(ptrace_setregs_from_tst) ( Int pid, ThreadArchState* arch );
nethercotefedd8102004-09-13 15:19:34 +0000788
sewardjb5f6f512005-03-10 23:59:00 +0000789// Used by leakcheck
790extern void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr));
791
nethercote9b3c7652004-10-19 13:18:00 +0000792
nethercote41c75da2004-10-18 15:34:14 +0000793// ---------------------------------------------------------------------
794// Platform-specific things defined in eg. x86/*.c
795// ---------------------------------------------------------------------
nethercote775508a2004-09-07 22:38:23 +0000796
njn2521d322005-05-08 14:45:13 +0000797// Do any platform specific redirects.
tom748a1312005-04-02 15:53:01 +0000798extern void VGP_(setup_redirects)(void);
sewardjb5f6f512005-03-10 23:59:00 +0000799
800///* ---------------------------------------------------------------------
801// Thread modelling
802// ------------------------------------------------------------------ */
803//extern void VG_(tm_thread_create) (ThreadId creator, ThreadId tid, Bool detached);
804//extern void VG_(tm_thread_exit) (ThreadId tid);
805//extern Bool VG_(tm_thread_exists) (ThreadId tid);
806//extern void VG_(tm_thread_detach) (ThreadId tid);
807//extern void VG_(tm_thread_join) (ThreadId joiner, ThreadId joinee);
808//extern void VG_(tm_thread_switchto)(ThreadId tid);
809//
810//extern void VG_(tm_mutex_init) (ThreadId tid, Addr mutexp);
811//extern void VG_(tm_mutex_destroy)(ThreadId tid, Addr mutexp);
812//extern void VG_(tm_mutex_trylock)(ThreadId tid, Addr mutexp);
813//extern void VG_(tm_mutex_giveup) (ThreadId tid, Addr mutexp);
814//extern void VG_(tm_mutex_acquire)(ThreadId tid, Addr mutexp);
815//extern void VG_(tm_mutex_tryunlock)(ThreadId tid, Addr mutexp);
816//extern void VG_(tm_mutex_unlock) (ThreadId tid, Addr mutexp);
817//extern Bool VG_(tm_mutex_exists) (Addr mutexp);
818//
819//extern UInt VG_(tm_error_update_extra) (Error *err);
820//extern Bool VG_(tm_error_equal) (VgRes res, Error *e1, Error *e2);
821//extern void VG_(tm_error_print) (Error *err);
822//
823//extern void VG_(tm_init) ();
824//
825//extern void VG_(tm_cond_init) (ThreadId tid, Addr condp);
826//extern void VG_(tm_cond_destroy) (ThreadId tid, Addr condp);
827//extern void VG_(tm_cond_wait) (ThreadId tid, Addr condp, Addr mutexp);
828//extern void VG_(tm_cond_wakeup) (ThreadId tid, Addr condp, Addr mutexp);
829//extern void VG_(tm_cond_signal) (ThreadId tid, Addr condp);
830//
831///* ----- pthreads ----- */
832//extern void VG_(pthread_init) ();
833//extern void VG_(pthread_startfunc_wrapper)(Addr wrapper);
834//
835//struct vg_pthread_newthread_data {
836// void *(*startfunc)(void *arg);
837// void *arg;
838//};
sewardj3b2736a2002-03-24 12:18:35 +0000839
840/* ---------------------------------------------------------------------
841 Finally - autoconf-generated settings
842 ------------------------------------------------------------------ */
843
844#include "config.h"
845
nethercotec06e2132004-09-03 13:45:29 +0000846#endif /* ndef __CORE_H */
847
sewardjde4a1d02002-03-22 01:27:54 +0000848/*--------------------------------------------------------------------*/
nethercote109d0df2004-09-02 08:10:13 +0000849/*--- end ---*/
sewardjde4a1d02002-03-22 01:27:54 +0000850/*--------------------------------------------------------------------*/