blob: aeb5c2380ca103b7bbbb368fcc70bcc02bc414a2 [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
48#include "vg_constants.h"
49
sewardj4cf05692002-10-27 20:28:29 +000050/* All stuff visible to core and skins goes in vg_skin.h. Things
51 * visible to core but not visible to any skins should go in this
52 * file, vg_include.h. */
njn25e49d8e72002-09-23 09:36:25 +000053#include "vg_skin.h"
sewardjde4a1d02002-03-22 01:27:54 +000054
55/* Total number of spill slots available for allocation, if a TempReg
56 doesn't make it into a RealReg. Just bomb the entire system if
57 this value is too small; we don't expect it will ever get
58 particularly high. */
59#define VG_MAX_SPILLSLOTS 24
60
61
62/* Constants for the slow translation lookup cache. */
63#define VG_TRANSTAB_SLOW_BITS 11
64#define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS)
65#define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1)
66
67/* Size of a buffer used for creating messages. */
68#define M_VG_MSGBUF 10000
69
70/* Size of a smallish table used to read /proc/self/map entries. */
sewardjebc82332002-04-24 14:44:23 +000071#define M_PROCMAP_BUF 50000
sewardjde4a1d02002-03-22 01:27:54 +000072
73/* Max length of pathname to a .so/executable file. */
74#define M_VG_LIBNAMESTR 100
75
76/* Max length of a text fragment used to construct error messages. */
77#define M_VG_ERRTXT 512
78
79/* Max length of the string copied from env var VG_ARGS at startup. */
80#define M_VG_CMDLINE_STRLEN 1000
81
82/* Max number of options for Valgrind which we can handle. */
83#define M_VG_CMDLINE_OPTS 100
84
85/* After this many different unsuppressed errors have been observed,
86 be more conservative about collecting new ones. */
87#define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50
88
89/* After this many different unsuppressed errors have been observed,
90 stop collecting errors at all, and tell the user their program is
91 evidently a steaming pile of camel dung. */
sewardj1bebcbf2002-04-24 21:24:18 +000092#define M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN 300
sewardjf2537be2002-04-24 21:03:47 +000093
94/* After this many total errors have been observed, stop collecting
95 errors at all. Counterpart to M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN. */
sewardj1bebcbf2002-04-24 21:24:18 +000096#define M_VG_COLLECT_NO_ERRORS_AFTER_FOUND 30000
sewardjde4a1d02002-03-22 01:27:54 +000097
sewardjde4a1d02002-03-22 01:27:54 +000098/* The maximum number of calls we're prepared to save in a
99 backtrace. */
100#define VG_DEEPEST_BACKTRACE 50
101
102/* Number of lists in which we keep track of malloc'd but not free'd
103 blocks. Should be prime. */
104#define VG_N_MALLOCLISTS 997
105
106/* Number of lists in which we keep track of ExeContexts. Should be
107 prime. */
108#define VG_N_EC_LISTS /*997*/ 4999
109
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
sewardj2e93c502002-04-12 11:12:52 +0000115/* Number of file descriptors that can simultaneously be waited on for
116 I/O to complete. Perhaps this should be the same as VG_N_THREADS
117 (surely a thread can't wait on more than one fd at once?. Who
118 knows.) */
njn9a07c222003-06-29 10:18:48 +0000119#define VG_N_WAITING_FDS 20
sewardj2e93c502002-04-12 11:12:52 +0000120
sewardjbf290b92002-05-01 02:28:01 +0000121/* Stack size for a thread. We try and check that they do not go
122 beyond it. */
sewardjf0b06452002-06-04 08:38:04 +0000123#define VG_PTHREAD_STACK_SIZE (1 << 20)
sewardjbf290b92002-05-01 02:28:01 +0000124
sewardj20917d82002-05-28 01:36:45 +0000125/* Number of entries in the semaphore-remapping table. */
126#define VG_N_SEMAPHORES 50
127
128/* Number of entries in the rwlock-remapping table. */
sewardj89745a52002-09-27 01:04:29 +0000129#define VG_N_RWLOCKS 500
sewardj20917d82002-05-28 01:36:45 +0000130
sewardj8ad94e12002-05-29 00:10:20 +0000131/* Number of entries in each thread's cleanup stack. */
sewardj61821c02003-05-04 13:02:10 +0000132#define VG_N_CLEANUPSTACK 16
sewardj8ad94e12002-05-29 00:10:20 +0000133
sewardj2cb00342002-06-28 01:46:26 +0000134/* Number of entries in each thread's fork-handler stack. */
135#define VG_N_FORKHANDLERSTACK 2
136
njn25e49d8e72002-09-23 09:36:25 +0000137/* Max number of callers for context in a suppression. */
138#define VG_N_SUPP_CALLERS 4
sewardj73cf3bc2002-11-03 03:20:15 +0000139
njn6eba4ef2003-05-01 08:06:41 +0000140/* Valgrind's stack sizes, in words */
141#define VG_STACK_SIZE_W 10000
142#define VG_SIGSTACK_SIZE_W 10000
njn12a57142003-04-30 20:49:10 +0000143
sewardjde4a1d02002-03-22 01:27:54 +0000144
145/* ---------------------------------------------------------------------
146 Basic types
147 ------------------------------------------------------------------ */
148
sewardjde4a1d02002-03-22 01:27:54 +0000149/* Just pray that gcc's constant folding works properly ... */
150#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
151 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
152 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
153
sewardjde4a1d02002-03-22 01:27:54 +0000154/* ---------------------------------------------------------------------
155 Command-line-settable options
156 ------------------------------------------------------------------ */
157
sewardj4f094a72002-11-05 23:37:35 +0000158/* Default destination port to be used in logging over a network, if
159 none specified. */
160#define VG_CLO_DEFAULT_LOGPORT 1500
sewardj73cf3bc2002-11-03 03:20:15 +0000161
162/* The max number of suppression files. */
sewardjde4a1d02002-03-22 01:27:54 +0000163#define VG_CLO_MAX_SFILES 10
164
sewardj4cf05692002-10-27 20:28:29 +0000165/* Describes where logging output is to be sent. */
166typedef
167 enum {
168 VgLogTo_Fd,
169 VgLogTo_File,
170 VgLogTo_Socket
171 } VgLogTo;
172
173
sewardj72f98ff2002-06-13 17:23:38 +0000174/* Should we stop collecting errors if too many appear? default: YES */
sewardj2e432902002-06-13 20:44:00 +0000175extern Bool VG_(clo_error_limit);
sewardjde4a1d02002-03-22 01:27:54 +0000176/* Enquire about whether to attach to GDB at errors? default: NO */
177extern Bool VG_(clo_GDB_attach);
sewardj6024b212003-07-13 10:54:33 +0000178/* The path to GDB? default: whatever ./configure found */
179extern Char* VG_(clo_GDB_path);
njn43c799e2003-04-08 00:08:52 +0000180/* Enquire about generating a suppression for each error? default: NO */
181extern Bool VG_(clo_gen_suppressions);
sewardjde4a1d02002-03-22 01:27:54 +0000182/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
183extern Int VG_(sanity_level);
sewardjde4a1d02002-03-22 01:27:54 +0000184/* Automatically attempt to demangle C++ names? default: YES */
185extern Bool VG_(clo_demangle);
sewardjde4a1d02002-03-22 01:27:54 +0000186/* Simulate child processes? default: NO */
187extern Bool VG_(clo_trace_children);
sewardj4cf05692002-10-27 20:28:29 +0000188
189/* Where logging output is to be sent to.
190
191 When log_to == VgLogTo_Fd, clo_logfile_fd holds the file id, and is
192 taken from the command line. clo_logfile_name is irrelevant.
193
194 When log_to == VgLogTo_File, clo_logfile_name holds the logfile
195 name, and is taken from the command line. clo_logfile_fd is then
196 made to hold the relevant file id, by opening clo_logfile_name
197 (concatenated with the process ID) for writing.
198
199 When log_to == VgLogTo_Socket, clo_logfile_name holds the
200 hostname:portnumber pair, and is taken from the command line.
201 clo_logfile_fd is then made to hold the relevant file handle, by
202 opening a connection to said hostname:portnumber pair.
203
204 Global default is to set log_to == VgLogTo_Fd and logfile_fd == 2
205 (stderr). */
206extern VgLogTo VG_(clo_log_to);
207extern Int VG_(clo_logfile_fd);
208extern Char* VG_(clo_logfile_name);
sewardjde4a1d02002-03-22 01:27:54 +0000209
sewardj6024b212003-07-13 10:54:33 +0000210/* The file descriptor to read for input. default: 0 == stdin */
211extern Int VG_(clo_input_fd);
sewardjde4a1d02002-03-22 01:27:54 +0000212/* The number of suppression files specified. */
213extern Int VG_(clo_n_suppressions);
214/* The names of the suppression files. */
215extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
216
217/* Single stepping? default: NO */
218extern Bool VG_(clo_single_step);
219/* Code improvement? default: YES */
220extern Bool VG_(clo_optimise);
njn25e49d8e72002-09-23 09:36:25 +0000221/* DEBUG: print generated code? default: 00000 ( == NO ) */
222extern Bool VG_(clo_trace_codegen);
sewardjde4a1d02002-03-22 01:27:54 +0000223/* DEBUG: print system calls? default: NO */
224extern Bool VG_(clo_trace_syscalls);
225/* DEBUG: print signal details? default: NO */
226extern Bool VG_(clo_trace_signals);
227/* DEBUG: print symtab details? default: NO */
228extern Bool VG_(clo_trace_symtab);
sewardj8937c812002-04-12 20:12:20 +0000229/* DEBUG: print thread scheduling events? default: NO */
230extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000231/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
232 (some), 2 (all) */
233extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000234/* Stop after this many basic blocks. default: Infinity. */
235extern ULong VG_(clo_stop_after);
236/* Display gory details for the k'th most popular error. default:
237 Infinity. */
238extern Int VG_(clo_dump_error);
239/* Number of parents of a backtrace. Default: 8. */
240extern Int VG_(clo_backtrace_size);
daywalker7e73e5f2003-07-04 16:18:15 +0000241/* Engage miscellaneous weird hacks needed for some progs. */
sewardj8d365b52002-05-12 10:52:16 +0000242extern Char* VG_(clo_weird_hacks);
sewardj858964b2002-10-05 14:15:43 +0000243/* Should we run __libc_freeres at exit? Sometimes causes crashes.
244 Default: YES. Note this is subservient to VG_(needs).libc_freeres;
245 if the latter says False, then the setting of VG_(clo_weird_hacks)
246 is ignored. Ie if a skin says no, I don't want this to run, that
247 cannot be overridden from the command line. */
248extern Bool VG_(clo_run_libc_freeres);
sewardjb5ff83e2002-12-01 19:40:49 +0000249/* Use the basic-block chaining optimisation? Default: YES */
sewardj22854b92002-11-30 14:00:47 +0000250extern Bool VG_(clo_chain_bb);
sewardjde4a1d02002-03-22 01:27:54 +0000251
252
253/* ---------------------------------------------------------------------
254 Debugging and profiling stuff
255 ------------------------------------------------------------------ */
256
sewardjde4a1d02002-03-22 01:27:54 +0000257/* Create a logfile into which messages can be dumped. */
258extern void VG_(startup_logging) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000259extern void VG_(shutdown_logging)( void );
sewardjde4a1d02002-03-22 01:27:54 +0000260
261extern void VGP_(init_profiling) ( void );
262extern void VGP_(done_profiling) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000263
njn25e49d8e72002-09-23 09:36:25 +0000264#undef VGP_PUSHCC
265#undef VGP_POPCC
266#define VGP_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x)
267#define VGP_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x)
sewardjde4a1d02002-03-22 01:27:54 +0000268
sewardjde4a1d02002-03-22 01:27:54 +0000269/* ---------------------------------------------------------------------
njn810086f2002-11-14 12:42:47 +0000270 Skin-related types
271 ------------------------------------------------------------------ */
272/* These structs are not exposed to skins to mitigate possibility of
273 binary-incompatibilities when the core/skin interface changes. Instead,
274 set functions are provided (see include/vg_skin.h). */
275typedef
276 struct {
277 Char* name;
278 Char* version;
279 Char* description;
280 Char* copyright_author;
281 Char* bug_reports_to;
njn120281f2003-02-03 12:20:07 +0000282 UInt avg_translation_sizeB;
njn810086f2002-11-14 12:42:47 +0000283 }
284 VgDetails;
285
286extern VgDetails VG_(details);
287
288/* If new fields are added to this type, update:
289 * - vg_main.c:initialisation of VG_(needs)
290 * - vg_main.c:sanity_check_needs()
291 *
292 * If the name of this type or any of its fields change, update:
293 * - dependent comments (just search for "VG_(needs)").
294 */
295typedef
296 struct {
297 Bool libc_freeres;
298 Bool core_errors;
299
300 Bool skin_errors;
301 Bool basic_block_discards;
302 Bool shadow_regs;
303 Bool command_line_options;
304 Bool client_requests;
305 Bool extended_UCode;
306 Bool syscall_wrapper;
njn810086f2002-11-14 12:42:47 +0000307 Bool sanity_checks;
308 Bool data_syms;
309 }
310 VgNeeds;
311
312extern VgNeeds VG_(needs);
313
314/* Events happening in core to track. To be notified, assign a function
315 to the function pointer. To ignore an event, don't do anything
316 (default assignment is to NULL in which case the call is skipped). */
317typedef
318 struct {
319 /* Memory events */
320 void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
njn810086f2002-11-14 12:42:47 +0000321 void (*new_mem_stack_signal) ( Addr a, UInt len );
322 void (*new_mem_brk) ( Addr a, UInt len );
323 void (*new_mem_mmap) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
324
njn3e884182003-04-15 13:03:23 +0000325 void (*copy_mem_remap) ( Addr from, Addr to, UInt len );
326 void (*change_mem_mprotect) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
327 void (*die_mem_stack_signal) ( Addr a, UInt len );
328 void (*die_mem_brk) ( Addr a, UInt len );
329 void (*die_mem_munmap) ( Addr a, UInt len );
330
njn9b007f62003-04-07 14:40:25 +0000331 void (*new_mem_stack_4) ( Addr new_ESP );
332 void (*new_mem_stack_8) ( Addr new_ESP );
333 void (*new_mem_stack_12) ( Addr new_ESP );
334 void (*new_mem_stack_16) ( Addr new_ESP );
335 void (*new_mem_stack_32) ( Addr new_ESP );
336 void (*new_mem_stack) ( Addr a, UInt len );
337
njn9b007f62003-04-07 14:40:25 +0000338 void (*die_mem_stack_4) ( Addr die_ESP );
339 void (*die_mem_stack_8) ( Addr die_ESP );
340 void (*die_mem_stack_12) ( Addr die_ESP );
341 void (*die_mem_stack_16) ( Addr die_ESP );
342 void (*die_mem_stack_32) ( Addr die_ESP );
343 void (*die_mem_stack) ( Addr a, UInt len );
344
njn3e884182003-04-15 13:03:23 +0000345 void (*ban_mem_stack) ( Addr a, UInt len );
njn810086f2002-11-14 12:42:47 +0000346
347 void (*pre_mem_read) ( CorePart part, ThreadState* tst,
348 Char* s, Addr a, UInt size );
349 void (*pre_mem_read_asciiz) ( CorePart part, ThreadState* tst,
350 Char* s, Addr a );
351 void (*pre_mem_write) ( CorePart part, ThreadState* tst,
352 Char* s, Addr a, UInt size );
353 /* Not implemented yet -- have to add in lots of places, which is a
354 pain. Won't bother unless/until there's a need. */
355 /* void (*post_mem_read) ( ThreadState* tst, Char* s,
356 Addr a, UInt size ); */
357 void (*post_mem_write) ( Addr a, UInt size );
358
359
njnd3040452003-05-19 15:04:06 +0000360 /* Register events */
361 void (*post_regs_write_init) ( void );
362 void (*post_reg_write_syscall_return) ( ThreadId tid, UInt reg );
363 void (*post_reg_write_deliver_signal) ( ThreadId tid, UInt reg );
364 void (*post_reg_write_pthread_return) ( ThreadId tid, UInt reg );
365 void (*post_reg_write_clientreq_return) ( ThreadId tid, UInt reg );
366 void (*post_reg_write_clientcall_return) ( ThreadId tid, UInt reg,
367 Addr f );
368
369
njn810086f2002-11-14 12:42:47 +0000370 /* Scheduler events (not exhaustive) */
371 void (*thread_run) ( ThreadId tid );
372
373
374 /* Thread events (not exhaustive) */
375 void (*post_thread_create) ( ThreadId tid, ThreadId child );
376 void (*post_thread_join) ( ThreadId joiner, ThreadId joinee );
377
378
379 /* Mutex events (not exhaustive) */
380 void (*pre_mutex_lock) ( ThreadId tid,
381 void* /*pthread_mutex_t* */ mutex );
382 void (*post_mutex_lock) ( ThreadId tid,
383 void* /*pthread_mutex_t* */ mutex );
384 void (*post_mutex_unlock) ( ThreadId tid,
385 void* /*pthread_mutex_t* */ mutex );
386
njnfdc28af2003-02-24 10:36:48 +0000387 /* Signal events (not exhaustive) */
njn3e884182003-04-15 13:03:23 +0000388 void (* pre_deliver_signal) ( ThreadId tid, Int sigNo, Bool alt_stack );
njnfdc28af2003-02-24 10:36:48 +0000389 void (*post_deliver_signal) ( ThreadId tid, Int sigNo );
390
njn810086f2002-11-14 12:42:47 +0000391
njnfdc28af2003-02-24 10:36:48 +0000392 /* Others... condition variable... */
njn810086f2002-11-14 12:42:47 +0000393 /* ... */
394 }
395 VgTrackEvents;
396
397extern VgTrackEvents VG_(track_events);
398
399
400/* ---------------------------------------------------------------------
401 Exports of vg_needs.c
402 ------------------------------------------------------------------ */
403
404void VG_(sanity_check_needs)(void);
405
406/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000407 Exports of vg_malloc2.c
408 ------------------------------------------------------------------ */
409
410/* Allocation arenas.
njn3e884182003-04-15 13:03:23 +0000411
412 CORE for the core's general use.
413 SKIN for the skin to use (and the only one it uses).
414 SYMTAB for Valgrind's symbol table storage.
415 JITTER for small storage during translation.
416 CLIENT for the client's mallocs/frees, if the skin replaces glibc's
417 malloc() et al -- redzone size is chosen by the skin.
418 DEMANGLE for the C++ demangler.
419 EXECTXT for storing ExeContexts.
420 ERRORS for storing CoreErrors.
421 TRANSIENT for very short-term use. It should be empty in between uses.
422
njn25e49d8e72002-09-23 09:36:25 +0000423 When adding a new arena, remember also to add it to ensure_mm_init().
sewardjde4a1d02002-03-22 01:27:54 +0000424*/
425typedef Int ArenaId;
426
njn3e884182003-04-15 13:03:23 +0000427#define VG_N_ARENAS 9
sewardjde4a1d02002-03-22 01:27:54 +0000428
njn3e884182003-04-15 13:03:23 +0000429#define VG_AR_CORE 0
430#define VG_AR_SKIN 1
431#define VG_AR_SYMTAB 2
432#define VG_AR_JITTER 3
433#define VG_AR_CLIENT 4
434#define VG_AR_DEMANGLE 5
435#define VG_AR_EXECTXT 6
436#define VG_AR_ERRORS 7
437#define VG_AR_TRANSIENT 8
sewardjde4a1d02002-03-22 01:27:54 +0000438
njn25e49d8e72002-09-23 09:36:25 +0000439extern void* VG_(arena_malloc) ( ArenaId arena, Int nbytes );
440extern void VG_(arena_free) ( ArenaId arena, void* ptr );
njn3e884182003-04-15 13:03:23 +0000441extern void* VG_(arena_calloc) ( ArenaId arena, Int alignment,
442 Int nmemb, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000443extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment,
444 Int size );
445extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB,
sewardjde4a1d02002-03-22 01:27:54 +0000446 Int req_pszB );
447
njn8a6b6c02003-04-22 22:45:55 +0000448extern Int VG_(arena_payload_szB) ( ArenaId aid, void* payload );
449
sewardjde4a1d02002-03-22 01:27:54 +0000450extern void VG_(mallocSanityCheckAll) ( void );
451
452extern void VG_(show_all_arena_stats) ( void );
453extern Bool VG_(is_empty_arena) ( ArenaId aid );
454
sewardjecf8e102003-07-12 12:11:39 +0000455/* Returns True if aa is inside any block mmap'd /dev/zero
456 by our low-level memory manager. */
457extern Bool VG_(is_inside_segment_mmapd_by_low_level_MM)( Addr aa );
458
sewardjde4a1d02002-03-22 01:27:54 +0000459
sewardjde4a1d02002-03-22 01:27:54 +0000460/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000461 Exports of vg_intercept.c
sewardj2e93c502002-04-12 11:12:52 +0000462 ------------------------------------------------------------------ */
463
464/* This doesn't export code or data that valgrind.so needs to link
465 against. However, the scheduler does need to know the following
466 request codes. A few, publically-visible, request codes are also
njn25e49d8e72002-09-23 09:36:25 +0000467 defined in valgrind.h, and similar headers for some skins. */
sewardj2e93c502002-04-12 11:12:52 +0000468
njn4c791212003-05-02 17:53:54 +0000469#define VG_USERREQ__MALLOC 0x2001
470#define VG_USERREQ__FREE 0x2002
471
472/*
473In vg_skin.h, so skins can use it.
474Call an arbitrary function with ThreadState as the first arg.
475#define VG_USERREQ__CLIENT_tstCALL0 0x2101
476#define VG_USERREQ__CLIENT_tstCALL1 0x2102
477#define VG_USERREQ__CLIENT_tstCALL2 0x2103
478#define VG_USERREQ__CLIENT_tstCALL3 0x2104
479*/
sewardj2e93c502002-04-12 11:12:52 +0000480
sewardj20917d82002-05-28 01:36:45 +0000481/* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn
482 MUST NOT return -- ever. Eventually it will do either __QUIT or
483 __WAIT_JOINER. */
484#define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001
485
486/* ( no-args ): calling thread disappears from the system forever.
487 Reclaim resources. */
488#define VG_USERREQ__QUIT 0x3002
489
490/* ( void* ): calling thread waits for joiner and returns the void* to
491 it. */
492#define VG_USERREQ__WAIT_JOINER 0x3003
493
494/* ( ThreadId, void** ): wait to join a thread. */
495#define VG_USERREQ__PTHREAD_JOIN 0x3004
496
497/* Set cancellation state and type for this thread. */
498#define VG_USERREQ__SET_CANCELSTATE 0x3005
499#define VG_USERREQ__SET_CANCELTYPE 0x3006
500
501/* ( no-args ): Test if we are at a cancellation point. */
502#define VG_USERREQ__TESTCANCEL 0x3007
503
504/* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call
505 with this arg to indicate that a cancel is now pending for the
506 specified thread. */
507#define VG_USERREQ__SET_CANCELPEND 0x3008
508
509/* Set/get detach state for this thread. */
510#define VG_USERREQ__SET_OR_GET_DETACH 0x3009
511
512#define VG_USERREQ__PTHREAD_GET_THREADID 0x300B
513#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C
514#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D
515#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E
516#define VG_USERREQ__PTHREAD_COND_WAIT 0x300F
517#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010
518#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011
519#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012
520#define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013
521#define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014
sewardj00a66b12002-10-12 16:42:35 +0000522#define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015
523#define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016
sewardj20917d82002-05-28 01:36:45 +0000524#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017
525#define VG_USERREQ__PTHREAD_SIGMASK 0x3018
526#define VG_USERREQ__SIGWAIT 0x3019
527#define VG_USERREQ__PTHREAD_KILL 0x301A
528#define VG_USERREQ__PTHREAD_YIELD 0x301B
sewardj00a66b12002-10-12 16:42:35 +0000529#define VG_USERREQ__PTHREAD_KEY_VALIDATE 0x301C
sewardj2e93c502002-04-12 11:12:52 +0000530
sewardj8ad94e12002-05-29 00:10:20 +0000531#define VG_USERREQ__CLEANUP_PUSH 0x3020
532#define VG_USERREQ__CLEANUP_POP 0x3021
sewardj870497a2002-05-29 01:06:47 +0000533#define VG_USERREQ__GET_KEY_D_AND_S 0x3022
sewardj8ad94e12002-05-29 00:10:20 +0000534
sewardjef037c72002-05-30 00:40:03 +0000535#define VG_USERREQ__NUKE_OTHER_THREADS 0x3023
sewardjefbfcdf2002-06-19 17:35:45 +0000536
537/* Ask how many signal handler returns have happened to this
538 thread. */
sewardj9a2224b2002-06-19 10:17:40 +0000539#define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024
sewardjef037c72002-05-30 00:40:03 +0000540
sewardj2cb00342002-06-28 01:46:26 +0000541/* Get/set entries for a thread's pthread_atfork stack. */
542#define VG_USERREQ__SET_FHSTACK_USED 0x3025
543#define VG_USERREQ__GET_FHSTACK_USED 0x3026
544#define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027
545#define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028
sewardjefbfcdf2002-06-19 17:35:45 +0000546
sewardj1fe7b002002-07-16 01:43:15 +0000547/* Denote the finish of VG_(__libc_freeres_wrapper). */
548#define VG_USERREQ__LIBC_FREERES_DONE 0x3029
549
sewardj45b4b372002-04-16 22:50:32 +0000550/* Cosmetic ... */
551#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
sewardj4dced352002-06-04 22:54:20 +0000552/* Log a pthread error from client-space. Cosmetic. */
553#define VG_USERREQ__PTHREAD_ERROR 0x3102
sewardj45b4b372002-04-16 22:50:32 +0000554
sewardj54cacf02002-04-12 23:24:59 +0000555/*
556In vg_constants.h:
557#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardj54cacf02002-04-12 23:24:59 +0000558*/
559
njn4c791212003-05-02 17:53:54 +0000560
sewardj1fe7b002002-07-16 01:43:15 +0000561/* The scheduler does need to know the address of it so it can be
562 called at program exit. */
563extern void VG_(__libc_freeres_wrapper)( void );
564
sewardj11f0bb42003-04-26 20:11:15 +0000565extern void VGR_(wait_for_fd_to_be_readable_or_erring) ( int fd );
566extern void VGR_(wait_for_fd_to_be_writable_or_erring) ( int fd );
567
568extern int VGR_(recv)(int s, void *buf, unsigned int/*size_t*/ len,
569 int flags);
570
571extern int VGR_(accept)(int s, /*struct sockaddr*/ void *addr,
572 /*socklen_t*/ void *addrlen);
573
574
575extern int VGR_(select) ( int n,
576 /*fd_set*/ void *rfds,
577 /*fd_set*/ void *wfds,
578 /*fd_set*/ void *xfds,
579 /*struct timeval*/ void *timeout );
580
581extern int VGR_(msgsnd)(int msgid,
582 const void *msgp,
583 /*size_t*/ unsigned int msgsz,
584 int msgflg);
585
586extern int VGR_(msgrcv)( int msqid,
587 void* msgp,
588 /*size_t*/ unsigned int msgsz,
589 long msgtyp,
590 int msgflg );
591
592extern int VGR_(readv)(int fd,
593 const /*struct iovec*/ void *iovV,
594 int count);
595
596extern int VGR_(writev)(int fd,
597 const /*struct iovec*/ void *iovV,
598 int count);
sewardj54cacf02002-04-12 23:24:59 +0000599
sewardj2e93c502002-04-12 11:12:52 +0000600/* ---------------------------------------------------------------------
601 Constants pertaining to the simulated CPU state, VG_(baseBlock),
602 which need to go here to avoid ugly circularities.
603 ------------------------------------------------------------------ */
604
sewardjb91ae7f2003-04-29 23:50:00 +0000605/* How big is the saved SSE/SSE2 state? Note that this subsumes the
606 FPU state. On machines without SSE, we just save/restore the FPU
607 state into the first part of this area. */
608/* A general comment about SSE save/restore: It appears that the 7th
609 word (which is the MXCSR) has to be &ed with 0x0000FFBF in order
610 that restoring from it later does not cause a GP fault (which is
611 delivered as a segfault). I guess this will have to be done
612 any time we do fxsave :-( 7th word means word offset 6 or byte
613 offset 24 from the start address of the save area.
614 */
615#define VG_SIZE_OF_SSESTATE 512
sewardj2e93c502002-04-12 11:12:52 +0000616/* ... and in words ... */
sewardjb91ae7f2003-04-29 23:50:00 +0000617#define VG_SIZE_OF_SSESTATE_W ((VG_SIZE_OF_SSESTATE+3)/4)
sewardj2e93c502002-04-12 11:12:52 +0000618
619
620/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000621 Exports of vg_defaults.c
622 ------------------------------------------------------------------ */
623
624extern Bool VG_(sk_malloc_called_by_scheduler);
625
626
627/* ---------------------------------------------------------------------
sewardj92a59562002-09-30 00:53:10 +0000628 Exports of vg_ldt.c
629 ------------------------------------------------------------------ */
630
631/* This is the hardware-format for a segment descriptor, ie what the
632 x86 actually deals with. It is 8 bytes long. It's ugly. */
633
634typedef struct _LDT_ENTRY {
635 union {
636 struct {
637 UShort LimitLow;
638 UShort BaseLow;
639 unsigned BaseMid : 8;
640 unsigned Type : 5;
641 unsigned Dpl : 2;
642 unsigned Pres : 1;
643 unsigned LimitHi : 4;
644 unsigned Sys : 1;
645 unsigned Reserved_0 : 1;
646 unsigned Default_Big : 1;
647 unsigned Granularity : 1;
648 unsigned BaseHi : 8;
649 } Bits;
650 struct {
651 UInt word1;
652 UInt word2;
653 } Words;
654 }
655 LdtEnt;
656} VgLdtEntry;
657
658/* Maximum number of LDT entries supported (by the x86). */
659#define VG_M_LDT_ENTRIES 8192
660/* The size of each LDT entry == sizeof(VgLdtEntry) */
661#define VG_LDT_ENTRY_SIZE 8
662
663/* Alloc & copy, and dealloc. */
664extern VgLdtEntry*
665 VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt );
666extern void
667 VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt );
668
669/* Simulate the modify_ldt syscall. */
670extern Int VG_(sys_modify_ldt) ( ThreadId tid,
671 Int func, void* ptr, UInt bytecount );
672
sewardje1042472002-09-30 12:33:11 +0000673/* Called from generated code. Given a segment selector and a virtual
674 address, return a linear address, and do limit checks too. */
675extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr );
676
sewardj92a59562002-09-30 00:53:10 +0000677
678/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000679 Exports of vg_scheduler.c
680 ------------------------------------------------------------------ */
681
sewardj2e93c502002-04-12 11:12:52 +0000682typedef
683 enum {
684 VgTs_Empty, /* this slot is not in use */
685 VgTs_Runnable, /* waiting to be scheduled */
686 VgTs_WaitJoiner, /* waiting for someone to do join on me */
687 VgTs_WaitJoinee, /* waiting for the thread I did join on */
688 VgTs_WaitFD, /* waiting for I/O completion on a fd */
689 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000690 VgTs_WaitCV, /* waiting on a condition variable */
sewardjb48e5002002-05-13 00:16:03 +0000691 VgTs_WaitSIG, /* waiting due to sigwait() */
sewardj2e93c502002-04-12 11:12:52 +0000692 VgTs_Sleeping /* sleeping for a while */
693 }
694 ThreadStatus;
sewardj8ad94e12002-05-29 00:10:20 +0000695
696/* An entry in a threads's cleanup stack. */
697typedef
698 struct {
699 void (*fn)(void*);
700 void* arg;
701 }
702 CleanupEntry;
sewardj2cb00342002-06-28 01:46:26 +0000703
704/* An entry in a thread's fork-handler stack. */
705typedef
706 struct {
707 void (*prepare)(void);
708 void (*parent)(void);
709 void (*child)(void);
710 }
711 ForkHandlerEntry;
712
713
njn25e49d8e72002-09-23 09:36:25 +0000714struct _ThreadState {
715 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
716 The thread identity is simply the index in vg_threads[].
717 ThreadId == 1 is the root thread and has the special property
718 that we don't try and allocate or deallocate its stack. For
719 convenience of generating error message, we also put the
720 ThreadId in this tid field, but be aware that it should
721 ALWAYS == the index in vg_threads[]. */
722 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000723
njn25e49d8e72002-09-23 09:36:25 +0000724 /* Current scheduling status.
sewardj5f07b662002-04-23 16:52:51 +0000725
njn25e49d8e72002-09-23 09:36:25 +0000726 Complications: whenever this is set to VgTs_WaitMX, you
727 should also set .m_edx to whatever the required return value
728 is for pthread_mutex_lock / pthread_cond_timedwait for when
729 the mutex finally gets unblocked. */
730 ThreadStatus status;
sewardj2e93c502002-04-12 11:12:52 +0000731
njn25e49d8e72002-09-23 09:36:25 +0000732 /* When .status == WaitMX, points to the mutex I am waiting for.
733 When .status == WaitCV, points to the mutex associated with
734 the condition variable indicated by the .associated_cv field.
735 In all other cases, should be NULL. */
736 void* /*pthread_mutex_t* */ associated_mx;
sewardj3b5d8862002-04-20 13:53:23 +0000737
njn25e49d8e72002-09-23 09:36:25 +0000738 /* When .status == WaitCV, points to the condition variable I am
739 waiting for. In all other cases, should be NULL. */
740 void* /*pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000741
njn25e49d8e72002-09-23 09:36:25 +0000742 /* If VgTs_Sleeping, this is when we should wake up, measured in
743 milliseconds as supplied by VG_(read_millisecond_counter).
sewardj2e93c502002-04-12 11:12:52 +0000744
njn25e49d8e72002-09-23 09:36:25 +0000745 If VgTs_WaitCV, this indicates the time at which
746 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
747 this means infinitely far in the future, viz,
748 pthread_cond_wait. */
749 UInt awaken_at;
sewardj20917d82002-05-28 01:36:45 +0000750
njn25e49d8e72002-09-23 09:36:25 +0000751 /* If VgTs_WaitJoiner, return value, as generated by joinees. */
752 void* joinee_retval;
sewardj20917d82002-05-28 01:36:45 +0000753
njn25e49d8e72002-09-23 09:36:25 +0000754 /* If VgTs_WaitJoinee, place to copy the return value to, and
755 the identity of the thread we're waiting for. */
756 void** joiner_thread_return;
757 ThreadId joiner_jee_tid;
sewardj8ad94e12002-05-29 00:10:20 +0000758
njn25e49d8e72002-09-23 09:36:25 +0000759 /* Whether or not detached. */
760 Bool detached;
sewardj20917d82002-05-28 01:36:45 +0000761
njn25e49d8e72002-09-23 09:36:25 +0000762 /* Cancelability state and type. */
763 Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */
764 Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */
765
766 /* Pointer to fn to call to do cancellation. Indicates whether
767 or not cancellation is pending. If NULL, not pending. Else
768 should be &thread_exit_wrapper(), indicating that
769 cancallation is pending. */
770 void (*cancel_pend)(void*);
sewardj2e93c502002-04-12 11:12:52 +0000771
njn25e49d8e72002-09-23 09:36:25 +0000772 /* The cleanup stack. */
773 Int custack_used;
774 CleanupEntry custack[VG_N_CLEANUPSTACK];
sewardj5f07b662002-04-23 16:52:51 +0000775
sewardj00a66b12002-10-12 16:42:35 +0000776 /* A pointer to the thread's-specific-data. This is handled almost
777 entirely from vg_libpthread.c. We just provide hooks to get and
778 set this ptr. This is either NULL, indicating the thread has
779 read/written none of its specifics so far, OR points to a
780 void*[VG_N_THREAD_KEYS], allocated and deallocated in
781 vg_libpthread.c. */
782 void** specifics_ptr;
sewardjb48e5002002-05-13 00:16:03 +0000783
njn25e49d8e72002-09-23 09:36:25 +0000784 /* This thread's blocked-signals mask. Semantics is that for a
785 signal to be delivered to this thread, the signal must not be
786 blocked by either the process-wide signal mask nor by this
787 one. So, if this thread is prepared to handle any signal that
788 the process as a whole is prepared to handle, this mask should
789 be made empty -- and that it is its default, starting
790 state. */
791 vki_ksigset_t sig_mask;
sewardjb48e5002002-05-13 00:16:03 +0000792
njn25e49d8e72002-09-23 09:36:25 +0000793 /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG,
794 is the set of signals for which we are sigwait()ing. */
795 vki_ksigset_t sigs_waited_for;
sewardj9a2224b2002-06-19 10:17:40 +0000796
njn25e49d8e72002-09-23 09:36:25 +0000797 /* Counts the number of times a signal handler for this thread
798 has returned. This makes it easy to implement pause(), by
799 polling this value, of course interspersed with nanosleeps,
800 and waiting till it changes. */
801 UInt n_signals_returned;
sewardj2e93c502002-04-12 11:12:52 +0000802
njn25e49d8e72002-09-23 09:36:25 +0000803 /* Stacks. When a thread slot is freed, we don't deallocate its
804 stack; we just leave it lying around for the next use of the
805 slot. If the next use of the slot requires a larger stack,
806 only then is the old one deallocated and a new one
807 allocated.
sewardj2e93c502002-04-12 11:12:52 +0000808
njn25e49d8e72002-09-23 09:36:25 +0000809 For the main thread (threadid == 0), this mechanism doesn't
810 apply. We don't know the size of the stack since we didn't
811 allocate it, and furthermore we never reallocate it. */
sewardj2e93c502002-04-12 11:12:52 +0000812
njn25e49d8e72002-09-23 09:36:25 +0000813 /* The allocated size of this thread's stack (permanently zero
814 if this is ThreadId == 0, since we didn't allocate its stack) */
815 UInt stack_size;
sewardj1e8cdc92002-04-18 11:37:52 +0000816
njn25e49d8e72002-09-23 09:36:25 +0000817 /* Address of the lowest word in this thread's stack. NULL means
818 not allocated yet.
819 */
820 Addr stack_base;
sewardj2e93c502002-04-12 11:12:52 +0000821
sewardj92a59562002-09-30 00:53:10 +0000822 /* Address of the highest legitimate word in this stack. This is
823 used for error messages only -- not critical for execution
824 correctness. Is is set for all stacks, specifically including
825 ThreadId == 0 (the main thread). */
njn25e49d8e72002-09-23 09:36:25 +0000826 Addr stack_highest_word;
827
sewardj92a59562002-09-30 00:53:10 +0000828 /* Pointer to this thread's Local (Segment) Descriptor Table.
829 Starts out as NULL, indicating there is no table, and we hope to
830 keep it that way. If the thread does __NR_modify_ldt to create
831 entries, we allocate a 8192-entry table at that point. This is
832 a straight copy of the Linux kernel's scheme. Don't forget to
833 deallocate this at thread exit. */
834 VgLdtEntry* ldt;
835
836 /* Saved machine context. Note the FPU state, %EIP and segment
837 registers are not shadowed.
838
839 Although the segment registers are 16 bits long, storage
840 management here, in VG_(baseBlock) and in VG_(m_state_static) is
841 simplified if we pretend they are 32 bits. */
842 UInt m_cs;
843 UInt m_ss;
844 UInt m_ds;
845 UInt m_es;
846 UInt m_fs;
847 UInt m_gs;
848
njn25e49d8e72002-09-23 09:36:25 +0000849 UInt m_eax;
850 UInt m_ebx;
851 UInt m_ecx;
852 UInt m_edx;
853 UInt m_esi;
854 UInt m_edi;
855 UInt m_ebp;
856 UInt m_esp;
857 UInt m_eflags;
858 UInt m_eip;
sewardjb91ae7f2003-04-29 23:50:00 +0000859
860 /* The SSE/FPU state. This array does not (necessarily) have the
861 required 16-byte alignment required to get stuff in/out by
862 fxsave/fxrestore. So we have to do it "by hand".
863 */
864 UInt m_sse[VG_SIZE_OF_SSESTATE_W];
njn25e49d8e72002-09-23 09:36:25 +0000865
866 UInt sh_eax;
867 UInt sh_ebx;
868 UInt sh_ecx;
869 UInt sh_edx;
870 UInt sh_esi;
871 UInt sh_edi;
872 UInt sh_ebp;
873 UInt sh_esp;
874 UInt sh_eflags;
875};
sewardj2e93c502002-04-12 11:12:52 +0000876
877
sewardj018f7622002-05-15 21:13:39 +0000878/* The thread table. */
879extern ThreadState VG_(threads)[VG_N_THREADS];
880
881/* Check that tid is in range and denotes a non-Empty thread. */
sewardjb48e5002002-05-13 00:16:03 +0000882extern Bool VG_(is_valid_tid) ( ThreadId tid );
883
sewardj018f7622002-05-15 21:13:39 +0000884/* Check that tid is in range. */
885extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid );
886
sewardj2e93c502002-04-12 11:12:52 +0000887/* Copy the specified thread's state into VG_(baseBlock) in
888 preparation for running it. */
889extern void VG_(load_thread_state)( ThreadId );
890
891/* Save the specified thread's state back in VG_(baseBlock), and fill
892 VG_(baseBlock) with junk, for sanity-check reasons. */
893extern void VG_(save_thread_state)( ThreadId );
894
sewardj1e8cdc92002-04-18 11:37:52 +0000895/* And for the currently running one, if valid. */
896extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000897
sewardj1e8cdc92002-04-18 11:37:52 +0000898/* Similarly ... */
899extern ThreadId VG_(get_current_tid) ( void );
900
sewardjccef2e62002-05-29 19:26:32 +0000901/* Nuke all threads except tid. */
902extern void VG_(nuke_all_threads_except) ( ThreadId me );
903
sewardj2e93c502002-04-12 11:12:52 +0000904
905/* Return codes from the scheduler. */
906typedef
sewardj7e87e382002-05-03 19:09:05 +0000907 enum {
908 VgSrc_Deadlock, /* no runnable threads and no prospect of any
909 even if we wait for a long time */
910 VgSrc_ExitSyscall, /* client called exit(). This is the normal
911 route out. */
912 VgSrc_BbsDone /* In a debugging run, the specified number of
913 bbs has been completed. */
914 }
sewardj2e93c502002-04-12 11:12:52 +0000915 VgSchedReturnCode;
916
sewardj7e87e382002-05-03 19:09:05 +0000917
sewardj2e93c502002-04-12 11:12:52 +0000918/* The scheduler. */
919extern VgSchedReturnCode VG_(scheduler) ( void );
920
921extern void VG_(scheduler_init) ( void );
922
sewardj15a43e12002-04-17 19:35:12 +0000923extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000924
925/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
926extern jmp_buf VG_(scheduler_jmpbuf);
sewardj872051c2002-07-13 12:12:56 +0000927/* This says whether scheduler_jmpbuf is actually valid. Needed so
928 that our signal handler doesn't longjmp when the buffer isn't
929 actually valid. */
930extern Bool VG_(scheduler_jmpbuf_valid);
sewardj2e93c502002-04-12 11:12:52 +0000931/* ... and if so, here's the signal which caused it to do so. */
932extern Int VG_(longjmpd_on_signal);
933
934
sewardj2e93c502002-04-12 11:12:52 +0000935/* The red-zone size which we put at the bottom (highest address) of
936 thread stacks, for paranoia reasons. This can be arbitrary, and
937 doesn't really need to be set at compile time. */
938#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
939
940#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
941 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
942
njn25e49d8e72002-09-23 09:36:25 +0000943/* Junk to fill up a thread's shadow regs with when shadow regs aren't
njnd3040452003-05-19 15:04:06 +0000944 being used. */
njn25e49d8e72002-09-23 09:36:25 +0000945#define VG_UNUSED_SHADOW_REG_VALUE 0x27182818
njnd3040452003-05-19 15:04:06 +0000946/* For sanity checking: if this ends up in a thread's shadow regs when
947 shadow regs aren't being used, something went wrong. */
948#define VG_USED_SHADOW_REG_VALUE 0x31415927
njn25e49d8e72002-09-23 09:36:25 +0000949
njnd3040452003-05-19 15:04:06 +0000950/* Write a value to a client's thread register, and shadow (if necessary) */
951#define SET_THREAD_REG( zztid, zzval, zzreg, zzREG, zzevent, zzargs... ) \
952 do { VG_(threads)[zztid].m_##zzreg = (zzval); \
953 VG_TRACK( zzevent, zztid, R_##zzREG, ##zzargs ); \
sewardj018f7622002-05-15 21:13:39 +0000954 } while (0)
955
njnd3040452003-05-19 15:04:06 +0000956#define SET_SYSCALL_RETVAL(zztid, zzval) \
957 SET_THREAD_REG(zztid, zzval, eax, EAX, post_reg_write_syscall_return)
958
959#define SET_SIGNAL_EDX(zztid, zzval) \
960 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_deliver_signal)
961
962#define SET_SIGNAL_ESP(zztid, zzval) \
963 SET_THREAD_REG(zztid, zzval, esp, ESP, post_reg_write_deliver_signal)
964
965#define SET_CLREQ_RETVAL(zztid, zzval) \
966 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_clientreq_return)
967
968#define SET_CLCALL_RETVAL(zztid, zzval, f) \
969 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_clientcall_return, f)
970
971#define SET_PTHREQ_ESP(zztid, zzval) \
972 SET_THREAD_REG(zztid, zzval, esp, ESP, post_reg_write_pthread_return)
973
974#define SET_PTHREQ_RETVAL(zztid, zzval) \
975 SET_THREAD_REG(zztid, zzval, edx, EDX, post_reg_write_pthread_return)
sewardj018f7622002-05-15 21:13:39 +0000976
sewardj2e93c502002-04-12 11:12:52 +0000977
sewardjd8acdf22002-11-13 21:57:52 +0000978/* This is or'd into a pthread mutex's __m_kind field if it is used
979 before Valgrind is up and running (prehistory). This is used so
980 that if some early code (like the dynamic linker) takes a lock
981 before Valgrind starts and then releases it afterwards, we can work
982 out what's happening. */
983#define VG_PTHREAD_PREHISTORY 0x80000000
984
sewardj2e93c502002-04-12 11:12:52 +0000985/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000986 Exports of vg_signals.c
987 ------------------------------------------------------------------ */
988
sewardjde4a1d02002-03-22 01:27:54 +0000989extern void VG_(sigstartup_actions) ( void );
sewardj839299f2003-06-14 11:57:59 +0000990extern void VG_(sigshutdown_actions) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000991
sewardjb48e5002002-05-13 00:16:03 +0000992extern Bool VG_(deliver_signals) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000993extern void VG_(unblock_host_signal) ( Int sigNo );
sewardj018f7622002-05-15 21:13:39 +0000994extern void VG_(handle_SCSS_change) ( Bool force_update );
995
sewardjde4a1d02002-03-22 01:27:54 +0000996
997/* Fake system calls for signal handling. */
sewardj2342c972002-05-22 23:34:20 +0000998extern void VG_(do__NR_sigaltstack) ( ThreadId tid );
sewardj2e93c502002-04-12 11:12:52 +0000999extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardj018f7622002-05-15 21:13:39 +00001000extern void VG_(do__NR_sigprocmask) ( ThreadId tid,
1001 Int how,
1002 vki_ksigset_t* set,
1003 vki_ksigset_t* oldset );
1004extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid,
1005 Int how,
1006 vki_ksigset_t* set,
1007 vki_ksigset_t* oldset );
1008extern void VG_(send_signal_to_thread) ( ThreadId thread,
1009 Int signo );
sewardjde4a1d02002-03-22 01:27:54 +00001010
sewardjefbfcdf2002-06-19 17:35:45 +00001011extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set );
1012
1013
sewardj2e93c502002-04-12 11:12:52 +00001014/* Modify the current thread's state once we have detected it is
1015 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +00001016extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +00001017
sewardj2e93c502002-04-12 11:12:52 +00001018/* Handy utilities to block/restore all host signals. */
1019extern void VG_(block_all_host_signals)
1020 ( /* OUT */ vki_ksigset_t* saved_mask );
sewardj018f7622002-05-15 21:13:39 +00001021extern void VG_(restore_all_host_signals)
sewardj2e93c502002-04-12 11:12:52 +00001022 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +00001023
1024/* ---------------------------------------------------------------------
1025 Exports of vg_mylibc.c
1026 ------------------------------------------------------------------ */
1027
njne427a662002-10-02 11:08:25 +00001028#define vg_assert(expr) \
1029 ((void) ((expr) ? 0 : \
1030 (VG_(core_assert_fail) (VG__STRING(expr), \
1031 __FILE__, __LINE__, \
1032 __PRETTY_FUNCTION__), 0)))
1033__attribute__ ((__noreturn__))
1034extern void VG_(core_assert_fail) ( Char* expr, Char* file,
1035 Int line, Char* fn );
1036__attribute__ ((__noreturn__))
1037extern void VG_(core_panic) ( Char* str );
sewardjde4a1d02002-03-22 01:27:54 +00001038
njn25e49d8e72002-09-23 09:36:25 +00001039/* VG_(brk) not public so skins cannot screw with curr_dataseg_end */
1040extern void* VG_(brk) ( void* end_data_segment );
sewardjde4a1d02002-03-22 01:27:54 +00001041
njn25e49d8e72002-09-23 09:36:25 +00001042/* Skins use VG_(strdup)() which doesn't expose ArenaId */
1043extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
sewardjde4a1d02002-03-22 01:27:54 +00001044
njn25e49d8e72002-09-23 09:36:25 +00001045/* Skins shouldn't need these...(?) */
sewardj5f07b662002-04-23 16:52:51 +00001046extern void VG_(start_rdtsc_calibration) ( void );
1047extern void VG_(end_rdtsc_calibration) ( void );
1048extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001049
njn25e49d8e72002-09-23 09:36:25 +00001050extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
sewardj2e93c502002-04-12 11:12:52 +00001051extern Int VG_(select)( Int n,
1052 vki_fd_set* readfds,
1053 vki_fd_set* writefds,
1054 vki_fd_set* exceptfds,
1055 struct vki_timeval * timeout );
1056extern Int VG_(nanosleep)( const struct vki_timespec *req,
1057 struct vki_timespec *rem );
1058
sewardj570f8902002-11-03 11:44:36 +00001059extern Int VG_(write_socket)( Int sd, void *msg, Int count );
sewardj73cf3bc2002-11-03 03:20:15 +00001060
1061/* --- Connecting over the network --- */
1062extern Int VG_(connect_via_socket)( UChar* str );
1063
sewardj570f8902002-11-03 11:44:36 +00001064
1065/* ---------------------------------------------------------------------
1066 Exports of vg_message.c
1067 ------------------------------------------------------------------ */
1068
1069/* Low-level -- send bytes directly to the message sink. Do not
1070 use. */
1071extern void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes );
1072
1073
sewardjde4a1d02002-03-22 01:27:54 +00001074/* ---------------------------------------------------------------------
1075 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
1076 vg_from_ucode.c).
1077 ------------------------------------------------------------------ */
1078
sewardjde4a1d02002-03-22 01:27:54 +00001079#define VG_IS_FLAG_SUBSET(set1,set2) \
1080 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
1081
1082#define VG_UNION_FLAG_SETS(set1,set2) \
1083 ( ((FlagSet)set1) | ((FlagSet)set2) )
1084
sewardjde4a1d02002-03-22 01:27:54 +00001085/* ---------------------------------------------------------------------
1086 Exports of vg_demangle.c
1087 ------------------------------------------------------------------ */
1088
1089extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
1090
sewardjde4a1d02002-03-22 01:27:54 +00001091/* ---------------------------------------------------------------------
1092 Exports of vg_from_ucode.c
1093 ------------------------------------------------------------------ */
1094
sewardj22854b92002-11-30 14:00:47 +00001095extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes, UShort jumps[VG_MAX_JUMPS] );
sewardjde4a1d02002-03-22 01:27:54 +00001096
njn25e49d8e72002-09-23 09:36:25 +00001097extern void VG_(print_ccall_stats) ( void );
1098extern void VG_(print_UInstr_histogram) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001099
sewardj22854b92002-11-30 14:00:47 +00001100extern void VG_(unchain_jumpsite) ( Addr jumpsite );
1101extern Addr VG_(get_jmp_dest) ( Addr jumpsite );
1102extern Bool VG_(is_unchained_jumpsite) ( Addr jumpsite );
1103extern Bool VG_(is_chained_jumpsite) ( Addr jumpsite );
1104
sewardjde4a1d02002-03-22 01:27:54 +00001105/* ---------------------------------------------------------------------
1106 Exports of vg_to_ucode.c
1107 ------------------------------------------------------------------ */
1108
1109extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
sewardjde4a1d02002-03-22 01:27:54 +00001110
1111/* ---------------------------------------------------------------------
1112 Exports of vg_translate.c
1113 ------------------------------------------------------------------ */
1114
njn810086f2002-11-14 12:42:47 +00001115/* Expandable arrays of uinstrs. */
1116struct _UCodeBlock {
sewardj22854b92002-11-30 14:00:47 +00001117 Addr orig_eip;
njn810086f2002-11-14 12:42:47 +00001118 Int used;
1119 Int size;
1120 UInstr* instrs;
1121 Int nextTemp;
1122};
1123
1124extern UCodeBlock* VG_(alloc_UCodeBlock) ( void );
1125
sewardj1e8cdc92002-04-18 11:37:52 +00001126extern void VG_(translate) ( ThreadState* tst,
1127 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001128 UInt* orig_size,
1129 Addr* trans_addr,
sewardj22854b92002-11-30 14:00:47 +00001130 UInt* trans_size,
1131 UShort jumps[VG_MAX_JUMPS]);
sewardjde4a1d02002-03-22 01:27:54 +00001132
njn25e49d8e72002-09-23 09:36:25 +00001133extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness,
1134 UInstr* u );
1135extern void VG_(saneUCodeBlock) ( UCodeBlock* cb );
1136extern Bool VG_(saneUCodeBlockCalls) ( UCodeBlock* cb );
sewardjde4a1d02002-03-22 01:27:54 +00001137
sewardjb5ff83e2002-12-01 19:40:49 +00001138
sewardjde4a1d02002-03-22 01:27:54 +00001139/* ---------------------------------------------------------------------
1140 Exports of vg_execontext.c.
1141 ------------------------------------------------------------------ */
1142
1143/* Records the PC and a bit of the call chain. The first 4 %eip
1144 values are used in comparisons do remove duplicate errors, and for
1145 comparing against suppression specifications. The rest are purely
1146 informational (but often important). */
1147
njn25e49d8e72002-09-23 09:36:25 +00001148struct _ExeContext {
1149 struct _ExeContext * next;
1150 /* Variable-length array. The size is VG_(clo_backtrace_size); at
1151 least 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1152 [1] is its caller, [2] is the caller of [1], etc. */
1153 Addr eips[0];
1154};
sewardjde4a1d02002-03-22 01:27:54 +00001155
1156
1157/* Initialise the ExeContext storage mechanism. */
1158extern void VG_(init_ExeContext_storage) ( void );
1159
1160/* Print stats (informational only). */
1161extern void VG_(show_ExeContext_stats) ( void );
1162
njn25e49d8e72002-09-23 09:36:25 +00001163/* Like VG_(get_ExeContext), but with a slightly different type */
1164extern ExeContext* VG_(get_ExeContext2) ( Addr eip, Addr ebp,
1165 Addr ebp_min, Addr ebp_max );
sewardjde4a1d02002-03-22 01:27:54 +00001166
1167
1168/* ---------------------------------------------------------------------
1169 Exports of vg_errcontext.c.
1170 ------------------------------------------------------------------ */
1171
njn25e49d8e72002-09-23 09:36:25 +00001172/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1173 * effectively extend it by defining their own enums in the (0..) range. */
sewardjde4a1d02002-03-22 01:27:54 +00001174typedef
njn25e49d8e72002-09-23 09:36:25 +00001175 enum {
1176 PThreadSupp = -1, /* Matches PThreadErr */
sewardjde4a1d02002-03-22 01:27:54 +00001177 }
njn25e49d8e72002-09-23 09:36:25 +00001178 CoreSuppKind;
1179
1180/* For each caller specified for a suppression, record the nature of
1181 the caller name. Not of interest to skins. */
1182typedef
1183 enum {
1184 ObjName, /* Name is of an shared object file. */
1185 FunName /* Name is of a function. */
1186 }
1187 SuppLocTy;
1188
njn810086f2002-11-14 12:42:47 +00001189/* Suppressions. Skins can get/set skin-relevant parts with functions
1190 declared in include/vg_skin.h. Extensible via the 'extra' field.
1191 Skins can use a normal enum (with element values in the normal range
1192 (0..)) for `skind'. */
1193struct _Supp {
1194 struct _Supp* next;
1195 /* The number of times this error has been suppressed. */
1196 Int count;
1197 /* The name by which the suppression is referred to. */
1198 Char* sname;
1199 /* First two (name of fn where err occurs, and immediate caller)
1200 * are mandatory; extra two are optional. */
1201 SuppLocTy caller_ty[VG_N_SUPP_CALLERS];
1202 Char* caller [VG_N_SUPP_CALLERS];
1203
1204 /* The skin-specific part */
1205 /* What kind of suppression. Must use the range (0..) */
1206 SuppKind skind;
1207 /* String -- use is optional. NULL by default. */
1208 Char* string;
1209 /* Anything else -- use is optional. NULL by default. */
1210 void* extra;
1211};
njn25e49d8e72002-09-23 09:36:25 +00001212
1213/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1214 * effectively extend it by defining their own enums in the (0..) range. */
1215typedef
1216 enum {
1217 PThreadErr = -1, /* Pthreading error */
1218 }
1219 CoreErrorKind;
1220
njn810086f2002-11-14 12:42:47 +00001221/* Errors. Extensible (via the 'extra' field). Skins can use a normal
1222 enum (with element values in the normal range (0..)) for `ekind'.
1223 Functions for getting/setting the skin-relevant fields are in
1224 include/vg_skin.h.
1225
1226 When errors are found and recorded with VG_(maybe_record_error)(), all
1227 the skin must do is pass in the four parameters; core will
1228 allocate/initialise the error record.
1229*/
1230struct _Error {
1231 struct _Error* next;
1232 /* NULL if unsuppressed; or ptr to suppression record. */
1233 Supp* supp;
1234 Int count;
njn810086f2002-11-14 12:42:47 +00001235 ThreadId tid;
njn810086f2002-11-14 12:42:47 +00001236
1237 /* The skin-specific part */
njnae17bec2003-01-28 19:59:38 +00001238 /* Initialised by core */
1239 ExeContext* where;
njn810086f2002-11-14 12:42:47 +00001240 /* Used by ALL. Must be in the range (0..) */
1241 Int ekind;
1242 /* Used frequently */
1243 Addr addr;
1244 /* Used frequently */
1245 Char* string;
1246 /* For any skin-specific extras */
1247 void* extra;
1248};
sewardjde4a1d02002-03-22 01:27:54 +00001249
1250
njn25e49d8e72002-09-23 09:36:25 +00001251extern void VG_(load_suppressions) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001252
njn25e49d8e72002-09-23 09:36:25 +00001253extern void VG_(record_pthread_error) ( ThreadId tid, Char* msg );
sewardjde4a1d02002-03-22 01:27:54 +00001254
njn25e49d8e72002-09-23 09:36:25 +00001255extern void VG_(show_all_errors) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001256
njn43c799e2003-04-08 00:08:52 +00001257extern Bool VG_(is_action_requested) ( Char* action, Bool* clo );
1258
1259extern void VG_(gen_suppression) ( Error* err );
sewardj99aac972002-12-26 01:53:45 +00001260
njn47363ab2003-04-21 13:24:40 +00001261extern UInt VG_(n_errs_found);
1262
sewardjde4a1d02002-03-22 01:27:54 +00001263/* ---------------------------------------------------------------------
1264 Exports of vg_procselfmaps.c
1265 ------------------------------------------------------------------ */
1266
njn3e884182003-04-15 13:03:23 +00001267/* Reads /proc/self/maps into a static buffer. */
1268void VG_(read_procselfmaps_contents) ( void );
1269
1270/* Parses /proc/self/maps, calling `record_mapping' for each entry. If
1271 `read_from_file' is True, /proc/self/maps is read directly, otherwise
1272 it's read from the buffer filled by VG_(read_procselfmaps_contents)(). */
sewardjde4a1d02002-03-22 01:27:54 +00001273extern
1274void VG_(read_procselfmaps) (
njn3e884182003-04-15 13:03:23 +00001275 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* ),
1276 Bool read_from_file
sewardjde4a1d02002-03-22 01:27:54 +00001277);
1278
1279
1280/* ---------------------------------------------------------------------
1281 Exports of vg_symtab2.c
1282 ------------------------------------------------------------------ */
1283
sewardj8a77ffb2003-07-10 23:31:27 +00001284extern void VG_(read_symbols) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001285extern void VG_(read_symtab_callback) ( Addr start, UInt size,
1286 Char rr, Char ww, Char xx,
1287 UInt foffset, UChar* filename );
sewardj8a77ffb2003-07-10 23:31:27 +00001288extern void VG_(unload_symbols) ( Addr start, UInt length );
sewardjde4a1d02002-03-22 01:27:54 +00001289
njn25e49d8e72002-09-23 09:36:25 +00001290extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname );
1291extern void VG_(mini_stack_dump) ( ExeContext* ec );
sewardj25c7c3a2003-07-10 00:17:58 +00001292extern Int VG_(setup_code_redirect_table) ( void );
1293
1294typedef
1295 struct {
1296 Addr entry_pt_orig;
1297 Addr entry_pt_subst;
1298 }
1299 CodeRedirect;
1300
1301#define VG_N_CODE_REDIRECTS 10
1302extern CodeRedirect VG_(code_redirect_table)[VG_N_CODE_REDIRECTS];
1303/* Table is terminated by a NULL entry_pt_orig field. */
sewardjde4a1d02002-03-22 01:27:54 +00001304
1305
1306/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001307 Exports of vg_main.c
1308 ------------------------------------------------------------------ */
1309
sewardjb91ae7f2003-04-29 23:50:00 +00001310/* Is this a SSE/SSE2-capable CPU? If so, we had better save/restore
1311 the SSE state all over the place. This is set up very early, in
1312 vg_startup.S. We have to determine it early since we can't even
1313 correctly snapshot the startup machine state without it. */
1314extern Bool VG_(have_ssestate);
1315
sewardj73cf3bc2002-11-03 03:20:15 +00001316/* Tell the logging mechanism whether we are logging to a file
1317 descriptor or a socket descriptor. */
1318extern Bool VG_(logging_to_filedes);
1319
njn25e49d8e72002-09-23 09:36:25 +00001320/* Sanity checks which may be done at any time. The scheduler decides when. */
1321extern void VG_(do_sanity_checks) ( Bool force_expensive );
1322
sewardjde4a1d02002-03-22 01:27:54 +00001323/* A structure used as an intermediary when passing the simulated
1324 CPU's state to some assembly fragments, particularly system calls.
1325 Stuff is copied from baseBlock to here, the assembly magic runs,
sewardjb91ae7f2003-04-29 23:50:00 +00001326 and then the inverse copy is done. Alignment: the SSE state must
1327 be 16-byte aligned. We ask for the whole struct to be 16-byte
1328 aligned, and the SSE state starts at the 6+8+1+1th == 16th word,
1329 so it too must be 16-byte aligned. Consequence: change this struct
1330 only _very carefully_ ! See also above comment re masking MXCSR.
1331*/
1332__attribute__ ((aligned (16)))
sewardj92a59562002-09-30 00:53:10 +00001333extern UInt VG_(m_state_static) [6 /* segment regs, Intel order */
1334 + 8 /* int regs, in Intel order */
sewardjde4a1d02002-03-22 01:27:54 +00001335 + 1 /* %eflags */
1336 + 1 /* %eip */
sewardjb91ae7f2003-04-29 23:50:00 +00001337 + VG_SIZE_OF_SSESTATE_W /* SSE state */
sewardjde4a1d02002-03-22 01:27:54 +00001338 ];
1339
1340/* Handy fns for doing the copy back and forth. */
1341extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1342extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1343
njn9b007f62003-04-07 14:40:25 +00001344/* Determine if %esp adjustment must be noted */
njnf4ce3d32003-02-10 10:17:26 +00001345extern Bool VG_(need_to_handle_esp_assignment) ( void );
1346
sewardjde4a1d02002-03-22 01:27:54 +00001347/* Called when some unhandleable client behaviour is detected.
1348 Prints a msg and aborts. */
njn25e49d8e72002-09-23 09:36:25 +00001349extern void VG_(unimplemented) ( Char* msg )
1350 __attribute__((__noreturn__));
sewardjde4a1d02002-03-22 01:27:54 +00001351
1352/* The stack on which Valgrind runs. We can't use the same stack as the
1353 simulatee -- that's an important design decision. */
njn6eba4ef2003-05-01 08:06:41 +00001354extern UInt VG_(stack)[VG_STACK_SIZE_W];
sewardjde4a1d02002-03-22 01:27:54 +00001355
njn25e49d8e72002-09-23 09:36:25 +00001356/* Similarly, we have to ask for signals to be delivered on an alternative
1357 stack, since it is possible, although unlikely, that we'll have to run
1358 client code from inside the Valgrind-installed signal handler. If this
1359 happens it will be done by vg_deliver_signal_immediately(). */
njn6eba4ef2003-05-01 08:06:41 +00001360extern UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W];
sewardjde4a1d02002-03-22 01:27:54 +00001361
sewardjde4a1d02002-03-22 01:27:54 +00001362/* Holds client's %esp at the point we gained control. From this the
1363 client's argc, argv and envp are deduced. */
1364extern Addr VG_(esp_at_startup);
sewardjde4a1d02002-03-22 01:27:54 +00001365
sewardjd5815ec2003-04-06 12:23:27 +00001366/* Indicates presence, and holds address of client's sysinfo page, a
1367 feature of some modern kernels used to provide vsyscalls, etc. */
1368extern Bool VG_(sysinfo_page_exists);
1369extern Addr VG_(sysinfo_page_addr);
1370
njn25e49d8e72002-09-23 09:36:25 +00001371/* Remove valgrind.so and skin's .so from a LD_PRELOAD=... string so child
1372 processes don't get traced into. Also mess up $libdir/valgrind so that
1373 our libpthread.so disappears from view. */
sewardj3e1eb1f2002-05-18 13:14:17 +00001374void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str,
1375 Char* ld_library_path_str );
sewardjde4a1d02002-03-22 01:27:54 +00001376
1377/* Something of a function looking for a home ... start up GDB. This
1378 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1379 *client's* stack. This is necessary to give GDB the illusion that
1380 the client program really was running on the real cpu. */
1381extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1382
njn41557122002-10-14 09:25:37 +00001383/* VG_(bbs_done) in include/vg_skin.h */
1384
sewardjde4a1d02002-03-22 01:27:54 +00001385/* 64-bit counter for the number of bbs to go before a debug exit. */
1386extern ULong VG_(bbs_to_go);
1387
1388/* Counts downwards in vg_run_innerloop. */
1389extern UInt VG_(dispatch_ctr);
1390
sewardjde4a1d02002-03-22 01:27:54 +00001391/* Is the client running on the simulated CPU or the real one? */
1392extern Bool VG_(running_on_simd_CPU); /* Initially False */
1393
sewardj7e87e382002-05-03 19:09:05 +00001394/* This is the ThreadId of the last thread the scheduler ran. */
1395extern ThreadId VG_(last_run_tid);
1396
njn25e49d8e72002-09-23 09:36:25 +00001397/* This is the argument to __NR_exit() supplied by the first thread to
1398 call that syscall. We eventually pass that to __NR_exit() for
1399 real. */
njn633de322003-05-12 20:40:13 +00001400extern Int VG_(exitcode);
njn25e49d8e72002-09-23 09:36:25 +00001401
sewardjde4a1d02002-03-22 01:27:54 +00001402
1403/* --- Counters, for informational purposes only. --- */
1404
1405/* Number of lookups which miss the fast tt helper. */
1406extern UInt VG_(tt_fast_misses);
1407
sewardjc0d8f682002-11-30 00:49:43 +00001408/* Counts for TT/TC informational messages. */
sewardjde4a1d02002-03-22 01:27:54 +00001409
sewardjde4a1d02002-03-22 01:27:54 +00001410/* Number and total o/t size of translations overall. */
1411extern UInt VG_(overall_in_count);
1412extern UInt VG_(overall_in_osize);
1413extern UInt VG_(overall_in_tsize);
1414/* Number and total o/t size of discards overall. */
1415extern UInt VG_(overall_out_count);
1416extern UInt VG_(overall_out_osize);
1417extern UInt VG_(overall_out_tsize);
sewardjc0d8f682002-11-30 00:49:43 +00001418/* The number of discards of TT/TC. */
1419extern UInt VG_(number_of_tc_discards);
sewardj22854b92002-11-30 14:00:47 +00001420/* Counts of chain and unchain operations done. */
1421extern UInt VG_(bb_enchain_count);
1422extern UInt VG_(bb_dechain_count);
1423/* Number of unchained jumps performed. */
1424extern UInt VG_(unchained_jumps_done);
1425
sewardjde4a1d02002-03-22 01:27:54 +00001426
1427/* Counts pertaining to the register allocator. */
1428
1429/* total number of uinstrs input to reg-alloc */
1430extern UInt VG_(uinstrs_prealloc);
1431
1432/* total number of uinstrs added due to spill code */
1433extern UInt VG_(uinstrs_spill);
1434
1435/* number of bbs requiring spill code */
1436extern UInt VG_(translations_needing_spill);
1437
1438/* total of register ranks over all translations */
1439extern UInt VG_(total_reg_rank);
1440
sewardjde4a1d02002-03-22 01:27:54 +00001441/* Counts pertaining to internal sanity checking. */
1442extern UInt VG_(sanity_fast_count);
1443extern UInt VG_(sanity_slow_count);
1444
sewardj2e93c502002-04-12 11:12:52 +00001445/* Counts pertaining to the scheduler. */
1446extern UInt VG_(num_scheduling_events_MINOR);
1447extern UInt VG_(num_scheduling_events_MAJOR);
1448
sewardjfa492d42002-12-08 18:20:01 +00001449/* Insert and extract the D flag from eflags */
1450UInt VG_(insertDflag)(UInt eflags, Int d);
1451Int VG_(extractDflag)(UInt eflags);
sewardjde4a1d02002-03-22 01:27:54 +00001452
sewardj49e630d2003-04-23 21:18:52 +00001453/* start address and size of the initial stack */
1454extern Addr VG_(foundstack_start);
1455extern UInt VG_(foundstack_size);
1456
1457
sewardjde4a1d02002-03-22 01:27:54 +00001458/* ---------------------------------------------------------------------
1459 Exports of vg_memory.c
1460 ------------------------------------------------------------------ */
1461
njn25e49d8e72002-09-23 09:36:25 +00001462extern void VG_(init_memory) ( void );
1463extern void VG_(new_exe_segment) ( Addr a, UInt len );
1464extern void VG_(remove_if_exe_segment) ( Addr a, UInt len );
sewardjde4a1d02002-03-22 01:27:54 +00001465
njn9b007f62003-04-07 14:40:25 +00001466extern __attribute__((regparm(1)))
1467 void VG_(unknown_esp_update) ( Addr new_ESP );
sewardjde4a1d02002-03-22 01:27:54 +00001468
sewardjde4a1d02002-03-22 01:27:54 +00001469/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001470 Exports of vg_syscalls.c
sewardjde4a1d02002-03-22 01:27:54 +00001471 ------------------------------------------------------------------ */
1472
njn25e49d8e72002-09-23 09:36:25 +00001473extern void VG_(init_dataseg_end_for_brk) ( void );
1474
sewardj2e93c502002-04-12 11:12:52 +00001475extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001476
njn25e49d8e72002-09-23 09:36:25 +00001477extern void* VG_(pre_known_blocking_syscall) ( ThreadId tid, Int syscallno );
1478extern void VG_(post_known_blocking_syscall)( ThreadId tid, Int syscallno,
1479 void* pre_res, Int res );
sewardjde4a1d02002-03-22 01:27:54 +00001480
1481extern Bool VG_(is_kerror) ( Int res );
1482
njnd3040452003-05-19 15:04:06 +00001483#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1484 VG_(load_thread_state)(thread_id); \
1485 VG_(copy_baseBlock_to_m_state_static)(); \
1486 VG_(do_syscall)(); \
1487 VG_(copy_m_state_static_to_baseBlock)(); \
1488 VG_(save_thread_state)(thread_id); \
1489 result_lvalue = VG_(threads)[thread_id].m_eax; \
1490 VG_TRACK( post_reg_write_syscall_return, thread_id, R_EAX );
sewardjde4a1d02002-03-22 01:27:54 +00001491
1492
1493/* ---------------------------------------------------------------------
1494 Exports of vg_transtab.c
1495 ------------------------------------------------------------------ */
1496
njn25e49d8e72002-09-23 09:36:25 +00001497/* The fast-cache for tt-lookup. */
1498extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE];
1499
sewardjde4a1d02002-03-22 01:27:54 +00001500extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
sewardj6c3769f2002-11-29 01:02:45 +00001501
sewardjc0d8f682002-11-30 00:49:43 +00001502extern void VG_(add_to_trans_tab) ( Addr orig_addr, Int orig_size,
sewardj22854b92002-11-30 14:00:47 +00001503 Addr trans_addr, Int trans_size,
1504 UShort jumps[VG_MAX_JUMPS]);
sewardj6c3769f2002-11-29 01:02:45 +00001505
sewardj97ad5522003-05-04 12:32:56 +00001506extern void VG_(invalidate_translations) ( Addr start, UInt range, Bool unchain_blocks );
sewardjde4a1d02002-03-22 01:27:54 +00001507
sewardj18d75132002-05-16 11:06:21 +00001508extern void VG_(init_tt_tc) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001509
1510extern void VG_(sanity_check_tc_tt) ( void );
1511extern Addr VG_(search_transtab) ( Addr original_addr );
1512
sewardjde4a1d02002-03-22 01:27:54 +00001513
1514
1515/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001516 Exports of vg_syscall.S
1517 ------------------------------------------------------------------ */
1518
1519extern void VG_(do_syscall) ( void );
1520
1521
1522/* ---------------------------------------------------------------------
1523 Exports of vg_startup.S
1524 ------------------------------------------------------------------ */
1525
sewardjde4a1d02002-03-22 01:27:54 +00001526extern void VG_(switch_to_real_CPU) ( void );
1527
sewardj35805422002-04-21 13:05:34 +00001528extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1529 Addr m_esp_at_error,
1530 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001531
1532
1533/* ---------------------------------------------------------------------
1534 Exports of vg_dispatch.S
1535 ------------------------------------------------------------------ */
1536
sewardj2e93c502002-04-12 11:12:52 +00001537/* Run a thread for a (very short) while, until some event happens
1538 which means we need to defer to the scheduler. */
1539extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001540
sewardj22854b92002-11-30 14:00:47 +00001541/* The patching routing called when a BB wants to chain itself to
1542 another. */
1543extern UInt VG_(patch_me);
sewardjde4a1d02002-03-22 01:27:54 +00001544
1545/* ---------------------------------------------------------------------
1546 Exports of vg_helpers.S
1547 ------------------------------------------------------------------ */
1548
sewardjde4a1d02002-03-22 01:27:54 +00001549/* Mul, div, etc, -- we don't codegen these directly. */
1550extern void VG_(helper_idiv_64_32);
1551extern void VG_(helper_div_64_32);
1552extern void VG_(helper_idiv_32_16);
1553extern void VG_(helper_div_32_16);
1554extern void VG_(helper_idiv_16_8);
1555extern void VG_(helper_div_16_8);
1556
1557extern void VG_(helper_imul_32_64);
1558extern void VG_(helper_mul_32_64);
1559extern void VG_(helper_imul_16_32);
1560extern void VG_(helper_mul_16_32);
1561extern void VG_(helper_imul_8_16);
1562extern void VG_(helper_mul_8_16);
1563
1564extern void VG_(helper_CLD);
1565extern void VG_(helper_STD);
1566extern void VG_(helper_get_dirflag);
1567
sewardj7d78e782002-06-02 00:04:00 +00001568extern void VG_(helper_CLC);
1569extern void VG_(helper_STC);
1570
sewardjde4a1d02002-03-22 01:27:54 +00001571extern void VG_(helper_shldl);
1572extern void VG_(helper_shldw);
1573extern void VG_(helper_shrdl);
1574extern void VG_(helper_shrdw);
1575
1576extern void VG_(helper_RDTSC);
1577extern void VG_(helper_CPUID);
1578
sewardjde4a1d02002-03-22 01:27:54 +00001579extern void VG_(helper_bsf);
1580extern void VG_(helper_bsr);
1581
1582extern void VG_(helper_fstsw_AX);
1583extern void VG_(helper_SAHF);
njnd6251f12003-06-03 13:38:51 +00001584extern void VG_(helper_LAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001585extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001586extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001587
sewardj51096432002-12-14 23:59:09 +00001588extern void VG_(helper_undefined_instruction);
1589
sewardj20917d82002-05-28 01:36:45 +00001590/* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001591extern void VG_(signalreturn_bogusRA)( void );
sewardj20917d82002-05-28 01:36:45 +00001592
njn4f9c9342002-04-29 16:03:24 +00001593/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001594 Things relating to the used skin
njn4f9c9342002-04-29 16:03:24 +00001595 ------------------------------------------------------------------ */
1596
njn25e49d8e72002-09-23 09:36:25 +00001597#define VG_TRACK(fn, args...) \
1598 do { \
1599 if (VG_(track_events).fn) \
1600 VG_(track_events).fn(args); \
1601 } while (0)
sewardj18d75132002-05-16 11:06:21 +00001602
1603
sewardjde4a1d02002-03-22 01:27:54 +00001604/* ---------------------------------------------------------------------
1605 The state of the simulated CPU.
1606 ------------------------------------------------------------------ */
1607
sewardjde4a1d02002-03-22 01:27:54 +00001608/* ---------------------------------------------------------------------
1609 Offsets into baseBlock for everything which needs to referred to
1610 from generated code. The order of these decls does not imply
1611 what the order of the actual offsets is. The latter is important
1612 and is set up in vg_main.c.
1613 ------------------------------------------------------------------ */
1614
1615/* An array of words. In generated code, %ebp always points to the
1616 start of this array. Useful stuff, like the simulated CPU state,
1617 and the addresses of helper functions, can then be found by
1618 indexing off %ebp. The following declares variables which, at
1619 startup time, are given values denoting offsets into baseBlock.
1620 These offsets are in *words* from the start of baseBlock. */
1621
sewardjb91ae7f2003-04-29 23:50:00 +00001622#define VG_BASEBLOCK_WORDS 400
sewardjde4a1d02002-03-22 01:27:54 +00001623
1624extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1625
1626
1627/* -----------------------------------------------------
1628 Read-write parts of baseBlock.
1629 -------------------------------------------------- */
1630
1631/* State of the simulated CPU. */
1632extern Int VGOFF_(m_eax);
1633extern Int VGOFF_(m_ecx);
1634extern Int VGOFF_(m_edx);
1635extern Int VGOFF_(m_ebx);
1636extern Int VGOFF_(m_esp);
1637extern Int VGOFF_(m_ebp);
1638extern Int VGOFF_(m_esi);
1639extern Int VGOFF_(m_edi);
1640extern Int VGOFF_(m_eflags);
sewardjb91ae7f2003-04-29 23:50:00 +00001641extern Int VGOFF_(m_ssestate);
sewardjde4a1d02002-03-22 01:27:54 +00001642extern Int VGOFF_(m_eip);
1643
sewardjfa492d42002-12-08 18:20:01 +00001644extern Int VGOFF_(m_dflag); /* D flag is handled specially */
1645
sewardj92a59562002-09-30 00:53:10 +00001646extern Int VGOFF_(m_cs);
1647extern Int VGOFF_(m_ss);
1648extern Int VGOFF_(m_ds);
1649extern Int VGOFF_(m_es);
1650extern Int VGOFF_(m_fs);
1651extern Int VGOFF_(m_gs);
1652
sewardjde4a1d02002-03-22 01:27:54 +00001653/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1654extern Int VGOFF_(spillslots);
1655
1656/* Records the valid bits for the 8 integer regs & flags reg. */
1657extern Int VGOFF_(sh_eax);
1658extern Int VGOFF_(sh_ecx);
1659extern Int VGOFF_(sh_edx);
1660extern Int VGOFF_(sh_ebx);
1661extern Int VGOFF_(sh_esp);
1662extern Int VGOFF_(sh_ebp);
1663extern Int VGOFF_(sh_esi);
1664extern Int VGOFF_(sh_edi);
1665extern Int VGOFF_(sh_eflags);
1666
sewardjde4a1d02002-03-22 01:27:54 +00001667/* -----------------------------------------------------
1668 Read-only parts of baseBlock.
1669 -------------------------------------------------- */
1670
sewardj92a59562002-09-30 00:53:10 +00001671/* This thread's LDT pointer. */
1672extern Int VGOFF_(ldt);
1673
njn211b6ad2003-02-03 12:33:31 +00001674/* Nb: Most helper offsets are in include/vg_skin.h, for use by skins */
sewardjde4a1d02002-03-22 01:27:54 +00001675
sewardj51096432002-12-14 23:59:09 +00001676extern Int VGOFF_(helper_undefined_instruction);
1677
njn25e49d8e72002-09-23 09:36:25 +00001678/* For storing extension-specific helpers, determined at runtime. The addr
1679 * and offset arrays together form a (addr, offset) map that allows a
1680 * helper's baseBlock offset to be computed from its address. It's done
1681 * like this so CCALL_M_Ns and other helper calls can use the function
1682 * address rather than having to much around with offsets. */
1683extern UInt VG_(n_compact_helpers);
1684extern UInt VG_(n_noncompact_helpers);
1685
1686extern Addr VG_(compact_helper_addrs) [];
1687extern Int VG_(compact_helper_offsets)[];
1688
1689extern Addr VG_(noncompact_helper_addrs) [];
1690extern Int VG_(noncompact_helper_offsets)[];
1691
sewardjde4a1d02002-03-22 01:27:54 +00001692#endif /* ndef __VG_INCLUDE_H */
1693
sewardj3b2736a2002-03-24 12:18:35 +00001694
1695/* ---------------------------------------------------------------------
1696 Finally - autoconf-generated settings
1697 ------------------------------------------------------------------ */
1698
1699#include "config.h"
1700
sewardjde4a1d02002-03-22 01:27:54 +00001701/*--------------------------------------------------------------------*/
1702/*--- end vg_include.h ---*/
1703/*--------------------------------------------------------------------*/