blob: 7eed65ad412866006d3226e116d485b9bb27aa51 [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
12 Copyright (C) 2000-2002 Julian Seward
13 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.) */
119#define VG_N_WAITING_FDS 10
120
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. */
132#define VG_N_CLEANUPSTACK 8
133
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
sewardjde4a1d02002-03-22 01:27:54 +0000140
141/* ---------------------------------------------------------------------
142 Basic types
143 ------------------------------------------------------------------ */
144
sewardjde4a1d02002-03-22 01:27:54 +0000145/* Just pray that gcc's constant folding works properly ... */
146#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
147 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
148 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
149
sewardjde4a1d02002-03-22 01:27:54 +0000150/* ---------------------------------------------------------------------
151 Command-line-settable options
152 ------------------------------------------------------------------ */
153
sewardj4f094a72002-11-05 23:37:35 +0000154/* Default destination port to be used in logging over a network, if
155 none specified. */
156#define VG_CLO_DEFAULT_LOGPORT 1500
sewardj73cf3bc2002-11-03 03:20:15 +0000157
158/* The max number of suppression files. */
sewardjde4a1d02002-03-22 01:27:54 +0000159#define VG_CLO_MAX_SFILES 10
160
sewardj4cf05692002-10-27 20:28:29 +0000161/* Describes where logging output is to be sent. */
162typedef
163 enum {
164 VgLogTo_Fd,
165 VgLogTo_File,
166 VgLogTo_Socket
167 } VgLogTo;
168
169
sewardj72f98ff2002-06-13 17:23:38 +0000170/* Should we stop collecting errors if too many appear? default: YES */
sewardj2e432902002-06-13 20:44:00 +0000171extern Bool VG_(clo_error_limit);
sewardjde4a1d02002-03-22 01:27:54 +0000172/* Enquire about whether to attach to GDB at errors? default: NO */
173extern Bool VG_(clo_GDB_attach);
njn43c799e2003-04-08 00:08:52 +0000174/* Enquire about generating a suppression for each error? default: NO */
175extern Bool VG_(clo_gen_suppressions);
sewardjde4a1d02002-03-22 01:27:54 +0000176/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
177extern Int VG_(sanity_level);
sewardjde4a1d02002-03-22 01:27:54 +0000178/* Automatically attempt to demangle C++ names? default: YES */
179extern Bool VG_(clo_demangle);
sewardjde4a1d02002-03-22 01:27:54 +0000180/* Simulate child processes? default: NO */
181extern Bool VG_(clo_trace_children);
sewardj4cf05692002-10-27 20:28:29 +0000182
183/* Where logging output is to be sent to.
184
185 When log_to == VgLogTo_Fd, clo_logfile_fd holds the file id, and is
186 taken from the command line. clo_logfile_name is irrelevant.
187
188 When log_to == VgLogTo_File, clo_logfile_name holds the logfile
189 name, and is taken from the command line. clo_logfile_fd is then
190 made to hold the relevant file id, by opening clo_logfile_name
191 (concatenated with the process ID) for writing.
192
193 When log_to == VgLogTo_Socket, clo_logfile_name holds the
194 hostname:portnumber pair, and is taken from the command line.
195 clo_logfile_fd is then made to hold the relevant file handle, by
196 opening a connection to said hostname:portnumber pair.
197
198 Global default is to set log_to == VgLogTo_Fd and logfile_fd == 2
199 (stderr). */
200extern VgLogTo VG_(clo_log_to);
201extern Int VG_(clo_logfile_fd);
202extern Char* VG_(clo_logfile_name);
sewardjde4a1d02002-03-22 01:27:54 +0000203
204/* The number of suppression files specified. */
205extern Int VG_(clo_n_suppressions);
206/* The names of the suppression files. */
207extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
208
209/* Single stepping? default: NO */
210extern Bool VG_(clo_single_step);
211/* Code improvement? default: YES */
212extern Bool VG_(clo_optimise);
njn25e49d8e72002-09-23 09:36:25 +0000213/* DEBUG: print generated code? default: 00000 ( == NO ) */
214extern Bool VG_(clo_trace_codegen);
sewardjde4a1d02002-03-22 01:27:54 +0000215/* DEBUG: print system calls? default: NO */
216extern Bool VG_(clo_trace_syscalls);
217/* DEBUG: print signal details? default: NO */
218extern Bool VG_(clo_trace_signals);
219/* DEBUG: print symtab details? default: NO */
220extern Bool VG_(clo_trace_symtab);
sewardj8937c812002-04-12 20:12:20 +0000221/* DEBUG: print thread scheduling events? default: NO */
222extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000223/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
224 (some), 2 (all) */
225extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000226/* Stop after this many basic blocks. default: Infinity. */
227extern ULong VG_(clo_stop_after);
228/* Display gory details for the k'th most popular error. default:
229 Infinity. */
230extern Int VG_(clo_dump_error);
231/* Number of parents of a backtrace. Default: 8. */
232extern Int VG_(clo_backtrace_size);
sewardj3984b852002-05-12 03:00:17 +0000233/* Engage miscellaneous wierd hacks needed for some progs. */
sewardj8d365b52002-05-12 10:52:16 +0000234extern Char* VG_(clo_weird_hacks);
sewardj858964b2002-10-05 14:15:43 +0000235/* Should we run __libc_freeres at exit? Sometimes causes crashes.
236 Default: YES. Note this is subservient to VG_(needs).libc_freeres;
237 if the latter says False, then the setting of VG_(clo_weird_hacks)
238 is ignored. Ie if a skin says no, I don't want this to run, that
239 cannot be overridden from the command line. */
240extern Bool VG_(clo_run_libc_freeres);
sewardjb5ff83e2002-12-01 19:40:49 +0000241/* Use the basic-block chaining optimisation? Default: YES */
sewardj22854b92002-11-30 14:00:47 +0000242extern Bool VG_(clo_chain_bb);
sewardjde4a1d02002-03-22 01:27:54 +0000243
244
245/* ---------------------------------------------------------------------
246 Debugging and profiling stuff
247 ------------------------------------------------------------------ */
248
sewardjde4a1d02002-03-22 01:27:54 +0000249/* Create a logfile into which messages can be dumped. */
250extern void VG_(startup_logging) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000251extern void VG_(shutdown_logging)( void );
sewardjde4a1d02002-03-22 01:27:54 +0000252
253extern void VGP_(init_profiling) ( void );
254extern void VGP_(done_profiling) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000255
njn25e49d8e72002-09-23 09:36:25 +0000256#undef VGP_PUSHCC
257#undef VGP_POPCC
258#define VGP_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x)
259#define VGP_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x)
sewardjde4a1d02002-03-22 01:27:54 +0000260
sewardjde4a1d02002-03-22 01:27:54 +0000261/* ---------------------------------------------------------------------
njn810086f2002-11-14 12:42:47 +0000262 Skin-related types
263 ------------------------------------------------------------------ */
264/* These structs are not exposed to skins to mitigate possibility of
265 binary-incompatibilities when the core/skin interface changes. Instead,
266 set functions are provided (see include/vg_skin.h). */
267typedef
268 struct {
269 Char* name;
270 Char* version;
271 Char* description;
272 Char* copyright_author;
273 Char* bug_reports_to;
njn120281f2003-02-03 12:20:07 +0000274 UInt avg_translation_sizeB;
njn810086f2002-11-14 12:42:47 +0000275 }
276 VgDetails;
277
278extern VgDetails VG_(details);
279
280/* If new fields are added to this type, update:
281 * - vg_main.c:initialisation of VG_(needs)
282 * - vg_main.c:sanity_check_needs()
283 *
284 * If the name of this type or any of its fields change, update:
285 * - dependent comments (just search for "VG_(needs)").
286 */
287typedef
288 struct {
289 Bool libc_freeres;
290 Bool core_errors;
291
292 Bool skin_errors;
293 Bool basic_block_discards;
294 Bool shadow_regs;
295 Bool command_line_options;
296 Bool client_requests;
297 Bool extended_UCode;
298 Bool syscall_wrapper;
njn810086f2002-11-14 12:42:47 +0000299 Bool sanity_checks;
300 Bool data_syms;
301 }
302 VgNeeds;
303
304extern VgNeeds VG_(needs);
305
306/* Events happening in core to track. To be notified, assign a function
307 to the function pointer. To ignore an event, don't do anything
308 (default assignment is to NULL in which case the call is skipped). */
309typedef
310 struct {
311 /* Memory events */
312 void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
njn810086f2002-11-14 12:42:47 +0000313 void (*new_mem_stack_signal) ( Addr a, UInt len );
314 void (*new_mem_brk) ( Addr a, UInt len );
315 void (*new_mem_mmap) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
316
njn3e884182003-04-15 13:03:23 +0000317 void (*copy_mem_remap) ( Addr from, Addr to, UInt len );
318 void (*change_mem_mprotect) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
319 void (*die_mem_stack_signal) ( Addr a, UInt len );
320 void (*die_mem_brk) ( Addr a, UInt len );
321 void (*die_mem_munmap) ( Addr a, UInt len );
322
njn9b007f62003-04-07 14:40:25 +0000323 void (*new_mem_stack_4) ( Addr new_ESP );
324 void (*new_mem_stack_8) ( Addr new_ESP );
325 void (*new_mem_stack_12) ( Addr new_ESP );
326 void (*new_mem_stack_16) ( Addr new_ESP );
327 void (*new_mem_stack_32) ( Addr new_ESP );
328 void (*new_mem_stack) ( Addr a, UInt len );
329
njn9b007f62003-04-07 14:40:25 +0000330 void (*die_mem_stack_4) ( Addr die_ESP );
331 void (*die_mem_stack_8) ( Addr die_ESP );
332 void (*die_mem_stack_12) ( Addr die_ESP );
333 void (*die_mem_stack_16) ( Addr die_ESP );
334 void (*die_mem_stack_32) ( Addr die_ESP );
335 void (*die_mem_stack) ( Addr a, UInt len );
336
njn3e884182003-04-15 13:03:23 +0000337 void (*ban_mem_stack) ( Addr a, UInt len );
njn810086f2002-11-14 12:42:47 +0000338
339 void (*pre_mem_read) ( CorePart part, ThreadState* tst,
340 Char* s, Addr a, UInt size );
341 void (*pre_mem_read_asciiz) ( CorePart part, ThreadState* tst,
342 Char* s, Addr a );
343 void (*pre_mem_write) ( CorePart part, ThreadState* tst,
344 Char* s, Addr a, UInt size );
345 /* Not implemented yet -- have to add in lots of places, which is a
346 pain. Won't bother unless/until there's a need. */
347 /* void (*post_mem_read) ( ThreadState* tst, Char* s,
348 Addr a, UInt size ); */
349 void (*post_mem_write) ( Addr a, UInt size );
350
351
352 /* Scheduler events (not exhaustive) */
353 void (*thread_run) ( ThreadId tid );
354
355
356 /* Thread events (not exhaustive) */
357 void (*post_thread_create) ( ThreadId tid, ThreadId child );
358 void (*post_thread_join) ( ThreadId joiner, ThreadId joinee );
359
360
361 /* Mutex events (not exhaustive) */
362 void (*pre_mutex_lock) ( ThreadId tid,
363 void* /*pthread_mutex_t* */ mutex );
364 void (*post_mutex_lock) ( ThreadId tid,
365 void* /*pthread_mutex_t* */ mutex );
366 void (*post_mutex_unlock) ( ThreadId tid,
367 void* /*pthread_mutex_t* */ mutex );
368
njnfdc28af2003-02-24 10:36:48 +0000369 /* Signal events (not exhaustive) */
njn3e884182003-04-15 13:03:23 +0000370 void (* pre_deliver_signal) ( ThreadId tid, Int sigNo, Bool alt_stack );
njnfdc28af2003-02-24 10:36:48 +0000371 void (*post_deliver_signal) ( ThreadId tid, Int sigNo );
372
njn810086f2002-11-14 12:42:47 +0000373
njnfdc28af2003-02-24 10:36:48 +0000374 /* Others... condition variable... */
njn810086f2002-11-14 12:42:47 +0000375 /* ... */
376 }
377 VgTrackEvents;
378
379extern VgTrackEvents VG_(track_events);
380
381
382/* ---------------------------------------------------------------------
383 Exports of vg_needs.c
384 ------------------------------------------------------------------ */
385
386void VG_(sanity_check_needs)(void);
387
388/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000389 Exports of vg_malloc2.c
390 ------------------------------------------------------------------ */
391
392/* Allocation arenas.
njn3e884182003-04-15 13:03:23 +0000393
394 CORE for the core's general use.
395 SKIN for the skin to use (and the only one it uses).
396 SYMTAB for Valgrind's symbol table storage.
397 JITTER for small storage during translation.
398 CLIENT for the client's mallocs/frees, if the skin replaces glibc's
399 malloc() et al -- redzone size is chosen by the skin.
400 DEMANGLE for the C++ demangler.
401 EXECTXT for storing ExeContexts.
402 ERRORS for storing CoreErrors.
403 TRANSIENT for very short-term use. It should be empty in between uses.
404
njn25e49d8e72002-09-23 09:36:25 +0000405 When adding a new arena, remember also to add it to ensure_mm_init().
sewardjde4a1d02002-03-22 01:27:54 +0000406*/
407typedef Int ArenaId;
408
njn3e884182003-04-15 13:03:23 +0000409#define VG_N_ARENAS 9
sewardjde4a1d02002-03-22 01:27:54 +0000410
njn3e884182003-04-15 13:03:23 +0000411#define VG_AR_CORE 0
412#define VG_AR_SKIN 1
413#define VG_AR_SYMTAB 2
414#define VG_AR_JITTER 3
415#define VG_AR_CLIENT 4
416#define VG_AR_DEMANGLE 5
417#define VG_AR_EXECTXT 6
418#define VG_AR_ERRORS 7
419#define VG_AR_TRANSIENT 8
sewardjde4a1d02002-03-22 01:27:54 +0000420
njn25e49d8e72002-09-23 09:36:25 +0000421extern void* VG_(arena_malloc) ( ArenaId arena, Int nbytes );
422extern void VG_(arena_free) ( ArenaId arena, void* ptr );
njn3e884182003-04-15 13:03:23 +0000423extern void* VG_(arena_calloc) ( ArenaId arena, Int alignment,
424 Int nmemb, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000425extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment,
426 Int size );
427extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB,
sewardjde4a1d02002-03-22 01:27:54 +0000428 Int req_pszB );
429
sewardjde4a1d02002-03-22 01:27:54 +0000430extern void VG_(mallocSanityCheckAll) ( void );
431
432extern void VG_(show_all_arena_stats) ( void );
433extern Bool VG_(is_empty_arena) ( ArenaId aid );
434
435
sewardjde4a1d02002-03-22 01:27:54 +0000436/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000437 Exports of vg_intercept.c
sewardj2e93c502002-04-12 11:12:52 +0000438 ------------------------------------------------------------------ */
439
440/* This doesn't export code or data that valgrind.so needs to link
441 against. However, the scheduler does need to know the following
442 request codes. A few, publically-visible, request codes are also
njn25e49d8e72002-09-23 09:36:25 +0000443 defined in valgrind.h, and similar headers for some skins. */
sewardj2e93c502002-04-12 11:12:52 +0000444
445#define VG_USERREQ__MALLOC 0x2001
njn3e884182003-04-15 13:03:23 +0000446#define VG_USERREQ__FREE 0x2002
sewardj2e93c502002-04-12 11:12:52 +0000447
sewardj20917d82002-05-28 01:36:45 +0000448/* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn
449 MUST NOT return -- ever. Eventually it will do either __QUIT or
450 __WAIT_JOINER. */
451#define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001
452
453/* ( no-args ): calling thread disappears from the system forever.
454 Reclaim resources. */
455#define VG_USERREQ__QUIT 0x3002
456
457/* ( void* ): calling thread waits for joiner and returns the void* to
458 it. */
459#define VG_USERREQ__WAIT_JOINER 0x3003
460
461/* ( ThreadId, void** ): wait to join a thread. */
462#define VG_USERREQ__PTHREAD_JOIN 0x3004
463
464/* Set cancellation state and type for this thread. */
465#define VG_USERREQ__SET_CANCELSTATE 0x3005
466#define VG_USERREQ__SET_CANCELTYPE 0x3006
467
468/* ( no-args ): Test if we are at a cancellation point. */
469#define VG_USERREQ__TESTCANCEL 0x3007
470
471/* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call
472 with this arg to indicate that a cancel is now pending for the
473 specified thread. */
474#define VG_USERREQ__SET_CANCELPEND 0x3008
475
476/* Set/get detach state for this thread. */
477#define VG_USERREQ__SET_OR_GET_DETACH 0x3009
478
479#define VG_USERREQ__PTHREAD_GET_THREADID 0x300B
480#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C
481#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D
482#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E
483#define VG_USERREQ__PTHREAD_COND_WAIT 0x300F
484#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010
485#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011
486#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012
487#define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013
488#define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014
sewardj00a66b12002-10-12 16:42:35 +0000489#define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015
490#define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016
sewardj20917d82002-05-28 01:36:45 +0000491#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017
492#define VG_USERREQ__PTHREAD_SIGMASK 0x3018
493#define VG_USERREQ__SIGWAIT 0x3019
494#define VG_USERREQ__PTHREAD_KILL 0x301A
495#define VG_USERREQ__PTHREAD_YIELD 0x301B
sewardj00a66b12002-10-12 16:42:35 +0000496#define VG_USERREQ__PTHREAD_KEY_VALIDATE 0x301C
sewardj2e93c502002-04-12 11:12:52 +0000497
sewardj8ad94e12002-05-29 00:10:20 +0000498#define VG_USERREQ__CLEANUP_PUSH 0x3020
499#define VG_USERREQ__CLEANUP_POP 0x3021
sewardj870497a2002-05-29 01:06:47 +0000500#define VG_USERREQ__GET_KEY_D_AND_S 0x3022
sewardj8ad94e12002-05-29 00:10:20 +0000501
sewardjef037c72002-05-30 00:40:03 +0000502#define VG_USERREQ__NUKE_OTHER_THREADS 0x3023
sewardjefbfcdf2002-06-19 17:35:45 +0000503
504/* Ask how many signal handler returns have happened to this
505 thread. */
sewardj9a2224b2002-06-19 10:17:40 +0000506#define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024
sewardjef037c72002-05-30 00:40:03 +0000507
sewardj2cb00342002-06-28 01:46:26 +0000508/* Get/set entries for a thread's pthread_atfork stack. */
509#define VG_USERREQ__SET_FHSTACK_USED 0x3025
510#define VG_USERREQ__GET_FHSTACK_USED 0x3026
511#define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027
512#define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028
sewardjefbfcdf2002-06-19 17:35:45 +0000513
sewardj1fe7b002002-07-16 01:43:15 +0000514/* Denote the finish of VG_(__libc_freeres_wrapper). */
515#define VG_USERREQ__LIBC_FREERES_DONE 0x3029
516
sewardj45b4b372002-04-16 22:50:32 +0000517/* Cosmetic ... */
518#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
sewardj4dced352002-06-04 22:54:20 +0000519/* Log a pthread error from client-space. Cosmetic. */
520#define VG_USERREQ__PTHREAD_ERROR 0x3102
njn3e884182003-04-15 13:03:23 +0000521/*
522In vg_skin.h, so skins can use it.
523Write a string to the logging sink.
sewardj69a72a52002-11-03 13:41:41 +0000524#define VG_USERREQ__LOGMESSAGE 0x3103
njn3e884182003-04-15 13:03:23 +0000525*/
sewardj45b4b372002-04-16 22:50:32 +0000526
sewardj54cacf02002-04-12 23:24:59 +0000527/*
528In vg_constants.h:
529#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardj54cacf02002-04-12 23:24:59 +0000530*/
531
sewardj1fe7b002002-07-16 01:43:15 +0000532/* The scheduler does need to know the address of it so it can be
533 called at program exit. */
534extern void VG_(__libc_freeres_wrapper)( void );
535
sewardj54cacf02002-04-12 23:24:59 +0000536
sewardj2e93c502002-04-12 11:12:52 +0000537/* ---------------------------------------------------------------------
538 Constants pertaining to the simulated CPU state, VG_(baseBlock),
539 which need to go here to avoid ugly circularities.
540 ------------------------------------------------------------------ */
541
542/* How big is the saved FPU state? */
543#define VG_SIZE_OF_FPUSTATE 108
544/* ... and in words ... */
545#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
546
547
548/* ---------------------------------------------------------------------
njn3e884182003-04-15 13:03:23 +0000549 Exports of vg_defaults.c
550 ------------------------------------------------------------------ */
551
552extern Bool VG_(sk_malloc_called_by_scheduler);
553
554
555/* ---------------------------------------------------------------------
sewardj92a59562002-09-30 00:53:10 +0000556 Exports of vg_ldt.c
557 ------------------------------------------------------------------ */
558
559/* This is the hardware-format for a segment descriptor, ie what the
560 x86 actually deals with. It is 8 bytes long. It's ugly. */
561
562typedef struct _LDT_ENTRY {
563 union {
564 struct {
565 UShort LimitLow;
566 UShort BaseLow;
567 unsigned BaseMid : 8;
568 unsigned Type : 5;
569 unsigned Dpl : 2;
570 unsigned Pres : 1;
571 unsigned LimitHi : 4;
572 unsigned Sys : 1;
573 unsigned Reserved_0 : 1;
574 unsigned Default_Big : 1;
575 unsigned Granularity : 1;
576 unsigned BaseHi : 8;
577 } Bits;
578 struct {
579 UInt word1;
580 UInt word2;
581 } Words;
582 }
583 LdtEnt;
584} VgLdtEntry;
585
586/* Maximum number of LDT entries supported (by the x86). */
587#define VG_M_LDT_ENTRIES 8192
588/* The size of each LDT entry == sizeof(VgLdtEntry) */
589#define VG_LDT_ENTRY_SIZE 8
590
591/* Alloc & copy, and dealloc. */
592extern VgLdtEntry*
593 VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt );
594extern void
595 VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt );
596
597/* Simulate the modify_ldt syscall. */
598extern Int VG_(sys_modify_ldt) ( ThreadId tid,
599 Int func, void* ptr, UInt bytecount );
600
sewardje1042472002-09-30 12:33:11 +0000601/* Called from generated code. Given a segment selector and a virtual
602 address, return a linear address, and do limit checks too. */
603extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr );
604
sewardj92a59562002-09-30 00:53:10 +0000605
606/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000607 Exports of vg_scheduler.c
608 ------------------------------------------------------------------ */
609
sewardj2e93c502002-04-12 11:12:52 +0000610typedef
611 enum {
612 VgTs_Empty, /* this slot is not in use */
613 VgTs_Runnable, /* waiting to be scheduled */
614 VgTs_WaitJoiner, /* waiting for someone to do join on me */
615 VgTs_WaitJoinee, /* waiting for the thread I did join on */
616 VgTs_WaitFD, /* waiting for I/O completion on a fd */
617 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000618 VgTs_WaitCV, /* waiting on a condition variable */
sewardjb48e5002002-05-13 00:16:03 +0000619 VgTs_WaitSIG, /* waiting due to sigwait() */
sewardj2e93c502002-04-12 11:12:52 +0000620 VgTs_Sleeping /* sleeping for a while */
621 }
622 ThreadStatus;
sewardj8ad94e12002-05-29 00:10:20 +0000623
624/* An entry in a threads's cleanup stack. */
625typedef
626 struct {
627 void (*fn)(void*);
628 void* arg;
629 }
630 CleanupEntry;
sewardj2cb00342002-06-28 01:46:26 +0000631
632/* An entry in a thread's fork-handler stack. */
633typedef
634 struct {
635 void (*prepare)(void);
636 void (*parent)(void);
637 void (*child)(void);
638 }
639 ForkHandlerEntry;
640
641
njn25e49d8e72002-09-23 09:36:25 +0000642struct _ThreadState {
643 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
644 The thread identity is simply the index in vg_threads[].
645 ThreadId == 1 is the root thread and has the special property
646 that we don't try and allocate or deallocate its stack. For
647 convenience of generating error message, we also put the
648 ThreadId in this tid field, but be aware that it should
649 ALWAYS == the index in vg_threads[]. */
650 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000651
njn25e49d8e72002-09-23 09:36:25 +0000652 /* Current scheduling status.
sewardj5f07b662002-04-23 16:52:51 +0000653
njn25e49d8e72002-09-23 09:36:25 +0000654 Complications: whenever this is set to VgTs_WaitMX, you
655 should also set .m_edx to whatever the required return value
656 is for pthread_mutex_lock / pthread_cond_timedwait for when
657 the mutex finally gets unblocked. */
658 ThreadStatus status;
sewardj2e93c502002-04-12 11:12:52 +0000659
njn25e49d8e72002-09-23 09:36:25 +0000660 /* When .status == WaitMX, points to the mutex I am waiting for.
661 When .status == WaitCV, points to the mutex associated with
662 the condition variable indicated by the .associated_cv field.
663 In all other cases, should be NULL. */
664 void* /*pthread_mutex_t* */ associated_mx;
sewardj3b5d8862002-04-20 13:53:23 +0000665
njn25e49d8e72002-09-23 09:36:25 +0000666 /* When .status == WaitCV, points to the condition variable I am
667 waiting for. In all other cases, should be NULL. */
668 void* /*pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000669
njn25e49d8e72002-09-23 09:36:25 +0000670 /* If VgTs_Sleeping, this is when we should wake up, measured in
671 milliseconds as supplied by VG_(read_millisecond_counter).
sewardj2e93c502002-04-12 11:12:52 +0000672
njn25e49d8e72002-09-23 09:36:25 +0000673 If VgTs_WaitCV, this indicates the time at which
674 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
675 this means infinitely far in the future, viz,
676 pthread_cond_wait. */
677 UInt awaken_at;
sewardj20917d82002-05-28 01:36:45 +0000678
njn25e49d8e72002-09-23 09:36:25 +0000679 /* If VgTs_WaitJoiner, return value, as generated by joinees. */
680 void* joinee_retval;
sewardj20917d82002-05-28 01:36:45 +0000681
njn25e49d8e72002-09-23 09:36:25 +0000682 /* If VgTs_WaitJoinee, place to copy the return value to, and
683 the identity of the thread we're waiting for. */
684 void** joiner_thread_return;
685 ThreadId joiner_jee_tid;
sewardj8ad94e12002-05-29 00:10:20 +0000686
njn25e49d8e72002-09-23 09:36:25 +0000687 /* Whether or not detached. */
688 Bool detached;
sewardj20917d82002-05-28 01:36:45 +0000689
njn25e49d8e72002-09-23 09:36:25 +0000690 /* Cancelability state and type. */
691 Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */
692 Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */
693
694 /* Pointer to fn to call to do cancellation. Indicates whether
695 or not cancellation is pending. If NULL, not pending. Else
696 should be &thread_exit_wrapper(), indicating that
697 cancallation is pending. */
698 void (*cancel_pend)(void*);
sewardj2e93c502002-04-12 11:12:52 +0000699
njn25e49d8e72002-09-23 09:36:25 +0000700 /* The cleanup stack. */
701 Int custack_used;
702 CleanupEntry custack[VG_N_CLEANUPSTACK];
sewardj5f07b662002-04-23 16:52:51 +0000703
sewardj00a66b12002-10-12 16:42:35 +0000704 /* A pointer to the thread's-specific-data. This is handled almost
705 entirely from vg_libpthread.c. We just provide hooks to get and
706 set this ptr. This is either NULL, indicating the thread has
707 read/written none of its specifics so far, OR points to a
708 void*[VG_N_THREAD_KEYS], allocated and deallocated in
709 vg_libpthread.c. */
710 void** specifics_ptr;
sewardjb48e5002002-05-13 00:16:03 +0000711
njn25e49d8e72002-09-23 09:36:25 +0000712 /* This thread's blocked-signals mask. Semantics is that for a
713 signal to be delivered to this thread, the signal must not be
714 blocked by either the process-wide signal mask nor by this
715 one. So, if this thread is prepared to handle any signal that
716 the process as a whole is prepared to handle, this mask should
717 be made empty -- and that it is its default, starting
718 state. */
719 vki_ksigset_t sig_mask;
sewardjb48e5002002-05-13 00:16:03 +0000720
njn25e49d8e72002-09-23 09:36:25 +0000721 /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG,
722 is the set of signals for which we are sigwait()ing. */
723 vki_ksigset_t sigs_waited_for;
sewardj9a2224b2002-06-19 10:17:40 +0000724
njn25e49d8e72002-09-23 09:36:25 +0000725 /* Counts the number of times a signal handler for this thread
726 has returned. This makes it easy to implement pause(), by
727 polling this value, of course interspersed with nanosleeps,
728 and waiting till it changes. */
729 UInt n_signals_returned;
sewardj2e93c502002-04-12 11:12:52 +0000730
njn25e49d8e72002-09-23 09:36:25 +0000731 /* Stacks. When a thread slot is freed, we don't deallocate its
732 stack; we just leave it lying around for the next use of the
733 slot. If the next use of the slot requires a larger stack,
734 only then is the old one deallocated and a new one
735 allocated.
sewardj2e93c502002-04-12 11:12:52 +0000736
njn25e49d8e72002-09-23 09:36:25 +0000737 For the main thread (threadid == 0), this mechanism doesn't
738 apply. We don't know the size of the stack since we didn't
739 allocate it, and furthermore we never reallocate it. */
sewardj2e93c502002-04-12 11:12:52 +0000740
njn25e49d8e72002-09-23 09:36:25 +0000741 /* The allocated size of this thread's stack (permanently zero
742 if this is ThreadId == 0, since we didn't allocate its stack) */
743 UInt stack_size;
sewardj1e8cdc92002-04-18 11:37:52 +0000744
njn25e49d8e72002-09-23 09:36:25 +0000745 /* Address of the lowest word in this thread's stack. NULL means
746 not allocated yet.
747 */
748 Addr stack_base;
sewardj2e93c502002-04-12 11:12:52 +0000749
sewardj92a59562002-09-30 00:53:10 +0000750 /* Address of the highest legitimate word in this stack. This is
751 used for error messages only -- not critical for execution
752 correctness. Is is set for all stacks, specifically including
753 ThreadId == 0 (the main thread). */
njn25e49d8e72002-09-23 09:36:25 +0000754 Addr stack_highest_word;
755
sewardj92a59562002-09-30 00:53:10 +0000756 /* Pointer to this thread's Local (Segment) Descriptor Table.
757 Starts out as NULL, indicating there is no table, and we hope to
758 keep it that way. If the thread does __NR_modify_ldt to create
759 entries, we allocate a 8192-entry table at that point. This is
760 a straight copy of the Linux kernel's scheme. Don't forget to
761 deallocate this at thread exit. */
762 VgLdtEntry* ldt;
763
764 /* Saved machine context. Note the FPU state, %EIP and segment
765 registers are not shadowed.
766
767 Although the segment registers are 16 bits long, storage
768 management here, in VG_(baseBlock) and in VG_(m_state_static) is
769 simplified if we pretend they are 32 bits. */
770 UInt m_cs;
771 UInt m_ss;
772 UInt m_ds;
773 UInt m_es;
774 UInt m_fs;
775 UInt m_gs;
776
njn25e49d8e72002-09-23 09:36:25 +0000777 UInt m_eax;
778 UInt m_ebx;
779 UInt m_ecx;
780 UInt m_edx;
781 UInt m_esi;
782 UInt m_edi;
783 UInt m_ebp;
784 UInt m_esp;
785 UInt m_eflags;
786 UInt m_eip;
787 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
788
789 UInt sh_eax;
790 UInt sh_ebx;
791 UInt sh_ecx;
792 UInt sh_edx;
793 UInt sh_esi;
794 UInt sh_edi;
795 UInt sh_ebp;
796 UInt sh_esp;
797 UInt sh_eflags;
798};
sewardj2e93c502002-04-12 11:12:52 +0000799
800
sewardj018f7622002-05-15 21:13:39 +0000801/* The thread table. */
802extern ThreadState VG_(threads)[VG_N_THREADS];
803
804/* Check that tid is in range and denotes a non-Empty thread. */
sewardjb48e5002002-05-13 00:16:03 +0000805extern Bool VG_(is_valid_tid) ( ThreadId tid );
806
sewardj018f7622002-05-15 21:13:39 +0000807/* Check that tid is in range. */
808extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid );
809
sewardj2e93c502002-04-12 11:12:52 +0000810/* Copy the specified thread's state into VG_(baseBlock) in
811 preparation for running it. */
812extern void VG_(load_thread_state)( ThreadId );
813
814/* Save the specified thread's state back in VG_(baseBlock), and fill
815 VG_(baseBlock) with junk, for sanity-check reasons. */
816extern void VG_(save_thread_state)( ThreadId );
817
sewardj1e8cdc92002-04-18 11:37:52 +0000818/* And for the currently running one, if valid. */
819extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000820
sewardj1e8cdc92002-04-18 11:37:52 +0000821/* Similarly ... */
822extern ThreadId VG_(get_current_tid) ( void );
823
sewardjccef2e62002-05-29 19:26:32 +0000824/* Nuke all threads except tid. */
825extern void VG_(nuke_all_threads_except) ( ThreadId me );
826
sewardj2e93c502002-04-12 11:12:52 +0000827
828/* Return codes from the scheduler. */
829typedef
sewardj7e87e382002-05-03 19:09:05 +0000830 enum {
831 VgSrc_Deadlock, /* no runnable threads and no prospect of any
832 even if we wait for a long time */
833 VgSrc_ExitSyscall, /* client called exit(). This is the normal
834 route out. */
835 VgSrc_BbsDone /* In a debugging run, the specified number of
836 bbs has been completed. */
837 }
sewardj2e93c502002-04-12 11:12:52 +0000838 VgSchedReturnCode;
839
sewardj7e87e382002-05-03 19:09:05 +0000840
sewardj2e93c502002-04-12 11:12:52 +0000841/* The scheduler. */
842extern VgSchedReturnCode VG_(scheduler) ( void );
843
844extern void VG_(scheduler_init) ( void );
845
sewardj15a43e12002-04-17 19:35:12 +0000846extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000847
848/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
849extern jmp_buf VG_(scheduler_jmpbuf);
sewardj872051c2002-07-13 12:12:56 +0000850/* This says whether scheduler_jmpbuf is actually valid. Needed so
851 that our signal handler doesn't longjmp when the buffer isn't
852 actually valid. */
853extern Bool VG_(scheduler_jmpbuf_valid);
sewardj2e93c502002-04-12 11:12:52 +0000854/* ... and if so, here's the signal which caused it to do so. */
855extern Int VG_(longjmpd_on_signal);
856
857
sewardj2e93c502002-04-12 11:12:52 +0000858/* The red-zone size which we put at the bottom (highest address) of
859 thread stacks, for paranoia reasons. This can be arbitrary, and
860 doesn't really need to be set at compile time. */
861#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
862
863#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
864 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
865
njn25e49d8e72002-09-23 09:36:25 +0000866/* Junk to fill up a thread's shadow regs with when shadow regs aren't
867 * being used. */
868#define VG_UNUSED_SHADOW_REG_VALUE 0x27182818
869
870/* What we set a shadow register to when written by SET_EAX and similar
871 * things. */
872extern UInt VG_(written_shadow_reg);
sewardj2e93c502002-04-12 11:12:52 +0000873
sewardj018f7622002-05-15 21:13:39 +0000874/* Write a value to the client's %EDX (request return value register)
875 and set the shadow to indicate it is defined. */
njn25e49d8e72002-09-23 09:36:25 +0000876#define SET_EDX(zztid, zzval) \
877 do { VG_(threads)[zztid].m_edx = (zzval); \
878 VG_(threads)[zztid].sh_edx = VG_(written_shadow_reg); \
sewardj018f7622002-05-15 21:13:39 +0000879 } while (0)
880
njn25e49d8e72002-09-23 09:36:25 +0000881#define SET_EAX(zztid, zzval) \
882 do { VG_(threads)[zztid].m_eax = (zzval); \
883 VG_(threads)[zztid].sh_eax = VG_(written_shadow_reg); \
sewardj018f7622002-05-15 21:13:39 +0000884 } while (0)
885
sewardj2e93c502002-04-12 11:12:52 +0000886
sewardjd8acdf22002-11-13 21:57:52 +0000887/* This is or'd into a pthread mutex's __m_kind field if it is used
888 before Valgrind is up and running (prehistory). This is used so
889 that if some early code (like the dynamic linker) takes a lock
890 before Valgrind starts and then releases it afterwards, we can work
891 out what's happening. */
892#define VG_PTHREAD_PREHISTORY 0x80000000
893
sewardj2e93c502002-04-12 11:12:52 +0000894/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000895 Exports of vg_signals.c
896 ------------------------------------------------------------------ */
897
sewardjde4a1d02002-03-22 01:27:54 +0000898extern void VG_(sigstartup_actions) ( void );
899
sewardjb48e5002002-05-13 00:16:03 +0000900extern Bool VG_(deliver_signals) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000901extern void VG_(unblock_host_signal) ( Int sigNo );
sewardj018f7622002-05-15 21:13:39 +0000902extern void VG_(handle_SCSS_change) ( Bool force_update );
903
sewardjde4a1d02002-03-22 01:27:54 +0000904
905/* Fake system calls for signal handling. */
sewardj2342c972002-05-22 23:34:20 +0000906extern void VG_(do__NR_sigaltstack) ( ThreadId tid );
sewardj2e93c502002-04-12 11:12:52 +0000907extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardj018f7622002-05-15 21:13:39 +0000908extern void VG_(do__NR_sigprocmask) ( ThreadId tid,
909 Int how,
910 vki_ksigset_t* set,
911 vki_ksigset_t* oldset );
912extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid,
913 Int how,
914 vki_ksigset_t* set,
915 vki_ksigset_t* oldset );
916extern void VG_(send_signal_to_thread) ( ThreadId thread,
917 Int signo );
sewardjde4a1d02002-03-22 01:27:54 +0000918
sewardjefbfcdf2002-06-19 17:35:45 +0000919extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set );
920
921
sewardj2e93c502002-04-12 11:12:52 +0000922/* Modify the current thread's state once we have detected it is
923 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +0000924extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000925
sewardj2e93c502002-04-12 11:12:52 +0000926/* Handy utilities to block/restore all host signals. */
927extern void VG_(block_all_host_signals)
928 ( /* OUT */ vki_ksigset_t* saved_mask );
sewardj018f7622002-05-15 21:13:39 +0000929extern void VG_(restore_all_host_signals)
sewardj2e93c502002-04-12 11:12:52 +0000930 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000931
932/* ---------------------------------------------------------------------
933 Exports of vg_mylibc.c
934 ------------------------------------------------------------------ */
935
njne427a662002-10-02 11:08:25 +0000936#define vg_assert(expr) \
937 ((void) ((expr) ? 0 : \
938 (VG_(core_assert_fail) (VG__STRING(expr), \
939 __FILE__, __LINE__, \
940 __PRETTY_FUNCTION__), 0)))
941__attribute__ ((__noreturn__))
942extern void VG_(core_assert_fail) ( Char* expr, Char* file,
943 Int line, Char* fn );
944__attribute__ ((__noreturn__))
945extern void VG_(core_panic) ( Char* str );
sewardjde4a1d02002-03-22 01:27:54 +0000946
njn25e49d8e72002-09-23 09:36:25 +0000947/* VG_(brk) not public so skins cannot screw with curr_dataseg_end */
948extern void* VG_(brk) ( void* end_data_segment );
sewardjde4a1d02002-03-22 01:27:54 +0000949
njn25e49d8e72002-09-23 09:36:25 +0000950/* Skins use VG_(strdup)() which doesn't expose ArenaId */
951extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
sewardjde4a1d02002-03-22 01:27:54 +0000952
njn25e49d8e72002-09-23 09:36:25 +0000953/* Skins shouldn't need these...(?) */
sewardj5f07b662002-04-23 16:52:51 +0000954extern void VG_(start_rdtsc_calibration) ( void );
955extern void VG_(end_rdtsc_calibration) ( void );
956extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000957
njn25e49d8e72002-09-23 09:36:25 +0000958extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
sewardj2e93c502002-04-12 11:12:52 +0000959extern Int VG_(select)( Int n,
960 vki_fd_set* readfds,
961 vki_fd_set* writefds,
962 vki_fd_set* exceptfds,
963 struct vki_timeval * timeout );
964extern Int VG_(nanosleep)( const struct vki_timespec *req,
965 struct vki_timespec *rem );
966
sewardj570f8902002-11-03 11:44:36 +0000967extern Int VG_(write_socket)( Int sd, void *msg, Int count );
sewardj73cf3bc2002-11-03 03:20:15 +0000968
969/* --- Connecting over the network --- */
970extern Int VG_(connect_via_socket)( UChar* str );
971
sewardj570f8902002-11-03 11:44:36 +0000972
973/* ---------------------------------------------------------------------
974 Exports of vg_message.c
975 ------------------------------------------------------------------ */
976
977/* Low-level -- send bytes directly to the message sink. Do not
978 use. */
979extern void VG_(send_bytes_to_logging_sink) ( Char* msg, Int nbytes );
980
981
sewardjde4a1d02002-03-22 01:27:54 +0000982/* ---------------------------------------------------------------------
983 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
984 vg_from_ucode.c).
985 ------------------------------------------------------------------ */
986
sewardjde4a1d02002-03-22 01:27:54 +0000987#define VG_IS_FLAG_SUBSET(set1,set2) \
988 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
989
990#define VG_UNION_FLAG_SETS(set1,set2) \
991 ( ((FlagSet)set1) | ((FlagSet)set2) )
992
sewardjde4a1d02002-03-22 01:27:54 +0000993/* ---------------------------------------------------------------------
994 Exports of vg_demangle.c
995 ------------------------------------------------------------------ */
996
997extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
998
sewardjde4a1d02002-03-22 01:27:54 +0000999/* ---------------------------------------------------------------------
1000 Exports of vg_from_ucode.c
1001 ------------------------------------------------------------------ */
1002
sewardj22854b92002-11-30 14:00:47 +00001003extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes, UShort jumps[VG_MAX_JUMPS] );
sewardjde4a1d02002-03-22 01:27:54 +00001004
njn25e49d8e72002-09-23 09:36:25 +00001005extern void VG_(print_ccall_stats) ( void );
1006extern void VG_(print_UInstr_histogram) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001007
sewardj22854b92002-11-30 14:00:47 +00001008extern void VG_(unchain_jumpsite) ( Addr jumpsite );
1009extern Addr VG_(get_jmp_dest) ( Addr jumpsite );
1010extern Bool VG_(is_unchained_jumpsite) ( Addr jumpsite );
1011extern Bool VG_(is_chained_jumpsite) ( Addr jumpsite );
1012
sewardjde4a1d02002-03-22 01:27:54 +00001013/* ---------------------------------------------------------------------
1014 Exports of vg_to_ucode.c
1015 ------------------------------------------------------------------ */
1016
1017extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
sewardjde4a1d02002-03-22 01:27:54 +00001018
1019/* ---------------------------------------------------------------------
1020 Exports of vg_translate.c
1021 ------------------------------------------------------------------ */
1022
njn810086f2002-11-14 12:42:47 +00001023/* Expandable arrays of uinstrs. */
1024struct _UCodeBlock {
sewardj22854b92002-11-30 14:00:47 +00001025 Addr orig_eip;
njn810086f2002-11-14 12:42:47 +00001026 Int used;
1027 Int size;
1028 UInstr* instrs;
1029 Int nextTemp;
1030};
1031
1032extern UCodeBlock* VG_(alloc_UCodeBlock) ( void );
1033
sewardj1e8cdc92002-04-18 11:37:52 +00001034extern void VG_(translate) ( ThreadState* tst,
1035 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001036 UInt* orig_size,
1037 Addr* trans_addr,
sewardj22854b92002-11-30 14:00:47 +00001038 UInt* trans_size,
1039 UShort jumps[VG_MAX_JUMPS]);
sewardjde4a1d02002-03-22 01:27:54 +00001040
njn25e49d8e72002-09-23 09:36:25 +00001041extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness,
1042 UInstr* u );
1043extern void VG_(saneUCodeBlock) ( UCodeBlock* cb );
1044extern Bool VG_(saneUCodeBlockCalls) ( UCodeBlock* cb );
sewardjde4a1d02002-03-22 01:27:54 +00001045
sewardjb5ff83e2002-12-01 19:40:49 +00001046
sewardjde4a1d02002-03-22 01:27:54 +00001047/* ---------------------------------------------------------------------
1048 Exports of vg_execontext.c.
1049 ------------------------------------------------------------------ */
1050
1051/* Records the PC and a bit of the call chain. The first 4 %eip
1052 values are used in comparisons do remove duplicate errors, and for
1053 comparing against suppression specifications. The rest are purely
1054 informational (but often important). */
1055
njn25e49d8e72002-09-23 09:36:25 +00001056struct _ExeContext {
1057 struct _ExeContext * next;
1058 /* Variable-length array. The size is VG_(clo_backtrace_size); at
1059 least 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1060 [1] is its caller, [2] is the caller of [1], etc. */
1061 Addr eips[0];
1062};
sewardjde4a1d02002-03-22 01:27:54 +00001063
1064
1065/* Initialise the ExeContext storage mechanism. */
1066extern void VG_(init_ExeContext_storage) ( void );
1067
1068/* Print stats (informational only). */
1069extern void VG_(show_ExeContext_stats) ( void );
1070
njn25e49d8e72002-09-23 09:36:25 +00001071/* Like VG_(get_ExeContext), but with a slightly different type */
1072extern ExeContext* VG_(get_ExeContext2) ( Addr eip, Addr ebp,
1073 Addr ebp_min, Addr ebp_max );
sewardjde4a1d02002-03-22 01:27:54 +00001074
1075
1076/* ---------------------------------------------------------------------
1077 Exports of vg_errcontext.c.
1078 ------------------------------------------------------------------ */
1079
njn25e49d8e72002-09-23 09:36:25 +00001080/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1081 * effectively extend it by defining their own enums in the (0..) range. */
sewardjde4a1d02002-03-22 01:27:54 +00001082typedef
njn25e49d8e72002-09-23 09:36:25 +00001083 enum {
1084 PThreadSupp = -1, /* Matches PThreadErr */
sewardjde4a1d02002-03-22 01:27:54 +00001085 }
njn25e49d8e72002-09-23 09:36:25 +00001086 CoreSuppKind;
1087
1088/* For each caller specified for a suppression, record the nature of
1089 the caller name. Not of interest to skins. */
1090typedef
1091 enum {
1092 ObjName, /* Name is of an shared object file. */
1093 FunName /* Name is of a function. */
1094 }
1095 SuppLocTy;
1096
njn810086f2002-11-14 12:42:47 +00001097/* Suppressions. Skins can get/set skin-relevant parts with functions
1098 declared in include/vg_skin.h. Extensible via the 'extra' field.
1099 Skins can use a normal enum (with element values in the normal range
1100 (0..)) for `skind'. */
1101struct _Supp {
1102 struct _Supp* next;
1103 /* The number of times this error has been suppressed. */
1104 Int count;
1105 /* The name by which the suppression is referred to. */
1106 Char* sname;
1107 /* First two (name of fn where err occurs, and immediate caller)
1108 * are mandatory; extra two are optional. */
1109 SuppLocTy caller_ty[VG_N_SUPP_CALLERS];
1110 Char* caller [VG_N_SUPP_CALLERS];
1111
1112 /* The skin-specific part */
1113 /* What kind of suppression. Must use the range (0..) */
1114 SuppKind skind;
1115 /* String -- use is optional. NULL by default. */
1116 Char* string;
1117 /* Anything else -- use is optional. NULL by default. */
1118 void* extra;
1119};
njn25e49d8e72002-09-23 09:36:25 +00001120
1121/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1122 * effectively extend it by defining their own enums in the (0..) range. */
1123typedef
1124 enum {
1125 PThreadErr = -1, /* Pthreading error */
1126 }
1127 CoreErrorKind;
1128
njn810086f2002-11-14 12:42:47 +00001129/* Errors. Extensible (via the 'extra' field). Skins can use a normal
1130 enum (with element values in the normal range (0..)) for `ekind'.
1131 Functions for getting/setting the skin-relevant fields are in
1132 include/vg_skin.h.
1133
1134 When errors are found and recorded with VG_(maybe_record_error)(), all
1135 the skin must do is pass in the four parameters; core will
1136 allocate/initialise the error record.
1137*/
1138struct _Error {
1139 struct _Error* next;
1140 /* NULL if unsuppressed; or ptr to suppression record. */
1141 Supp* supp;
1142 Int count;
njn810086f2002-11-14 12:42:47 +00001143 ThreadId tid;
njn810086f2002-11-14 12:42:47 +00001144
1145 /* The skin-specific part */
njnae17bec2003-01-28 19:59:38 +00001146 /* Initialised by core */
1147 ExeContext* where;
njn810086f2002-11-14 12:42:47 +00001148 /* Used by ALL. Must be in the range (0..) */
1149 Int ekind;
1150 /* Used frequently */
1151 Addr addr;
1152 /* Used frequently */
1153 Char* string;
1154 /* For any skin-specific extras */
1155 void* extra;
1156};
sewardjde4a1d02002-03-22 01:27:54 +00001157
1158
njn25e49d8e72002-09-23 09:36:25 +00001159extern void VG_(load_suppressions) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001160
njn25e49d8e72002-09-23 09:36:25 +00001161extern void VG_(record_pthread_error) ( ThreadId tid, Char* msg );
sewardjde4a1d02002-03-22 01:27:54 +00001162
njn25e49d8e72002-09-23 09:36:25 +00001163extern void VG_(show_all_errors) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001164
sewardj99aac972002-12-26 01:53:45 +00001165/* Get hold of the suppression list ... just so we don't have to
1166 make it global. */
1167extern Supp* VG_(get_suppressions) ( void );
1168
njn43c799e2003-04-08 00:08:52 +00001169extern Bool VG_(is_action_requested) ( Char* action, Bool* clo );
1170
1171extern void VG_(gen_suppression) ( Error* err );
sewardj99aac972002-12-26 01:53:45 +00001172
sewardjde4a1d02002-03-22 01:27:54 +00001173/* ---------------------------------------------------------------------
1174 Exports of vg_procselfmaps.c
1175 ------------------------------------------------------------------ */
1176
njn3e884182003-04-15 13:03:23 +00001177/* Reads /proc/self/maps into a static buffer. */
1178void VG_(read_procselfmaps_contents) ( void );
1179
1180/* Parses /proc/self/maps, calling `record_mapping' for each entry. If
1181 `read_from_file' is True, /proc/self/maps is read directly, otherwise
1182 it's read from the buffer filled by VG_(read_procselfmaps_contents)(). */
sewardjde4a1d02002-03-22 01:27:54 +00001183extern
1184void VG_(read_procselfmaps) (
njn3e884182003-04-15 13:03:23 +00001185 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* ),
1186 Bool read_from_file
sewardjde4a1d02002-03-22 01:27:54 +00001187);
1188
1189
1190/* ---------------------------------------------------------------------
1191 Exports of vg_symtab2.c
1192 ------------------------------------------------------------------ */
1193
njn25e49d8e72002-09-23 09:36:25 +00001194extern void VG_(maybe_read_symbols) ( void );
1195extern void VG_(read_symtab_callback) ( Addr start, UInt size,
1196 Char rr, Char ww, Char xx,
1197 UInt foffset, UChar* filename );
1198extern void VG_(maybe_unload_symbols) ( Addr start, UInt length );
sewardjde4a1d02002-03-22 01:27:54 +00001199
njn25e49d8e72002-09-23 09:36:25 +00001200extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname );
1201extern void VG_(mini_stack_dump) ( ExeContext* ec );
sewardjde4a1d02002-03-22 01:27:54 +00001202
1203
1204/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001205 Exports of vg_main.c
1206 ------------------------------------------------------------------ */
1207
sewardj73cf3bc2002-11-03 03:20:15 +00001208/* Tell the logging mechanism whether we are logging to a file
1209 descriptor or a socket descriptor. */
1210extern Bool VG_(logging_to_filedes);
1211
njn25e49d8e72002-09-23 09:36:25 +00001212/* Sanity checks which may be done at any time. The scheduler decides when. */
1213extern void VG_(do_sanity_checks) ( Bool force_expensive );
1214
sewardjde4a1d02002-03-22 01:27:54 +00001215/* A structure used as an intermediary when passing the simulated
1216 CPU's state to some assembly fragments, particularly system calls.
1217 Stuff is copied from baseBlock to here, the assembly magic runs,
njn25e49d8e72002-09-23 09:36:25 +00001218 and then the inverse copy is done.
1219 */
sewardj92a59562002-09-30 00:53:10 +00001220extern UInt VG_(m_state_static) [6 /* segment regs, Intel order */
1221 + 8 /* int regs, in Intel order */
sewardjde4a1d02002-03-22 01:27:54 +00001222 + 1 /* %eflags */
1223 + 1 /* %eip */
1224 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1225 ];
1226
1227/* Handy fns for doing the copy back and forth. */
1228extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1229extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1230
njn9b007f62003-04-07 14:40:25 +00001231/* Determine if %esp adjustment must be noted */
njnf4ce3d32003-02-10 10:17:26 +00001232extern Bool VG_(need_to_handle_esp_assignment) ( void );
1233
sewardjde4a1d02002-03-22 01:27:54 +00001234/* Called when some unhandleable client behaviour is detected.
1235 Prints a msg and aborts. */
njn25e49d8e72002-09-23 09:36:25 +00001236extern void VG_(unimplemented) ( Char* msg )
1237 __attribute__((__noreturn__));
sewardjde4a1d02002-03-22 01:27:54 +00001238
1239/* The stack on which Valgrind runs. We can't use the same stack as the
1240 simulatee -- that's an important design decision. */
1241extern UInt VG_(stack)[10000];
1242
njn25e49d8e72002-09-23 09:36:25 +00001243/* Similarly, we have to ask for signals to be delivered on an alternative
1244 stack, since it is possible, although unlikely, that we'll have to run
1245 client code from inside the Valgrind-installed signal handler. If this
1246 happens it will be done by vg_deliver_signal_immediately(). */
sewardjde4a1d02002-03-22 01:27:54 +00001247extern UInt VG_(sigstack)[10000];
1248
sewardjde4a1d02002-03-22 01:27:54 +00001249/* Holds client's %esp at the point we gained control. From this the
1250 client's argc, argv and envp are deduced. */
1251extern Addr VG_(esp_at_startup);
sewardjde4a1d02002-03-22 01:27:54 +00001252
sewardjd5815ec2003-04-06 12:23:27 +00001253/* Indicates presence, and holds address of client's sysinfo page, a
1254 feature of some modern kernels used to provide vsyscalls, etc. */
1255extern Bool VG_(sysinfo_page_exists);
1256extern Addr VG_(sysinfo_page_addr);
1257
njn25e49d8e72002-09-23 09:36:25 +00001258/* Remove valgrind.so and skin's .so from a LD_PRELOAD=... string so child
1259 processes don't get traced into. Also mess up $libdir/valgrind so that
1260 our libpthread.so disappears from view. */
sewardj3e1eb1f2002-05-18 13:14:17 +00001261void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str,
1262 Char* ld_library_path_str );
sewardjde4a1d02002-03-22 01:27:54 +00001263
1264/* Something of a function looking for a home ... start up GDB. This
1265 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1266 *client's* stack. This is necessary to give GDB the illusion that
1267 the client program really was running on the real cpu. */
1268extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1269
njn41557122002-10-14 09:25:37 +00001270/* VG_(bbs_done) in include/vg_skin.h */
1271
sewardjde4a1d02002-03-22 01:27:54 +00001272/* 64-bit counter for the number of bbs to go before a debug exit. */
1273extern ULong VG_(bbs_to_go);
1274
1275/* Counts downwards in vg_run_innerloop. */
1276extern UInt VG_(dispatch_ctr);
1277
sewardjde4a1d02002-03-22 01:27:54 +00001278/* Is the client running on the simulated CPU or the real one? */
1279extern Bool VG_(running_on_simd_CPU); /* Initially False */
1280
sewardj7e87e382002-05-03 19:09:05 +00001281/* This is the ThreadId of the last thread the scheduler ran. */
1282extern ThreadId VG_(last_run_tid);
1283
njn25e49d8e72002-09-23 09:36:25 +00001284/* This is the argument to __NR_exit() supplied by the first thread to
1285 call that syscall. We eventually pass that to __NR_exit() for
1286 real. */
1287extern UInt VG_(exitcode);
1288
sewardjde4a1d02002-03-22 01:27:54 +00001289
1290/* --- Counters, for informational purposes only. --- */
1291
1292/* Number of lookups which miss the fast tt helper. */
1293extern UInt VG_(tt_fast_misses);
1294
sewardjc0d8f682002-11-30 00:49:43 +00001295/* Counts for TT/TC informational messages. */
sewardjde4a1d02002-03-22 01:27:54 +00001296
sewardjde4a1d02002-03-22 01:27:54 +00001297/* Number and total o/t size of translations overall. */
1298extern UInt VG_(overall_in_count);
1299extern UInt VG_(overall_in_osize);
1300extern UInt VG_(overall_in_tsize);
1301/* Number and total o/t size of discards overall. */
1302extern UInt VG_(overall_out_count);
1303extern UInt VG_(overall_out_osize);
1304extern UInt VG_(overall_out_tsize);
sewardjc0d8f682002-11-30 00:49:43 +00001305/* The number of discards of TT/TC. */
1306extern UInt VG_(number_of_tc_discards);
sewardj22854b92002-11-30 14:00:47 +00001307/* Counts of chain and unchain operations done. */
1308extern UInt VG_(bb_enchain_count);
1309extern UInt VG_(bb_dechain_count);
1310/* Number of unchained jumps performed. */
1311extern UInt VG_(unchained_jumps_done);
1312
sewardjde4a1d02002-03-22 01:27:54 +00001313
1314/* Counts pertaining to the register allocator. */
1315
1316/* total number of uinstrs input to reg-alloc */
1317extern UInt VG_(uinstrs_prealloc);
1318
1319/* total number of uinstrs added due to spill code */
1320extern UInt VG_(uinstrs_spill);
1321
1322/* number of bbs requiring spill code */
1323extern UInt VG_(translations_needing_spill);
1324
1325/* total of register ranks over all translations */
1326extern UInt VG_(total_reg_rank);
1327
sewardjde4a1d02002-03-22 01:27:54 +00001328/* Counts pertaining to internal sanity checking. */
1329extern UInt VG_(sanity_fast_count);
1330extern UInt VG_(sanity_slow_count);
1331
sewardj2e93c502002-04-12 11:12:52 +00001332/* Counts pertaining to the scheduler. */
1333extern UInt VG_(num_scheduling_events_MINOR);
1334extern UInt VG_(num_scheduling_events_MAJOR);
1335
sewardjfa492d42002-12-08 18:20:01 +00001336/* Insert and extract the D flag from eflags */
1337UInt VG_(insertDflag)(UInt eflags, Int d);
1338Int VG_(extractDflag)(UInt eflags);
sewardjde4a1d02002-03-22 01:27:54 +00001339
1340/* ---------------------------------------------------------------------
1341 Exports of vg_memory.c
1342 ------------------------------------------------------------------ */
1343
njn25e49d8e72002-09-23 09:36:25 +00001344extern void VG_(init_memory) ( void );
1345extern void VG_(new_exe_segment) ( Addr a, UInt len );
1346extern void VG_(remove_if_exe_segment) ( Addr a, UInt len );
sewardjde4a1d02002-03-22 01:27:54 +00001347
njn9b007f62003-04-07 14:40:25 +00001348extern __attribute__((regparm(1)))
1349 void VG_(unknown_esp_update) ( Addr new_ESP );
sewardjde4a1d02002-03-22 01:27:54 +00001350
sewardjde4a1d02002-03-22 01:27:54 +00001351/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001352 Exports of vg_syscalls.c
sewardjde4a1d02002-03-22 01:27:54 +00001353 ------------------------------------------------------------------ */
1354
njn25e49d8e72002-09-23 09:36:25 +00001355extern void VG_(init_dataseg_end_for_brk) ( void );
1356
sewardj2e93c502002-04-12 11:12:52 +00001357extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001358
njn25e49d8e72002-09-23 09:36:25 +00001359extern void* VG_(pre_known_blocking_syscall) ( ThreadId tid, Int syscallno );
1360extern void VG_(post_known_blocking_syscall)( ThreadId tid, Int syscallno,
1361 void* pre_res, Int res );
sewardjde4a1d02002-03-22 01:27:54 +00001362
1363extern Bool VG_(is_kerror) ( Int res );
1364
njn25e49d8e72002-09-23 09:36:25 +00001365#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1366 VG_(load_thread_state)(thread_id); \
1367 VG_(copy_baseBlock_to_m_state_static)(); \
1368 VG_(do_syscall)(); \
1369 VG_(copy_m_state_static_to_baseBlock)(); \
1370 VG_(save_thread_state)(thread_id); \
1371 VG_(threads)[thread_id].sh_eax = VG_(written_shadow_reg);\
sewardj018f7622002-05-15 21:13:39 +00001372 result_lvalue = VG_(threads)[thread_id].m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001373
1374
1375/* ---------------------------------------------------------------------
1376 Exports of vg_transtab.c
1377 ------------------------------------------------------------------ */
1378
njn25e49d8e72002-09-23 09:36:25 +00001379/* The fast-cache for tt-lookup. */
1380extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE];
1381
sewardjde4a1d02002-03-22 01:27:54 +00001382extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
sewardj6c3769f2002-11-29 01:02:45 +00001383
sewardjc0d8f682002-11-30 00:49:43 +00001384extern void VG_(add_to_trans_tab) ( Addr orig_addr, Int orig_size,
sewardj22854b92002-11-30 14:00:47 +00001385 Addr trans_addr, Int trans_size,
1386 UShort jumps[VG_MAX_JUMPS]);
sewardj6c3769f2002-11-29 01:02:45 +00001387
sewardj18d75132002-05-16 11:06:21 +00001388extern void VG_(invalidate_translations) ( Addr start, UInt range );
sewardjde4a1d02002-03-22 01:27:54 +00001389
sewardj18d75132002-05-16 11:06:21 +00001390extern void VG_(init_tt_tc) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001391
1392extern void VG_(sanity_check_tc_tt) ( void );
1393extern Addr VG_(search_transtab) ( Addr original_addr );
1394
sewardjde4a1d02002-03-22 01:27:54 +00001395
1396
1397/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001398 Exports of vg_syscall.S
1399 ------------------------------------------------------------------ */
1400
1401extern void VG_(do_syscall) ( void );
1402
1403
1404/* ---------------------------------------------------------------------
1405 Exports of vg_startup.S
1406 ------------------------------------------------------------------ */
1407
sewardjde4a1d02002-03-22 01:27:54 +00001408extern void VG_(switch_to_real_CPU) ( void );
1409
sewardj35805422002-04-21 13:05:34 +00001410extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1411 Addr m_esp_at_error,
1412 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001413
1414
1415/* ---------------------------------------------------------------------
1416 Exports of vg_dispatch.S
1417 ------------------------------------------------------------------ */
1418
sewardj2e93c502002-04-12 11:12:52 +00001419/* Run a thread for a (very short) while, until some event happens
1420 which means we need to defer to the scheduler. */
1421extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001422
sewardj22854b92002-11-30 14:00:47 +00001423/* The patching routing called when a BB wants to chain itself to
1424 another. */
1425extern UInt VG_(patch_me);
sewardjde4a1d02002-03-22 01:27:54 +00001426
1427/* ---------------------------------------------------------------------
1428 Exports of vg_helpers.S
1429 ------------------------------------------------------------------ */
1430
sewardjde4a1d02002-03-22 01:27:54 +00001431/* Mul, div, etc, -- we don't codegen these directly. */
1432extern void VG_(helper_idiv_64_32);
1433extern void VG_(helper_div_64_32);
1434extern void VG_(helper_idiv_32_16);
1435extern void VG_(helper_div_32_16);
1436extern void VG_(helper_idiv_16_8);
1437extern void VG_(helper_div_16_8);
1438
1439extern void VG_(helper_imul_32_64);
1440extern void VG_(helper_mul_32_64);
1441extern void VG_(helper_imul_16_32);
1442extern void VG_(helper_mul_16_32);
1443extern void VG_(helper_imul_8_16);
1444extern void VG_(helper_mul_8_16);
1445
1446extern void VG_(helper_CLD);
1447extern void VG_(helper_STD);
1448extern void VG_(helper_get_dirflag);
1449
sewardj7d78e782002-06-02 00:04:00 +00001450extern void VG_(helper_CLC);
1451extern void VG_(helper_STC);
1452
sewardjde4a1d02002-03-22 01:27:54 +00001453extern void VG_(helper_shldl);
1454extern void VG_(helper_shldw);
1455extern void VG_(helper_shrdl);
1456extern void VG_(helper_shrdw);
1457
1458extern void VG_(helper_RDTSC);
1459extern void VG_(helper_CPUID);
1460
sewardjde4a1d02002-03-22 01:27:54 +00001461extern void VG_(helper_bsf);
1462extern void VG_(helper_bsr);
1463
1464extern void VG_(helper_fstsw_AX);
1465extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001466extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001467extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001468
sewardj51096432002-12-14 23:59:09 +00001469extern void VG_(helper_undefined_instruction);
1470
sewardj20917d82002-05-28 01:36:45 +00001471/* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001472extern void VG_(signalreturn_bogusRA)( void );
sewardj20917d82002-05-28 01:36:45 +00001473
njn4f9c9342002-04-29 16:03:24 +00001474/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001475 Things relating to the used skin
njn4f9c9342002-04-29 16:03:24 +00001476 ------------------------------------------------------------------ */
1477
njn25e49d8e72002-09-23 09:36:25 +00001478#define VG_TRACK(fn, args...) \
1479 do { \
1480 if (VG_(track_events).fn) \
1481 VG_(track_events).fn(args); \
1482 } while (0)
sewardj18d75132002-05-16 11:06:21 +00001483
1484
sewardjde4a1d02002-03-22 01:27:54 +00001485/* ---------------------------------------------------------------------
1486 The state of the simulated CPU.
1487 ------------------------------------------------------------------ */
1488
sewardjde4a1d02002-03-22 01:27:54 +00001489/* ---------------------------------------------------------------------
1490 Offsets into baseBlock for everything which needs to referred to
1491 from generated code. The order of these decls does not imply
1492 what the order of the actual offsets is. The latter is important
1493 and is set up in vg_main.c.
1494 ------------------------------------------------------------------ */
1495
1496/* An array of words. In generated code, %ebp always points to the
1497 start of this array. Useful stuff, like the simulated CPU state,
1498 and the addresses of helper functions, can then be found by
1499 indexing off %ebp. The following declares variables which, at
1500 startup time, are given values denoting offsets into baseBlock.
1501 These offsets are in *words* from the start of baseBlock. */
1502
1503#define VG_BASEBLOCK_WORDS 200
1504
1505extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1506
1507
1508/* -----------------------------------------------------
1509 Read-write parts of baseBlock.
1510 -------------------------------------------------- */
1511
1512/* State of the simulated CPU. */
1513extern Int VGOFF_(m_eax);
1514extern Int VGOFF_(m_ecx);
1515extern Int VGOFF_(m_edx);
1516extern Int VGOFF_(m_ebx);
1517extern Int VGOFF_(m_esp);
1518extern Int VGOFF_(m_ebp);
1519extern Int VGOFF_(m_esi);
1520extern Int VGOFF_(m_edi);
1521extern Int VGOFF_(m_eflags);
1522extern Int VGOFF_(m_fpustate);
1523extern Int VGOFF_(m_eip);
1524
sewardjfa492d42002-12-08 18:20:01 +00001525extern Int VGOFF_(m_dflag); /* D flag is handled specially */
1526
sewardj92a59562002-09-30 00:53:10 +00001527extern Int VGOFF_(m_cs);
1528extern Int VGOFF_(m_ss);
1529extern Int VGOFF_(m_ds);
1530extern Int VGOFF_(m_es);
1531extern Int VGOFF_(m_fs);
1532extern Int VGOFF_(m_gs);
1533
sewardjde4a1d02002-03-22 01:27:54 +00001534/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1535extern Int VGOFF_(spillslots);
1536
1537/* Records the valid bits for the 8 integer regs & flags reg. */
1538extern Int VGOFF_(sh_eax);
1539extern Int VGOFF_(sh_ecx);
1540extern Int VGOFF_(sh_edx);
1541extern Int VGOFF_(sh_ebx);
1542extern Int VGOFF_(sh_esp);
1543extern Int VGOFF_(sh_ebp);
1544extern Int VGOFF_(sh_esi);
1545extern Int VGOFF_(sh_edi);
1546extern Int VGOFF_(sh_eflags);
1547
sewardjde4a1d02002-03-22 01:27:54 +00001548/* -----------------------------------------------------
1549 Read-only parts of baseBlock.
1550 -------------------------------------------------- */
1551
sewardj92a59562002-09-30 00:53:10 +00001552/* This thread's LDT pointer. */
1553extern Int VGOFF_(ldt);
1554
njn211b6ad2003-02-03 12:33:31 +00001555/* Nb: Most helper offsets are in include/vg_skin.h, for use by skins */
sewardjde4a1d02002-03-22 01:27:54 +00001556
sewardj51096432002-12-14 23:59:09 +00001557extern Int VGOFF_(helper_undefined_instruction);
1558
njn25e49d8e72002-09-23 09:36:25 +00001559/* For storing extension-specific helpers, determined at runtime. The addr
1560 * and offset arrays together form a (addr, offset) map that allows a
1561 * helper's baseBlock offset to be computed from its address. It's done
1562 * like this so CCALL_M_Ns and other helper calls can use the function
1563 * address rather than having to much around with offsets. */
1564extern UInt VG_(n_compact_helpers);
1565extern UInt VG_(n_noncompact_helpers);
1566
1567extern Addr VG_(compact_helper_addrs) [];
1568extern Int VG_(compact_helper_offsets)[];
1569
1570extern Addr VG_(noncompact_helper_addrs) [];
1571extern Int VG_(noncompact_helper_offsets)[];
1572
sewardjf220ccc2002-10-23 21:53:49 +00001573#define VGL_(x) vgIntercept_##x
sewardjde4a1d02002-03-22 01:27:54 +00001574
1575#endif /* ndef __VG_INCLUDE_H */
1576
sewardj3b2736a2002-03-24 12:18:35 +00001577
1578/* ---------------------------------------------------------------------
1579 Finally - autoconf-generated settings
1580 ------------------------------------------------------------------ */
1581
1582#include "config.h"
1583
sewardjde4a1d02002-03-22 01:27:54 +00001584/*--------------------------------------------------------------------*/
1585/*--- end vg_include.h ---*/
1586/*--------------------------------------------------------------------*/