blob: 9229880ea3a3d5237780895a751e0ad563a7ddba [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
njn25e49d8e72002-09-23 09:36:25 +00003/*--- A header file for all private parts of Valgrind's core. ---*/
sewardjde4a1d02002-03-22 01:27:54 +00004/*--- Include no other! ---*/
5/*--- vg_include.h ---*/
6/*--------------------------------------------------------------------*/
7
8/*
njnc9539842002-10-02 13:26:35 +00009 This file is part of Valgrind, an extensible x86 protected-mode
10 emulator for monitoring program execution on x86-Unixes.
sewardjde4a1d02002-03-22 01:27:54 +000011
njn0e1b5142003-04-15 14:58:06 +000012 Copyright (C) 2000-2003 Julian Seward
sewardjde4a1d02002-03-22 01:27:54 +000013 jseward@acm.org
sewardjde4a1d02002-03-22 01:27:54 +000014
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of the
18 License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 02111-1307, USA.
29
njn25e49d8e72002-09-23 09:36:25 +000030 The GNU General Public License is contained in the file COPYING.
sewardjde4a1d02002-03-22 01:27:54 +000031*/
32
33#ifndef __VG_INCLUDE_H
34#define __VG_INCLUDE_H
35
sewardjde4a1d02002-03-22 01:27:54 +000036/* ---------------------------------------------------------------------
sewardj2d94c112002-06-03 01:25:54 +000037 Where to send bug reports to.
38 ------------------------------------------------------------------ */
39
40#define VG_EMAIL_ADDR "jseward@acm.org"
41
42
43/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +000044 Build options and table sizes. You should be able to change these
45 options or sizes, recompile, and still have a working system.
46 ------------------------------------------------------------------ */
47
jsgf855d93d2003-10-13 22:26:55 +000048/* For system call numbers __NR_... */
49#include "vg_unistd.h"
50
sewardjde4a1d02002-03-22 01:27:54 +000051#include "vg_constants.h"
52
sewardj4cf05692002-10-27 20:28:29 +000053/* All stuff visible to core and skins goes in vg_skin.h. Things
54 * visible to core but not visible to any skins should go in this
55 * file, vg_include.h. */
njn25e49d8e72002-09-23 09:36:25 +000056#include "vg_skin.h"
fitzhardinge39de4b42003-10-31 07:12:21 +000057#include "valgrind.h"
sewardjde4a1d02002-03-22 01:27:54 +000058
59/* Total number of spill slots available for allocation, if a TempReg
60 doesn't make it into a RealReg. Just bomb the entire system if
61 this value is too small; we don't expect it will ever get
62 particularly high. */
63#define VG_MAX_SPILLSLOTS 24
64
65
66/* Constants for the slow translation lookup cache. */
67#define VG_TRANSTAB_SLOW_BITS 11
68#define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS)
69#define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1)
70
71/* Size of a buffer used for creating messages. */
72#define M_VG_MSGBUF 10000
73
74/* Size of a smallish table used to read /proc/self/map entries. */
sewardjebc82332002-04-24 14:44:23 +000075#define M_PROCMAP_BUF 50000
sewardjde4a1d02002-03-22 01:27:54 +000076
77/* Max length of pathname to a .so/executable file. */
78#define M_VG_LIBNAMESTR 100
79
80/* Max length of a text fragment used to construct error messages. */
81#define M_VG_ERRTXT 512
82
83/* Max length of the string copied from env var VG_ARGS at startup. */
84#define M_VG_CMDLINE_STRLEN 1000
85
86/* Max number of options for Valgrind which we can handle. */
87#define M_VG_CMDLINE_OPTS 100
88
89/* After this many different unsuppressed errors have been observed,
90 be more conservative about collecting new ones. */
91#define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50
92
93/* After this many different unsuppressed errors have been observed,
94 stop collecting errors at all, and tell the user their program is
95 evidently a steaming pile of camel dung. */
sewardj1bebcbf2002-04-24 21:24:18 +000096#define M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN 300
sewardjf2537be2002-04-24 21:03:47 +000097
98/* After this many total errors have been observed, stop collecting
99 errors at all. Counterpart to M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN. */
sewardj1bebcbf2002-04-24 21:24:18 +0000100#define M_VG_COLLECT_NO_ERRORS_AFTER_FOUND 30000
sewardjde4a1d02002-03-22 01:27:54 +0000101
sewardjde4a1d02002-03-22 01:27:54 +0000102/* The maximum number of calls we're prepared to save in a
103 backtrace. */
104#define VG_DEEPEST_BACKTRACE 50
105
sewardjde4a1d02002-03-22 01:27:54 +0000106/* Number of lists in which we keep track of ExeContexts. Should be
107 prime. */
sewardj59fb25c2003-09-28 16:32:58 +0000108#define VG_N_EC_LISTS 4999 /* a prime number */
sewardjde4a1d02002-03-22 01:27:54 +0000109
sewardj2e93c502002-04-12 11:12:52 +0000110/* Defines the thread-scheduling timeslice, in terms of the number of
111 basic blocks we attempt to run each thread for. Smaller values
112 give finer interleaving but much increased scheduling overheads. */
sewardj4505b9e2002-05-28 11:27:31 +0000113#define VG_SCHEDULING_QUANTUM 50000
sewardj2e93c502002-04-12 11:12:52 +0000114
jsgf855d93d2003-10-13 22:26:55 +0000115/* Maximum FD Valgrind can use for its internal file descriptors. */
116#define VG_MAX_SAFE_FD 1024 /* usual ulimit */
117
118/* Maximum allowed application-visible file descriptor. Valgrind's
119 internal fds hide above this (starting at VG_MAX_FD+1). This is
120 derived from the default fd limit (1024) minus the 2 fds per thread
121 and a small number of extra fds. */
122#define VG_MAX_FD (VG_MAX_SAFE_FD - (VG_N_THREADS*2 + 4))
sewardj2e93c502002-04-12 11:12:52 +0000123
sewardjbf290b92002-05-01 02:28:01 +0000124/* Stack size for a thread. We try and check that they do not go
125 beyond it. */
sewardjf0b06452002-06-04 08:38:04 +0000126#define VG_PTHREAD_STACK_SIZE (1 << 20)
sewardjbf290b92002-05-01 02:28:01 +0000127
sewardj20917d82002-05-28 01:36:45 +0000128/* Number of entries in the semaphore-remapping table. */
129#define VG_N_SEMAPHORES 50
130
131/* Number of entries in the rwlock-remapping table. */
sewardj89745a52002-09-27 01:04:29 +0000132#define VG_N_RWLOCKS 500
sewardj20917d82002-05-28 01:36:45 +0000133
sewardj8ad94e12002-05-29 00:10:20 +0000134/* Number of entries in each thread's cleanup stack. */
sewardj61821c02003-05-04 13:02:10 +0000135#define VG_N_CLEANUPSTACK 16
sewardj8ad94e12002-05-29 00:10:20 +0000136
sewardj2cb00342002-06-28 01:46:26 +0000137/* Number of entries in each thread's fork-handler stack. */
sewardj4700f042003-07-26 17:49:58 +0000138#define VG_N_FORKHANDLERSTACK 4
sewardj2cb00342002-06-28 01:46:26 +0000139
njn25e49d8e72002-09-23 09:36:25 +0000140/* Max number of callers for context in a suppression. */
141#define VG_N_SUPP_CALLERS 4
sewardj73cf3bc2002-11-03 03:20:15 +0000142
njn6eba4ef2003-05-01 08:06:41 +0000143/* Valgrind's stack sizes, in words */
144#define VG_STACK_SIZE_W 10000
145#define VG_SIGSTACK_SIZE_W 10000
njn12a57142003-04-30 20:49:10 +0000146
sewardjde4a1d02002-03-22 01:27:54 +0000147/* ---------------------------------------------------------------------
148 Basic types
149 ------------------------------------------------------------------ */
150
sewardjde4a1d02002-03-22 01:27:54 +0000151/* Just pray that gcc's constant folding works properly ... */
152#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
153 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
154 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
155
sewardjde4a1d02002-03-22 01:27:54 +0000156/* ---------------------------------------------------------------------
157 Command-line-settable options
158 ------------------------------------------------------------------ */
159
sewardj4f094a72002-11-05 23:37:35 +0000160/* Default destination port to be used in logging over a network, if
161 none specified. */
162#define VG_CLO_DEFAULT_LOGPORT 1500
sewardj73cf3bc2002-11-03 03:20:15 +0000163
164/* The max number of suppression files. */
sewardjde4a1d02002-03-22 01:27:54 +0000165#define VG_CLO_MAX_SFILES 10
166
sewardj4cf05692002-10-27 20:28:29 +0000167/* Describes where logging output is to be sent. */
168typedef
169 enum {
170 VgLogTo_Fd,
171 VgLogTo_File,
172 VgLogTo_Socket
173 } VgLogTo;
174
jsgf855d93d2003-10-13 22:26:55 +0000175/* pid of main process */
176extern Int VG_(main_pid);
177
178/* pgrp of process (global to all threads) */
179extern Int VG_(main_pgrp);
sewardj4cf05692002-10-27 20:28:29 +0000180
sewardj72f98ff2002-06-13 17:23:38 +0000181/* Should we stop collecting errors if too many appear? default: YES */
sewardj2e432902002-06-13 20:44:00 +0000182extern Bool VG_(clo_error_limit);
sewardjde4a1d02002-03-22 01:27:54 +0000183/* Enquire about whether to attach to GDB at errors? default: NO */
184extern Bool VG_(clo_GDB_attach);
sewardj6024b212003-07-13 10:54:33 +0000185/* The path to GDB? default: whatever ./configure found */
186extern Char* VG_(clo_GDB_path);
njn43c799e2003-04-08 00:08:52 +0000187/* Enquire about generating a suppression for each error? default: NO */
188extern Bool VG_(clo_gen_suppressions);
sewardjde4a1d02002-03-22 01:27:54 +0000189/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
190extern Int VG_(sanity_level);
sewardjde4a1d02002-03-22 01:27:54 +0000191/* Automatically attempt to demangle C++ names? default: YES */
192extern Bool VG_(clo_demangle);
sewardjde4a1d02002-03-22 01:27:54 +0000193/* Simulate child processes? default: NO */
194extern Bool VG_(clo_trace_children);
sewardj4cf05692002-10-27 20:28:29 +0000195
196/* Where logging output is to be sent to.
197
198 When log_to == VgLogTo_Fd, clo_logfile_fd holds the file id, and is
199 taken from the command line. clo_logfile_name is irrelevant.
200
201 When log_to == VgLogTo_File, clo_logfile_name holds the logfile
202 name, and is taken from the command line. clo_logfile_fd is then
203 made to hold the relevant file id, by opening clo_logfile_name
204 (concatenated with the process ID) for writing.
205
206 When log_to == VgLogTo_Socket, clo_logfile_name holds the
207 hostname:portnumber pair, and is taken from the command line.
208 clo_logfile_fd is then made to hold the relevant file handle, by
209 opening a connection to said hostname:portnumber pair.
210
211 Global default is to set log_to == VgLogTo_Fd and logfile_fd == 2
212 (stderr). */
213extern VgLogTo VG_(clo_log_to);
214extern Int VG_(clo_logfile_fd);
215extern Char* VG_(clo_logfile_name);
sewardjde4a1d02002-03-22 01:27:54 +0000216
sewardj6024b212003-07-13 10:54:33 +0000217/* The file descriptor to read for input. default: 0 == stdin */
218extern Int VG_(clo_input_fd);
sewardjde4a1d02002-03-22 01:27:54 +0000219/* The number of suppression files specified. */
220extern Int VG_(clo_n_suppressions);
221/* The names of the suppression files. */
222extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
223
224/* Single stepping? default: NO */
225extern Bool VG_(clo_single_step);
226/* Code improvement? default: YES */
227extern Bool VG_(clo_optimise);
njn25e49d8e72002-09-23 09:36:25 +0000228/* DEBUG: print generated code? default: 00000 ( == NO ) */
229extern Bool VG_(clo_trace_codegen);
sewardjde4a1d02002-03-22 01:27:54 +0000230/* DEBUG: print system calls? default: NO */
231extern Bool VG_(clo_trace_syscalls);
232/* DEBUG: print signal details? default: NO */
233extern Bool VG_(clo_trace_signals);
234/* DEBUG: print symtab details? default: NO */
235extern Bool VG_(clo_trace_symtab);
sewardj8937c812002-04-12 20:12:20 +0000236/* DEBUG: print thread scheduling events? default: NO */
237extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000238/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
239 (some), 2 (all) */
240extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000241/* Stop after this many basic blocks. default: Infinity. */
242extern ULong VG_(clo_stop_after);
243/* Display gory details for the k'th most popular error. default:
244 Infinity. */
245extern Int VG_(clo_dump_error);
246/* Number of parents of a backtrace. Default: 8. */
247extern Int VG_(clo_backtrace_size);
daywalker7e73e5f2003-07-04 16:18:15 +0000248/* Engage miscellaneous weird hacks needed for some progs. */
sewardj8d365b52002-05-12 10:52:16 +0000249extern Char* VG_(clo_weird_hacks);
jsgf855d93d2003-10-13 22:26:55 +0000250/* How often we should poll for signals, assuming we need to poll for
251 signals. */
252extern Int VG_(clo_signal_polltime);
fitzhardinge89f9a322003-10-30 07:25:59 +0000253/* Assume we're running on a plain 2.4 kernel */
254extern Bool VG_(clo_assume_24);
jsgf855d93d2003-10-13 22:26:55 +0000255
256/* Low latency syscalls and signals */
257extern Bool VG_(clo_lowlat_syscalls);
258extern Bool VG_(clo_lowlat_signals);
259
sewardj858964b2002-10-05 14:15:43 +0000260/* Should we run __libc_freeres at exit? Sometimes causes crashes.
261 Default: YES. Note this is subservient to VG_(needs).libc_freeres;
262 if the latter says False, then the setting of VG_(clo_weird_hacks)
263 is ignored. Ie if a skin says no, I don't want this to run, that
264 cannot be overridden from the command line. */
265extern Bool VG_(clo_run_libc_freeres);
sewardjb5ff83e2002-12-01 19:40:49 +0000266/* Use the basic-block chaining optimisation? Default: YES */
sewardj22854b92002-11-30 14:00:47 +0000267extern Bool VG_(clo_chain_bb);
sewardjde4a1d02002-03-22 01:27:54 +0000268
269
270/* ---------------------------------------------------------------------
271 Debugging and profiling stuff
272 ------------------------------------------------------------------ */
273
sewardjde4a1d02002-03-22 01:27:54 +0000274/* Create a logfile into which messages can be dumped. */
275extern void VG_(startup_logging) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000276extern void VG_(shutdown_logging)( void );
sewardjde4a1d02002-03-22 01:27:54 +0000277
278extern void VGP_(init_profiling) ( void );
279extern void VGP_(done_profiling) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000280
njn25e49d8e72002-09-23 09:36:25 +0000281#undef VGP_PUSHCC
282#undef VGP_POPCC
283#define VGP_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x)
284#define VGP_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x)
sewardjde4a1d02002-03-22 01:27:54 +0000285
sewardjde4a1d02002-03-22 01:27:54 +0000286/* ---------------------------------------------------------------------
njn810086f2002-11-14 12:42:47 +0000287 Skin-related types
288 ------------------------------------------------------------------ */
289/* These structs are not exposed to skins to mitigate possibility of
290 binary-incompatibilities when the core/skin interface changes. Instead,
291 set functions are provided (see include/vg_skin.h). */
292typedef
293 struct {
294 Char* name;
295 Char* version;
296 Char* description;
297 Char* copyright_author;
298 Char* bug_reports_to;
njn120281f2003-02-03 12:20:07 +0000299 UInt avg_translation_sizeB;
njn810086f2002-11-14 12:42:47 +0000300 }
301 VgDetails;
302
303extern VgDetails VG_(details);
304
305/* If new fields are added to this type, update:
306 * - vg_main.c:initialisation of VG_(needs)
307 * - vg_main.c:sanity_check_needs()
308 *
309 * If the name of this type or any of its fields change, update:
310 * - dependent comments (just search for "VG_(needs)").
311 */
312typedef
313 struct {
314 Bool libc_freeres;
315 Bool core_errors;
316
317 Bool skin_errors;
318 Bool basic_block_discards;
319 Bool shadow_regs;
320 Bool command_line_options;
321 Bool client_requests;
322 Bool extended_UCode;
323 Bool syscall_wrapper;
njn810086f2002-11-14 12:42:47 +0000324 Bool sanity_checks;
325 Bool data_syms;
326 }
327 VgNeeds;
328
329extern VgNeeds VG_(needs);
330
331/* Events happening in core to track. To be notified, assign a function
332 to the function pointer. To ignore an event, don't do anything
333 (default assignment is to NULL in which case the call is skipped). */
334typedef
335 struct {
336 /* Memory events */
337 void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
njn810086f2002-11-14 12:42:47 +0000338 void (*new_mem_stack_signal) ( Addr a, UInt len );
339 void (*new_mem_brk) ( Addr a, UInt len );
340 void (*new_mem_mmap) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
341
njn3e884182003-04-15 13:03:23 +0000342 void (*copy_mem_remap) ( Addr from, Addr to, UInt len );
343 void (*change_mem_mprotect) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
344 void (*die_mem_stack_signal) ( Addr a, UInt len );
345 void (*die_mem_brk) ( Addr a, UInt len );
346 void (*die_mem_munmap) ( Addr a, UInt len );
347
njn9b007f62003-04-07 14:40:25 +0000348 void (*new_mem_stack_4) ( Addr new_ESP );
349 void (*new_mem_stack_8) ( Addr new_ESP );
350 void (*new_mem_stack_12) ( Addr new_ESP );
351 void (*new_mem_stack_16) ( Addr new_ESP );
352 void (*new_mem_stack_32) ( Addr new_ESP );
353 void (*new_mem_stack) ( Addr a, UInt len );
354
njn9b007f62003-04-07 14:40:25 +0000355 void (*die_mem_stack_4) ( Addr die_ESP );
356 void (*die_mem_stack_8) ( Addr die_ESP );
357 void (*die_mem_stack_12) ( Addr die_ESP );
358 void (*die_mem_stack_16) ( Addr die_ESP );
359 void (*die_mem_stack_32) ( Addr die_ESP );
360 void (*die_mem_stack) ( Addr a, UInt len );
361
njn3e884182003-04-15 13:03:23 +0000362 void (*ban_mem_stack) ( Addr a, UInt len );
njn810086f2002-11-14 12:42:47 +0000363
njn72718642003-07-24 08:45:32 +0000364 void (*pre_mem_read) ( CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +0000365 Char* s, Addr a, UInt size );
njn72718642003-07-24 08:45:32 +0000366 void (*pre_mem_read_asciiz) ( CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +0000367 Char* s, Addr a );
njn72718642003-07-24 08:45:32 +0000368 void (*pre_mem_write) ( CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +0000369 Char* s, Addr a, UInt size );
370 /* Not implemented yet -- have to add in lots of places, which is a
371 pain. Won't bother unless/until there's a need. */
372 /* void (*post_mem_read) ( ThreadState* tst, Char* s,
373 Addr a, UInt size ); */
374 void (*post_mem_write) ( Addr a, UInt size );
375
376
njnd3040452003-05-19 15:04:06 +0000377 /* Register events */
378 void (*post_regs_write_init) ( void );
379 void (*post_reg_write_syscall_return) ( ThreadId tid, UInt reg );
380 void (*post_reg_write_deliver_signal) ( ThreadId tid, UInt reg );
381 void (*post_reg_write_pthread_return) ( ThreadId tid, UInt reg );
382 void (*post_reg_write_clientreq_return) ( ThreadId tid, UInt reg );
383 void (*post_reg_write_clientcall_return) ( ThreadId tid, UInt reg,
384 Addr f );
385
386
njn810086f2002-11-14 12:42:47 +0000387 /* Scheduler events (not exhaustive) */
388 void (*thread_run) ( ThreadId tid );
389
390
391 /* Thread events (not exhaustive) */
392 void (*post_thread_create) ( ThreadId tid, ThreadId child );
393 void (*post_thread_join) ( ThreadId joiner, ThreadId joinee );
394
395
396 /* Mutex events (not exhaustive) */
397 void (*pre_mutex_lock) ( ThreadId tid,
398 void* /*pthread_mutex_t* */ mutex );
399 void (*post_mutex_lock) ( ThreadId tid,
400 void* /*pthread_mutex_t* */ mutex );
401 void (*post_mutex_unlock) ( ThreadId tid,
402 void* /*pthread_mutex_t* */ mutex );
403
njnfdc28af2003-02-24 10:36:48 +0000404 /* Signal events (not exhaustive) */
njn3e884182003-04-15 13:03:23 +0000405 void (* pre_deliver_signal) ( ThreadId tid, Int sigNo, Bool alt_stack );
njnfdc28af2003-02-24 10:36:48 +0000406 void (*post_deliver_signal) ( ThreadId tid, Int sigNo );
407
njn810086f2002-11-14 12:42:47 +0000408
njnfdc28af2003-02-24 10:36:48 +0000409 /* Others... condition variable... */
njn810086f2002-11-14 12:42:47 +0000410 /* ... */
411 }
412 VgTrackEvents;
413
414extern VgTrackEvents VG_(track_events);
415
416
417/* ---------------------------------------------------------------------
418 Exports of vg_needs.c
419 ------------------------------------------------------------------ */
420
421void VG_(sanity_check_needs)(void);
422
423/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000424 Exports of vg_malloc2.c
425 ------------------------------------------------------------------ */
426
427/* Allocation arenas.
njn3e884182003-04-15 13:03:23 +0000428
429 CORE for the core's general use.
430 SKIN for the skin to use (and the only one it uses).
431 SYMTAB for Valgrind's symbol table storage.
432 JITTER for small storage during translation.
433 CLIENT for the client's mallocs/frees, if the skin replaces glibc's
434 malloc() et al -- redzone size is chosen by the skin.
435 DEMANGLE for the C++ demangler.
436 EXECTXT for storing ExeContexts.
437 ERRORS for storing CoreErrors.
438 TRANSIENT for very short-term use. It should be empty in between uses.
439
njn25e49d8e72002-09-23 09:36:25 +0000440 When adding a new arena, remember also to add it to ensure_mm_init().
sewardjde4a1d02002-03-22 01:27:54 +0000441*/
442typedef Int ArenaId;
443
njn3e884182003-04-15 13:03:23 +0000444#define VG_N_ARENAS 9
sewardjde4a1d02002-03-22 01:27:54 +0000445
njn3e884182003-04-15 13:03:23 +0000446#define VG_AR_CORE 0
447#define VG_AR_SKIN 1
448#define VG_AR_SYMTAB 2
449#define VG_AR_JITTER 3
450#define VG_AR_CLIENT 4
451#define VG_AR_DEMANGLE 5
452#define VG_AR_EXECTXT 6
453#define VG_AR_ERRORS 7
454#define VG_AR_TRANSIENT 8
sewardjde4a1d02002-03-22 01:27:54 +0000455
njn25e49d8e72002-09-23 09:36:25 +0000456extern void* VG_(arena_malloc) ( ArenaId arena, Int nbytes );
457extern void VG_(arena_free) ( ArenaId arena, void* ptr );
njn3e884182003-04-15 13:03:23 +0000458extern void* VG_(arena_calloc) ( ArenaId arena, Int alignment,
459 Int nmemb, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000460extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment,
461 Int size );
462extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB,
sewardjde4a1d02002-03-22 01:27:54 +0000463 Int req_pszB );
464
njn8a6b6c02003-04-22 22:45:55 +0000465extern Int VG_(arena_payload_szB) ( ArenaId aid, void* payload );
466
sewardjde4a1d02002-03-22 01:27:54 +0000467extern void VG_(mallocSanityCheckAll) ( void );
468
469extern void VG_(show_all_arena_stats) ( void );
470extern Bool VG_(is_empty_arena) ( ArenaId aid );
471
sewardjecf8e102003-07-12 12:11:39 +0000472/* Returns True if aa is inside any block mmap'd /dev/zero
473 by our low-level memory manager. */
474extern Bool VG_(is_inside_segment_mmapd_by_low_level_MM)( Addr aa );
475
sewardjde4a1d02002-03-22 01:27:54 +0000476
sewardjde4a1d02002-03-22 01:27:54 +0000477/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000478 Exports of vg_intercept.c
sewardj2e93c502002-04-12 11:12:52 +0000479 ------------------------------------------------------------------ */
480
481/* This doesn't export code or data that valgrind.so needs to link
482 against. However, the scheduler does need to know the following
483 request codes. A few, publically-visible, request codes are also
njn25e49d8e72002-09-23 09:36:25 +0000484 defined in valgrind.h, and similar headers for some skins. */
sewardj2e93c502002-04-12 11:12:52 +0000485
njn4c791212003-05-02 17:53:54 +0000486#define VG_USERREQ__MALLOC 0x2001
487#define VG_USERREQ__FREE 0x2002
488
sewardj20917d82002-05-28 01:36:45 +0000489/* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn
490 MUST NOT return -- ever. Eventually it will do either __QUIT or
491 __WAIT_JOINER. */
492#define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001
493
494/* ( no-args ): calling thread disappears from the system forever.
495 Reclaim resources. */
496#define VG_USERREQ__QUIT 0x3002
497
498/* ( void* ): calling thread waits for joiner and returns the void* to
499 it. */
500#define VG_USERREQ__WAIT_JOINER 0x3003
501
502/* ( ThreadId, void** ): wait to join a thread. */
503#define VG_USERREQ__PTHREAD_JOIN 0x3004
504
505/* Set cancellation state and type for this thread. */
506#define VG_USERREQ__SET_CANCELSTATE 0x3005
507#define VG_USERREQ__SET_CANCELTYPE 0x3006
508
509/* ( no-args ): Test if we are at a cancellation point. */
510#define VG_USERREQ__TESTCANCEL 0x3007
511
512/* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call
513 with this arg to indicate that a cancel is now pending for the
514 specified thread. */
515#define VG_USERREQ__SET_CANCELPEND 0x3008
516
517/* Set/get detach state for this thread. */
518#define VG_USERREQ__SET_OR_GET_DETACH 0x3009
519
520#define VG_USERREQ__PTHREAD_GET_THREADID 0x300B
521#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C
522#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D
523#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E
524#define VG_USERREQ__PTHREAD_COND_WAIT 0x300F
525#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010
526#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011
527#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012
528#define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013
529#define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014
sewardj00a66b12002-10-12 16:42:35 +0000530#define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015
531#define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016
sewardj20917d82002-05-28 01:36:45 +0000532#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017
533#define VG_USERREQ__PTHREAD_SIGMASK 0x3018
jsgf855d93d2003-10-13 22:26:55 +0000534#define VG_USERREQ__SIGWAIT 0x3019 /* unused */
sewardj20917d82002-05-28 01:36:45 +0000535#define VG_USERREQ__PTHREAD_KILL 0x301A
536#define VG_USERREQ__PTHREAD_YIELD 0x301B
sewardj00a66b12002-10-12 16:42:35 +0000537#define VG_USERREQ__PTHREAD_KEY_VALIDATE 0x301C
sewardj2e93c502002-04-12 11:12:52 +0000538
sewardj8ad94e12002-05-29 00:10:20 +0000539#define VG_USERREQ__CLEANUP_PUSH 0x3020
540#define VG_USERREQ__CLEANUP_POP 0x3021
sewardj870497a2002-05-29 01:06:47 +0000541#define VG_USERREQ__GET_KEY_D_AND_S 0x3022
sewardj8ad94e12002-05-29 00:10:20 +0000542
sewardjef037c72002-05-30 00:40:03 +0000543#define VG_USERREQ__NUKE_OTHER_THREADS 0x3023
sewardjefbfcdf2002-06-19 17:35:45 +0000544
545/* Ask how many signal handler returns have happened to this
546 thread. */
jsgf855d93d2003-10-13 22:26:55 +0000547#define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024 /* unused */
sewardjef037c72002-05-30 00:40:03 +0000548
sewardj2cb00342002-06-28 01:46:26 +0000549/* Get/set entries for a thread's pthread_atfork stack. */
550#define VG_USERREQ__SET_FHSTACK_USED 0x3025
551#define VG_USERREQ__GET_FHSTACK_USED 0x3026
552#define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027
553#define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028
sewardjefbfcdf2002-06-19 17:35:45 +0000554
sewardj1fe7b002002-07-16 01:43:15 +0000555/* Denote the finish of VG_(__libc_freeres_wrapper). */
556#define VG_USERREQ__LIBC_FREERES_DONE 0x3029
557
sewardj45b4b372002-04-16 22:50:32 +0000558/* Cosmetic ... */
559#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
sewardj4dced352002-06-04 22:54:20 +0000560/* Log a pthread error from client-space. Cosmetic. */
561#define VG_USERREQ__PTHREAD_ERROR 0x3102
fitzhardinge39de4b42003-10-31 07:12:21 +0000562/* Internal equivalent of VALGRIND_PRINTF . */
563#define VG_USERREQ__INTERNAL_PRINTF 0x3103
564/* Internal equivalent of VALGRIND_PRINTF_BACKTRACE . */
565#define VG_USERREQ__INTERNAL_PRINTF_BACKTRACE 0x3104
sewardj45b4b372002-04-16 22:50:32 +0000566
sewardj54cacf02002-04-12 23:24:59 +0000567/*
568In vg_constants.h:
569#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardj54cacf02002-04-12 23:24:59 +0000570*/
571
njn4c791212003-05-02 17:53:54 +0000572
sewardj1fe7b002002-07-16 01:43:15 +0000573/* The scheduler does need to know the address of it so it can be
574 called at program exit. */
575extern void VG_(__libc_freeres_wrapper)( void );
576
fitzhardinge39de4b42003-10-31 07:12:21 +0000577__attribute__((weak))
578int
579VALGRIND_INTERNAL_PRINTF(char *format, ...)
580{
581 unsigned int _qzz_res = 0;
582 va_list vargs;
583 va_start(vargs, format);
584 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, VG_USERREQ__INTERNAL_PRINTF,
585 (unsigned int)format, (unsigned int)vargs, 0, 0);
586 va_end(vargs);
587 return _qzz_res;
588}
589
590__attribute__((weak))
591int
592VALGRIND_INTERNAL_PRINTF_BACKTRACE(char *format, ...)
593{
594 unsigned int _qzz_res = 0;
595 va_list vargs;
596 va_start(vargs, format);
597 VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, VG_USERREQ__INTERNAL_PRINTF_BACKTRACE,
598 (unsigned int)format, (unsigned int)vargs, 0, 0);
599 va_end(vargs);
600 return _qzz_res;
601}
602
sewardj54cacf02002-04-12 23:24:59 +0000603
sewardj2e93c502002-04-12 11:12:52 +0000604/* ---------------------------------------------------------------------
605 Constants pertaining to the simulated CPU state, VG_(baseBlock),
606 which need to go here to avoid ugly circularities.
607 ------------------------------------------------------------------ */
608
sewardjb91ae7f2003-04-29 23:50:00 +0000609/* How big is the saved SSE/SSE2 state? Note that this subsumes the
610 FPU state. On machines without SSE, we just save/restore the FPU
611 state into the first part of this area. */
612/* A general comment about SSE save/restore: It appears that the 7th
613 word (which is the MXCSR) has to be &ed with 0x0000FFBF in order
614 that restoring from it later does not cause a GP fault (which is
615 delivered as a segfault). I guess this will have to be done
616 any time we do fxsave :-( 7th word means word offset 6 or byte
617 offset 24 from the start address of the save area.
618 */
619#define VG_SIZE_OF_SSESTATE 512
sewardj2e93c502002-04-12 11:12:52 +0000620/* ... and in words ... */
sewardjb91ae7f2003-04-29 23:50:00 +0000621#define VG_SIZE_OF_SSESTATE_W ((VG_SIZE_OF_SSESTATE+3)/4)
sewardj2e93c502002-04-12 11:12:52 +0000622
623
624/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000625 Exports of vg_defaults.c
626 ------------------------------------------------------------------ */
627
628extern Bool VG_(sk_malloc_called_by_scheduler);
629
630
631/* ---------------------------------------------------------------------
sewardj92a59562002-09-30 00:53:10 +0000632 Exports of vg_ldt.c
633 ------------------------------------------------------------------ */
634
635/* This is the hardware-format for a segment descriptor, ie what the
636 x86 actually deals with. It is 8 bytes long. It's ugly. */
637
638typedef struct _LDT_ENTRY {
639 union {
640 struct {
641 UShort LimitLow;
642 UShort BaseLow;
643 unsigned BaseMid : 8;
644 unsigned Type : 5;
645 unsigned Dpl : 2;
646 unsigned Pres : 1;
647 unsigned LimitHi : 4;
648 unsigned Sys : 1;
649 unsigned Reserved_0 : 1;
650 unsigned Default_Big : 1;
651 unsigned Granularity : 1;
652 unsigned BaseHi : 8;
653 } Bits;
654 struct {
655 UInt word1;
656 UInt word2;
657 } Words;
658 }
659 LdtEnt;
660} VgLdtEntry;
661
662/* Maximum number of LDT entries supported (by the x86). */
663#define VG_M_LDT_ENTRIES 8192
664/* The size of each LDT entry == sizeof(VgLdtEntry) */
665#define VG_LDT_ENTRY_SIZE 8
666
667/* Alloc & copy, and dealloc. */
668extern VgLdtEntry*
669 VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt );
670extern void
671 VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt );
672
673/* Simulate the modify_ldt syscall. */
674extern Int VG_(sys_modify_ldt) ( ThreadId tid,
675 Int func, void* ptr, UInt bytecount );
676
sewardje1042472002-09-30 12:33:11 +0000677/* Called from generated code. Given a segment selector and a virtual
678 address, return a linear address, and do limit checks too. */
679extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr );
680
sewardj92a59562002-09-30 00:53:10 +0000681
682/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000683 Exports of vg_scheduler.c
684 ------------------------------------------------------------------ */
685
sewardj2e93c502002-04-12 11:12:52 +0000686typedef
jsgf855d93d2003-10-13 22:26:55 +0000687 enum ThreadStatus {
sewardj2e93c502002-04-12 11:12:52 +0000688 VgTs_Empty, /* this slot is not in use */
689 VgTs_Runnable, /* waiting to be scheduled */
690 VgTs_WaitJoiner, /* waiting for someone to do join on me */
691 VgTs_WaitJoinee, /* waiting for the thread I did join on */
sewardj2e93c502002-04-12 11:12:52 +0000692 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000693 VgTs_WaitCV, /* waiting on a condition variable */
jsgf855d93d2003-10-13 22:26:55 +0000694 VgTs_WaitSys, /* waiting for a syscall to complete */
695 VgTs_Sleeping, /* sleeping for a while */
sewardj2e93c502002-04-12 11:12:52 +0000696 }
697 ThreadStatus;
sewardj8ad94e12002-05-29 00:10:20 +0000698
699/* An entry in a threads's cleanup stack. */
700typedef
701 struct {
702 void (*fn)(void*);
703 void* arg;
704 }
705 CleanupEntry;
sewardj2cb00342002-06-28 01:46:26 +0000706
707/* An entry in a thread's fork-handler stack. */
708typedef
709 struct {
710 void (*prepare)(void);
711 void (*parent)(void);
712 void (*child)(void);
713 }
714 ForkHandlerEntry;
715
jsgf855d93d2003-10-13 22:26:55 +0000716typedef struct ProxyLWP ProxyLWP;
sewardj2cb00342002-06-28 01:46:26 +0000717
njn72718642003-07-24 08:45:32 +0000718typedef
719 struct _ThreadState {
njn25e49d8e72002-09-23 09:36:25 +0000720 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
721 The thread identity is simply the index in vg_threads[].
722 ThreadId == 1 is the root thread and has the special property
723 that we don't try and allocate or deallocate its stack. For
724 convenience of generating error message, we also put the
725 ThreadId in this tid field, but be aware that it should
726 ALWAYS == the index in vg_threads[]. */
727 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000728
njn25e49d8e72002-09-23 09:36:25 +0000729 /* Current scheduling status.
sewardj5f07b662002-04-23 16:52:51 +0000730
njn25e49d8e72002-09-23 09:36:25 +0000731 Complications: whenever this is set to VgTs_WaitMX, you
732 should also set .m_edx to whatever the required return value
733 is for pthread_mutex_lock / pthread_cond_timedwait for when
734 the mutex finally gets unblocked. */
735 ThreadStatus status;
sewardj2e93c502002-04-12 11:12:52 +0000736
njn25e49d8e72002-09-23 09:36:25 +0000737 /* When .status == WaitMX, points to the mutex I am waiting for.
738 When .status == WaitCV, points to the mutex associated with
739 the condition variable indicated by the .associated_cv field.
740 In all other cases, should be NULL. */
741 void* /*pthread_mutex_t* */ associated_mx;
sewardj3b5d8862002-04-20 13:53:23 +0000742
njn25e49d8e72002-09-23 09:36:25 +0000743 /* When .status == WaitCV, points to the condition variable I am
744 waiting for. In all other cases, should be NULL. */
745 void* /*pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000746
njn25e49d8e72002-09-23 09:36:25 +0000747 /* If VgTs_Sleeping, this is when we should wake up, measured in
njn6c846552003-09-16 07:41:43 +0000748 milliseconds as supplied by VG_(read_millisecond_timer).
sewardj2e93c502002-04-12 11:12:52 +0000749
njn25e49d8e72002-09-23 09:36:25 +0000750 If VgTs_WaitCV, this indicates the time at which
751 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
752 this means infinitely far in the future, viz,
753 pthread_cond_wait. */
754 UInt awaken_at;
sewardj20917d82002-05-28 01:36:45 +0000755
njn25e49d8e72002-09-23 09:36:25 +0000756 /* If VgTs_WaitJoiner, return value, as generated by joinees. */
757 void* joinee_retval;
sewardj20917d82002-05-28 01:36:45 +0000758
njn25e49d8e72002-09-23 09:36:25 +0000759 /* If VgTs_WaitJoinee, place to copy the return value to, and
760 the identity of the thread we're waiting for. */
761 void** joiner_thread_return;
762 ThreadId joiner_jee_tid;
sewardj8ad94e12002-05-29 00:10:20 +0000763
jsgf855d93d2003-10-13 22:26:55 +0000764 /* If VgTs_WaitSys, this is the result of the pre-syscall check */
765 void *sys_pre_res;
766
767 /* If VgTs_WaitSys, this is the syscall we're currently running */
768 Int syscallno;
769
770 /* Details about this thread's proxy LWP */
771 ProxyLWP *proxy;
772
njn25e49d8e72002-09-23 09:36:25 +0000773 /* Whether or not detached. */
774 Bool detached;
sewardj20917d82002-05-28 01:36:45 +0000775
njn25e49d8e72002-09-23 09:36:25 +0000776 /* Cancelability state and type. */
777 Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */
778 Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */
779
780 /* Pointer to fn to call to do cancellation. Indicates whether
781 or not cancellation is pending. If NULL, not pending. Else
782 should be &thread_exit_wrapper(), indicating that
783 cancallation is pending. */
784 void (*cancel_pend)(void*);
sewardj2e93c502002-04-12 11:12:52 +0000785
njn25e49d8e72002-09-23 09:36:25 +0000786 /* The cleanup stack. */
787 Int custack_used;
788 CleanupEntry custack[VG_N_CLEANUPSTACK];
sewardj5f07b662002-04-23 16:52:51 +0000789
sewardj00a66b12002-10-12 16:42:35 +0000790 /* A pointer to the thread's-specific-data. This is handled almost
791 entirely from vg_libpthread.c. We just provide hooks to get and
792 set this ptr. This is either NULL, indicating the thread has
793 read/written none of its specifics so far, OR points to a
794 void*[VG_N_THREAD_KEYS], allocated and deallocated in
795 vg_libpthread.c. */
796 void** specifics_ptr;
sewardjb48e5002002-05-13 00:16:03 +0000797
njn25e49d8e72002-09-23 09:36:25 +0000798 /* This thread's blocked-signals mask. Semantics is that for a
799 signal to be delivered to this thread, the signal must not be
jsgf855d93d2003-10-13 22:26:55 +0000800 blocked by this signal mask. If more than one thread accepts a
801 signal, then it will be delivered to one at random. If all
802 threads block the signal, it will remain pending until either a
803 thread unblocks it or someone uses sigwaitsig/sigtimedwait.
804
805 sig_mask reflects what the client told us its signal mask should
806 be, but isn't necessarily the current signal mask of the proxy
807 LWP: it may have more signals blocked because of signal
808 handling, or it may be different because of sigsuspend.
809 */
njn25e49d8e72002-09-23 09:36:25 +0000810 vki_ksigset_t sig_mask;
sewardjb48e5002002-05-13 00:16:03 +0000811
jsgf855d93d2003-10-13 22:26:55 +0000812 /* Effective signal mask. This is the mask which is currently
813 applying; it may be different from sig_mask while a signal
814 handler is running.
815 */
816 vki_ksigset_t eff_sig_mask;
sewardj2e93c502002-04-12 11:12:52 +0000817
njn25e49d8e72002-09-23 09:36:25 +0000818 /* Stacks. When a thread slot is freed, we don't deallocate its
819 stack; we just leave it lying around for the next use of the
820 slot. If the next use of the slot requires a larger stack,
821 only then is the old one deallocated and a new one
822 allocated.
sewardj2e93c502002-04-12 11:12:52 +0000823
njn25e49d8e72002-09-23 09:36:25 +0000824 For the main thread (threadid == 0), this mechanism doesn't
825 apply. We don't know the size of the stack since we didn't
826 allocate it, and furthermore we never reallocate it. */
sewardj2e93c502002-04-12 11:12:52 +0000827
njn25e49d8e72002-09-23 09:36:25 +0000828 /* The allocated size of this thread's stack (permanently zero
829 if this is ThreadId == 0, since we didn't allocate its stack) */
830 UInt stack_size;
sewardj1e8cdc92002-04-18 11:37:52 +0000831
njn25e49d8e72002-09-23 09:36:25 +0000832 /* Address of the lowest word in this thread's stack. NULL means
833 not allocated yet.
834 */
835 Addr stack_base;
sewardj2e93c502002-04-12 11:12:52 +0000836
sewardj92a59562002-09-30 00:53:10 +0000837 /* Address of the highest legitimate word in this stack. This is
838 used for error messages only -- not critical for execution
839 correctness. Is is set for all stacks, specifically including
840 ThreadId == 0 (the main thread). */
njn25e49d8e72002-09-23 09:36:25 +0000841 Addr stack_highest_word;
842
sewardj92a59562002-09-30 00:53:10 +0000843 /* Pointer to this thread's Local (Segment) Descriptor Table.
844 Starts out as NULL, indicating there is no table, and we hope to
845 keep it that way. If the thread does __NR_modify_ldt to create
846 entries, we allocate a 8192-entry table at that point. This is
847 a straight copy of the Linux kernel's scheme. Don't forget to
848 deallocate this at thread exit. */
849 VgLdtEntry* ldt;
850
851 /* Saved machine context. Note the FPU state, %EIP and segment
852 registers are not shadowed.
853
854 Although the segment registers are 16 bits long, storage
855 management here, in VG_(baseBlock) and in VG_(m_state_static) is
856 simplified if we pretend they are 32 bits. */
857 UInt m_cs;
858 UInt m_ss;
859 UInt m_ds;
860 UInt m_es;
861 UInt m_fs;
862 UInt m_gs;
863
njn25e49d8e72002-09-23 09:36:25 +0000864 UInt m_eax;
865 UInt m_ebx;
866 UInt m_ecx;
867 UInt m_edx;
868 UInt m_esi;
869 UInt m_edi;
870 UInt m_ebp;
871 UInt m_esp;
872 UInt m_eflags;
873 UInt m_eip;
sewardjb91ae7f2003-04-29 23:50:00 +0000874
875 /* The SSE/FPU state. This array does not (necessarily) have the
876 required 16-byte alignment required to get stuff in/out by
877 fxsave/fxrestore. So we have to do it "by hand".
878 */
879 UInt m_sse[VG_SIZE_OF_SSESTATE_W];
njn25e49d8e72002-09-23 09:36:25 +0000880
881 UInt sh_eax;
882 UInt sh_ebx;
883 UInt sh_ecx;
884 UInt sh_edx;
885 UInt sh_esi;
886 UInt sh_edi;
887 UInt sh_ebp;
888 UInt sh_esp;
889 UInt sh_eflags;
njn72718642003-07-24 08:45:32 +0000890}
891ThreadState;
sewardj2e93c502002-04-12 11:12:52 +0000892
893
sewardj018f7622002-05-15 21:13:39 +0000894/* The thread table. */
895extern ThreadState VG_(threads)[VG_N_THREADS];
896
897/* Check that tid is in range and denotes a non-Empty thread. */
sewardjb48e5002002-05-13 00:16:03 +0000898extern Bool VG_(is_valid_tid) ( ThreadId tid );
899
sewardj018f7622002-05-15 21:13:39 +0000900/* Check that tid is in range. */
901extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid );
902
njn72718642003-07-24 08:45:32 +0000903/* Determine if 'tid' is that of the current running thread (Nb: returns
904 False if no thread is currently running. */
905extern Bool VG_(is_running_thread)(ThreadId tid);
906
jsgf855d93d2003-10-13 22:26:55 +0000907/* Get the ThreadState for a particular thread */
908extern ThreadState *VG_(get_ThreadState)(ThreadId tid);
909
sewardj2e93c502002-04-12 11:12:52 +0000910/* Copy the specified thread's state into VG_(baseBlock) in
911 preparation for running it. */
912extern void VG_(load_thread_state)( ThreadId );
913
914/* Save the specified thread's state back in VG_(baseBlock), and fill
915 VG_(baseBlock) with junk, for sanity-check reasons. */
916extern void VG_(save_thread_state)( ThreadId );
917
sewardj1e8cdc92002-04-18 11:37:52 +0000918/* And for the currently running one, if valid. */
919extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000920
sewardj1e8cdc92002-04-18 11:37:52 +0000921/* Similarly ... */
922extern ThreadId VG_(get_current_tid) ( void );
923
sewardjccef2e62002-05-29 19:26:32 +0000924/* Nuke all threads except tid. */
925extern void VG_(nuke_all_threads_except) ( ThreadId me );
926
jsgf855d93d2003-10-13 22:26:55 +0000927/* Give a hint to the scheduler that it may be a good time to find a
928 new runnable thread. If prefer_sched != VG_INVALID_THREADID, then
929 try to schedule that thread.
930*/
931extern void VG_(need_resched) ( ThreadId prefer_sched );
932
933/* Add a new timeout event for a thread*/
934extern void VG_(add_timeout) ( ThreadId tid, UInt time );
sewardj2e93c502002-04-12 11:12:52 +0000935
936/* Return codes from the scheduler. */
937typedef
sewardj7e87e382002-05-03 19:09:05 +0000938 enum {
939 VgSrc_Deadlock, /* no runnable threads and no prospect of any
940 even if we wait for a long time */
941 VgSrc_ExitSyscall, /* client called exit(). This is the normal
942 route out. */
jsgf855d93d2003-10-13 22:26:55 +0000943 VgSrc_BbsDone, /* In a debugging run, the specified number of
sewardj7e87e382002-05-03 19:09:05 +0000944 bbs has been completed. */
jsgf855d93d2003-10-13 22:26:55 +0000945 VgSrc_FatalSig /* Killed by the default action of a fatal
946 signal */
sewardj7e87e382002-05-03 19:09:05 +0000947 }
sewardj2e93c502002-04-12 11:12:52 +0000948 VgSchedReturnCode;
949
sewardj7e87e382002-05-03 19:09:05 +0000950
sewardj2e93c502002-04-12 11:12:52 +0000951/* The scheduler. */
952extern VgSchedReturnCode VG_(scheduler) ( void );
953
954extern void VG_(scheduler_init) ( void );
955
sewardj15a43e12002-04-17 19:35:12 +0000956extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000957
958/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
959extern jmp_buf VG_(scheduler_jmpbuf);
sewardj872051c2002-07-13 12:12:56 +0000960/* This says whether scheduler_jmpbuf is actually valid. Needed so
961 that our signal handler doesn't longjmp when the buffer isn't
962 actually valid. */
963extern Bool VG_(scheduler_jmpbuf_valid);
sewardj2e93c502002-04-12 11:12:52 +0000964/* ... and if so, here's the signal which caused it to do so. */
965extern Int VG_(longjmpd_on_signal);
966
967
sewardj2e93c502002-04-12 11:12:52 +0000968/* The red-zone size which we put at the bottom (highest address) of
969 thread stacks, for paranoia reasons. This can be arbitrary, and
970 doesn't really need to be set at compile time. */
971#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
972
973#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
974 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
975
njn25e49d8e72002-09-23 09:36:25 +0000976/* Junk to fill up a thread's shadow regs with when shadow regs aren't
njnd3040452003-05-19 15:04:06 +0000977 being used. */
njn25e49d8e72002-09-23 09:36:25 +0000978#define VG_UNUSED_SHADOW_REG_VALUE 0x27182818
njnd3040452003-05-19 15:04:06 +0000979/* For sanity checking: if this ends up in a thread's shadow regs when
980 shadow regs aren't being used, something went wrong. */
981#define VG_USED_SHADOW_REG_VALUE 0x31415927
njn25e49d8e72002-09-23 09:36:25 +0000982
njnd3040452003-05-19 15:04:06 +0000983/* Write a value to a client's thread register, and shadow (if necessary) */
984#define SET_THREAD_REG( zztid, zzval, zzreg, zzREG, zzevent, zzargs... ) \
985 do { VG_(threads)[zztid].m_##zzreg = (zzval); \
986 VG_TRACK( zzevent, zztid, R_##zzREG, ##zzargs ); \
sewardj018f7622002-05-15 21:13:39 +0000987 } while (0)
988
njnd3040452003-05-19 15:04:06 +0000989#define SET_SYSCALL_RETVAL(zztid, zzval) \
990 SET_THREAD_REG(zztid, zzval, eax, EAX, post_reg_write_syscall_return)
991
992#define SET_SIGNAL_EDX(zztid, zzval) \
993 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_deliver_signal)
994
995#define SET_SIGNAL_ESP(zztid, zzval) \
996 SET_THREAD_REG(zztid, zzval, esp, ESP, post_reg_write_deliver_signal)
997
998#define SET_CLREQ_RETVAL(zztid, zzval) \
999 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_clientreq_return)
1000
1001#define SET_CLCALL_RETVAL(zztid, zzval, f) \
1002 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_clientcall_return, f)
1003
1004#define SET_PTHREQ_ESP(zztid, zzval) \
1005 SET_THREAD_REG(zztid, zzval, esp, ESP, post_reg_write_pthread_return)
1006
1007#define SET_PTHREQ_RETVAL(zztid, zzval) \
1008 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_pthread_return)
sewardj018f7622002-05-15 21:13:39 +00001009
sewardj2e93c502002-04-12 11:12:52 +00001010
sewardjd8acdf22002-11-13 21:57:52 +00001011/* This is or'd into a pthread mutex's __m_kind field if it is used
1012 before Valgrind is up and running (prehistory). This is used so
1013 that if some early code (like the dynamic linker) takes a lock
1014 before Valgrind starts and then releases it afterwards, we can work
1015 out what's happening. */
1016#define VG_PTHREAD_PREHISTORY 0x80000000
1017
sewardj2e93c502002-04-12 11:12:52 +00001018/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001019 Exports of vg_signals.c
1020 ------------------------------------------------------------------ */
1021
jsgf855d93d2003-10-13 22:26:55 +00001022extern Bool VG_(do_signal_routing); /* whether scheduler LWP has to route signals */
1023
1024/* RT signal allocation */
1025extern Int VG_(sig_rtmin);
1026extern Int VG_(sig_rtmax);
1027extern Int VG_(sig_alloc_rtsig) ( Int high );
1028
sewardjde4a1d02002-03-22 01:27:54 +00001029extern void VG_(sigstartup_actions) ( void );
sewardj839299f2003-06-14 11:57:59 +00001030extern void VG_(sigshutdown_actions) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001031
jsgf855d93d2003-10-13 22:26:55 +00001032extern void VG_(deliver_signal) ( ThreadId tid, const vki_ksiginfo_t *, Bool async );
sewardjde4a1d02002-03-22 01:27:54 +00001033extern void VG_(unblock_host_signal) ( Int sigNo );
sewardj018f7622002-05-15 21:13:39 +00001034extern void VG_(handle_SCSS_change) ( Bool force_update );
1035
jsgf855d93d2003-10-13 22:26:55 +00001036extern Bool VG_(is_sig_ign) ( Int sigNo );
1037
1038/* Route pending signals from the scheduler LWP to the appropriate
1039 thread LWP. */
1040extern void VG_(route_signals) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001041
1042/* Fake system calls for signal handling. */
sewardj2342c972002-05-22 23:34:20 +00001043extern void VG_(do__NR_sigaltstack) ( ThreadId tid );
sewardj2e93c502002-04-12 11:12:52 +00001044extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardj018f7622002-05-15 21:13:39 +00001045extern void VG_(do__NR_sigprocmask) ( ThreadId tid,
1046 Int how,
1047 vki_ksigset_t* set,
1048 vki_ksigset_t* oldset );
1049extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid,
1050 Int how,
1051 vki_ksigset_t* set,
1052 vki_ksigset_t* oldset );
1053extern void VG_(send_signal_to_thread) ( ThreadId thread,
1054 Int signo );
sewardjde4a1d02002-03-22 01:27:54 +00001055
sewardjefbfcdf2002-06-19 17:35:45 +00001056extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set );
1057
1058
sewardj2e93c502002-04-12 11:12:52 +00001059/* Modify the current thread's state once we have detected it is
1060 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +00001061extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +00001062
sewardj2e93c502002-04-12 11:12:52 +00001063/* Handy utilities to block/restore all host signals. */
1064extern void VG_(block_all_host_signals)
1065 ( /* OUT */ vki_ksigset_t* saved_mask );
sewardj018f7622002-05-15 21:13:39 +00001066extern void VG_(restore_all_host_signals)
sewardj2e93c502002-04-12 11:12:52 +00001067 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +00001068
jsgf855d93d2003-10-13 22:26:55 +00001069extern vki_ksiginfo_t VG_(unresumable_siginfo);
1070
1071extern void VG_(kill_self)(Int sigNo);
1072
sewardjde4a1d02002-03-22 01:27:54 +00001073/* ---------------------------------------------------------------------
1074 Exports of vg_mylibc.c
1075 ------------------------------------------------------------------ */
1076
njne427a662002-10-02 11:08:25 +00001077#define vg_assert(expr) \
1078 ((void) ((expr) ? 0 : \
1079 (VG_(core_assert_fail) (VG__STRING(expr), \
1080 __FILE__, __LINE__, \
1081 __PRETTY_FUNCTION__), 0)))
1082__attribute__ ((__noreturn__))
daywalker3222e0a2003-09-18 01:39:50 +00001083extern void VG_(core_assert_fail) ( const Char* expr, const Char* file,
1084 Int line, const Char* fn );
njne427a662002-10-02 11:08:25 +00001085__attribute__ ((__noreturn__))
1086extern void VG_(core_panic) ( Char* str );
sewardjde4a1d02002-03-22 01:27:54 +00001087
njn25e49d8e72002-09-23 09:36:25 +00001088/* VG_(brk) not public so skins cannot screw with curr_dataseg_end */
1089extern void* VG_(brk) ( void* end_data_segment );
sewardjde4a1d02002-03-22 01:27:54 +00001090
njn25e49d8e72002-09-23 09:36:25 +00001091/* Skins use VG_(strdup)() which doesn't expose ArenaId */
1092extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
sewardjde4a1d02002-03-22 01:27:54 +00001093
njn25e49d8e72002-09-23 09:36:25 +00001094/* Skins shouldn't need these...(?) */
sewardj5f07b662002-04-23 16:52:51 +00001095extern void VG_(start_rdtsc_calibration) ( void );
1096extern void VG_(end_rdtsc_calibration) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001097
njn25e49d8e72002-09-23 09:36:25 +00001098extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
sewardj2e93c502002-04-12 11:12:52 +00001099extern Int VG_(select)( Int n,
1100 vki_fd_set* readfds,
1101 vki_fd_set* writefds,
1102 vki_fd_set* exceptfds,
1103 struct vki_timeval * timeout );
jsgf855d93d2003-10-13 22:26:55 +00001104extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout);
sewardj2e93c502002-04-12 11:12:52 +00001105extern Int VG_(nanosleep)( const struct vki_timespec *req,
1106 struct vki_timespec *rem );
1107
jsgf855d93d2003-10-13 22:26:55 +00001108/* Move an fd into the Valgrind-safe range */
1109Int VG_(safe_fd)(Int oldfd);
1110
sewardj570f8902002-11-03 11:44:36 +00001111extern Int VG_(write_socket)( Int sd, void *msg, Int count );
sewardj73cf3bc2002-11-03 03:20:15 +00001112
1113/* --- Connecting over the network --- */
1114extern Int VG_(connect_via_socket)( UChar* str );
1115
sewardj570f8902002-11-03 11:44:36 +00001116
1117/* ---------------------------------------------------------------------
1118 Exports of vg_message.c
1119 ------------------------------------------------------------------ */
1120
1121/* Low-level -- send bytes directly to the message sink. Do not
1122 use. */
1123extern void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes );
1124
1125
sewardjde4a1d02002-03-22 01:27:54 +00001126/* ---------------------------------------------------------------------
1127 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
1128 vg_from_ucode.c).
1129 ------------------------------------------------------------------ */
1130
sewardjde4a1d02002-03-22 01:27:54 +00001131#define VG_IS_FLAG_SUBSET(set1,set2) \
1132 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
1133
1134#define VG_UNION_FLAG_SETS(set1,set2) \
1135 ( ((FlagSet)set1) | ((FlagSet)set2) )
1136
sewardjde4a1d02002-03-22 01:27:54 +00001137/* ---------------------------------------------------------------------
1138 Exports of vg_demangle.c
1139 ------------------------------------------------------------------ */
1140
1141extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
1142
sewardjde4a1d02002-03-22 01:27:54 +00001143/* ---------------------------------------------------------------------
1144 Exports of vg_from_ucode.c
1145 ------------------------------------------------------------------ */
1146
sewardj22854b92002-11-30 14:00:47 +00001147extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes, UShort jumps[VG_MAX_JUMPS] );
sewardjde4a1d02002-03-22 01:27:54 +00001148
njn25e49d8e72002-09-23 09:36:25 +00001149extern void VG_(print_ccall_stats) ( void );
1150extern void VG_(print_UInstr_histogram) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001151
sewardj22854b92002-11-30 14:00:47 +00001152extern void VG_(unchain_jumpsite) ( Addr jumpsite );
1153extern Addr VG_(get_jmp_dest) ( Addr jumpsite );
1154extern Bool VG_(is_unchained_jumpsite) ( Addr jumpsite );
1155extern Bool VG_(is_chained_jumpsite) ( Addr jumpsite );
1156
sewardjde4a1d02002-03-22 01:27:54 +00001157/* ---------------------------------------------------------------------
1158 Exports of vg_to_ucode.c
1159 ------------------------------------------------------------------ */
1160
1161extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
sewardjde4a1d02002-03-22 01:27:54 +00001162
1163/* ---------------------------------------------------------------------
1164 Exports of vg_translate.c
1165 ------------------------------------------------------------------ */
1166
njn810086f2002-11-14 12:42:47 +00001167/* Expandable arrays of uinstrs. */
1168struct _UCodeBlock {
sewardj22854b92002-11-30 14:00:47 +00001169 Addr orig_eip;
njn810086f2002-11-14 12:42:47 +00001170 Int used;
1171 Int size;
1172 UInstr* instrs;
1173 Int nextTemp;
1174};
1175
1176extern UCodeBlock* VG_(alloc_UCodeBlock) ( void );
1177
njn72718642003-07-24 08:45:32 +00001178extern void VG_(translate) ( ThreadId tid,
sewardj1e8cdc92002-04-18 11:37:52 +00001179 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001180 UInt* orig_size,
1181 Addr* trans_addr,
sewardj22854b92002-11-30 14:00:47 +00001182 UInt* trans_size,
1183 UShort jumps[VG_MAX_JUMPS]);
sewardjde4a1d02002-03-22 01:27:54 +00001184
njn25e49d8e72002-09-23 09:36:25 +00001185extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness,
1186 UInstr* u );
1187extern void VG_(saneUCodeBlock) ( UCodeBlock* cb );
1188extern Bool VG_(saneUCodeBlockCalls) ( UCodeBlock* cb );
sewardjde4a1d02002-03-22 01:27:54 +00001189
sewardjb5ff83e2002-12-01 19:40:49 +00001190
sewardjde4a1d02002-03-22 01:27:54 +00001191/* ---------------------------------------------------------------------
1192 Exports of vg_execontext.c.
1193 ------------------------------------------------------------------ */
1194
1195/* Records the PC and a bit of the call chain. The first 4 %eip
1196 values are used in comparisons do remove duplicate errors, and for
1197 comparing against suppression specifications. The rest are purely
1198 informational (but often important). */
1199
njn25e49d8e72002-09-23 09:36:25 +00001200struct _ExeContext {
1201 struct _ExeContext * next;
1202 /* Variable-length array. The size is VG_(clo_backtrace_size); at
njn6c846552003-09-16 07:41:43 +00001203 least 1, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
njn25e49d8e72002-09-23 09:36:25 +00001204 [1] is its caller, [2] is the caller of [1], etc. */
1205 Addr eips[0];
1206};
sewardjde4a1d02002-03-22 01:27:54 +00001207
1208
sewardjde4a1d02002-03-22 01:27:54 +00001209/* Print stats (informational only). */
1210extern void VG_(show_ExeContext_stats) ( void );
1211
njn25e49d8e72002-09-23 09:36:25 +00001212/* Like VG_(get_ExeContext), but with a slightly different type */
1213extern ExeContext* VG_(get_ExeContext2) ( Addr eip, Addr ebp,
1214 Addr ebp_min, Addr ebp_max );
sewardjde4a1d02002-03-22 01:27:54 +00001215
1216
1217/* ---------------------------------------------------------------------
1218 Exports of vg_errcontext.c.
1219 ------------------------------------------------------------------ */
1220
njn25e49d8e72002-09-23 09:36:25 +00001221/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1222 * effectively extend it by defining their own enums in the (0..) range. */
sewardjde4a1d02002-03-22 01:27:54 +00001223typedef
njn25e49d8e72002-09-23 09:36:25 +00001224 enum {
1225 PThreadSupp = -1, /* Matches PThreadErr */
sewardjde4a1d02002-03-22 01:27:54 +00001226 }
njn25e49d8e72002-09-23 09:36:25 +00001227 CoreSuppKind;
1228
1229/* For each caller specified for a suppression, record the nature of
1230 the caller name. Not of interest to skins. */
1231typedef
1232 enum {
1233 ObjName, /* Name is of an shared object file. */
1234 FunName /* Name is of a function. */
1235 }
1236 SuppLocTy;
1237
njn810086f2002-11-14 12:42:47 +00001238/* Suppressions. Skins can get/set skin-relevant parts with functions
1239 declared in include/vg_skin.h. Extensible via the 'extra' field.
1240 Skins can use a normal enum (with element values in the normal range
1241 (0..)) for `skind'. */
1242struct _Supp {
1243 struct _Supp* next;
1244 /* The number of times this error has been suppressed. */
1245 Int count;
1246 /* The name by which the suppression is referred to. */
1247 Char* sname;
1248 /* First two (name of fn where err occurs, and immediate caller)
1249 * are mandatory; extra two are optional. */
1250 SuppLocTy caller_ty[VG_N_SUPP_CALLERS];
1251 Char* caller [VG_N_SUPP_CALLERS];
1252
1253 /* The skin-specific part */
1254 /* What kind of suppression. Must use the range (0..) */
1255 SuppKind skind;
1256 /* String -- use is optional. NULL by default. */
1257 Char* string;
1258 /* Anything else -- use is optional. NULL by default. */
1259 void* extra;
1260};
njn25e49d8e72002-09-23 09:36:25 +00001261
1262/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1263 * effectively extend it by defining their own enums in the (0..) range. */
1264typedef
1265 enum {
1266 PThreadErr = -1, /* Pthreading error */
1267 }
1268 CoreErrorKind;
1269
njn810086f2002-11-14 12:42:47 +00001270/* Errors. Extensible (via the 'extra' field). Skins can use a normal
1271 enum (with element values in the normal range (0..)) for `ekind'.
1272 Functions for getting/setting the skin-relevant fields are in
1273 include/vg_skin.h.
1274
1275 When errors are found and recorded with VG_(maybe_record_error)(), all
1276 the skin must do is pass in the four parameters; core will
1277 allocate/initialise the error record.
1278*/
1279struct _Error {
1280 struct _Error* next;
1281 /* NULL if unsuppressed; or ptr to suppression record. */
1282 Supp* supp;
1283 Int count;
njn810086f2002-11-14 12:42:47 +00001284 ThreadId tid;
njn810086f2002-11-14 12:42:47 +00001285
1286 /* The skin-specific part */
njnae17bec2003-01-28 19:59:38 +00001287 /* Initialised by core */
1288 ExeContext* where;
njn810086f2002-11-14 12:42:47 +00001289 /* Used by ALL. Must be in the range (0..) */
1290 Int ekind;
1291 /* Used frequently */
1292 Addr addr;
1293 /* Used frequently */
1294 Char* string;
1295 /* For any skin-specific extras */
1296 void* extra;
1297};
sewardjde4a1d02002-03-22 01:27:54 +00001298
1299
njn25e49d8e72002-09-23 09:36:25 +00001300extern void VG_(load_suppressions) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001301
njn25e49d8e72002-09-23 09:36:25 +00001302extern void VG_(record_pthread_error) ( ThreadId tid, Char* msg );
sewardjde4a1d02002-03-22 01:27:54 +00001303
njn25e49d8e72002-09-23 09:36:25 +00001304extern void VG_(show_all_errors) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001305
njn43c799e2003-04-08 00:08:52 +00001306extern Bool VG_(is_action_requested) ( Char* action, Bool* clo );
1307
1308extern void VG_(gen_suppression) ( Error* err );
sewardj99aac972002-12-26 01:53:45 +00001309
njn47363ab2003-04-21 13:24:40 +00001310extern UInt VG_(n_errs_found);
1311
sewardjde4a1d02002-03-22 01:27:54 +00001312/* ---------------------------------------------------------------------
1313 Exports of vg_procselfmaps.c
1314 ------------------------------------------------------------------ */
1315
njnfa1016e2003-09-25 17:54:11 +00001316/* Reads /proc/self/maps into a static buffer which can be parsed by
1317 VG_(parse_procselfmaps)(). */
1318extern void VG_(read_procselfmaps) ( void );
njn3e884182003-04-15 13:03:23 +00001319
1320/* Parses /proc/self/maps, calling `record_mapping' for each entry. If
1321 `read_from_file' is True, /proc/self/maps is read directly, otherwise
1322 it's read from the buffer filled by VG_(read_procselfmaps_contents)(). */
sewardjde4a1d02002-03-22 01:27:54 +00001323extern
njnfa1016e2003-09-25 17:54:11 +00001324void VG_(parse_procselfmaps) (
1325 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
sewardjde4a1d02002-03-22 01:27:54 +00001326);
1327
1328
1329/* ---------------------------------------------------------------------
1330 Exports of vg_symtab2.c
1331 ------------------------------------------------------------------ */
1332
njnfa1016e2003-09-25 17:54:11 +00001333extern void VG_(mini_stack_dump) ( Addr eips[], UInt n_eips );
1334extern void VG_(read_all_symbols) ( void );
1335extern void VG_(read_seg_symbols) ( Addr start, UInt size,
1336 Char rr, Char ww, Char xx,
1337 UInt foffset, UChar* filename );
1338extern void VG_(unload_symbols) ( Addr start, UInt length );
sewardjde4a1d02002-03-22 01:27:54 +00001339
njn25e49d8e72002-09-23 09:36:25 +00001340extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname );
sewardj25c7c3a2003-07-10 00:17:58 +00001341extern Int VG_(setup_code_redirect_table) ( void );
1342
1343typedef
1344 struct {
1345 Addr entry_pt_orig;
1346 Addr entry_pt_subst;
1347 }
1348 CodeRedirect;
1349
1350#define VG_N_CODE_REDIRECTS 10
1351extern CodeRedirect VG_(code_redirect_table)[VG_N_CODE_REDIRECTS];
1352/* Table is terminated by a NULL entry_pt_orig field. */
sewardjde4a1d02002-03-22 01:27:54 +00001353
1354
1355/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001356 Exports of vg_main.c
1357 ------------------------------------------------------------------ */
1358
sewardjb91ae7f2003-04-29 23:50:00 +00001359/* Is this a SSE/SSE2-capable CPU? If so, we had better save/restore
1360 the SSE state all over the place. This is set up very early, in
1361 vg_startup.S. We have to determine it early since we can't even
1362 correctly snapshot the startup machine state without it. */
1363extern Bool VG_(have_ssestate);
1364
sewardj73cf3bc2002-11-03 03:20:15 +00001365/* Tell the logging mechanism whether we are logging to a file
1366 descriptor or a socket descriptor. */
1367extern Bool VG_(logging_to_filedes);
1368
njn25e49d8e72002-09-23 09:36:25 +00001369/* Sanity checks which may be done at any time. The scheduler decides when. */
1370extern void VG_(do_sanity_checks) ( Bool force_expensive );
1371
sewardjde4a1d02002-03-22 01:27:54 +00001372/* A structure used as an intermediary when passing the simulated
1373 CPU's state to some assembly fragments, particularly system calls.
1374 Stuff is copied from baseBlock to here, the assembly magic runs,
sewardjb91ae7f2003-04-29 23:50:00 +00001375 and then the inverse copy is done. Alignment: the SSE state must
1376 be 16-byte aligned. We ask for the whole struct to be 16-byte
1377 aligned, and the SSE state starts at the 6+8+1+1th == 16th word,
1378 so it too must be 16-byte aligned. Consequence: change this struct
1379 only _very carefully_ ! See also above comment re masking MXCSR.
1380*/
1381__attribute__ ((aligned (16)))
sewardj92a59562002-09-30 00:53:10 +00001382extern UInt VG_(m_state_static) [6 /* segment regs, Intel order */
1383 + 8 /* int regs, in Intel order */
sewardjde4a1d02002-03-22 01:27:54 +00001384 + 1 /* %eflags */
1385 + 1 /* %eip */
sewardjb91ae7f2003-04-29 23:50:00 +00001386 + VG_SIZE_OF_SSESTATE_W /* SSE state */
sewardjde4a1d02002-03-22 01:27:54 +00001387 ];
1388
1389/* Handy fns for doing the copy back and forth. */
1390extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1391extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1392
njn9b007f62003-04-07 14:40:25 +00001393/* Determine if %esp adjustment must be noted */
njnf4ce3d32003-02-10 10:17:26 +00001394extern Bool VG_(need_to_handle_esp_assignment) ( void );
1395
sewardjde4a1d02002-03-22 01:27:54 +00001396/* Called when some unhandleable client behaviour is detected.
1397 Prints a msg and aborts. */
njn25e49d8e72002-09-23 09:36:25 +00001398extern void VG_(unimplemented) ( Char* msg )
1399 __attribute__((__noreturn__));
sewardjde4a1d02002-03-22 01:27:54 +00001400
1401/* The stack on which Valgrind runs. We can't use the same stack as the
1402 simulatee -- that's an important design decision. */
njn6eba4ef2003-05-01 08:06:41 +00001403extern UInt VG_(stack)[VG_STACK_SIZE_W];
sewardjde4a1d02002-03-22 01:27:54 +00001404
njn25e49d8e72002-09-23 09:36:25 +00001405/* Similarly, we have to ask for signals to be delivered on an alternative
1406 stack, since it is possible, although unlikely, that we'll have to run
1407 client code from inside the Valgrind-installed signal handler. If this
1408 happens it will be done by vg_deliver_signal_immediately(). */
njn6eba4ef2003-05-01 08:06:41 +00001409extern UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W];
sewardjde4a1d02002-03-22 01:27:54 +00001410
sewardjde4a1d02002-03-22 01:27:54 +00001411/* Holds client's %esp at the point we gained control. From this the
1412 client's argc, argv and envp are deduced. */
1413extern Addr VG_(esp_at_startup);
sewardjde4a1d02002-03-22 01:27:54 +00001414
sewardjd5815ec2003-04-06 12:23:27 +00001415/* Indicates presence, and holds address of client's sysinfo page, a
1416 feature of some modern kernels used to provide vsyscalls, etc. */
1417extern Bool VG_(sysinfo_page_exists);
1418extern Addr VG_(sysinfo_page_addr);
1419
njn25e49d8e72002-09-23 09:36:25 +00001420/* Remove valgrind.so and skin's .so from a LD_PRELOAD=... string so child
1421 processes don't get traced into. Also mess up $libdir/valgrind so that
1422 our libpthread.so disappears from view. */
sewardj3e1eb1f2002-05-18 13:14:17 +00001423void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str,
1424 Char* ld_library_path_str );
sewardjde4a1d02002-03-22 01:27:54 +00001425
1426/* Something of a function looking for a home ... start up GDB. This
1427 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1428 *client's* stack. This is necessary to give GDB the illusion that
1429 the client program really was running on the real cpu. */
1430extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1431
njn41557122002-10-14 09:25:37 +00001432/* VG_(bbs_done) in include/vg_skin.h */
1433
sewardjde4a1d02002-03-22 01:27:54 +00001434/* 64-bit counter for the number of bbs to go before a debug exit. */
1435extern ULong VG_(bbs_to_go);
1436
1437/* Counts downwards in vg_run_innerloop. */
1438extern UInt VG_(dispatch_ctr);
1439
sewardjde4a1d02002-03-22 01:27:54 +00001440/* Is the client running on the simulated CPU or the real one? */
1441extern Bool VG_(running_on_simd_CPU); /* Initially False */
1442
sewardj7e87e382002-05-03 19:09:05 +00001443/* This is the ThreadId of the last thread the scheduler ran. */
1444extern ThreadId VG_(last_run_tid);
1445
njn25e49d8e72002-09-23 09:36:25 +00001446/* This is the argument to __NR_exit() supplied by the first thread to
1447 call that syscall. We eventually pass that to __NR_exit() for
1448 real. */
njn633de322003-05-12 20:40:13 +00001449extern Int VG_(exitcode);
njn25e49d8e72002-09-23 09:36:25 +00001450
jsgf855d93d2003-10-13 22:26:55 +00001451/* If we're doing the default action of a fatal signal */
1452extern jmp_buf VG_(fatal_signal_jmpbuf);
1453extern Bool VG_(fatal_signal_set); /* jmp_buf is valid */
1454extern Int VG_(fatal_sigNo); /* the fatal signal */
sewardjde4a1d02002-03-22 01:27:54 +00001455
1456/* --- Counters, for informational purposes only. --- */
1457
1458/* Number of lookups which miss the fast tt helper. */
1459extern UInt VG_(tt_fast_misses);
1460
sewardjc0d8f682002-11-30 00:49:43 +00001461/* Counts for TT/TC informational messages. */
sewardjde4a1d02002-03-22 01:27:54 +00001462
sewardjde4a1d02002-03-22 01:27:54 +00001463/* Number and total o/t size of translations overall. */
1464extern UInt VG_(overall_in_count);
1465extern UInt VG_(overall_in_osize);
1466extern UInt VG_(overall_in_tsize);
1467/* Number and total o/t size of discards overall. */
1468extern UInt VG_(overall_out_count);
1469extern UInt VG_(overall_out_osize);
1470extern UInt VG_(overall_out_tsize);
sewardjc0d8f682002-11-30 00:49:43 +00001471/* The number of discards of TT/TC. */
1472extern UInt VG_(number_of_tc_discards);
sewardj22854b92002-11-30 14:00:47 +00001473/* Counts of chain and unchain operations done. */
1474extern UInt VG_(bb_enchain_count);
1475extern UInt VG_(bb_dechain_count);
1476/* Number of unchained jumps performed. */
1477extern UInt VG_(unchained_jumps_done);
1478
sewardjde4a1d02002-03-22 01:27:54 +00001479
1480/* Counts pertaining to the register allocator. */
1481
1482/* total number of uinstrs input to reg-alloc */
1483extern UInt VG_(uinstrs_prealloc);
1484
1485/* total number of uinstrs added due to spill code */
1486extern UInt VG_(uinstrs_spill);
1487
1488/* number of bbs requiring spill code */
1489extern UInt VG_(translations_needing_spill);
1490
1491/* total of register ranks over all translations */
1492extern UInt VG_(total_reg_rank);
1493
sewardjde4a1d02002-03-22 01:27:54 +00001494/* Counts pertaining to internal sanity checking. */
1495extern UInt VG_(sanity_fast_count);
1496extern UInt VG_(sanity_slow_count);
1497
sewardj2e93c502002-04-12 11:12:52 +00001498/* Counts pertaining to the scheduler. */
1499extern UInt VG_(num_scheduling_events_MINOR);
1500extern UInt VG_(num_scheduling_events_MAJOR);
1501
sewardjfa492d42002-12-08 18:20:01 +00001502/* Insert and extract the D flag from eflags */
1503UInt VG_(insertDflag)(UInt eflags, Int d);
1504Int VG_(extractDflag)(UInt eflags);
sewardjde4a1d02002-03-22 01:27:54 +00001505
sewardj49e630d2003-04-23 21:18:52 +00001506/* start address and size of the initial stack */
1507extern Addr VG_(foundstack_start);
1508extern UInt VG_(foundstack_size);
1509
1510
sewardjde4a1d02002-03-22 01:27:54 +00001511/* ---------------------------------------------------------------------
1512 Exports of vg_memory.c
1513 ------------------------------------------------------------------ */
1514
njnfa1016e2003-09-25 17:54:11 +00001515extern void VG_(init_memory) ( void );
1516extern void VG_(new_exeseg_startup) ( Addr a, UInt len, Char rr, Char ww,
1517 Char xx, UInt foffset,
1518 UChar* filename );
1519extern void VG_(new_exeseg_mmap) ( Addr a, UInt len );
1520extern void VG_(remove_if_exeseg) ( Addr a, UInt len );
sewardjde4a1d02002-03-22 01:27:54 +00001521
njn9b007f62003-04-07 14:40:25 +00001522extern __attribute__((regparm(1)))
njnfa1016e2003-09-25 17:54:11 +00001523 void VG_(unknown_esp_update) ( Addr new_ESP );
sewardjde4a1d02002-03-22 01:27:54 +00001524
jsgf855d93d2003-10-13 22:26:55 +00001525extern Bool VG_(is_addressable)(Addr p, Int sz);
1526
1527/* ---------------------------------------------------------------------
1528 Exports of vg_proxylwp.c
1529 ------------------------------------------------------------------ */
1530
1531/* Issue a syscall for thread tid */
1532extern Int VG_(sys_issue)(int tid);
1533
1534extern void VG_(proxy_init) ( void );
1535extern void VG_(proxy_create) ( ThreadId tid );
1536extern void VG_(proxy_delete) ( ThreadId tid, Bool force );
1537extern void VG_(proxy_results) ( void );
1538extern void VG_(proxy_sendsig) ( ThreadId tid, Int signo );
1539extern void VG_(proxy_setsigmask)(ThreadId tid);
1540extern void VG_(proxy_sigack) ( ThreadId tid, const vki_ksigset_t *);
1541extern void VG_(proxy_abort_syscall) ( ThreadId tid );
1542extern void VG_(proxy_waitsig) ( void );
1543
1544extern void VG_(proxy_shutdown) ( void ); /* shut down the syscall workers */
1545extern Int VG_(proxy_resfd) ( void ); /* FD something can select on to know
1546 a syscall finished */
1547
1548/* Sanity-check the whole proxy-LWP machinery */
1549void VG_(proxy_sanity)(void);
1550
1551/* Send a signal from a thread's proxy to the thread. This longjmps
1552 back into the proxy's main loop, so it doesn't return. */
1553__attribute__ ((__noreturn__))
1554extern void VG_(proxy_handlesig)( const vki_ksiginfo_t *siginfo,
1555 const struct vki_sigcontext *sigcontext );
1556
1557
sewardjde4a1d02002-03-22 01:27:54 +00001558/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001559 Exports of vg_syscalls.c
sewardjde4a1d02002-03-22 01:27:54 +00001560 ------------------------------------------------------------------ */
1561
njn25e49d8e72002-09-23 09:36:25 +00001562extern void VG_(init_dataseg_end_for_brk) ( void );
1563
jsgf855d93d2003-10-13 22:26:55 +00001564extern Bool VG_(pre_syscall) ( ThreadId tid );
1565extern void VG_(post_syscall)( ThreadId tid );
fitzhardingee1c06d82003-10-30 07:21:44 +00001566extern void VG_(restart_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001567
1568extern Bool VG_(is_kerror) ( Int res );
1569
jsgf855d93d2003-10-13 22:26:55 +00001570/* Internal atfork handlers */
1571typedef void (*vg_atfork_t)(ThreadId);
1572extern void VG_(atfork)(vg_atfork_t pre, vg_atfork_t parent, vg_atfork_t child);
sewardjde4a1d02002-03-22 01:27:54 +00001573
1574/* ---------------------------------------------------------------------
1575 Exports of vg_transtab.c
1576 ------------------------------------------------------------------ */
1577
njn25e49d8e72002-09-23 09:36:25 +00001578/* The fast-cache for tt-lookup. */
1579extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE];
1580
sewardjde4a1d02002-03-22 01:27:54 +00001581extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
sewardj6c3769f2002-11-29 01:02:45 +00001582
sewardjc0d8f682002-11-30 00:49:43 +00001583extern void VG_(add_to_trans_tab) ( Addr orig_addr, Int orig_size,
sewardj22854b92002-11-30 14:00:47 +00001584 Addr trans_addr, Int trans_size,
1585 UShort jumps[VG_MAX_JUMPS]);
sewardj6c3769f2002-11-29 01:02:45 +00001586
sewardj97ad5522003-05-04 12:32:56 +00001587extern void VG_(invalidate_translations) ( Addr start, UInt range, Bool unchain_blocks );
sewardjde4a1d02002-03-22 01:27:54 +00001588
sewardj18d75132002-05-16 11:06:21 +00001589extern void VG_(init_tt_tc) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001590
1591extern void VG_(sanity_check_tc_tt) ( void );
1592extern Addr VG_(search_transtab) ( Addr original_addr );
1593
sewardjde4a1d02002-03-22 01:27:54 +00001594
1595
1596/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001597 Exports of vg_syscall.S
1598 ------------------------------------------------------------------ */
1599
jsgf855d93d2003-10-13 22:26:55 +00001600extern Int VG_(do_syscall) ( UInt, ... );
1601extern Int VG_(clone) ( Int (*fn)(void *), void *stack, Int flags, void *arg,
1602 Int *child_tid, Int *parent_tid);
sewardjde4a1d02002-03-22 01:27:54 +00001603
1604/* ---------------------------------------------------------------------
1605 Exports of vg_startup.S
1606 ------------------------------------------------------------------ */
1607
sewardjde4a1d02002-03-22 01:27:54 +00001608extern void VG_(switch_to_real_CPU) ( void );
1609
sewardj35805422002-04-21 13:05:34 +00001610extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1611 Addr m_esp_at_error,
1612 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001613
1614
1615/* ---------------------------------------------------------------------
1616 Exports of vg_dispatch.S
1617 ------------------------------------------------------------------ */
1618
sewardj2e93c502002-04-12 11:12:52 +00001619/* Run a thread for a (very short) while, until some event happens
1620 which means we need to defer to the scheduler. */
1621extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001622
sewardj22854b92002-11-30 14:00:47 +00001623/* The patching routing called when a BB wants to chain itself to
1624 another. */
1625extern UInt VG_(patch_me);
sewardjde4a1d02002-03-22 01:27:54 +00001626
1627/* ---------------------------------------------------------------------
1628 Exports of vg_helpers.S
1629 ------------------------------------------------------------------ */
1630
sewardjde4a1d02002-03-22 01:27:54 +00001631/* Mul, div, etc, -- we don't codegen these directly. */
1632extern void VG_(helper_idiv_64_32);
1633extern void VG_(helper_div_64_32);
1634extern void VG_(helper_idiv_32_16);
1635extern void VG_(helper_div_32_16);
1636extern void VG_(helper_idiv_16_8);
1637extern void VG_(helper_div_16_8);
1638
1639extern void VG_(helper_imul_32_64);
1640extern void VG_(helper_mul_32_64);
1641extern void VG_(helper_imul_16_32);
1642extern void VG_(helper_mul_16_32);
1643extern void VG_(helper_imul_8_16);
1644extern void VG_(helper_mul_8_16);
1645
1646extern void VG_(helper_CLD);
1647extern void VG_(helper_STD);
1648extern void VG_(helper_get_dirflag);
1649
sewardj7d78e782002-06-02 00:04:00 +00001650extern void VG_(helper_CLC);
1651extern void VG_(helper_STC);
1652
sewardjde4a1d02002-03-22 01:27:54 +00001653extern void VG_(helper_shldl);
1654extern void VG_(helper_shldw);
1655extern void VG_(helper_shrdl);
1656extern void VG_(helper_shrdw);
1657
daywalkerb18d2532003-09-27 20:15:01 +00001658extern void VG_(helper_IN);
1659extern void VG_(helper_OUT);
1660
sewardjde4a1d02002-03-22 01:27:54 +00001661extern void VG_(helper_RDTSC);
1662extern void VG_(helper_CPUID);
1663
sewardjde4a1d02002-03-22 01:27:54 +00001664extern void VG_(helper_bsf);
1665extern void VG_(helper_bsr);
1666
1667extern void VG_(helper_fstsw_AX);
1668extern void VG_(helper_SAHF);
njnd6251f12003-06-03 13:38:51 +00001669extern void VG_(helper_LAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001670extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001671extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001672
sewardj51096432002-12-14 23:59:09 +00001673extern void VG_(helper_undefined_instruction);
1674
sewardj20917d82002-05-28 01:36:45 +00001675/* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001676extern void VG_(signalreturn_bogusRA)( void );
sewardj20917d82002-05-28 01:36:45 +00001677
njn4f9c9342002-04-29 16:03:24 +00001678/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001679 Things relating to the used skin
njn4f9c9342002-04-29 16:03:24 +00001680 ------------------------------------------------------------------ */
1681
njn25e49d8e72002-09-23 09:36:25 +00001682#define VG_TRACK(fn, args...) \
1683 do { \
1684 if (VG_(track_events).fn) \
1685 VG_(track_events).fn(args); \
1686 } while (0)
sewardj18d75132002-05-16 11:06:21 +00001687
1688
sewardjde4a1d02002-03-22 01:27:54 +00001689/* ---------------------------------------------------------------------
1690 The state of the simulated CPU.
1691 ------------------------------------------------------------------ */
1692
sewardjde4a1d02002-03-22 01:27:54 +00001693/* ---------------------------------------------------------------------
1694 Offsets into baseBlock for everything which needs to referred to
1695 from generated code. The order of these decls does not imply
1696 what the order of the actual offsets is. The latter is important
1697 and is set up in vg_main.c.
1698 ------------------------------------------------------------------ */
1699
1700/* An array of words. In generated code, %ebp always points to the
1701 start of this array. Useful stuff, like the simulated CPU state,
1702 and the addresses of helper functions, can then be found by
1703 indexing off %ebp. The following declares variables which, at
1704 startup time, are given values denoting offsets into baseBlock.
1705 These offsets are in *words* from the start of baseBlock. */
1706
sewardjb91ae7f2003-04-29 23:50:00 +00001707#define VG_BASEBLOCK_WORDS 400
sewardjde4a1d02002-03-22 01:27:54 +00001708
1709extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1710
1711
1712/* -----------------------------------------------------
1713 Read-write parts of baseBlock.
1714 -------------------------------------------------- */
1715
1716/* State of the simulated CPU. */
1717extern Int VGOFF_(m_eax);
1718extern Int VGOFF_(m_ecx);
1719extern Int VGOFF_(m_edx);
1720extern Int VGOFF_(m_ebx);
1721extern Int VGOFF_(m_esp);
1722extern Int VGOFF_(m_ebp);
1723extern Int VGOFF_(m_esi);
1724extern Int VGOFF_(m_edi);
1725extern Int VGOFF_(m_eflags);
sewardjb91ae7f2003-04-29 23:50:00 +00001726extern Int VGOFF_(m_ssestate);
sewardjde4a1d02002-03-22 01:27:54 +00001727extern Int VGOFF_(m_eip);
1728
sewardjfa492d42002-12-08 18:20:01 +00001729extern Int VGOFF_(m_dflag); /* D flag is handled specially */
1730
sewardj92a59562002-09-30 00:53:10 +00001731extern Int VGOFF_(m_cs);
1732extern Int VGOFF_(m_ss);
1733extern Int VGOFF_(m_ds);
1734extern Int VGOFF_(m_es);
1735extern Int VGOFF_(m_fs);
1736extern Int VGOFF_(m_gs);
1737
sewardjde4a1d02002-03-22 01:27:54 +00001738/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1739extern Int VGOFF_(spillslots);
1740
1741/* Records the valid bits for the 8 integer regs & flags reg. */
1742extern Int VGOFF_(sh_eax);
1743extern Int VGOFF_(sh_ecx);
1744extern Int VGOFF_(sh_edx);
1745extern Int VGOFF_(sh_ebx);
1746extern Int VGOFF_(sh_esp);
1747extern Int VGOFF_(sh_ebp);
1748extern Int VGOFF_(sh_esi);
1749extern Int VGOFF_(sh_edi);
1750extern Int VGOFF_(sh_eflags);
1751
sewardjde4a1d02002-03-22 01:27:54 +00001752/* -----------------------------------------------------
1753 Read-only parts of baseBlock.
1754 -------------------------------------------------- */
1755
sewardj92a59562002-09-30 00:53:10 +00001756/* This thread's LDT pointer. */
1757extern Int VGOFF_(ldt);
1758
njn211b6ad2003-02-03 12:33:31 +00001759/* Nb: Most helper offsets are in include/vg_skin.h, for use by skins */
sewardjde4a1d02002-03-22 01:27:54 +00001760
sewardj51096432002-12-14 23:59:09 +00001761extern Int VGOFF_(helper_undefined_instruction);
1762
njn25e49d8e72002-09-23 09:36:25 +00001763/* For storing extension-specific helpers, determined at runtime. The addr
1764 * and offset arrays together form a (addr, offset) map that allows a
1765 * helper's baseBlock offset to be computed from its address. It's done
1766 * like this so CCALL_M_Ns and other helper calls can use the function
1767 * address rather than having to much around with offsets. */
1768extern UInt VG_(n_compact_helpers);
1769extern UInt VG_(n_noncompact_helpers);
1770
1771extern Addr VG_(compact_helper_addrs) [];
1772extern Int VG_(compact_helper_offsets)[];
1773
1774extern Addr VG_(noncompact_helper_addrs) [];
1775extern Int VG_(noncompact_helper_offsets)[];
1776
sewardjde4a1d02002-03-22 01:27:54 +00001777#endif /* ndef __VG_INCLUDE_H */
1778
sewardj3b2736a2002-03-24 12:18:35 +00001779
1780/* ---------------------------------------------------------------------
1781 Finally - autoconf-generated settings
1782 ------------------------------------------------------------------ */
1783
1784#include "config.h"
1785
sewardjde4a1d02002-03-22 01:27:54 +00001786/*--------------------------------------------------------------------*/
1787/*--- end vg_include.h ---*/
1788/*--------------------------------------------------------------------*/