blob: 2793b9ada3a49d39965ca238cd534fb11b2d4d8a [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
sewardj73cf3bc2002-11-03 03:20:15 +0000154/* Default socket to be used in logging over a network, if none
155 specified. */
156#define VG_CLO_DEFAULT_LOGSOCKET 1500
157
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);
174/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
175extern Int VG_(sanity_level);
sewardjde4a1d02002-03-22 01:27:54 +0000176/* Automatically attempt to demangle C++ names? default: YES */
177extern Bool VG_(clo_demangle);
sewardjde4a1d02002-03-22 01:27:54 +0000178/* Round malloc sizes upwards to integral number of words? default:
179 NO */
180extern Bool VG_(clo_sloppy_malloc);
sewardj246d4662002-06-14 10:17:05 +0000181/* Minimum alignment in functions that don't specify alignment explicitly.
182 default: 0, i.e. use default of the machine (== 4) */
183extern Int VG_(clo_alignment);
sewardjde4a1d02002-03-22 01:27:54 +0000184/* Simulate child processes? default: NO */
185extern Bool VG_(clo_trace_children);
sewardj4cf05692002-10-27 20:28:29 +0000186
187/* Where logging output is to be sent to.
188
189 When log_to == VgLogTo_Fd, clo_logfile_fd holds the file id, and is
190 taken from the command line. clo_logfile_name is irrelevant.
191
192 When log_to == VgLogTo_File, clo_logfile_name holds the logfile
193 name, and is taken from the command line. clo_logfile_fd is then
194 made to hold the relevant file id, by opening clo_logfile_name
195 (concatenated with the process ID) for writing.
196
197 When log_to == VgLogTo_Socket, clo_logfile_name holds the
198 hostname:portnumber pair, and is taken from the command line.
199 clo_logfile_fd is then made to hold the relevant file handle, by
200 opening a connection to said hostname:portnumber pair.
201
202 Global default is to set log_to == VgLogTo_Fd and logfile_fd == 2
203 (stderr). */
204extern VgLogTo VG_(clo_log_to);
205extern Int VG_(clo_logfile_fd);
206extern Char* VG_(clo_logfile_name);
sewardjde4a1d02002-03-22 01:27:54 +0000207
208/* The number of suppression files specified. */
209extern Int VG_(clo_n_suppressions);
210/* The names of the suppression files. */
211extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
212
213/* Single stepping? default: NO */
214extern Bool VG_(clo_single_step);
215/* Code improvement? default: YES */
216extern Bool VG_(clo_optimise);
njn25e49d8e72002-09-23 09:36:25 +0000217/* DEBUG: print generated code? default: 00000 ( == NO ) */
218extern Bool VG_(clo_trace_codegen);
sewardjde4a1d02002-03-22 01:27:54 +0000219/* DEBUG: print system calls? default: NO */
220extern Bool VG_(clo_trace_syscalls);
221/* DEBUG: print signal details? default: NO */
222extern Bool VG_(clo_trace_signals);
223/* DEBUG: print symtab details? default: NO */
224extern Bool VG_(clo_trace_symtab);
225/* DEBUG: print malloc details? default: NO */
226extern Bool VG_(clo_trace_malloc);
sewardj8937c812002-04-12 20:12:20 +0000227/* DEBUG: print thread scheduling events? default: NO */
228extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000229/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
230 (some), 2 (all) */
231extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000232/* Stop after this many basic blocks. default: Infinity. */
233extern ULong VG_(clo_stop_after);
234/* Display gory details for the k'th most popular error. default:
235 Infinity. */
236extern Int VG_(clo_dump_error);
237/* Number of parents of a backtrace. Default: 8. */
238extern Int VG_(clo_backtrace_size);
sewardj3984b852002-05-12 03:00:17 +0000239/* Engage miscellaneous wierd hacks needed for some progs. */
sewardj8d365b52002-05-12 10:52:16 +0000240extern Char* VG_(clo_weird_hacks);
sewardj858964b2002-10-05 14:15:43 +0000241/* Should we run __libc_freeres at exit? Sometimes causes crashes.
242 Default: YES. Note this is subservient to VG_(needs).libc_freeres;
243 if the latter says False, then the setting of VG_(clo_weird_hacks)
244 is ignored. Ie if a skin says no, I don't want this to run, that
245 cannot be overridden from the command line. */
246extern Bool VG_(clo_run_libc_freeres);
sewardjde4a1d02002-03-22 01:27:54 +0000247
248
249/* ---------------------------------------------------------------------
250 Debugging and profiling stuff
251 ------------------------------------------------------------------ */
252
njn25e49d8e72002-09-23 09:36:25 +0000253/* Change to 1 to get more accurate but more expensive core profiling. */
254#if 0
255# define VGP_ACCURATE_PROFILING
256#endif
257
sewardjde4a1d02002-03-22 01:27:54 +0000258/* Create a logfile into which messages can be dumped. */
259extern void VG_(startup_logging) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000260extern void VG_(shutdown_logging)( void );
sewardjde4a1d02002-03-22 01:27:54 +0000261
262extern void VGP_(init_profiling) ( void );
263extern void VGP_(done_profiling) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000264
njn25e49d8e72002-09-23 09:36:25 +0000265#undef VGP_PUSHCC
266#undef VGP_POPCC
267#define VGP_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x)
268#define VGP_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x)
sewardjde4a1d02002-03-22 01:27:54 +0000269
njn25e49d8e72002-09-23 09:36:25 +0000270/* Use this for ones that happen a lot and thus we don't want to put in
271 all the time, eg. for %esp assignment. */
272#ifdef VGP_ACCURATE_PROFILING
273# define VGP_MAYBE_PUSHCC(x) if (VG_(clo_profile)) VGP_(pushcc)(x)
274# define VGP_MAYBE_POPCC(x) if (VG_(clo_profile)) VGP_(popcc)(x)
sewardjde4a1d02002-03-22 01:27:54 +0000275#else
njn25e49d8e72002-09-23 09:36:25 +0000276# define VGP_MAYBE_PUSHCC(x)
277# define VGP_MAYBE_POPCC(x)
278#endif
sewardjde4a1d02002-03-22 01:27:54 +0000279
280
281/* ---------------------------------------------------------------------
282 Exports of vg_malloc2.c
283 ------------------------------------------------------------------ */
284
285/* Allocation arenas.
njn25e49d8e72002-09-23 09:36:25 +0000286 CORE is for the core's general use.
287 SKIN is for the skin to use (and the only one it uses).
sewardjde4a1d02002-03-22 01:27:54 +0000288 SYMTAB is for Valgrind's symbol table storage.
njn25e49d8e72002-09-23 09:36:25 +0000289 JITTER is for small storage during translation.
sewardjde4a1d02002-03-22 01:27:54 +0000290 CLIENT is for the client's mallocs/frees.
291 DEMANGLE is for the C++ demangler.
292 EXECTXT is for storing ExeContexts.
njn25e49d8e72002-09-23 09:36:25 +0000293 ERRORS is for storing CoreErrors.
sewardjde4a1d02002-03-22 01:27:54 +0000294 TRANSIENT is for very short-term use. It should be empty
295 in between uses.
njn25e49d8e72002-09-23 09:36:25 +0000296 When adding a new arena, remember also to add it to ensure_mm_init().
sewardjde4a1d02002-03-22 01:27:54 +0000297*/
298typedef Int ArenaId;
299
njn25e49d8e72002-09-23 09:36:25 +0000300#define VG_N_ARENAS 9
sewardjde4a1d02002-03-22 01:27:54 +0000301
njn25e49d8e72002-09-23 09:36:25 +0000302#define VG_AR_CORE 0 /* :: ArenaId */
303#define VG_AR_SKIN 1 /* :: ArenaId */
304#define VG_AR_SYMTAB 2 /* :: ArenaId */
305#define VG_AR_JITTER 3 /* :: ArenaId */
306#define VG_AR_CLIENT 4 /* :: ArenaId */
307#define VG_AR_DEMANGLE 5 /* :: ArenaId */
308#define VG_AR_EXECTXT 6 /* :: ArenaId */
309#define VG_AR_ERRORS 7 /* :: ArenaId */
310#define VG_AR_TRANSIENT 8 /* :: ArenaId */
sewardjde4a1d02002-03-22 01:27:54 +0000311
njn25e49d8e72002-09-23 09:36:25 +0000312extern void* VG_(arena_malloc) ( ArenaId arena, Int nbytes );
313extern void VG_(arena_free) ( ArenaId arena, void* ptr );
314extern void* VG_(arena_calloc) ( ArenaId arena, Int nmemb, Int nbytes );
315extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment,
316 Int size );
317extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB,
sewardjde4a1d02002-03-22 01:27:54 +0000318 Int req_pszB );
319
sewardjde4a1d02002-03-22 01:27:54 +0000320extern void VG_(mallocSanityCheckAll) ( void );
321
322extern void VG_(show_all_arena_stats) ( void );
323extern Bool VG_(is_empty_arena) ( ArenaId aid );
324
325
326/* The red-zone size for the client. This can be arbitrary, but
327 unfortunately must be set at compile time. */
328#define VG_AR_CLIENT_REDZONE_SZW 4
329
330#define VG_AR_CLIENT_REDZONE_SZB \
331 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
332
333
334/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +0000335 Exports of vg_clientfuncs.c
sewardj2e93c502002-04-12 11:12:52 +0000336 ------------------------------------------------------------------ */
337
338/* This doesn't export code or data that valgrind.so needs to link
339 against. However, the scheduler does need to know the following
340 request codes. A few, publically-visible, request codes are also
njn25e49d8e72002-09-23 09:36:25 +0000341 defined in valgrind.h, and similar headers for some skins. */
sewardj2e93c502002-04-12 11:12:52 +0000342
343#define VG_USERREQ__MALLOC 0x2001
344#define VG_USERREQ__BUILTIN_NEW 0x2002
345#define VG_USERREQ__BUILTIN_VEC_NEW 0x2003
346
347#define VG_USERREQ__FREE 0x2004
348#define VG_USERREQ__BUILTIN_DELETE 0x2005
349#define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006
350
351#define VG_USERREQ__CALLOC 0x2007
352#define VG_USERREQ__REALLOC 0x2008
353#define VG_USERREQ__MEMALIGN 0x2009
354
355
sewardj20917d82002-05-28 01:36:45 +0000356/* (Fn, Arg): Create a new thread and run Fn applied to Arg in it. Fn
357 MUST NOT return -- ever. Eventually it will do either __QUIT or
358 __WAIT_JOINER. */
359#define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001
360
361/* ( no-args ): calling thread disappears from the system forever.
362 Reclaim resources. */
363#define VG_USERREQ__QUIT 0x3002
364
365/* ( void* ): calling thread waits for joiner and returns the void* to
366 it. */
367#define VG_USERREQ__WAIT_JOINER 0x3003
368
369/* ( ThreadId, void** ): wait to join a thread. */
370#define VG_USERREQ__PTHREAD_JOIN 0x3004
371
372/* Set cancellation state and type for this thread. */
373#define VG_USERREQ__SET_CANCELSTATE 0x3005
374#define VG_USERREQ__SET_CANCELTYPE 0x3006
375
376/* ( no-args ): Test if we are at a cancellation point. */
377#define VG_USERREQ__TESTCANCEL 0x3007
378
379/* ( ThreadId, &thread_exit_wrapper is the only allowable arg ): call
380 with this arg to indicate that a cancel is now pending for the
381 specified thread. */
382#define VG_USERREQ__SET_CANCELPEND 0x3008
383
384/* Set/get detach state for this thread. */
385#define VG_USERREQ__SET_OR_GET_DETACH 0x3009
386
387#define VG_USERREQ__PTHREAD_GET_THREADID 0x300B
388#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x300C
389#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x300D
390#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x300E
391#define VG_USERREQ__PTHREAD_COND_WAIT 0x300F
392#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x3010
393#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x3011
394#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x3012
395#define VG_USERREQ__PTHREAD_KEY_CREATE 0x3013
396#define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014
sewardj00a66b12002-10-12 16:42:35 +0000397#define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015
398#define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016
sewardj20917d82002-05-28 01:36:45 +0000399#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017
400#define VG_USERREQ__PTHREAD_SIGMASK 0x3018
401#define VG_USERREQ__SIGWAIT 0x3019
402#define VG_USERREQ__PTHREAD_KILL 0x301A
403#define VG_USERREQ__PTHREAD_YIELD 0x301B
sewardj00a66b12002-10-12 16:42:35 +0000404#define VG_USERREQ__PTHREAD_KEY_VALIDATE 0x301C
sewardj2e93c502002-04-12 11:12:52 +0000405
sewardj8ad94e12002-05-29 00:10:20 +0000406#define VG_USERREQ__CLEANUP_PUSH 0x3020
407#define VG_USERREQ__CLEANUP_POP 0x3021
sewardj870497a2002-05-29 01:06:47 +0000408#define VG_USERREQ__GET_KEY_D_AND_S 0x3022
sewardj8ad94e12002-05-29 00:10:20 +0000409
sewardjef037c72002-05-30 00:40:03 +0000410#define VG_USERREQ__NUKE_OTHER_THREADS 0x3023
sewardjefbfcdf2002-06-19 17:35:45 +0000411
412/* Ask how many signal handler returns have happened to this
413 thread. */
sewardj9a2224b2002-06-19 10:17:40 +0000414#define VG_USERREQ__GET_N_SIGS_RETURNED 0x3024
sewardjef037c72002-05-30 00:40:03 +0000415
sewardj2cb00342002-06-28 01:46:26 +0000416/* Get/set entries for a thread's pthread_atfork stack. */
417#define VG_USERREQ__SET_FHSTACK_USED 0x3025
418#define VG_USERREQ__GET_FHSTACK_USED 0x3026
419#define VG_USERREQ__SET_FHSTACK_ENTRY 0x3027
420#define VG_USERREQ__GET_FHSTACK_ENTRY 0x3028
sewardjefbfcdf2002-06-19 17:35:45 +0000421
sewardj1fe7b002002-07-16 01:43:15 +0000422/* Denote the finish of VG_(__libc_freeres_wrapper). */
423#define VG_USERREQ__LIBC_FREERES_DONE 0x3029
424
sewardj45b4b372002-04-16 22:50:32 +0000425/* Cosmetic ... */
426#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
sewardj4dced352002-06-04 22:54:20 +0000427/* Log a pthread error from client-space. Cosmetic. */
428#define VG_USERREQ__PTHREAD_ERROR 0x3102
sewardj45b4b372002-04-16 22:50:32 +0000429
sewardj54cacf02002-04-12 23:24:59 +0000430/*
431In vg_constants.h:
432#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardj54cacf02002-04-12 23:24:59 +0000433*/
434
sewardj1fe7b002002-07-16 01:43:15 +0000435/* The scheduler does need to know the address of it so it can be
436 called at program exit. */
437extern void VG_(__libc_freeres_wrapper)( void );
438
sewardj54cacf02002-04-12 23:24:59 +0000439
sewardj2e93c502002-04-12 11:12:52 +0000440/* ---------------------------------------------------------------------
441 Constants pertaining to the simulated CPU state, VG_(baseBlock),
442 which need to go here to avoid ugly circularities.
443 ------------------------------------------------------------------ */
444
445/* How big is the saved FPU state? */
446#define VG_SIZE_OF_FPUSTATE 108
447/* ... and in words ... */
448#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
449
450
451/* ---------------------------------------------------------------------
sewardj92a59562002-09-30 00:53:10 +0000452 Exports of vg_ldt.c
453 ------------------------------------------------------------------ */
454
455/* This is the hardware-format for a segment descriptor, ie what the
456 x86 actually deals with. It is 8 bytes long. It's ugly. */
457
458typedef struct _LDT_ENTRY {
459 union {
460 struct {
461 UShort LimitLow;
462 UShort BaseLow;
463 unsigned BaseMid : 8;
464 unsigned Type : 5;
465 unsigned Dpl : 2;
466 unsigned Pres : 1;
467 unsigned LimitHi : 4;
468 unsigned Sys : 1;
469 unsigned Reserved_0 : 1;
470 unsigned Default_Big : 1;
471 unsigned Granularity : 1;
472 unsigned BaseHi : 8;
473 } Bits;
474 struct {
475 UInt word1;
476 UInt word2;
477 } Words;
478 }
479 LdtEnt;
480} VgLdtEntry;
481
482/* Maximum number of LDT entries supported (by the x86). */
483#define VG_M_LDT_ENTRIES 8192
484/* The size of each LDT entry == sizeof(VgLdtEntry) */
485#define VG_LDT_ENTRY_SIZE 8
486
487/* Alloc & copy, and dealloc. */
488extern VgLdtEntry*
489 VG_(allocate_LDT_for_thread) ( VgLdtEntry* parent_ldt );
490extern void
491 VG_(deallocate_LDT_for_thread) ( VgLdtEntry* ldt );
492
493/* Simulate the modify_ldt syscall. */
494extern Int VG_(sys_modify_ldt) ( ThreadId tid,
495 Int func, void* ptr, UInt bytecount );
496
sewardje1042472002-09-30 12:33:11 +0000497/* Called from generated code. Given a segment selector and a virtual
498 address, return a linear address, and do limit checks too. */
499extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr );
500
sewardj92a59562002-09-30 00:53:10 +0000501
502/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000503 Exports of vg_scheduler.c
504 ------------------------------------------------------------------ */
505
sewardj2e93c502002-04-12 11:12:52 +0000506typedef
507 enum {
508 VgTs_Empty, /* this slot is not in use */
509 VgTs_Runnable, /* waiting to be scheduled */
510 VgTs_WaitJoiner, /* waiting for someone to do join on me */
511 VgTs_WaitJoinee, /* waiting for the thread I did join on */
512 VgTs_WaitFD, /* waiting for I/O completion on a fd */
513 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000514 VgTs_WaitCV, /* waiting on a condition variable */
sewardjb48e5002002-05-13 00:16:03 +0000515 VgTs_WaitSIG, /* waiting due to sigwait() */
sewardj2e93c502002-04-12 11:12:52 +0000516 VgTs_Sleeping /* sleeping for a while */
517 }
518 ThreadStatus;
sewardj8ad94e12002-05-29 00:10:20 +0000519
520/* An entry in a threads's cleanup stack. */
521typedef
522 struct {
523 void (*fn)(void*);
524 void* arg;
525 }
526 CleanupEntry;
sewardj2cb00342002-06-28 01:46:26 +0000527
528/* An entry in a thread's fork-handler stack. */
529typedef
530 struct {
531 void (*prepare)(void);
532 void (*parent)(void);
533 void (*child)(void);
534 }
535 ForkHandlerEntry;
536
537
njn25e49d8e72002-09-23 09:36:25 +0000538struct _ThreadState {
539 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
540 The thread identity is simply the index in vg_threads[].
541 ThreadId == 1 is the root thread and has the special property
542 that we don't try and allocate or deallocate its stack. For
543 convenience of generating error message, we also put the
544 ThreadId in this tid field, but be aware that it should
545 ALWAYS == the index in vg_threads[]. */
546 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000547
njn25e49d8e72002-09-23 09:36:25 +0000548 /* Current scheduling status.
sewardj5f07b662002-04-23 16:52:51 +0000549
njn25e49d8e72002-09-23 09:36:25 +0000550 Complications: whenever this is set to VgTs_WaitMX, you
551 should also set .m_edx to whatever the required return value
552 is for pthread_mutex_lock / pthread_cond_timedwait for when
553 the mutex finally gets unblocked. */
554 ThreadStatus status;
sewardj2e93c502002-04-12 11:12:52 +0000555
njn25e49d8e72002-09-23 09:36:25 +0000556 /* When .status == WaitMX, points to the mutex I am waiting for.
557 When .status == WaitCV, points to the mutex associated with
558 the condition variable indicated by the .associated_cv field.
559 In all other cases, should be NULL. */
560 void* /*pthread_mutex_t* */ associated_mx;
sewardj3b5d8862002-04-20 13:53:23 +0000561
njn25e49d8e72002-09-23 09:36:25 +0000562 /* When .status == WaitCV, points to the condition variable I am
563 waiting for. In all other cases, should be NULL. */
564 void* /*pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000565
njn25e49d8e72002-09-23 09:36:25 +0000566 /* If VgTs_Sleeping, this is when we should wake up, measured in
567 milliseconds as supplied by VG_(read_millisecond_counter).
sewardj2e93c502002-04-12 11:12:52 +0000568
njn25e49d8e72002-09-23 09:36:25 +0000569 If VgTs_WaitCV, this indicates the time at which
570 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
571 this means infinitely far in the future, viz,
572 pthread_cond_wait. */
573 UInt awaken_at;
sewardj20917d82002-05-28 01:36:45 +0000574
njn25e49d8e72002-09-23 09:36:25 +0000575 /* If VgTs_WaitJoiner, return value, as generated by joinees. */
576 void* joinee_retval;
sewardj20917d82002-05-28 01:36:45 +0000577
njn25e49d8e72002-09-23 09:36:25 +0000578 /* If VgTs_WaitJoinee, place to copy the return value to, and
579 the identity of the thread we're waiting for. */
580 void** joiner_thread_return;
581 ThreadId joiner_jee_tid;
sewardj8ad94e12002-05-29 00:10:20 +0000582
njn25e49d8e72002-09-23 09:36:25 +0000583 /* Whether or not detached. */
584 Bool detached;
sewardj20917d82002-05-28 01:36:45 +0000585
njn25e49d8e72002-09-23 09:36:25 +0000586 /* Cancelability state and type. */
587 Bool cancel_st; /* False==PTH_CANCEL_DISABLE; True==.._ENABLE */
588 Bool cancel_ty; /* False==PTH_CANC_ASYNCH; True==..._DEFERRED */
589
590 /* Pointer to fn to call to do cancellation. Indicates whether
591 or not cancellation is pending. If NULL, not pending. Else
592 should be &thread_exit_wrapper(), indicating that
593 cancallation is pending. */
594 void (*cancel_pend)(void*);
sewardj2e93c502002-04-12 11:12:52 +0000595
njn25e49d8e72002-09-23 09:36:25 +0000596 /* The cleanup stack. */
597 Int custack_used;
598 CleanupEntry custack[VG_N_CLEANUPSTACK];
sewardj5f07b662002-04-23 16:52:51 +0000599
sewardj00a66b12002-10-12 16:42:35 +0000600 /* A pointer to the thread's-specific-data. This is handled almost
601 entirely from vg_libpthread.c. We just provide hooks to get and
602 set this ptr. This is either NULL, indicating the thread has
603 read/written none of its specifics so far, OR points to a
604 void*[VG_N_THREAD_KEYS], allocated and deallocated in
605 vg_libpthread.c. */
606 void** specifics_ptr;
sewardjb48e5002002-05-13 00:16:03 +0000607
njn25e49d8e72002-09-23 09:36:25 +0000608 /* This thread's blocked-signals mask. Semantics is that for a
609 signal to be delivered to this thread, the signal must not be
610 blocked by either the process-wide signal mask nor by this
611 one. So, if this thread is prepared to handle any signal that
612 the process as a whole is prepared to handle, this mask should
613 be made empty -- and that it is its default, starting
614 state. */
615 vki_ksigset_t sig_mask;
sewardjb48e5002002-05-13 00:16:03 +0000616
njn25e49d8e72002-09-23 09:36:25 +0000617 /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG,
618 is the set of signals for which we are sigwait()ing. */
619 vki_ksigset_t sigs_waited_for;
sewardj9a2224b2002-06-19 10:17:40 +0000620
njn25e49d8e72002-09-23 09:36:25 +0000621 /* Counts the number of times a signal handler for this thread
622 has returned. This makes it easy to implement pause(), by
623 polling this value, of course interspersed with nanosleeps,
624 and waiting till it changes. */
625 UInt n_signals_returned;
sewardj2e93c502002-04-12 11:12:52 +0000626
njn25e49d8e72002-09-23 09:36:25 +0000627 /* Stacks. When a thread slot is freed, we don't deallocate its
628 stack; we just leave it lying around for the next use of the
629 slot. If the next use of the slot requires a larger stack,
630 only then is the old one deallocated and a new one
631 allocated.
sewardj2e93c502002-04-12 11:12:52 +0000632
njn25e49d8e72002-09-23 09:36:25 +0000633 For the main thread (threadid == 0), this mechanism doesn't
634 apply. We don't know the size of the stack since we didn't
635 allocate it, and furthermore we never reallocate it. */
sewardj2e93c502002-04-12 11:12:52 +0000636
njn25e49d8e72002-09-23 09:36:25 +0000637 /* The allocated size of this thread's stack (permanently zero
638 if this is ThreadId == 0, since we didn't allocate its stack) */
639 UInt stack_size;
sewardj1e8cdc92002-04-18 11:37:52 +0000640
njn25e49d8e72002-09-23 09:36:25 +0000641 /* Address of the lowest word in this thread's stack. NULL means
642 not allocated yet.
643 */
644 Addr stack_base;
sewardj2e93c502002-04-12 11:12:52 +0000645
sewardj92a59562002-09-30 00:53:10 +0000646 /* Address of the highest legitimate word in this stack. This is
647 used for error messages only -- not critical for execution
648 correctness. Is is set for all stacks, specifically including
649 ThreadId == 0 (the main thread). */
njn25e49d8e72002-09-23 09:36:25 +0000650 Addr stack_highest_word;
651
sewardj92a59562002-09-30 00:53:10 +0000652 /* Pointer to this thread's Local (Segment) Descriptor Table.
653 Starts out as NULL, indicating there is no table, and we hope to
654 keep it that way. If the thread does __NR_modify_ldt to create
655 entries, we allocate a 8192-entry table at that point. This is
656 a straight copy of the Linux kernel's scheme. Don't forget to
657 deallocate this at thread exit. */
658 VgLdtEntry* ldt;
659
660 /* Saved machine context. Note the FPU state, %EIP and segment
661 registers are not shadowed.
662
663 Although the segment registers are 16 bits long, storage
664 management here, in VG_(baseBlock) and in VG_(m_state_static) is
665 simplified if we pretend they are 32 bits. */
666 UInt m_cs;
667 UInt m_ss;
668 UInt m_ds;
669 UInt m_es;
670 UInt m_fs;
671 UInt m_gs;
672
njn25e49d8e72002-09-23 09:36:25 +0000673 UInt m_eax;
674 UInt m_ebx;
675 UInt m_ecx;
676 UInt m_edx;
677 UInt m_esi;
678 UInt m_edi;
679 UInt m_ebp;
680 UInt m_esp;
681 UInt m_eflags;
682 UInt m_eip;
683 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
684
685 UInt sh_eax;
686 UInt sh_ebx;
687 UInt sh_ecx;
688 UInt sh_edx;
689 UInt sh_esi;
690 UInt sh_edi;
691 UInt sh_ebp;
692 UInt sh_esp;
693 UInt sh_eflags;
694};
sewardj2e93c502002-04-12 11:12:52 +0000695
696
sewardj018f7622002-05-15 21:13:39 +0000697/* The thread table. */
698extern ThreadState VG_(threads)[VG_N_THREADS];
699
700/* Check that tid is in range and denotes a non-Empty thread. */
sewardjb48e5002002-05-13 00:16:03 +0000701extern Bool VG_(is_valid_tid) ( ThreadId tid );
702
sewardj018f7622002-05-15 21:13:39 +0000703/* Check that tid is in range. */
704extern Bool VG_(is_valid_or_empty_tid) ( ThreadId tid );
705
sewardj2e93c502002-04-12 11:12:52 +0000706/* Copy the specified thread's state into VG_(baseBlock) in
707 preparation for running it. */
708extern void VG_(load_thread_state)( ThreadId );
709
710/* Save the specified thread's state back in VG_(baseBlock), and fill
711 VG_(baseBlock) with junk, for sanity-check reasons. */
712extern void VG_(save_thread_state)( ThreadId );
713
sewardj1e8cdc92002-04-18 11:37:52 +0000714/* And for the currently running one, if valid. */
715extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000716
sewardj1e8cdc92002-04-18 11:37:52 +0000717/* Similarly ... */
718extern ThreadId VG_(get_current_tid) ( void );
719
sewardjccef2e62002-05-29 19:26:32 +0000720/* Nuke all threads except tid. */
721extern void VG_(nuke_all_threads_except) ( ThreadId me );
722
sewardj2e93c502002-04-12 11:12:52 +0000723
724/* Return codes from the scheduler. */
725typedef
sewardj7e87e382002-05-03 19:09:05 +0000726 enum {
727 VgSrc_Deadlock, /* no runnable threads and no prospect of any
728 even if we wait for a long time */
729 VgSrc_ExitSyscall, /* client called exit(). This is the normal
730 route out. */
731 VgSrc_BbsDone /* In a debugging run, the specified number of
732 bbs has been completed. */
733 }
sewardj2e93c502002-04-12 11:12:52 +0000734 VgSchedReturnCode;
735
sewardj7e87e382002-05-03 19:09:05 +0000736
sewardj2e93c502002-04-12 11:12:52 +0000737/* The scheduler. */
738extern VgSchedReturnCode VG_(scheduler) ( void );
739
740extern void VG_(scheduler_init) ( void );
741
sewardj15a43e12002-04-17 19:35:12 +0000742extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000743
744/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
745extern jmp_buf VG_(scheduler_jmpbuf);
sewardj872051c2002-07-13 12:12:56 +0000746/* This says whether scheduler_jmpbuf is actually valid. Needed so
747 that our signal handler doesn't longjmp when the buffer isn't
748 actually valid. */
749extern Bool VG_(scheduler_jmpbuf_valid);
sewardj2e93c502002-04-12 11:12:52 +0000750/* ... and if so, here's the signal which caused it to do so. */
751extern Int VG_(longjmpd_on_signal);
752
753
sewardja1679dd2002-05-10 22:31:40 +0000754/* Possible places where the main stack might be based. We check that
755 the initial stack, which we can't move, is allocated here.
756 VG_(scheduler_init) checks this. Andrea Archelangi's 2.4 kernels
757 have been rumoured to start stacks at 0x80000000, so that too is
njn25e49d8e72002-09-23 09:36:25 +0000758 considered. It seems systems with longer uptimes tend to to use
759 stacks which start at 0x40000000 sometimes. JRS 2002-Aug-21: I
760 also have reports of stacks starting at 0xE0000000.*/
761
sewardja1679dd2002-05-10 22:31:40 +0000762#define VG_STARTUP_STACK_BASE_1 (Addr)0xC0000000
763#define VG_STARTUP_STACK_BASE_2 (Addr)0x80000000
daywalkera2562202002-07-15 19:39:51 +0000764#define VG_STARTUP_STACK_BASE_3 (Addr)0x40000000
njn25e49d8e72002-09-23 09:36:25 +0000765#define VG_STARTUP_STACK_BASE_4 (Addr)0xE0000000
sewardja1679dd2002-05-10 22:31:40 +0000766#define VG_STARTUP_STACK_SMALLERTHAN 0x100000 /* 1024k */
767
768#define VG_STACK_MATCHES_BASE(zzstack, zzbase) \
769 ( \
770 ((zzstack) & ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN)) \
771 == \
772 ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN) \
773 )
sewardj2e93c502002-04-12 11:12:52 +0000774
775
776/* The red-zone size which we put at the bottom (highest address) of
777 thread stacks, for paranoia reasons. This can be arbitrary, and
778 doesn't really need to be set at compile time. */
779#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
780
781#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
782 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
783
njn25e49d8e72002-09-23 09:36:25 +0000784/* Junk to fill up a thread's shadow regs with when shadow regs aren't
785 * being used. */
786#define VG_UNUSED_SHADOW_REG_VALUE 0x27182818
787
788/* What we set a shadow register to when written by SET_EAX and similar
789 * things. */
790extern UInt VG_(written_shadow_reg);
sewardj2e93c502002-04-12 11:12:52 +0000791
sewardj018f7622002-05-15 21:13:39 +0000792/* Write a value to the client's %EDX (request return value register)
793 and set the shadow to indicate it is defined. */
njn25e49d8e72002-09-23 09:36:25 +0000794#define SET_EDX(zztid, zzval) \
795 do { VG_(threads)[zztid].m_edx = (zzval); \
796 VG_(threads)[zztid].sh_edx = VG_(written_shadow_reg); \
sewardj018f7622002-05-15 21:13:39 +0000797 } while (0)
798
njn25e49d8e72002-09-23 09:36:25 +0000799#define SET_EAX(zztid, zzval) \
800 do { VG_(threads)[zztid].m_eax = (zzval); \
801 VG_(threads)[zztid].sh_eax = VG_(written_shadow_reg); \
sewardj018f7622002-05-15 21:13:39 +0000802 } while (0)
803
sewardj2e93c502002-04-12 11:12:52 +0000804
805/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000806 Exports of vg_signals.c
807 ------------------------------------------------------------------ */
808
sewardjde4a1d02002-03-22 01:27:54 +0000809extern void VG_(sigstartup_actions) ( void );
810
sewardjb48e5002002-05-13 00:16:03 +0000811extern Bool VG_(deliver_signals) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000812extern void VG_(unblock_host_signal) ( Int sigNo );
sewardj018f7622002-05-15 21:13:39 +0000813extern void VG_(handle_SCSS_change) ( Bool force_update );
814
sewardjde4a1d02002-03-22 01:27:54 +0000815
816/* Fake system calls for signal handling. */
sewardj2342c972002-05-22 23:34:20 +0000817extern void VG_(do__NR_sigaltstack) ( ThreadId tid );
sewardj2e93c502002-04-12 11:12:52 +0000818extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardj018f7622002-05-15 21:13:39 +0000819extern void VG_(do__NR_sigprocmask) ( ThreadId tid,
820 Int how,
821 vki_ksigset_t* set,
822 vki_ksigset_t* oldset );
823extern void VG_(do_pthread_sigmask_SCSS_upd) ( ThreadId tid,
824 Int how,
825 vki_ksigset_t* set,
826 vki_ksigset_t* oldset );
827extern void VG_(send_signal_to_thread) ( ThreadId thread,
828 Int signo );
sewardjde4a1d02002-03-22 01:27:54 +0000829
sewardjefbfcdf2002-06-19 17:35:45 +0000830extern void VG_(do_sigpending) ( ThreadId tid, vki_ksigset_t* set );
831
832
sewardj2e93c502002-04-12 11:12:52 +0000833/* Modify the current thread's state once we have detected it is
834 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +0000835extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000836
sewardj2e93c502002-04-12 11:12:52 +0000837/* Handy utilities to block/restore all host signals. */
838extern void VG_(block_all_host_signals)
839 ( /* OUT */ vki_ksigset_t* saved_mask );
sewardj018f7622002-05-15 21:13:39 +0000840extern void VG_(restore_all_host_signals)
sewardj2e93c502002-04-12 11:12:52 +0000841 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000842
843/* ---------------------------------------------------------------------
844 Exports of vg_mylibc.c
845 ------------------------------------------------------------------ */
846
njne427a662002-10-02 11:08:25 +0000847#define vg_assert(expr) \
848 ((void) ((expr) ? 0 : \
849 (VG_(core_assert_fail) (VG__STRING(expr), \
850 __FILE__, __LINE__, \
851 __PRETTY_FUNCTION__), 0)))
852__attribute__ ((__noreturn__))
853extern void VG_(core_assert_fail) ( Char* expr, Char* file,
854 Int line, Char* fn );
855__attribute__ ((__noreturn__))
856extern void VG_(core_panic) ( Char* str );
sewardjde4a1d02002-03-22 01:27:54 +0000857
njn25e49d8e72002-09-23 09:36:25 +0000858/* VG_(brk) not public so skins cannot screw with curr_dataseg_end */
859extern void* VG_(brk) ( void* end_data_segment );
sewardjde4a1d02002-03-22 01:27:54 +0000860
njn25e49d8e72002-09-23 09:36:25 +0000861/* Skins use VG_(strdup)() which doesn't expose ArenaId */
862extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
sewardjde4a1d02002-03-22 01:27:54 +0000863
njn25e49d8e72002-09-23 09:36:25 +0000864/* Skins shouldn't need these...(?) */
sewardj5f07b662002-04-23 16:52:51 +0000865extern void VG_(start_rdtsc_calibration) ( void );
866extern void VG_(end_rdtsc_calibration) ( void );
867extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000868
njn25e49d8e72002-09-23 09:36:25 +0000869extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
sewardj2e93c502002-04-12 11:12:52 +0000870extern Int VG_(select)( Int n,
871 vki_fd_set* readfds,
872 vki_fd_set* writefds,
873 vki_fd_set* exceptfds,
874 struct vki_timeval * timeout );
875extern Int VG_(nanosleep)( const struct vki_timespec *req,
876 struct vki_timespec *rem );
877
sewardj73cf3bc2002-11-03 03:20:15 +0000878extern Int VG_(write_socket)( Int sd, void *msg, Int count );
879
880/* --- Connecting over the network --- */
881extern Int VG_(connect_via_socket)( UChar* str );
882
sewardjde4a1d02002-03-22 01:27:54 +0000883/* ---------------------------------------------------------------------
884 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
885 vg_from_ucode.c).
886 ------------------------------------------------------------------ */
887
sewardjde4a1d02002-03-22 01:27:54 +0000888#define VG_IS_FLAG_SUBSET(set1,set2) \
889 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
890
891#define VG_UNION_FLAG_SETS(set1,set2) \
892 ( ((FlagSet)set1) | ((FlagSet)set2) )
893
sewardjde4a1d02002-03-22 01:27:54 +0000894/* ---------------------------------------------------------------------
895 Exports of vg_demangle.c
896 ------------------------------------------------------------------ */
897
898extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
899
sewardjde4a1d02002-03-22 01:27:54 +0000900/* ---------------------------------------------------------------------
901 Exports of vg_from_ucode.c
902 ------------------------------------------------------------------ */
903
904extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
905
njn25e49d8e72002-09-23 09:36:25 +0000906extern void VG_(print_ccall_stats) ( void );
907extern void VG_(print_UInstr_histogram) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000908
909/* ---------------------------------------------------------------------
910 Exports of vg_to_ucode.c
911 ------------------------------------------------------------------ */
912
913extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
sewardjde4a1d02002-03-22 01:27:54 +0000914
915/* ---------------------------------------------------------------------
916 Exports of vg_translate.c
917 ------------------------------------------------------------------ */
918
sewardj1e8cdc92002-04-18 11:37:52 +0000919extern void VG_(translate) ( ThreadState* tst,
920 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +0000921 UInt* orig_size,
922 Addr* trans_addr,
923 UInt* trans_size );
924
njn25e49d8e72002-09-23 09:36:25 +0000925extern Char* VG_(nameCondcode) ( Condcode cond );
926extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness,
927 UInstr* u );
928extern void VG_(saneUCodeBlock) ( UCodeBlock* cb );
929extern Bool VG_(saneUCodeBlockCalls) ( UCodeBlock* cb );
sewardjde4a1d02002-03-22 01:27:54 +0000930
931/* ---------------------------------------------------------------------
932 Exports of vg_execontext.c.
933 ------------------------------------------------------------------ */
934
935/* Records the PC and a bit of the call chain. The first 4 %eip
936 values are used in comparisons do remove duplicate errors, and for
937 comparing against suppression specifications. The rest are purely
938 informational (but often important). */
939
njn25e49d8e72002-09-23 09:36:25 +0000940struct _ExeContext {
941 struct _ExeContext * next;
942 /* Variable-length array. The size is VG_(clo_backtrace_size); at
943 least 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
944 [1] is its caller, [2] is the caller of [1], etc. */
945 Addr eips[0];
946};
sewardjde4a1d02002-03-22 01:27:54 +0000947
948
949/* Initialise the ExeContext storage mechanism. */
950extern void VG_(init_ExeContext_storage) ( void );
951
952/* Print stats (informational only). */
953extern void VG_(show_ExeContext_stats) ( void );
954
njn25e49d8e72002-09-23 09:36:25 +0000955/* Like VG_(get_ExeContext), but with a slightly different type */
956extern ExeContext* VG_(get_ExeContext2) ( Addr eip, Addr ebp,
957 Addr ebp_min, Addr ebp_max );
sewardjde4a1d02002-03-22 01:27:54 +0000958
959
960/* ---------------------------------------------------------------------
961 Exports of vg_errcontext.c.
962 ------------------------------------------------------------------ */
963
njn25e49d8e72002-09-23 09:36:25 +0000964/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
965 * effectively extend it by defining their own enums in the (0..) range. */
sewardjde4a1d02002-03-22 01:27:54 +0000966typedef
njn25e49d8e72002-09-23 09:36:25 +0000967 enum {
968 PThreadSupp = -1, /* Matches PThreadErr */
sewardjde4a1d02002-03-22 01:27:54 +0000969 }
njn25e49d8e72002-09-23 09:36:25 +0000970 CoreSuppKind;
971
972/* For each caller specified for a suppression, record the nature of
973 the caller name. Not of interest to skins. */
974typedef
975 enum {
976 ObjName, /* Name is of an shared object file. */
977 FunName /* Name is of a function. */
978 }
979 SuppLocTy;
980
981/* Suppressions. Skin part `SkinSupp' (which is all skins have to deal
982 with) is in vg_skin.h */
983typedef
984 struct _CoreSupp {
985 struct _CoreSupp* next;
986 /* The number of times this error has been suppressed. */
987 Int count;
988 /* The name by which the suppression is referred to. */
989 Char* sname;
990 /* First two (name of fn where err occurs, and immediate caller)
991 * are mandatory; extra two are optional. */
992 SuppLocTy caller_ty[VG_N_SUPP_CALLERS];
993 Char* caller [VG_N_SUPP_CALLERS];
994 /* The skin-specific part */
995 SkinSupp skin_supp;
996 }
997 CoreSupp;
998
999/* Note: it is imperative this doesn't overlap with (0..) at all, as skins
1000 * effectively extend it by defining their own enums in the (0..) range. */
1001typedef
1002 enum {
1003 PThreadErr = -1, /* Pthreading error */
1004 }
1005 CoreErrorKind;
1006
1007/* Errors. Skin part `SkinError' (which is all skins have to deal
1008 with) is in vg_skin.h */
1009typedef
1010 struct _CoreErrContext {
1011 struct _CoreErrContext* next;
1012 /* NULL if unsuppressed; or ptr to suppression record. */
1013 CoreSupp* supp;
1014 Int count;
1015 ExeContext* where;
1016 ThreadId tid;
1017 /* These record %EIP, %ESP and %EBP at the error point. They
1018 are only used to make GDB-attaching convenient; there is no
1019 other purpose; specifically they are not used to do
1020 comparisons between errors. */
1021 UInt m_eip;
1022 UInt m_esp;
1023 UInt m_ebp;
1024 /* The skin-specific part */
1025 SkinError skin_err;
1026 }
1027 CoreError;
sewardjde4a1d02002-03-22 01:27:54 +00001028
1029
njn25e49d8e72002-09-23 09:36:25 +00001030extern void VG_(load_suppressions) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001031
njn25e49d8e72002-09-23 09:36:25 +00001032extern void VG_(record_pthread_error) ( ThreadId tid, Char* msg );
sewardjde4a1d02002-03-22 01:27:54 +00001033
njn25e49d8e72002-09-23 09:36:25 +00001034extern void VG_(show_all_errors) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001035
1036/* ---------------------------------------------------------------------
1037 Exports of vg_procselfmaps.c
1038 ------------------------------------------------------------------ */
1039
1040extern
1041void VG_(read_procselfmaps) (
1042 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
1043);
1044
1045
1046/* ---------------------------------------------------------------------
1047 Exports of vg_symtab2.c
1048 ------------------------------------------------------------------ */
1049
1050/* We assume the executable is loaded here ... can't really find
njn25e49d8e72002-09-23 09:36:25 +00001051 out. There is a hacky sanity check in VG_(init_memory)()
sewardjde4a1d02002-03-22 01:27:54 +00001052 which should trip up most stupidities.
1053*/
1054#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
1055
njn25e49d8e72002-09-23 09:36:25 +00001056extern void VG_(maybe_read_symbols) ( void );
1057extern void VG_(read_symtab_callback) ( Addr start, UInt size,
1058 Char rr, Char ww, Char xx,
1059 UInt foffset, UChar* filename );
1060extern void VG_(maybe_unload_symbols) ( Addr start, UInt length );
sewardjde4a1d02002-03-22 01:27:54 +00001061
njn25e49d8e72002-09-23 09:36:25 +00001062extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnname );
1063extern void VG_(mini_stack_dump) ( ExeContext* ec );
sewardjde4a1d02002-03-22 01:27:54 +00001064
1065
1066/* ---------------------------------------------------------------------
1067 Exports of vg_clientmalloc.c
1068 ------------------------------------------------------------------ */
1069
njn25e49d8e72002-09-23 09:36:25 +00001070extern void VG_(client_malloc_init)();
sewardjde4a1d02002-03-22 01:27:54 +00001071
sewardj2e93c502002-04-12 11:12:52 +00001072/* These are called from the scheduler, when it intercepts a user
1073 request. */
sewardj8c824512002-04-14 04:16:48 +00001074extern void* VG_(client_malloc) ( ThreadState* tst,
1075 UInt size, VgAllocKind kind );
1076extern void* VG_(client_memalign) ( ThreadState* tst,
1077 UInt align, UInt size );
1078extern void VG_(client_free) ( ThreadState* tst,
1079 void* ptrV, VgAllocKind kind );
1080extern void* VG_(client_calloc) ( ThreadState* tst,
1081 UInt nmemb, UInt size1 );
1082extern void* VG_(client_realloc) ( ThreadState* tst,
1083 void* ptrV, UInt size_new );
sewardjde4a1d02002-03-22 01:27:54 +00001084
1085
1086/* ---------------------------------------------------------------------
1087 Exports of vg_main.c
1088 ------------------------------------------------------------------ */
1089
sewardj73cf3bc2002-11-03 03:20:15 +00001090/* Tell the logging mechanism whether we are logging to a file
1091 descriptor or a socket descriptor. */
1092extern Bool VG_(logging_to_filedes);
1093
njn25e49d8e72002-09-23 09:36:25 +00001094/* Sanity checks which may be done at any time. The scheduler decides when. */
1095extern void VG_(do_sanity_checks) ( Bool force_expensive );
1096
sewardjde4a1d02002-03-22 01:27:54 +00001097/* A structure used as an intermediary when passing the simulated
1098 CPU's state to some assembly fragments, particularly system calls.
1099 Stuff is copied from baseBlock to here, the assembly magic runs,
njn25e49d8e72002-09-23 09:36:25 +00001100 and then the inverse copy is done.
1101 */
sewardj92a59562002-09-30 00:53:10 +00001102extern UInt VG_(m_state_static) [6 /* segment regs, Intel order */
1103 + 8 /* int regs, in Intel order */
sewardjde4a1d02002-03-22 01:27:54 +00001104 + 1 /* %eflags */
1105 + 1 /* %eip */
1106 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1107 ];
1108
1109/* Handy fns for doing the copy back and forth. */
1110extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1111extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1112
sewardjde4a1d02002-03-22 01:27:54 +00001113/* Called when some unhandleable client behaviour is detected.
1114 Prints a msg and aborts. */
njn25e49d8e72002-09-23 09:36:25 +00001115extern void VG_(unimplemented) ( Char* msg )
1116 __attribute__((__noreturn__));
sewardjde4a1d02002-03-22 01:27:54 +00001117
1118/* The stack on which Valgrind runs. We can't use the same stack as the
1119 simulatee -- that's an important design decision. */
1120extern UInt VG_(stack)[10000];
1121
njn25e49d8e72002-09-23 09:36:25 +00001122/* Similarly, we have to ask for signals to be delivered on an alternative
1123 stack, since it is possible, although unlikely, that we'll have to run
1124 client code from inside the Valgrind-installed signal handler. If this
1125 happens it will be done by vg_deliver_signal_immediately(). */
sewardjde4a1d02002-03-22 01:27:54 +00001126extern UInt VG_(sigstack)[10000];
1127
sewardjde4a1d02002-03-22 01:27:54 +00001128/* Holds client's %esp at the point we gained control. From this the
1129 client's argc, argv and envp are deduced. */
1130extern Addr VG_(esp_at_startup);
sewardjde4a1d02002-03-22 01:27:54 +00001131
njn25e49d8e72002-09-23 09:36:25 +00001132/* Remove valgrind.so and skin's .so from a LD_PRELOAD=... string so child
1133 processes don't get traced into. Also mess up $libdir/valgrind so that
1134 our libpthread.so disappears from view. */
sewardj3e1eb1f2002-05-18 13:14:17 +00001135void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str,
1136 Char* ld_library_path_str );
sewardjde4a1d02002-03-22 01:27:54 +00001137
1138/* Something of a function looking for a home ... start up GDB. This
1139 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1140 *client's* stack. This is necessary to give GDB the illusion that
1141 the client program really was running on the real cpu. */
1142extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1143
njn41557122002-10-14 09:25:37 +00001144/* VG_(bbs_done) in include/vg_skin.h */
1145
sewardjde4a1d02002-03-22 01:27:54 +00001146/* 64-bit counter for the number of bbs to go before a debug exit. */
1147extern ULong VG_(bbs_to_go);
1148
1149/* Counts downwards in vg_run_innerloop. */
1150extern UInt VG_(dispatch_ctr);
1151
sewardjde4a1d02002-03-22 01:27:54 +00001152/* Is the client running on the simulated CPU or the real one? */
1153extern Bool VG_(running_on_simd_CPU); /* Initially False */
1154
1155/* The current LRU epoch. */
1156extern UInt VG_(current_epoch);
1157
sewardj7e87e382002-05-03 19:09:05 +00001158/* This is the ThreadId of the last thread the scheduler ran. */
1159extern ThreadId VG_(last_run_tid);
1160
njn25e49d8e72002-09-23 09:36:25 +00001161/* This is the argument to __NR_exit() supplied by the first thread to
1162 call that syscall. We eventually pass that to __NR_exit() for
1163 real. */
1164extern UInt VG_(exitcode);
1165
sewardjde4a1d02002-03-22 01:27:54 +00001166
1167/* --- Counters, for informational purposes only. --- */
1168
1169/* Number of lookups which miss the fast tt helper. */
1170extern UInt VG_(tt_fast_misses);
1171
1172/* Counts for LRU informational messages. */
1173
1174/* Number and total o/t size of new translations this epoch. */
1175extern UInt VG_(this_epoch_in_count);
1176extern UInt VG_(this_epoch_in_osize);
1177extern UInt VG_(this_epoch_in_tsize);
1178/* Number and total o/t size of discarded translations this epoch. */
1179extern UInt VG_(this_epoch_out_count);
1180extern UInt VG_(this_epoch_out_osize);
1181extern UInt VG_(this_epoch_out_tsize);
1182/* Number and total o/t size of translations overall. */
1183extern UInt VG_(overall_in_count);
1184extern UInt VG_(overall_in_osize);
1185extern UInt VG_(overall_in_tsize);
1186/* Number and total o/t size of discards overall. */
1187extern UInt VG_(overall_out_count);
1188extern UInt VG_(overall_out_osize);
1189extern UInt VG_(overall_out_tsize);
1190
1191/* The number of LRU-clearings of TT/TC. */
1192extern UInt VG_(number_of_lrus);
1193
1194/* Counts pertaining to the register allocator. */
1195
1196/* total number of uinstrs input to reg-alloc */
1197extern UInt VG_(uinstrs_prealloc);
1198
1199/* total number of uinstrs added due to spill code */
1200extern UInt VG_(uinstrs_spill);
1201
1202/* number of bbs requiring spill code */
1203extern UInt VG_(translations_needing_spill);
1204
1205/* total of register ranks over all translations */
1206extern UInt VG_(total_reg_rank);
1207
sewardjde4a1d02002-03-22 01:27:54 +00001208/* Counts pertaining to internal sanity checking. */
1209extern UInt VG_(sanity_fast_count);
1210extern UInt VG_(sanity_slow_count);
1211
sewardj2e93c502002-04-12 11:12:52 +00001212/* Counts pertaining to the scheduler. */
1213extern UInt VG_(num_scheduling_events_MINOR);
1214extern UInt VG_(num_scheduling_events_MAJOR);
1215
sewardjde4a1d02002-03-22 01:27:54 +00001216
1217/* ---------------------------------------------------------------------
1218 Exports of vg_memory.c
1219 ------------------------------------------------------------------ */
1220
njn25e49d8e72002-09-23 09:36:25 +00001221extern void VG_(init_memory) ( void );
1222extern void VG_(new_exe_segment) ( Addr a, UInt len );
1223extern void VG_(remove_if_exe_segment) ( Addr a, UInt len );
sewardjde4a1d02002-03-22 01:27:54 +00001224
njn25e49d8e72002-09-23 09:36:25 +00001225/* Called from generated code. */
1226extern void VG_(handle_esp_assignment) ( Addr new_espA );
sewardjde4a1d02002-03-22 01:27:54 +00001227
1228/* Nasty kludgery to deal with applications which switch stacks,
1229 like netscape. */
sewardjde4a1d02002-03-22 01:27:54 +00001230#define VG_PLAUSIBLE_STACK_SIZE 8000000
1231
sewardjde4a1d02002-03-22 01:27:54 +00001232/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001233 Exports of vg_syscalls.c
sewardjde4a1d02002-03-22 01:27:54 +00001234 ------------------------------------------------------------------ */
1235
njn25e49d8e72002-09-23 09:36:25 +00001236extern void VG_(init_dataseg_end_for_brk) ( void );
1237
sewardj2e93c502002-04-12 11:12:52 +00001238extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001239
njn25e49d8e72002-09-23 09:36:25 +00001240extern void* VG_(pre_known_blocking_syscall) ( ThreadId tid, Int syscallno );
1241extern void VG_(post_known_blocking_syscall)( ThreadId tid, Int syscallno,
1242 void* pre_res, Int res );
sewardjde4a1d02002-03-22 01:27:54 +00001243
1244extern Bool VG_(is_kerror) ( Int res );
1245
njn25e49d8e72002-09-23 09:36:25 +00001246#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1247 VG_(load_thread_state)(thread_id); \
1248 VG_(copy_baseBlock_to_m_state_static)(); \
1249 VG_(do_syscall)(); \
1250 VG_(copy_m_state_static_to_baseBlock)(); \
1251 VG_(save_thread_state)(thread_id); \
1252 VG_(threads)[thread_id].sh_eax = VG_(written_shadow_reg);\
sewardj018f7622002-05-15 21:13:39 +00001253 result_lvalue = VG_(threads)[thread_id].m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001254
1255
1256/* ---------------------------------------------------------------------
1257 Exports of vg_transtab.c
1258 ------------------------------------------------------------------ */
1259
1260/* An entry in the translation table (TT). */
1261typedef
1262 struct {
1263 /* +0 */ Addr orig_addr;
1264 /* +4 */ Addr trans_addr;
1265 /* +8 */ UInt mru_epoch;
1266 /* +12 */ UShort orig_size;
1267 /* +14 */ UShort trans_size;
1268 }
1269 TTEntry;
1270
1271/* The number of basic blocks in an epoch (one age-step). */
1272#define VG_BBS_PER_EPOCH 20000
1273
njn25e49d8e72002-09-23 09:36:25 +00001274/* The fast-cache for tt-lookup. */
1275extern Addr VG_(tt_fast)[VG_TT_FAST_SIZE];
1276
sewardjde4a1d02002-03-22 01:27:54 +00001277extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1278extern void VG_(maybe_do_lru_pass) ( void );
1279extern void VG_(flush_transtab) ( void );
1280extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1281extern void VG_(add_to_trans_tab) ( TTEntry* tte );
sewardj18d75132002-05-16 11:06:21 +00001282extern void VG_(invalidate_translations) ( Addr start, UInt range );
sewardjde4a1d02002-03-22 01:27:54 +00001283
sewardj18d75132002-05-16 11:06:21 +00001284extern void VG_(init_tt_tc) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001285
1286extern void VG_(sanity_check_tc_tt) ( void );
1287extern Addr VG_(search_transtab) ( Addr original_addr );
1288
1289extern void VG_(invalidate_tt_fast)( void );
1290
1291
1292/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +00001293 Exports of vg_syscall.S
1294 ------------------------------------------------------------------ */
1295
1296extern void VG_(do_syscall) ( void );
1297
1298
1299/* ---------------------------------------------------------------------
1300 Exports of vg_startup.S
1301 ------------------------------------------------------------------ */
1302
sewardjde4a1d02002-03-22 01:27:54 +00001303extern void VG_(switch_to_real_CPU) ( void );
1304
sewardj35805422002-04-21 13:05:34 +00001305extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1306 Addr m_esp_at_error,
1307 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001308
1309
1310/* ---------------------------------------------------------------------
1311 Exports of vg_dispatch.S
1312 ------------------------------------------------------------------ */
1313
sewardj2e93c502002-04-12 11:12:52 +00001314/* Run a thread for a (very short) while, until some event happens
1315 which means we need to defer to the scheduler. */
1316extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001317
1318
1319/* ---------------------------------------------------------------------
1320 Exports of vg_helpers.S
1321 ------------------------------------------------------------------ */
1322
sewardjde4a1d02002-03-22 01:27:54 +00001323/* Mul, div, etc, -- we don't codegen these directly. */
1324extern void VG_(helper_idiv_64_32);
1325extern void VG_(helper_div_64_32);
1326extern void VG_(helper_idiv_32_16);
1327extern void VG_(helper_div_32_16);
1328extern void VG_(helper_idiv_16_8);
1329extern void VG_(helper_div_16_8);
1330
1331extern void VG_(helper_imul_32_64);
1332extern void VG_(helper_mul_32_64);
1333extern void VG_(helper_imul_16_32);
1334extern void VG_(helper_mul_16_32);
1335extern void VG_(helper_imul_8_16);
1336extern void VG_(helper_mul_8_16);
1337
1338extern void VG_(helper_CLD);
1339extern void VG_(helper_STD);
1340extern void VG_(helper_get_dirflag);
1341
sewardj7d78e782002-06-02 00:04:00 +00001342extern void VG_(helper_CLC);
1343extern void VG_(helper_STC);
1344
sewardjde4a1d02002-03-22 01:27:54 +00001345extern void VG_(helper_shldl);
1346extern void VG_(helper_shldw);
1347extern void VG_(helper_shrdl);
1348extern void VG_(helper_shrdw);
1349
1350extern void VG_(helper_RDTSC);
1351extern void VG_(helper_CPUID);
1352
sewardjde4a1d02002-03-22 01:27:54 +00001353extern void VG_(helper_bsf);
1354extern void VG_(helper_bsr);
1355
1356extern void VG_(helper_fstsw_AX);
1357extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001358extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001359extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001360
sewardj20917d82002-05-28 01:36:45 +00001361/* NOT A FUNCTION; this is a bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001362extern void VG_(signalreturn_bogusRA)( void );
sewardj20917d82002-05-28 01:36:45 +00001363
njn4f9c9342002-04-29 16:03:24 +00001364/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +00001365 Things relating to the used skin
njn4f9c9342002-04-29 16:03:24 +00001366 ------------------------------------------------------------------ */
1367
njn25e49d8e72002-09-23 09:36:25 +00001368#define VG_TRACK(fn, args...) \
1369 do { \
1370 if (VG_(track_events).fn) \
1371 VG_(track_events).fn(args); \
1372 } while (0)
sewardj18d75132002-05-16 11:06:21 +00001373
1374
sewardjde4a1d02002-03-22 01:27:54 +00001375/* ---------------------------------------------------------------------
1376 The state of the simulated CPU.
1377 ------------------------------------------------------------------ */
1378
sewardjde4a1d02002-03-22 01:27:54 +00001379/* ---------------------------------------------------------------------
1380 Offsets into baseBlock for everything which needs to referred to
1381 from generated code. The order of these decls does not imply
1382 what the order of the actual offsets is. The latter is important
1383 and is set up in vg_main.c.
1384 ------------------------------------------------------------------ */
1385
1386/* An array of words. In generated code, %ebp always points to the
1387 start of this array. Useful stuff, like the simulated CPU state,
1388 and the addresses of helper functions, can then be found by
1389 indexing off %ebp. The following declares variables which, at
1390 startup time, are given values denoting offsets into baseBlock.
1391 These offsets are in *words* from the start of baseBlock. */
1392
1393#define VG_BASEBLOCK_WORDS 200
1394
1395extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1396
1397
1398/* -----------------------------------------------------
1399 Read-write parts of baseBlock.
1400 -------------------------------------------------- */
1401
1402/* State of the simulated CPU. */
1403extern Int VGOFF_(m_eax);
1404extern Int VGOFF_(m_ecx);
1405extern Int VGOFF_(m_edx);
1406extern Int VGOFF_(m_ebx);
1407extern Int VGOFF_(m_esp);
1408extern Int VGOFF_(m_ebp);
1409extern Int VGOFF_(m_esi);
1410extern Int VGOFF_(m_edi);
1411extern Int VGOFF_(m_eflags);
1412extern Int VGOFF_(m_fpustate);
1413extern Int VGOFF_(m_eip);
1414
sewardj92a59562002-09-30 00:53:10 +00001415extern Int VGOFF_(m_cs);
1416extern Int VGOFF_(m_ss);
1417extern Int VGOFF_(m_ds);
1418extern Int VGOFF_(m_es);
1419extern Int VGOFF_(m_fs);
1420extern Int VGOFF_(m_gs);
1421
sewardjde4a1d02002-03-22 01:27:54 +00001422/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1423extern Int VGOFF_(spillslots);
1424
1425/* Records the valid bits for the 8 integer regs & flags reg. */
1426extern Int VGOFF_(sh_eax);
1427extern Int VGOFF_(sh_ecx);
1428extern Int VGOFF_(sh_edx);
1429extern Int VGOFF_(sh_ebx);
1430extern Int VGOFF_(sh_esp);
1431extern Int VGOFF_(sh_ebp);
1432extern Int VGOFF_(sh_esi);
1433extern Int VGOFF_(sh_edi);
1434extern Int VGOFF_(sh_eflags);
1435
sewardjde4a1d02002-03-22 01:27:54 +00001436/* -----------------------------------------------------
1437 Read-only parts of baseBlock.
1438 -------------------------------------------------- */
1439
sewardj92a59562002-09-30 00:53:10 +00001440/* This thread's LDT pointer. */
1441extern Int VGOFF_(ldt);
1442
sewardjde4a1d02002-03-22 01:27:54 +00001443/* Offsets of addresses of helper functions. A "helper" function is
1444 one which is called from generated code. */
1445
1446extern Int VGOFF_(helper_idiv_64_32);
1447extern Int VGOFF_(helper_div_64_32);
1448extern Int VGOFF_(helper_idiv_32_16);
1449extern Int VGOFF_(helper_div_32_16);
1450extern Int VGOFF_(helper_idiv_16_8);
1451extern Int VGOFF_(helper_div_16_8);
1452
1453extern Int VGOFF_(helper_imul_32_64);
1454extern Int VGOFF_(helper_mul_32_64);
1455extern Int VGOFF_(helper_imul_16_32);
1456extern Int VGOFF_(helper_mul_16_32);
1457extern Int VGOFF_(helper_imul_8_16);
1458extern Int VGOFF_(helper_mul_8_16);
1459
1460extern Int VGOFF_(helper_CLD);
1461extern Int VGOFF_(helper_STD);
1462extern Int VGOFF_(helper_get_dirflag);
1463
sewardj7d78e782002-06-02 00:04:00 +00001464extern Int VGOFF_(helper_CLC);
1465extern Int VGOFF_(helper_STC);
1466
sewardjde4a1d02002-03-22 01:27:54 +00001467extern Int VGOFF_(helper_shldl);
1468extern Int VGOFF_(helper_shldw);
1469extern Int VGOFF_(helper_shrdl);
1470extern Int VGOFF_(helper_shrdw);
1471
1472extern Int VGOFF_(helper_RDTSC);
1473extern Int VGOFF_(helper_CPUID);
1474
sewardjde4a1d02002-03-22 01:27:54 +00001475extern Int VGOFF_(helper_bsf);
1476extern Int VGOFF_(helper_bsr);
1477
1478extern Int VGOFF_(helper_fstsw_AX);
1479extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001480extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001481extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001482
sewardjde4a1d02002-03-22 01:27:54 +00001483extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
sewardjde4a1d02002-03-22 01:27:54 +00001484
njn25e49d8e72002-09-23 09:36:25 +00001485/* For storing extension-specific helpers, determined at runtime. The addr
1486 * and offset arrays together form a (addr, offset) map that allows a
1487 * helper's baseBlock offset to be computed from its address. It's done
1488 * like this so CCALL_M_Ns and other helper calls can use the function
1489 * address rather than having to much around with offsets. */
1490extern UInt VG_(n_compact_helpers);
1491extern UInt VG_(n_noncompact_helpers);
1492
1493extern Addr VG_(compact_helper_addrs) [];
1494extern Int VG_(compact_helper_offsets)[];
1495
1496extern Addr VG_(noncompact_helper_addrs) [];
1497extern Int VG_(noncompact_helper_offsets)[];
1498
sewardjf220ccc2002-10-23 21:53:49 +00001499#define VGL_(x) vgIntercept_##x
sewardjde4a1d02002-03-22 01:27:54 +00001500
1501#endif /* ndef __VG_INCLUDE_H */
1502
sewardj3b2736a2002-03-24 12:18:35 +00001503
1504/* ---------------------------------------------------------------------
1505 Finally - autoconf-generated settings
1506 ------------------------------------------------------------------ */
1507
1508#include "config.h"
1509
sewardjde4a1d02002-03-22 01:27:54 +00001510/*--------------------------------------------------------------------*/
1511/*--- end vg_include.h ---*/
1512/*--------------------------------------------------------------------*/