blob: d1cfca053b3e84d89fe7ac82bf31f560412a75a3 [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
3/*--- A header file for all parts of Valgrind. ---*/
4/*--- Include no other! ---*/
5/*--- vg_include.h ---*/
6/*--------------------------------------------------------------------*/
7
8/*
9 This file is part of Valgrind, an x86 protected-mode emulator
10 designed for debugging and profiling binaries on x86-Unixes.
11
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
30 The GNU General Public License is contained in the file LICENSE.
31*/
32
33#ifndef __VG_INCLUDE_H
34#define __VG_INCLUDE_H
35
36
37#include <stdarg.h> /* ANSI varargs stuff */
38#include <setjmp.h> /* for jmp_buf */
39
40
41/* ---------------------------------------------------------------------
42 Build options and table sizes. You should be able to change these
43 options or sizes, recompile, and still have a working system.
44 ------------------------------------------------------------------ */
45
46#include "vg_constants.h"
47
48
49/* Set to 1 to enable time profiling. Since this uses SIGPROF, we
50 don't want this permanently enabled -- only for profiling
51 builds. */
52#if 0
53# define VG_PROFILE
54#endif
55
56
57/* Total number of integer registers available for allocation. That's
58 all of them except %esp, %edi and %ebp. %edi is a general spare
59 temporary. %ebp permanently points at VG_(baseBlock). Note that
60 it's important that this tie in with what rankToRealRegNo() says.
61 DO NOT CHANGE THIS VALUE FROM 5. ! */
62#define VG_MAX_REALREGS 5
63
64/* Total number of spill slots available for allocation, if a TempReg
65 doesn't make it into a RealReg. Just bomb the entire system if
66 this value is too small; we don't expect it will ever get
67 particularly high. */
68#define VG_MAX_SPILLSLOTS 24
69
70
71/* Constants for the slow translation lookup cache. */
72#define VG_TRANSTAB_SLOW_BITS 11
73#define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS)
74#define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1)
75
76/* Size of a buffer used for creating messages. */
77#define M_VG_MSGBUF 10000
78
79/* Size of a smallish table used to read /proc/self/map entries. */
sewardjebc82332002-04-24 14:44:23 +000080#define M_PROCMAP_BUF 50000
sewardjde4a1d02002-03-22 01:27:54 +000081
82/* Max length of pathname to a .so/executable file. */
83#define M_VG_LIBNAMESTR 100
84
85/* Max length of a text fragment used to construct error messages. */
86#define M_VG_ERRTXT 512
87
88/* Max length of the string copied from env var VG_ARGS at startup. */
89#define M_VG_CMDLINE_STRLEN 1000
90
91/* Max number of options for Valgrind which we can handle. */
92#define M_VG_CMDLINE_OPTS 100
93
94/* After this many different unsuppressed errors have been observed,
95 be more conservative about collecting new ones. */
96#define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50
97
98/* After this many different unsuppressed errors have been observed,
99 stop collecting errors at all, and tell the user their program is
100 evidently a steaming pile of camel dung. */
sewardj1bebcbf2002-04-24 21:24:18 +0000101#define M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN 300
sewardjf2537be2002-04-24 21:03:47 +0000102
103/* After this many total errors have been observed, stop collecting
104 errors at all. Counterpart to M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN. */
sewardj1bebcbf2002-04-24 21:24:18 +0000105#define M_VG_COLLECT_NO_ERRORS_AFTER_FOUND 30000
sewardjde4a1d02002-03-22 01:27:54 +0000106
107/* These many bytes below %ESP are considered addressible if we're
108 doing the --workaround-gcc296-bugs hack. */
sewardjb581a132002-05-08 00:32:50 +0000109#define VG_GCC296_BUG_STACK_SLOP 1024
sewardjde4a1d02002-03-22 01:27:54 +0000110
111/* The maximum number of calls we're prepared to save in a
112 backtrace. */
113#define VG_DEEPEST_BACKTRACE 50
114
115/* Number of lists in which we keep track of malloc'd but not free'd
116 blocks. Should be prime. */
117#define VG_N_MALLOCLISTS 997
118
119/* Number of lists in which we keep track of ExeContexts. Should be
120 prime. */
121#define VG_N_EC_LISTS /*997*/ 4999
122
sewardj2e93c502002-04-12 11:12:52 +0000123/* Defines the thread-scheduling timeslice, in terms of the number of
124 basic blocks we attempt to run each thread for. Smaller values
125 give finer interleaving but much increased scheduling overheads. */
sewardjd8091eb2002-04-24 02:19:36 +0000126#define VG_SCHEDULING_QUANTUM 20000
sewardj2e93c502002-04-12 11:12:52 +0000127
128/* The maximum number of pthreads that we support. This is
129 deliberately not very high since our implementation of some of the
sewardj5f07b662002-04-23 16:52:51 +0000130 scheduler algorithms is surely O(N) in the number of threads, since
131 that's simple, at least. And (in practice) we hope that most
sewardj2e93c502002-04-12 11:12:52 +0000132 programs do not need many threads. */
sewardjebc82332002-04-24 14:44:23 +0000133#define VG_N_THREADS 50
sewardj5f07b662002-04-23 16:52:51 +0000134
135/* Maximum number of pthread keys available. Again, we start low until
136 the need for a higher number presents itself. */
137#define VG_N_THREAD_KEYS 10
sewardj2e93c502002-04-12 11:12:52 +0000138
139/* Number of file descriptors that can simultaneously be waited on for
140 I/O to complete. Perhaps this should be the same as VG_N_THREADS
141 (surely a thread can't wait on more than one fd at once?. Who
142 knows.) */
143#define VG_N_WAITING_FDS 10
144
sewardjbf290b92002-05-01 02:28:01 +0000145/* Stack size for a thread. We try and check that they do not go
146 beyond it. */
147#define VG_PTHREAD_STACK_SIZE 65536
148
sewardjde4a1d02002-03-22 01:27:54 +0000149
150/* ---------------------------------------------------------------------
151 Basic types
152 ------------------------------------------------------------------ */
153
154typedef unsigned char UChar;
155typedef unsigned short UShort;
156typedef unsigned int UInt;
157typedef unsigned long long int ULong;
158
159typedef signed char Char;
160typedef signed short Short;
161typedef signed int Int;
162typedef signed long long int Long;
163
164typedef unsigned int Addr;
165
166typedef unsigned char Bool;
167#define False ((Bool)0)
168#define True ((Bool)1)
169
170#define mycat_wrk(aaa,bbb) aaa##bbb
171#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
172
173/* Just pray that gcc's constant folding works properly ... */
174#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
175 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
176 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
177
178
179/* ---------------------------------------------------------------------
180 Now the basic types are set up, we can haul in the kernel-interface
181 definitions.
182 ------------------------------------------------------------------ */
183
184#include "./vg_kerneliface.h"
185
186
187/* ---------------------------------------------------------------------
188 Command-line-settable options
189 ------------------------------------------------------------------ */
190
191#define VG_CLO_SMC_NONE 0
192#define VG_CLO_SMC_SOME 1
193#define VG_CLO_SMC_ALL 2
194
195#define VG_CLO_MAX_SFILES 10
196
sewardj97ced732002-03-25 00:07:36 +0000197/* Shall we V-check addrs (they are always A checked too): default: YES */
198extern Bool VG_(clo_check_addrVs);
sewardjde4a1d02002-03-22 01:27:54 +0000199/* Enquire about whether to attach to GDB at errors? default: NO */
200extern Bool VG_(clo_GDB_attach);
201/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
202extern Int VG_(sanity_level);
203/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
204extern Int VG_(clo_verbosity);
205/* Automatically attempt to demangle C++ names? default: YES */
206extern Bool VG_(clo_demangle);
207/* Do leak check at exit? default: NO */
208extern Bool VG_(clo_leak_check);
209/* In leak check, show reachable-but-not-freed blocks? default: NO */
210extern Bool VG_(clo_show_reachable);
211/* How closely should we compare ExeContexts in leak records? default: 2 */
212extern Int VG_(clo_leak_resolution);
213/* Round malloc sizes upwards to integral number of words? default:
214 NO */
215extern Bool VG_(clo_sloppy_malloc);
216/* Allow loads from partially-valid addresses? default: YES */
217extern Bool VG_(clo_partial_loads_ok);
218/* Simulate child processes? default: NO */
219extern Bool VG_(clo_trace_children);
220/* The file id on which we send all messages. default: 2 (stderr). */
221extern Int VG_(clo_logfile_fd);
222/* Max volume of the freed blocks queue. */
223extern Int VG_(clo_freelist_vol);
224/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
225 default: NO */
226extern Bool VG_(clo_workaround_gcc296_bugs);
227
228/* The number of suppression files specified. */
229extern Int VG_(clo_n_suppressions);
230/* The names of the suppression files. */
231extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
232
233/* Single stepping? default: NO */
234extern Bool VG_(clo_single_step);
235/* Code improvement? default: YES */
236extern Bool VG_(clo_optimise);
237/* Memory-check instrumentation? default: YES */
238extern Bool VG_(clo_instrument);
239/* DEBUG: clean up instrumented code? default: YES */
240extern Bool VG_(clo_cleanup);
njn4f9c9342002-04-29 16:03:24 +0000241/* Cache simulation instrumentation? default: NO */
242extern Bool VG_(clo_cachesim);
sewardjde4a1d02002-03-22 01:27:54 +0000243/* SMC write checks? default: SOME (1,2,4 byte movs to mem) */
244extern Int VG_(clo_smc_check);
245/* DEBUG: print system calls? default: NO */
246extern Bool VG_(clo_trace_syscalls);
247/* DEBUG: print signal details? default: NO */
248extern Bool VG_(clo_trace_signals);
249/* DEBUG: print symtab details? default: NO */
250extern Bool VG_(clo_trace_symtab);
251/* DEBUG: print malloc details? default: NO */
252extern Bool VG_(clo_trace_malloc);
sewardj8937c812002-04-12 20:12:20 +0000253/* DEBUG: print thread scheduling events? default: NO */
254extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000255/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
256 (some), 2 (all) */
257extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000258/* Stop after this many basic blocks. default: Infinity. */
259extern ULong VG_(clo_stop_after);
260/* Display gory details for the k'th most popular error. default:
261 Infinity. */
262extern Int VG_(clo_dump_error);
263/* Number of parents of a backtrace. Default: 8. */
264extern Int VG_(clo_backtrace_size);
sewardj3984b852002-05-12 03:00:17 +0000265/* Engage miscellaneous wierd hacks needed for some progs. */
sewardj8d365b52002-05-12 10:52:16 +0000266extern Char* VG_(clo_weird_hacks);
sewardjde4a1d02002-03-22 01:27:54 +0000267
268
269/* ---------------------------------------------------------------------
270 Debugging and profiling stuff
271 ------------------------------------------------------------------ */
272
273/* No, really. I _am_ that strange. */
274#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
275
276/* Tools for building messages from multiple parts. */
277typedef
278 enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg }
279 VgMsgKind;
280
281extern void VG_(start_msg) ( VgMsgKind kind );
282extern void VG_(add_to_msg) ( Char* format, ... );
283extern void VG_(end_msg) ( void );
284
285/* Send a simple, single-part message. */
286extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
287
288/* Create a logfile into which messages can be dumped. */
289extern void VG_(startup_logging) ( void );
290extern void VG_(shutdown_logging) ( void );
291
292
293/* Profiling stuff */
294#ifdef VG_PROFILE
295
296#define VGP_M_STACK 10
297
sewardj671ff542002-05-07 09:25:30 +0000298#define VGP_M_CCS 26 /* == the # of elems in VGP_LIST */
sewardjde4a1d02002-03-22 01:27:54 +0000299#define VGP_LIST \
sewardj671ff542002-05-07 09:25:30 +0000300 VGP_PAIR(VgpUnc=0, "unclassified"), \
301 VGP_PAIR(VgpRun, "running"), \
302 VGP_PAIR(VgpSched, "scheduler"), \
sewardjde4a1d02002-03-22 01:27:54 +0000303 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
304 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
305 VGP_PAIR(VgpTranslate, "translate-main"), \
306 VGP_PAIR(VgpToUCode, "to-ucode"), \
307 VGP_PAIR(VgpFromUcode, "from-ucode"), \
308 VGP_PAIR(VgpImprove, "improve"), \
309 VGP_PAIR(VgpInstrument, "instrument"), \
310 VGP_PAIR(VgpCleanup, "cleanup"), \
311 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
312 VGP_PAIR(VgpDoLRU, "do-lru"), \
313 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
314 VGP_PAIR(VgpInitAudit, "init-mem-audit"), \
315 VGP_PAIR(VgpExeContext, "exe-context"), \
316 VGP_PAIR(VgpReadSyms, "read-syms"), \
317 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
318 VGP_PAIR(VgpSARP, "set-addr-range-perms"), \
319 VGP_PAIR(VgpSyscall, "syscall wrapper"), \
njn4f9c9342002-04-29 16:03:24 +0000320 VGP_PAIR(VgpCacheInstrument, "cache instrument"), \
321 VGP_PAIR(VgpCacheGetBBCC,"cache get BBCC"), \
322 VGP_PAIR(VgpCacheSimulate, "cache simulate"), \
323 VGP_PAIR(VgpCacheDump, "cache stats dump"), \
sewardjde4a1d02002-03-22 01:27:54 +0000324 VGP_PAIR(VgpSpare1, "spare 1"), \
325 VGP_PAIR(VgpSpare2, "spare 2")
326
327#define VGP_PAIR(enumname,str) enumname
328typedef enum { VGP_LIST } VgpCC;
329#undef VGP_PAIR
330
331extern void VGP_(init_profiling) ( void );
332extern void VGP_(done_profiling) ( void );
333extern void VGP_(pushcc) ( VgpCC );
334extern void VGP_(popcc) ( void );
335
336#define VGP_PUSHCC(cc) VGP_(pushcc)(cc)
337#define VGP_POPCC VGP_(popcc)()
338
339#else
340
341#define VGP_PUSHCC(cc) /* */
342#define VGP_POPCC /* */
343
344#endif /* VG_PROFILE */
345
346
347/* ---------------------------------------------------------------------
348 Exports of vg_malloc2.c
349 ------------------------------------------------------------------ */
350
351/* Allocation arenas.
352 SYMTAB is for Valgrind's symbol table storage.
353 CLIENT is for the client's mallocs/frees.
354 DEMANGLE is for the C++ demangler.
355 EXECTXT is for storing ExeContexts.
356 ERRCTXT is for storing ErrContexts.
357 PRIVATE is for Valgrind general stuff.
358 TRANSIENT is for very short-term use. It should be empty
359 in between uses.
360 When adding a new arena, remember also to add it
361 to ensure_mm_init().
362*/
363typedef Int ArenaId;
364
365#define VG_N_ARENAS 7
366
367#define VG_AR_PRIVATE 0 /* :: ArenaId */
368#define VG_AR_SYMTAB 1 /* :: ArenaId */
369#define VG_AR_CLIENT 2 /* :: ArenaId */
370#define VG_AR_DEMANGLE 3 /* :: ArenaId */
371#define VG_AR_EXECTXT 4 /* :: ArenaId */
372#define VG_AR_ERRCTXT 5 /* :: ArenaId */
373#define VG_AR_TRANSIENT 6 /* :: ArenaId */
374
375extern void* VG_(malloc) ( ArenaId arena, Int nbytes );
376extern void VG_(free) ( ArenaId arena, void* ptr );
377extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes );
378extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size );
379extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB,
380 Int req_pszB );
381
382extern void VG_(mallocSanityCheckArena) ( ArenaId arena );
383extern void VG_(mallocSanityCheckAll) ( void );
384
385extern void VG_(show_all_arena_stats) ( void );
386extern Bool VG_(is_empty_arena) ( ArenaId aid );
387
388
389/* The red-zone size for the client. This can be arbitrary, but
390 unfortunately must be set at compile time. */
391#define VG_AR_CLIENT_REDZONE_SZW 4
392
393#define VG_AR_CLIENT_REDZONE_SZB \
394 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
395
396
397/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000398 Exports of vg_clientfuns.c
399 ------------------------------------------------------------------ */
400
401/* This doesn't export code or data that valgrind.so needs to link
402 against. However, the scheduler does need to know the following
403 request codes. A few, publically-visible, request codes are also
404 defined in valgrind.h. */
405
406#define VG_USERREQ__MALLOC 0x2001
407#define VG_USERREQ__BUILTIN_NEW 0x2002
408#define VG_USERREQ__BUILTIN_VEC_NEW 0x2003
409
410#define VG_USERREQ__FREE 0x2004
411#define VG_USERREQ__BUILTIN_DELETE 0x2005
412#define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006
413
414#define VG_USERREQ__CALLOC 0x2007
415#define VG_USERREQ__REALLOC 0x2008
416#define VG_USERREQ__MEMALIGN 0x2009
417
418
419#define VG_USERREQ__PTHREAD_CREATE 0x3001
sewardjbc5b99f2002-04-13 00:08:51 +0000420#define VG_USERREQ__PTHREAD_JOIN 0x3002
421#define VG_USERREQ__PTHREAD_GET_THREADID 0x3003
sewardj3b5d8862002-04-20 13:53:23 +0000422#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x3004
sewardj30671ff2002-04-21 00:13:57 +0000423#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x3005
424#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x3006
425#define VG_USERREQ__PTHREAD_CANCEL 0x3007
426#define VG_USERREQ__PTHREAD_EXIT 0x3008
427#define VG_USERREQ__PTHREAD_COND_WAIT 0x3009
sewardj5f07b662002-04-23 16:52:51 +0000428#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x300A
429#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x300B
430#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x300C
431#define VG_USERREQ__PTHREAD_KEY_CREATE 0x300D
432#define VG_USERREQ__PTHREAD_KEY_DELETE 0x300E
433#define VG_USERREQ__PTHREAD_SETSPECIFIC 0x300F
434#define VG_USERREQ__PTHREAD_GETSPECIFIC 0x3010
sewardj56fc53d2002-04-24 01:17:42 +0000435#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3011
sewardjb48e5002002-05-13 00:16:03 +0000436#define VG_USERREQ__PTHREAD_SIGMASK 0x3012
437#define VG_USERREQ__SIGWAIT 0x3013
sewardj2e93c502002-04-12 11:12:52 +0000438
sewardj45b4b372002-04-16 22:50:32 +0000439/* Cosmetic ... */
440#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
441
sewardj54cacf02002-04-12 23:24:59 +0000442/*
443In vg_constants.h:
444#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardjbc5b99f2002-04-13 00:08:51 +0000445#define VG_USERREQ__PTHREAD_RETURNS 0x4002
sewardj54cacf02002-04-12 23:24:59 +0000446*/
447
448
sewardj2e93c502002-04-12 11:12:52 +0000449/* ---------------------------------------------------------------------
450 Constants pertaining to the simulated CPU state, VG_(baseBlock),
451 which need to go here to avoid ugly circularities.
452 ------------------------------------------------------------------ */
453
454/* How big is the saved FPU state? */
455#define VG_SIZE_OF_FPUSTATE 108
456/* ... and in words ... */
457#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
458
459
460/* ---------------------------------------------------------------------
461 Exports of vg_scheduler.c
462 ------------------------------------------------------------------ */
463
464/* ThreadIds are simply indices into the vg_threads[] array. */
465typedef
466 UInt
467 ThreadId;
468
sewardj6072c362002-04-19 14:40:57 +0000469/* Special magic value for an invalid ThreadId. It corresponds to
470 LinuxThreads using zero as the initial value for
471 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
472#define VG_INVALID_THREADID ((ThreadId)(0))
sewardj2e93c502002-04-12 11:12:52 +0000473
474typedef
475 enum {
476 VgTs_Empty, /* this slot is not in use */
477 VgTs_Runnable, /* waiting to be scheduled */
478 VgTs_WaitJoiner, /* waiting for someone to do join on me */
479 VgTs_WaitJoinee, /* waiting for the thread I did join on */
480 VgTs_WaitFD, /* waiting for I/O completion on a fd */
481 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000482 VgTs_WaitCV, /* waiting on a condition variable */
sewardjb48e5002002-05-13 00:16:03 +0000483 VgTs_WaitSIG, /* waiting due to sigwait() */
sewardj2e93c502002-04-12 11:12:52 +0000484 VgTs_Sleeping /* sleeping for a while */
485 }
486 ThreadStatus;
487
488typedef
489 struct {
sewardj6072c362002-04-19 14:40:57 +0000490 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
491 The thread identity is simply the index in vg_threads[].
492 ThreadId == 1 is the root thread and has the special property
sewardj1e8cdc92002-04-18 11:37:52 +0000493 that we don't try and allocate or deallocate its stack. For
494 convenience of generating error message, we also put the
495 ThreadId in this tid field, but be aware that it should
sewardj604ec3c2002-04-18 22:38:41 +0000496 ALWAYS == the index in vg_threads[]. */
sewardj1e8cdc92002-04-18 11:37:52 +0000497 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000498
sewardj5f07b662002-04-23 16:52:51 +0000499 /* Current scheduling status.
500
501 Complications: whenever this is set to VgTs_WaitMX, you
502 should also set .m_edx to whatever the required return value
503 is for pthread_mutex_lock / pthread_cond_timedwait for when
504 the mutex finally gets unblocked. */
sewardj2e93c502002-04-12 11:12:52 +0000505 ThreadStatus status;
506
507 /* Identity of joiner (thread who called join on me), or
508 VG_INVALID_THREADID if no one asked to join yet. */
509 ThreadId joiner;
510
sewardj3b5d8862002-04-20 13:53:23 +0000511 /* When .status == WaitMX, points to the mutex I am waiting for.
512 When .status == WaitCV, points to the mutex associated with
513 the condition variable indicated by the .associated_cv field.
514 In all other cases, should be NULL. */
515 void* /* pthread_mutex_t* */ associated_mx;
516
517 /* When .status == WaitCV, points to the condition variable I am
518 waiting for. In all other cases, should be NULL. */
519 void* /* pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000520
sewardj5f07b662002-04-23 16:52:51 +0000521 /* If VgTs_Sleeping, this is when we should wake up, measured in
522 milliseconds as supplied by VG_(read_millisecond_counter).
523
524 If VgTs_WaitCV, this indicates the time at which
525 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
526 this means infinitely far in the future, viz,
527 pthread_cond_wait. */
528 UInt awaken_at;
sewardj2e93c502002-04-12 11:12:52 +0000529
530 /* return value */
531 void* retval;
532
sewardj5f07b662002-04-23 16:52:51 +0000533 /* thread-specific data */
534 void* specifics[VG_N_THREAD_KEYS];
535
sewardjb48e5002002-05-13 00:16:03 +0000536 /* This thread's blocked-signals mask. Semantics is that for a
537 signal to be delivered to this thread, the signal must not be
538 blocked by either the process-wide signal mask nor by this
539 one. So, if this thread is prepared to handle any signal that
540 the process as a whole is prepared to handle, this mask should
541 be made empty -- and that it is its default, starting
542 state. */
543 vki_ksigset_t sig_mask;
544
545 /* When not VgTs_WaitSIG, has no meaning. When VgTs_WaitSIG,
546 is the set of signals for which we are sigwait()ing. */
547 vki_ksigset_t sigs_waited_for;
548
sewardj2e93c502002-04-12 11:12:52 +0000549 /* Stacks. When a thread slot is freed, we don't deallocate its
550 stack; we just leave it lying around for the next use of the
551 slot. If the next use of the slot requires a larger stack,
552 only then is the old one deallocated and a new one
553 allocated.
554
555 For the main thread (threadid == 0), this mechanism doesn't
556 apply. We don't know the size of the stack since we didn't
557 allocate it, and furthermore we never reallocate it. */
558
559 /* The allocated size of this thread's stack (permanently zero
560 if this is ThreadId == 0, since we didn't allocate its stack) */
561 UInt stack_size;
562
563 /* Address of the lowest word in this thread's stack. NULL means
564 not allocated yet.
565 */
566 Addr stack_base;
567
sewardj1e8cdc92002-04-18 11:37:52 +0000568 /* Address of the highest legitimate word in this stack. This is
569 used for error messages only -- not critical for execution
570 correctness. Is is set for all stacks, specifically including
571 ThreadId == 0 (the main thread). */
572 Addr stack_highest_word;
573
sewardj2e93c502002-04-12 11:12:52 +0000574 /* Saved machine context. */
575 UInt m_eax;
576 UInt m_ebx;
577 UInt m_ecx;
578 UInt m_edx;
579 UInt m_esi;
580 UInt m_edi;
581 UInt m_ebp;
582 UInt m_esp;
583 UInt m_eflags;
584 UInt m_eip;
585 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
586
587 UInt sh_eax;
588 UInt sh_ebx;
589 UInt sh_ecx;
590 UInt sh_edx;
591 UInt sh_esi;
592 UInt sh_edi;
593 UInt sh_ebp;
594 UInt sh_esp;
595 UInt sh_eflags;
596 }
597 ThreadState;
598
599
sewardjb48e5002002-05-13 00:16:03 +0000600/* Trivial range check on tid. */
601extern Bool VG_(is_valid_tid) ( ThreadId tid );
602
sewardj2e93c502002-04-12 11:12:52 +0000603/* Copy the specified thread's state into VG_(baseBlock) in
604 preparation for running it. */
605extern void VG_(load_thread_state)( ThreadId );
606
607/* Save the specified thread's state back in VG_(baseBlock), and fill
608 VG_(baseBlock) with junk, for sanity-check reasons. */
609extern void VG_(save_thread_state)( ThreadId );
610
611/* Get the thread state block for the specified thread. */
612extern ThreadState* VG_(get_thread_state)( ThreadId );
sewardjb48e5002002-05-13 00:16:03 +0000613extern ThreadState* VG_(get_thread_state_UNCHECKED)( ThreadId );
sewardj2e93c502002-04-12 11:12:52 +0000614
sewardj1e8cdc92002-04-18 11:37:52 +0000615/* And for the currently running one, if valid. */
616extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000617
sewardj1e8cdc92002-04-18 11:37:52 +0000618/* Similarly ... */
619extern ThreadId VG_(get_current_tid) ( void );
620
621/* Which thread is this address in the stack of, if any? Used for
622 error message generation. */
623extern ThreadId VG_(identify_stack_addr)( Addr a );
624
sewardj2e93c502002-04-12 11:12:52 +0000625
626/* Return codes from the scheduler. */
627typedef
sewardj7e87e382002-05-03 19:09:05 +0000628 enum {
629 VgSrc_Deadlock, /* no runnable threads and no prospect of any
630 even if we wait for a long time */
631 VgSrc_ExitSyscall, /* client called exit(). This is the normal
632 route out. */
633 VgSrc_BbsDone /* In a debugging run, the specified number of
634 bbs has been completed. */
635 }
sewardj2e93c502002-04-12 11:12:52 +0000636 VgSchedReturnCode;
637
sewardj7e87e382002-05-03 19:09:05 +0000638
sewardj2e93c502002-04-12 11:12:52 +0000639/* The scheduler. */
640extern VgSchedReturnCode VG_(scheduler) ( void );
641
642extern void VG_(scheduler_init) ( void );
643
sewardj15a43e12002-04-17 19:35:12 +0000644extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000645
646/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
647extern jmp_buf VG_(scheduler_jmpbuf);
648/* ... and if so, here's the signal which caused it to do so. */
649extern Int VG_(longjmpd_on_signal);
650
651
sewardja1679dd2002-05-10 22:31:40 +0000652/* Possible places where the main stack might be based. We check that
653 the initial stack, which we can't move, is allocated here.
654 VG_(scheduler_init) checks this. Andrea Archelangi's 2.4 kernels
655 have been rumoured to start stacks at 0x80000000, so that too is
656 considered.
sewardj2e93c502002-04-12 11:12:52 +0000657*/
sewardja1679dd2002-05-10 22:31:40 +0000658#define VG_STARTUP_STACK_BASE_1 (Addr)0xC0000000
659#define VG_STARTUP_STACK_BASE_2 (Addr)0x80000000
660#define VG_STARTUP_STACK_SMALLERTHAN 0x100000 /* 1024k */
661
662#define VG_STACK_MATCHES_BASE(zzstack, zzbase) \
663 ( \
664 ((zzstack) & ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN)) \
665 == \
666 ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN) \
667 )
sewardj2e93c502002-04-12 11:12:52 +0000668
669
670/* The red-zone size which we put at the bottom (highest address) of
671 thread stacks, for paranoia reasons. This can be arbitrary, and
672 doesn't really need to be set at compile time. */
673#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
674
675#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
676 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
677
678
679
680/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000681 Exports of vg_signals.c
682 ------------------------------------------------------------------ */
683
sewardjde4a1d02002-03-22 01:27:54 +0000684extern void VG_(sigstartup_actions) ( void );
685
sewardjb48e5002002-05-13 00:16:03 +0000686extern Bool VG_(deliver_signals) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000687extern void VG_(unblock_host_signal) ( Int sigNo );
sewardjb48e5002002-05-13 00:16:03 +0000688extern void VG_(notify_signal_machinery_of_thread_exit) ( ThreadId tid );
689extern void VG_(update_sigstate_following_WaitSIG_change) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000690
691/* Fake system calls for signal handling. */
sewardj2e93c502002-04-12 11:12:52 +0000692extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +0000693extern void VG_(do__NR_sigprocmask) ( Int how, vki_ksigset_t* set );
694
sewardj2e93c502002-04-12 11:12:52 +0000695/* Modify the current thread's state once we have detected it is
696 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +0000697extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000698
sewardj2e93c502002-04-12 11:12:52 +0000699/* Handy utilities to block/restore all host signals. */
700extern void VG_(block_all_host_signals)
701 ( /* OUT */ vki_ksigset_t* saved_mask );
702extern void VG_(restore_host_signals)
703 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000704
705/* ---------------------------------------------------------------------
706 Exports of vg_mylibc.c
707 ------------------------------------------------------------------ */
708
709
sewardjfbe18b92002-05-10 00:46:59 +0000710#if !defined(NULL)
711# define NULL ((void*)0)
712#endif
sewardjde4a1d02002-03-22 01:27:54 +0000713
714extern void VG_(exit)( Int status )
715 __attribute__ ((__noreturn__));
716
717extern void VG_(printf) ( const char *format, ... );
718/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
719
720extern void VG_(sprintf) ( Char* buf, Char *format, ... );
721
722extern void VG_(vprintf) ( void(*send)(Char),
723 const Char *format, va_list vargs );
724
725extern Bool VG_(isspace) ( Char c );
726
727extern Int VG_(strlen) ( const Char* str );
728
729extern Long VG_(atoll) ( Char* str );
730
731extern Char* VG_(strcat) ( Char* dest, const Char* src );
732extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
733extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
734
735extern Char* VG_(strcpy) ( Char* dest, const Char* src );
736
737extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
738extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
739
740extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
741extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
742
743extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
744extern Char* VG_(strchr) ( const Char* s, Char c );
745extern Char* VG_(strdup) ( ArenaId aid, const Char* s);
746
747extern Char* VG_(getenv) ( Char* name );
748extern Int VG_(getpid) ( void );
sewardj5f07b662002-04-23 16:52:51 +0000749
750extern void VG_(start_rdtsc_calibration) ( void );
751extern void VG_(end_rdtsc_calibration) ( void );
752extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000753
754
755extern Char VG_(toupper) ( Char c );
756
757extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
758
759extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
760
761extern Bool VG_(stringMatch) ( Char* pat, Char* str );
762
763
764#define __STRING(x) #x
765
766/* Asserts are permanently enabled. Hurrah! */
767#define vg_assert(expr) \
768 ((void) ((expr) ? 0 : \
769 (VG_(assert_fail) (__STRING(expr), \
770 __FILE__, __LINE__, \
771 __PRETTY_FUNCTION__), 0)))
772
773extern void VG_(assert_fail) ( Char* expr, Char* file,
774 Int line, Char* fn )
775 __attribute__ ((__noreturn__));
776
njn4f9c9342002-04-29 16:03:24 +0000777/* Reading and writing files. */
sewardjde4a1d02002-03-22 01:27:54 +0000778extern Int VG_(open_read) ( Char* pathname );
njn4f9c9342002-04-29 16:03:24 +0000779extern Int VG_(open_write) ( Char* pathname );
780extern Int VG_(create_and_write) ( Char* pathname );
sewardjde4a1d02002-03-22 01:27:54 +0000781extern void VG_(close) ( Int fd );
782extern Int VG_(read) ( Int fd, void* buf, Int count);
783extern Int VG_(write) ( Int fd, void* buf, Int count);
sewardjb3586202002-05-09 17:38:13 +0000784extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
sewardjde4a1d02002-03-22 01:27:54 +0000785
sewardj2e93c502002-04-12 11:12:52 +0000786extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
787
788extern Int VG_(select)( Int n,
789 vki_fd_set* readfds,
790 vki_fd_set* writefds,
791 vki_fd_set* exceptfds,
792 struct vki_timeval * timeout );
793extern Int VG_(nanosleep)( const struct vki_timespec *req,
794 struct vki_timespec *rem );
795
796
sewardjde4a1d02002-03-22 01:27:54 +0000797/* mmap-ery ... */
798extern void* VG_(mmap)( void* start, UInt length,
799 UInt prot, UInt flags, UInt fd, UInt offset );
800
sewardj2e93c502002-04-12 11:12:52 +0000801extern Int VG_(munmap)( void* start, Int length );
sewardjde4a1d02002-03-22 01:27:54 +0000802
sewardjb3586202002-05-09 17:38:13 +0000803extern void* VG_(brk) ( void* end_data_segment );
804
sewardjde4a1d02002-03-22 01:27:54 +0000805
806/* Print a (panic) message, and abort. */
807extern void VG_(panic) ( Char* str )
808 __attribute__ ((__noreturn__));
809
810/* Get memory by anonymous mmap. */
sewardje6a25242002-04-21 22:03:07 +0000811extern void* VG_(get_memory_from_mmap) ( Int nBytes );
812
813/* Crude stand-in for the glibc system() call. */
814extern Int VG_(system) ( Char* cmd );
815
sewardjde4a1d02002-03-22 01:27:54 +0000816
817/* Signal stuff. Note that these use the vk_ (kernel) structure
818 definitions, which are different in places from those that glibc
819 defines. Since we're operating right at the kernel interface,
820 glibc's view of the world is entirely irrelevant. */
sewardjb48e5002002-05-13 00:16:03 +0000821extern Int VG_(ksigfillset)( vki_ksigset_t* set );
822extern Int VG_(ksigemptyset)( vki_ksigset_t* set );
823extern Bool VG_(kisemptysigset)( vki_ksigset_t* set );
824extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum );
sewardjde4a1d02002-03-22 01:27:54 +0000825
826extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set,
827 vki_ksigset_t* oldset );
828extern Int VG_(ksigaction) ( Int signum,
829 const vki_ksigaction* act,
830 vki_ksigaction* oldact );
831extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
sewardjb48e5002002-05-13 00:16:03 +0000832extern void VG_(ksigaddset_from_set)( vki_ksigset_t* dst,
833 vki_ksigset_t* src );
834extern void VG_(ksigdelset_from_set)( vki_ksigset_t* dst,
835 vki_ksigset_t* src );
836
sewardjde4a1d02002-03-22 01:27:54 +0000837
838extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int));
839
840extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss );
841
842
843
844/* ---------------------------------------------------------------------
845 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
846 vg_from_ucode.c).
847 ------------------------------------------------------------------ */
848
849/* Tags which describe what operands are. */
850typedef
851 enum { TempReg=0, ArchReg=1, RealReg=2,
852 SpillNo=3, Literal=4, Lit16=5,
853 NoValue=6 }
854 Tag;
855
856
857/* Microinstruction opcodes. */
858typedef
859 enum {
860 NOP,
861 GET,
862 PUT,
863 LOAD,
864 STORE,
865 MOV,
866 CMOV, /* Used for cmpxchg and cmov */
867 WIDEN,
868 JMP,
869
870 /* Read/write the %EFLAGS register into a TempReg. */
871 GETF, PUTF,
872
873 ADD, ADC, AND, OR, XOR, SUB, SBB,
874 SHL, SHR, SAR, ROL, ROR, RCL, RCR,
875 NOT, NEG, INC, DEC, BSWAP,
876 CC2VAL,
877
878 /* Not strictly needed, but useful for making better
879 translations of address calculations. */
880 LEA1, /* reg2 := const + reg1 */
881 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
882
883 /* not for translating x86 calls -- only to call helpers */
884 CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences
885 for CALLM. */
886 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */
887 CALLM, /* call to a machine-code helper */
888
889 /* Hack for translating string (REP-) insns. Jump to literal if
890 TempReg/RealReg is zero. */
891 JIFZ,
892
893 /* FPU ops which read/write mem or don't touch mem at all. */
894 FPU_R,
895 FPU_W,
896 FPU,
897
898 /* Advance the simulated %eip by some small (< 128) number. */
899 INCEIP,
900
901 /* uinstrs which are not needed for mere translation of x86 code,
902 only for instrumentation of it. */
903 LOADV,
904 STOREV,
905 GETV,
906 PUTV,
907 TESTV,
908 SETV,
909 /* Get/set the v-bit (and it is only one bit) for the simulated
910 %eflags register. */
911 GETVF,
912 PUTVF,
913
914 /* Do a unary or binary tag op. Only for post-instrumented
915 code. For TAG1, first and only arg is a TempReg, and is both
916 arg and result reg. For TAG2, first arg is src, second is
917 dst, in the normal way; both are TempRegs. In both cases,
918 3rd arg is a RiCHelper with a Lit16 tag. This indicates
919 which tag op to do. */
920 TAG1,
921 TAG2
922 }
923 Opcode;
924
925
926/* Condition codes, observing the Intel encoding. CondAlways is an
927 extra. */
928typedef
929 enum {
930 CondO = 0, /* overflow */
931 CondNO = 1, /* no overflow */
932 CondB = 2, /* below */
933 CondNB = 3, /* not below */
934 CondZ = 4, /* zero */
935 CondNZ = 5, /* not zero */
936 CondBE = 6, /* below or equal */
937 CondNBE = 7, /* not below or equal */
938 CondS = 8, /* negative */
939 ConsNS = 9, /* not negative */
940 CondP = 10, /* parity even */
941 CondNP = 11, /* not parity even */
942 CondL = 12, /* jump less */
943 CondNL = 13, /* not less */
944 CondLE = 14, /* less or equal */
945 CondNLE = 15, /* not less or equal */
946 CondAlways = 16 /* Jump always */
947 }
948 Condcode;
949
950
sewardj2e93c502002-04-12 11:12:52 +0000951/* Descriptions of additional properties of *unconditional* jumps. */
952typedef
953 enum {
954 JmpBoring=0, /* boring unconditional jump */
955 JmpCall=1, /* jump due to an x86 call insn */
956 JmpRet=2, /* jump due to an x86 ret insn */
957 JmpSyscall=3, /* do a system call, then jump */
958 JmpClientReq=4 /* do a client request, then jump */
959 }
960 JmpKind;
961
962
sewardjde4a1d02002-03-22 01:27:54 +0000963/* Flags. User-level code can only read/write O(verflow), S(ign),
964 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
965 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
966 thusly:
967 76543210
968 DOSZACP
969 and bit 7 must always be zero since it is unused.
970*/
971typedef UChar FlagSet;
972
973#define FlagD (1<<6)
974#define FlagO (1<<5)
975#define FlagS (1<<4)
976#define FlagZ (1<<3)
977#define FlagA (1<<2)
978#define FlagC (1<<1)
979#define FlagP (1<<0)
980
981#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
982#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
983#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
984#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
985#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
986#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
sewardj4a7456e2002-03-24 13:52:19 +0000987#define FlagsZCP ( FlagZ | FlagC | FlagP)
sewardjde4a1d02002-03-22 01:27:54 +0000988#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000989#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000990
991#define FlagsALL (FlagsOSZACP | FlagD)
992#define FlagsEmpty (FlagSet)0
993
994#define VG_IS_FLAG_SUBSET(set1,set2) \
995 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
996
997#define VG_UNION_FLAG_SETS(set1,set2) \
998 ( ((FlagSet)set1) | ((FlagSet)set2) )
999
1000
1001
1002/* A Micro (u)-instruction. */
1003typedef
1004 struct {
1005 /* word 1 */
1006 UInt lit32; /* 32-bit literal */
1007
1008 /* word 2 */
1009 UShort val1; /* first operand */
1010 UShort val2; /* second operand */
1011
1012 /* word 3 */
1013 UShort val3; /* third operand */
1014 UChar opcode; /* opcode */
1015 UChar size; /* data transfer size */
1016
1017 /* word 4 */
1018 FlagSet flags_r; /* :: FlagSet */
1019 FlagSet flags_w; /* :: FlagSet */
1020 UChar tag1:4; /* first operand tag */
1021 UChar tag2:4; /* second operand tag */
1022 UChar tag3:4; /* third operand tag */
1023 UChar extra4b:4; /* Spare field, used by WIDEN for src
1024 -size, and by LEA2 for scale
njn4f9c9342002-04-29 16:03:24 +00001025 (1,2,4 or 8), and by unconditional JMPs for
1026 orig x86 instr size if --cachesim=yes */
1027
sewardjde4a1d02002-03-22 01:27:54 +00001028
1029 /* word 5 */
1030 UChar cond; /* condition, for jumps */
1031 Bool smc_check:1; /* do a smc test, if writes memory. */
1032 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
sewardj2e93c502002-04-12 11:12:52 +00001033 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
sewardjde4a1d02002-03-22 01:27:54 +00001034 }
1035 UInstr;
1036
1037
1038/* Expandable arrays of uinstrs. */
1039typedef
1040 struct {
1041 Int used;
1042 Int size;
1043 UInstr* instrs;
1044 Int nextTemp;
1045 }
1046 UCodeBlock;
1047
1048/* Refer to `the last instruction stuffed in', including as an
1049 lvalue. */
1050#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
1051
1052/* An invalid temporary number :-) */
1053#define INVALID_TEMPREG 999999999
1054
1055
1056/* ---------------------------------------------------------------------
1057 Exports of vg_demangle.c
1058 ------------------------------------------------------------------ */
1059
1060extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
1061
1062
1063/* ---------------------------------------------------------------------
1064 Exports of vg_from_ucode.c
1065 ------------------------------------------------------------------ */
1066
1067extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
1068
1069
1070/* ---------------------------------------------------------------------
1071 Exports of vg_to_ucode.c
1072 ------------------------------------------------------------------ */
1073
1074extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
1075extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
1076extern Char VG_(nameOfIntSize) ( Int size );
1077extern UInt VG_(extend_s_8to32) ( UInt x );
1078extern Int VG_(getNewTemp) ( UCodeBlock* cb );
1079extern Int VG_(getNewShadow) ( UCodeBlock* cb );
1080
1081#define SHADOW(tempreg) ((tempreg)+1)
1082
1083
1084/* ---------------------------------------------------------------------
1085 Exports of vg_translate.c
1086 ------------------------------------------------------------------ */
1087
sewardj1e8cdc92002-04-18 11:37:52 +00001088extern void VG_(translate) ( ThreadState* tst,
1089 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001090 UInt* orig_size,
1091 Addr* trans_addr,
1092 UInt* trans_size );
1093
1094extern void VG_(emptyUInstr) ( UInstr* u );
1095extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
1096extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
1097 Tag tag1, UInt val1 );
1098extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
1099 Tag tag1, UInt val1,
1100 Tag tag2, UInt val2 );
1101extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
1102 Tag tag1, UInt val1,
1103 Tag tag2, UInt val2,
1104 Tag tag3, UInt val3 );
1105extern void VG_(setFlagRW) ( UInstr* u,
1106 FlagSet fr, FlagSet fw );
1107
1108extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
1109extern Bool VG_(anyFlagUse) ( UInstr* u );
1110
1111
1112
1113extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
1114extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
1115
njn4f9c9342002-04-29 16:03:24 +00001116extern UCodeBlock* VG_(allocCodeBlock) ( void );
1117extern void VG_(freeCodeBlock) ( UCodeBlock* cb );
1118extern void VG_(copyUInstr) ( UCodeBlock* cb, UInstr* instr );
1119
sewardjde4a1d02002-03-22 01:27:54 +00001120extern Char* VG_(nameCondcode) ( Condcode cond );
1121extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
1122extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
1123extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
1124extern Int VG_(rankToRealRegNo) ( Int rank );
1125
1126extern void* VG_(jitmalloc) ( Int nbytes );
1127extern void VG_(jitfree) ( void* ptr );
1128
1129
1130/* ---------------------------------------------------------------------
1131 Exports of vg_execontext.c.
1132 ------------------------------------------------------------------ */
1133
1134/* Records the PC and a bit of the call chain. The first 4 %eip
1135 values are used in comparisons do remove duplicate errors, and for
1136 comparing against suppression specifications. The rest are purely
1137 informational (but often important). */
1138
1139typedef
1140 struct _ExeContextRec {
1141 struct _ExeContextRec * next;
1142 /* The size of this array is VG_(clo_backtrace_size); at least
1143 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1144 [1] is its caller, [2] is the caller of [1], etc. */
1145 Addr eips[0];
1146 }
1147 ExeContext;
1148
1149
1150/* Initialise the ExeContext storage mechanism. */
1151extern void VG_(init_ExeContext_storage) ( void );
1152
1153/* Print stats (informational only). */
1154extern void VG_(show_ExeContext_stats) ( void );
1155
1156
1157/* Take a snapshot of the client's stack. Search our collection of
1158 ExeContexts to see if we already have it, and if not, allocate a
1159 new one. Either way, return a pointer to the context. */
sewardj8c824512002-04-14 04:16:48 +00001160extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame,
1161 Addr eip, Addr ebp );
sewardjde4a1d02002-03-22 01:27:54 +00001162
1163/* Print an ExeContext. */
1164extern void VG_(pp_ExeContext) ( ExeContext* );
1165
1166/* Compare two ExeContexts, just comparing the top two callers. */
1167extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
1168
1169/* Compare two ExeContexts, just comparing the top four callers. */
1170extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
1171
1172/* Compare two ExeContexts, comparing all callers. */
1173extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
1174
1175
1176
1177/* ---------------------------------------------------------------------
1178 Exports of vg_errcontext.c.
1179 ------------------------------------------------------------------ */
1180
1181extern void VG_(load_suppressions) ( void );
1182extern void VG_(show_all_errors) ( void );
1183extern void VG_(record_value_error) ( Int size );
sewardjaabd5ad2002-04-19 15:43:37 +00001184extern void VG_(record_free_error) ( ThreadState* tst, Addr a );
1185extern void VG_(record_freemismatch_error) ( ThreadState* tst, Addr a );
sewardjde4a1d02002-03-22 01:27:54 +00001186extern void VG_(record_address_error) ( Addr a, Int size,
1187 Bool isWrite );
sewardj1e8cdc92002-04-18 11:37:52 +00001188
1189extern void VG_(record_jump_error) ( ThreadState* tst, Addr a );
sewardj8c824512002-04-14 04:16:48 +00001190
1191extern void VG_(record_param_err) ( ThreadState* tst,
1192 Addr a,
sewardjde4a1d02002-03-22 01:27:54 +00001193 Bool isWriteLack,
1194 Char* msg );
sewardj8c824512002-04-14 04:16:48 +00001195extern void VG_(record_user_err) ( ThreadState* tst,
1196 Addr a, Bool isWriteLack );
sewardjde4a1d02002-03-22 01:27:54 +00001197
1198
1199/* The classification of a faulting address. */
1200typedef
sewardjb581a132002-05-08 00:32:50 +00001201 enum { Undescribed, /* as-yet unclassified */
1202 Stack,
1203 Unknown, /* classification yielded nothing useful */
1204 Freed, Mallocd,
1205 UserG, UserS }
sewardjde4a1d02002-03-22 01:27:54 +00001206 AddrKind;
1207
1208/* Records info about a faulting address. */
1209typedef
1210 struct {
1211 /* ALL */
1212 AddrKind akind;
1213 /* Freed, Mallocd */
1214 Int blksize;
1215 /* Freed, Mallocd */
1216 Int rwoffset;
1217 /* Freed, Mallocd */
1218 ExeContext* lastchange;
sewardj1e8cdc92002-04-18 11:37:52 +00001219 /* Stack */
1220 ThreadId stack_tid;
sewardjb581a132002-05-08 00:32:50 +00001221 /* True if is just-below %esp -- could be a gcc bug. */
1222 Bool maybe_gcc;
sewardjde4a1d02002-03-22 01:27:54 +00001223 }
1224 AddrInfo;
1225
1226
1227/* ---------------------------------------------------------------------
1228 Exports of vg_clientperms.c
1229 ------------------------------------------------------------------ */
1230
1231extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
1232
sewardj8c824512002-04-14 04:16:48 +00001233extern UInt VG_(handle_client_request) ( ThreadState* tst, UInt* arg_block );
sewardjde4a1d02002-03-22 01:27:54 +00001234
1235extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
1236
1237extern void VG_(show_client_block_stats) ( void );
1238
1239
1240/* ---------------------------------------------------------------------
1241 Exports of vg_procselfmaps.c
1242 ------------------------------------------------------------------ */
1243
1244extern
1245void VG_(read_procselfmaps) (
1246 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
1247);
1248
1249
1250/* ---------------------------------------------------------------------
1251 Exports of vg_symtab2.c
1252 ------------------------------------------------------------------ */
1253
1254/* We assume the executable is loaded here ... can't really find
1255 out. There is a hacky sanity check in vg_init_memory_audit()
1256 which should trip up most stupidities.
1257*/
1258#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
1259
1260extern void VG_(read_symbols) ( void );
1261extern void VG_(mini_stack_dump) ( ExeContext* ec );
1262extern void VG_(what_obj_and_fun_is_this)
1263 ( Addr a,
1264 Char* obj_buf, Int n_obj_buf,
1265 Char* fun_buf, Int n_fun_buf );
njn4f9c9342002-04-29 16:03:24 +00001266extern Bool VG_(what_line_is_this) ( Addr a,
1267 UChar* filename, Int n_filename,
1268 UInt* lineno );
1269extern Bool VG_(what_fn_is_this) ( Bool no_demangle, Addr a,
1270 Char* fn_name, Int n_fn_name);
sewardjde4a1d02002-03-22 01:27:54 +00001271
1272extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
1273
1274
1275/* ---------------------------------------------------------------------
1276 Exports of vg_clientmalloc.c
1277 ------------------------------------------------------------------ */
1278
sewardjde4a1d02002-03-22 01:27:54 +00001279typedef
1280 enum {
1281 Vg_AllocMalloc = 0,
sewardj2e93c502002-04-12 11:12:52 +00001282 Vg_AllocNew = 1,
sewardjde4a1d02002-03-22 01:27:54 +00001283 Vg_AllocNewVec = 2
1284 }
1285 VgAllocKind;
1286
1287/* Description of a malloc'd chunk. */
1288typedef
1289 struct _ShadowChunk {
1290 struct _ShadowChunk* next;
1291 ExeContext* where; /* where malloc'd/free'd */
1292 UInt size : 30; /* size requested. */
1293 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1294 Addr data; /* ptr to actual block. */
1295 }
1296 ShadowChunk;
1297
1298extern void VG_(clientmalloc_done) ( void );
1299extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
1300extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1301
sewardj2e93c502002-04-12 11:12:52 +00001302/* These are called from the scheduler, when it intercepts a user
1303 request. */
sewardj8c824512002-04-14 04:16:48 +00001304extern void* VG_(client_malloc) ( ThreadState* tst,
1305 UInt size, VgAllocKind kind );
1306extern void* VG_(client_memalign) ( ThreadState* tst,
1307 UInt align, UInt size );
1308extern void VG_(client_free) ( ThreadState* tst,
1309 void* ptrV, VgAllocKind kind );
1310extern void* VG_(client_calloc) ( ThreadState* tst,
1311 UInt nmemb, UInt size1 );
1312extern void* VG_(client_realloc) ( ThreadState* tst,
1313 void* ptrV, UInt size_new );
sewardjde4a1d02002-03-22 01:27:54 +00001314
1315
1316/* ---------------------------------------------------------------------
1317 Exports of vg_main.c
1318 ------------------------------------------------------------------ */
1319
sewardjde4a1d02002-03-22 01:27:54 +00001320/* A structure used as an intermediary when passing the simulated
1321 CPU's state to some assembly fragments, particularly system calls.
1322 Stuff is copied from baseBlock to here, the assembly magic runs,
1323 and then the inverse copy is done. */
1324
1325extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
1326 + 1 /* %eflags */
1327 + 1 /* %eip */
1328 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1329 ];
1330
1331/* Handy fns for doing the copy back and forth. */
1332extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1333extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1334
sewardjde4a1d02002-03-22 01:27:54 +00001335/* Called when some unhandleable client behaviour is detected.
1336 Prints a msg and aborts. */
1337extern void VG_(unimplemented) ( Char* msg );
sewardjcfc39b22002-05-08 01:58:18 +00001338extern void VG_(nvidia_moan) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001339
1340/* The stack on which Valgrind runs. We can't use the same stack as the
1341 simulatee -- that's an important design decision. */
1342extern UInt VG_(stack)[10000];
1343
1344/* Similarly, we have to ask for signals to be delivered on an
1345 alternative stack, since it is possible, although unlikely, that
1346 we'll have to run client code from inside the Valgrind-installed
1347 signal handler. If this happens it will be done by
1348 vg_deliver_signal_immediately(). */
1349extern UInt VG_(sigstack)[10000];
1350
sewardjde4a1d02002-03-22 01:27:54 +00001351/* Holds client's %esp at the point we gained control. From this the
1352 client's argc, argv and envp are deduced. */
1353extern Addr VG_(esp_at_startup);
1354extern Int VG_(client_argc);
1355extern Char** VG_(client_argv);
1356extern Char** VG_(client_envp);
1357
1358/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
1359 don't get traced into. */
1360extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
1361
1362/* Something of a function looking for a home ... start up GDB. This
1363 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1364 *client's* stack. This is necessary to give GDB the illusion that
1365 the client program really was running on the real cpu. */
1366extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1367
1368/* Spew out vast amounts of junk during JITting? */
1369extern Bool VG_(disassemble);
1370
1371/* 64-bit counter for the number of basic blocks done. */
1372extern ULong VG_(bbs_done);
1373/* 64-bit counter for the number of bbs to go before a debug exit. */
1374extern ULong VG_(bbs_to_go);
1375
1376/* Counts downwards in vg_run_innerloop. */
1377extern UInt VG_(dispatch_ctr);
1378
sewardjde4a1d02002-03-22 01:27:54 +00001379/* Is the client running on the simulated CPU or the real one? */
1380extern Bool VG_(running_on_simd_CPU); /* Initially False */
1381
1382/* The current LRU epoch. */
1383extern UInt VG_(current_epoch);
1384
sewardj7e87e382002-05-03 19:09:05 +00001385/* This is the ThreadId of the last thread the scheduler ran. */
1386extern ThreadId VG_(last_run_tid);
1387
sewardjde4a1d02002-03-22 01:27:54 +00001388
1389/* --- Counters, for informational purposes only. --- */
1390
1391/* Number of lookups which miss the fast tt helper. */
1392extern UInt VG_(tt_fast_misses);
1393
1394/* Counts for LRU informational messages. */
1395
1396/* Number and total o/t size of new translations this epoch. */
1397extern UInt VG_(this_epoch_in_count);
1398extern UInt VG_(this_epoch_in_osize);
1399extern UInt VG_(this_epoch_in_tsize);
1400/* Number and total o/t size of discarded translations this epoch. */
1401extern UInt VG_(this_epoch_out_count);
1402extern UInt VG_(this_epoch_out_osize);
1403extern UInt VG_(this_epoch_out_tsize);
1404/* Number and total o/t size of translations overall. */
1405extern UInt VG_(overall_in_count);
1406extern UInt VG_(overall_in_osize);
1407extern UInt VG_(overall_in_tsize);
1408/* Number and total o/t size of discards overall. */
1409extern UInt VG_(overall_out_count);
1410extern UInt VG_(overall_out_osize);
1411extern UInt VG_(overall_out_tsize);
1412
1413/* The number of LRU-clearings of TT/TC. */
1414extern UInt VG_(number_of_lrus);
1415
1416/* Counts pertaining to the register allocator. */
1417
1418/* total number of uinstrs input to reg-alloc */
1419extern UInt VG_(uinstrs_prealloc);
1420
1421/* total number of uinstrs added due to spill code */
1422extern UInt VG_(uinstrs_spill);
1423
1424/* number of bbs requiring spill code */
1425extern UInt VG_(translations_needing_spill);
1426
1427/* total of register ranks over all translations */
1428extern UInt VG_(total_reg_rank);
1429
1430/* Counts pertaining to the self-modifying-code detection machinery. */
1431
1432/* Total number of writes checked. */
1433//extern UInt VG_(smc_total_check4s);
1434
1435/* Number of writes which the fast smc check couldn't show were
1436 harmless. */
1437extern UInt VG_(smc_cache_passed);
1438
1439/* Numnber of writes which really did write on original code. */
1440extern UInt VG_(smc_fancy_passed);
1441
1442/* Number of translations discarded as a result. */
1443//extern UInt VG_(smc_discard_count);
1444
1445/* Counts pertaining to internal sanity checking. */
1446extern UInt VG_(sanity_fast_count);
1447extern UInt VG_(sanity_slow_count);
1448
sewardj2e93c502002-04-12 11:12:52 +00001449/* Counts pertaining to the scheduler. */
1450extern UInt VG_(num_scheduling_events_MINOR);
1451extern UInt VG_(num_scheduling_events_MAJOR);
1452
sewardjde4a1d02002-03-22 01:27:54 +00001453
1454/* ---------------------------------------------------------------------
1455 Exports of vg_memory.c
1456 ------------------------------------------------------------------ */
1457
1458extern void VGM_(init_memory_audit) ( void );
1459extern Addr VGM_(curr_dataseg_end);
1460extern void VG_(show_reg_tags) ( void );
1461extern void VG_(detect_memory_leaks) ( void );
1462extern void VG_(done_prof_mem) ( void );
1463
1464/* Set permissions for an address range. Not speed-critical. */
1465extern void VGM_(make_noaccess) ( Addr a, UInt len );
1466extern void VGM_(make_writable) ( Addr a, UInt len );
1467extern void VGM_(make_readable) ( Addr a, UInt len );
1468/* Use with care! (read: use for shmat only) */
1469extern void VGM_(make_readwritable) ( Addr a, UInt len );
1470extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1471 UInt len );
1472
1473/* Check permissions for an address range. Not speed-critical. */
1474extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1475extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1476extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1477
sewardj0c3b53f2002-05-01 01:58:35 +00001478/* Sanity checks which may be done at any time. The scheduler decides
1479 when. */
1480extern void VG_(do_sanity_checks) ( Bool force_expensive );
sewardjde4a1d02002-03-22 01:27:54 +00001481/* Very cheap ... */
1482extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1483
1484/* These functions are called from generated code. */
1485extern void VG_(helperc_STOREV4) ( UInt, Addr );
1486extern void VG_(helperc_STOREV2) ( UInt, Addr );
1487extern void VG_(helperc_STOREV1) ( UInt, Addr );
1488
1489extern UInt VG_(helperc_LOADV1) ( Addr );
1490extern UInt VG_(helperc_LOADV2) ( Addr );
1491extern UInt VG_(helperc_LOADV4) ( Addr );
1492
1493extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1494extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1495extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1496
1497/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1498 space and pass the addresses and values of all addressible,
1499 defined, aligned words to notify_word. This is the basis for the
1500 leak detector. Returns the number of calls made to notify_word. */
1501UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1502
1503/* Is this address within some small distance below %ESP? Used only
1504 for the --workaround-gcc296-bugs kludge. */
sewardj8c824512002-04-14 04:16:48 +00001505extern Bool VG_(is_just_below_ESP)( Addr esp, Addr aa );
sewardjde4a1d02002-03-22 01:27:54 +00001506
1507/* Nasty kludgery to deal with applications which switch stacks,
1508 like netscape. */
sewardjde4a1d02002-03-22 01:27:54 +00001509#define VG_PLAUSIBLE_STACK_SIZE 8000000
1510
sewardjc3bd5f52002-05-01 03:24:23 +00001511/* Needed by the pthreads implementation. */
1512#define VGM_WORD_VALID 0
1513#define VGM_WORD_INVALID 0xFFFFFFFF
1514
sewardjde4a1d02002-03-22 01:27:54 +00001515
1516/* ---------------------------------------------------------------------
1517 Exports of vg_syscall_mem.c
1518 ------------------------------------------------------------------ */
1519
sewardj2e93c502002-04-12 11:12:52 +00001520extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001521
sewardj2e93c502002-04-12 11:12:52 +00001522extern void VG_(check_known_blocking_syscall) ( ThreadId tid,
1523 Int syscallno,
1524 Int* /*IN*/ res );
sewardjde4a1d02002-03-22 01:27:54 +00001525
1526extern Bool VG_(is_kerror) ( Int res );
1527
sewardj2e93c502002-04-12 11:12:52 +00001528#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1529 VG_(load_thread_state)(thread_id); \
sewardjde4a1d02002-03-22 01:27:54 +00001530 VG_(copy_baseBlock_to_m_state_static)(); \
1531 VG_(do_syscall)(); \
1532 VG_(copy_m_state_static_to_baseBlock)(); \
sewardj2e93c502002-04-12 11:12:52 +00001533 VG_(save_thread_state)(thread_id); \
1534 result_lvalue = VG_(get_thread_state)(thread_id)->m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001535
1536
1537/* ---------------------------------------------------------------------
1538 Exports of vg_transtab.c
1539 ------------------------------------------------------------------ */
1540
1541/* An entry in the translation table (TT). */
1542typedef
1543 struct {
1544 /* +0 */ Addr orig_addr;
1545 /* +4 */ Addr trans_addr;
1546 /* +8 */ UInt mru_epoch;
1547 /* +12 */ UShort orig_size;
1548 /* +14 */ UShort trans_size;
1549 }
1550 TTEntry;
1551
1552/* The number of basic blocks in an epoch (one age-step). */
1553#define VG_BBS_PER_EPOCH 20000
1554
1555extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1556extern void VG_(maybe_do_lru_pass) ( void );
1557extern void VG_(flush_transtab) ( void );
1558extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1559extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1560
1561extern void VG_(smc_mark_original) ( Addr original_addr,
1562 Int original_len );
1563
1564extern void VG_(init_transtab_and_SMC) ( void );
1565
1566extern void VG_(sanity_check_tc_tt) ( void );
1567extern Addr VG_(search_transtab) ( Addr original_addr );
1568
1569extern void VG_(invalidate_tt_fast)( void );
1570
1571
1572/* ---------------------------------------------------------------------
1573 Exports of vg_vtagops.c
1574 ------------------------------------------------------------------ */
1575
1576/* Lists the names of value-tag operations used in instrumented
1577 code. These are the third argument to TAG1 and TAG2 uinsns. */
1578
1579typedef
1580 enum {
1581 /* Unary. */
1582 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1583 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1584
1585 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1586
1587 VgT_Left4, VgT_Left2, VgT_Left1,
1588
1589 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1590 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1591
1592 /* Binary; 1st is rd; 2nd is rd+wr */
1593 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1594 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1595
1596 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1597 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1598 VgT_DebugFn
1599 }
1600 VgTagOp;
1601
1602extern Char* VG_(nameOfTagOp) ( VgTagOp );
1603extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1604
1605
1606/* ---------------------------------------------------------------------
1607 Exports of vg_syscall.S
1608 ------------------------------------------------------------------ */
1609
1610extern void VG_(do_syscall) ( void );
1611
1612
1613/* ---------------------------------------------------------------------
1614 Exports of vg_startup.S
1615 ------------------------------------------------------------------ */
1616
sewardjde4a1d02002-03-22 01:27:54 +00001617extern void VG_(switch_to_real_CPU) ( void );
1618
sewardj35805422002-04-21 13:05:34 +00001619extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1620 Addr m_esp_at_error,
1621 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001622
1623
1624/* ---------------------------------------------------------------------
1625 Exports of vg_dispatch.S
1626 ------------------------------------------------------------------ */
1627
sewardj2e93c502002-04-12 11:12:52 +00001628/* Run a thread for a (very short) while, until some event happens
1629 which means we need to defer to the scheduler. */
1630extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001631
1632
1633/* ---------------------------------------------------------------------
1634 Exports of vg_helpers.S
1635 ------------------------------------------------------------------ */
1636
sewardjde4a1d02002-03-22 01:27:54 +00001637/* SMC fast checks. */
1638extern void VG_(helper_smc_check4);
1639
1640/* Mul, div, etc, -- we don't codegen these directly. */
1641extern void VG_(helper_idiv_64_32);
1642extern void VG_(helper_div_64_32);
1643extern void VG_(helper_idiv_32_16);
1644extern void VG_(helper_div_32_16);
1645extern void VG_(helper_idiv_16_8);
1646extern void VG_(helper_div_16_8);
1647
1648extern void VG_(helper_imul_32_64);
1649extern void VG_(helper_mul_32_64);
1650extern void VG_(helper_imul_16_32);
1651extern void VG_(helper_mul_16_32);
1652extern void VG_(helper_imul_8_16);
1653extern void VG_(helper_mul_8_16);
1654
1655extern void VG_(helper_CLD);
1656extern void VG_(helper_STD);
1657extern void VG_(helper_get_dirflag);
1658
1659extern void VG_(helper_shldl);
1660extern void VG_(helper_shldw);
1661extern void VG_(helper_shrdl);
1662extern void VG_(helper_shrdw);
1663
1664extern void VG_(helper_RDTSC);
1665extern void VG_(helper_CPUID);
1666
sewardjde4a1d02002-03-22 01:27:54 +00001667extern void VG_(helper_bsf);
1668extern void VG_(helper_bsr);
1669
1670extern void VG_(helper_fstsw_AX);
1671extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001672extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001673extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001674
1675extern void VG_(helper_value_check4_fail);
1676extern void VG_(helper_value_check2_fail);
1677extern void VG_(helper_value_check1_fail);
1678extern void VG_(helper_value_check0_fail);
1679
sewardjbc5b99f2002-04-13 00:08:51 +00001680/* NOT FUNCTIONS; these are bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001681extern void VG_(signalreturn_bogusRA)( void );
sewardjbc5b99f2002-04-13 00:08:51 +00001682extern void VG_(pthreadreturn_bogusRA)( void );
sewardj54cacf02002-04-12 23:24:59 +00001683
njn4f9c9342002-04-29 16:03:24 +00001684/* ---------------------------------------------------------------------
1685 Exports of vg_cachesim.c
1686 ------------------------------------------------------------------ */
1687
1688extern UCodeBlock* VG_(cachesim_instrument)(UCodeBlock* cb_in, Addr orig_addr);
1689
1690typedef struct _iCC iCC;
1691typedef struct _idCC idCC;
1692
1693extern void VG_(init_cachesim) ( void );
1694extern void VG_(show_cachesim_results)( Int client_argc, Char** client_argv );
1695
1696extern void VG_(cachesim_log_non_mem_instr)( iCC* cc );
1697extern void VG_(cachesim_log_mem_instr) ( idCC* cc, Addr data_addr );
sewardjde4a1d02002-03-22 01:27:54 +00001698
1699/* ---------------------------------------------------------------------
1700 The state of the simulated CPU.
1701 ------------------------------------------------------------------ */
1702
1703/* This is the Intel register encoding. */
1704#define R_EAX 0
1705#define R_ECX 1
1706#define R_EDX 2
1707#define R_EBX 3
1708#define R_ESP 4
1709#define R_EBP 5
1710#define R_ESI 6
1711#define R_EDI 7
1712
1713#define R_AL (0+R_EAX)
1714#define R_CL (0+R_ECX)
1715#define R_DL (0+R_EDX)
1716#define R_BL (0+R_EBX)
1717#define R_AH (4+R_EAX)
1718#define R_CH (4+R_ECX)
1719#define R_DH (4+R_EDX)
1720#define R_BH (4+R_EBX)
1721
1722
1723/* ---------------------------------------------------------------------
1724 Offsets into baseBlock for everything which needs to referred to
1725 from generated code. The order of these decls does not imply
1726 what the order of the actual offsets is. The latter is important
1727 and is set up in vg_main.c.
1728 ------------------------------------------------------------------ */
1729
1730/* An array of words. In generated code, %ebp always points to the
1731 start of this array. Useful stuff, like the simulated CPU state,
1732 and the addresses of helper functions, can then be found by
1733 indexing off %ebp. The following declares variables which, at
1734 startup time, are given values denoting offsets into baseBlock.
1735 These offsets are in *words* from the start of baseBlock. */
1736
1737#define VG_BASEBLOCK_WORDS 200
1738
1739extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1740
1741
1742/* -----------------------------------------------------
1743 Read-write parts of baseBlock.
1744 -------------------------------------------------- */
1745
1746/* State of the simulated CPU. */
1747extern Int VGOFF_(m_eax);
1748extern Int VGOFF_(m_ecx);
1749extern Int VGOFF_(m_edx);
1750extern Int VGOFF_(m_ebx);
1751extern Int VGOFF_(m_esp);
1752extern Int VGOFF_(m_ebp);
1753extern Int VGOFF_(m_esi);
1754extern Int VGOFF_(m_edi);
1755extern Int VGOFF_(m_eflags);
1756extern Int VGOFF_(m_fpustate);
1757extern Int VGOFF_(m_eip);
1758
1759/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1760extern Int VGOFF_(spillslots);
1761
1762/* Records the valid bits for the 8 integer regs & flags reg. */
1763extern Int VGOFF_(sh_eax);
1764extern Int VGOFF_(sh_ecx);
1765extern Int VGOFF_(sh_edx);
1766extern Int VGOFF_(sh_ebx);
1767extern Int VGOFF_(sh_esp);
1768extern Int VGOFF_(sh_ebp);
1769extern Int VGOFF_(sh_esi);
1770extern Int VGOFF_(sh_edi);
1771extern Int VGOFF_(sh_eflags);
1772
1773
1774/* -----------------------------------------------------
1775 Read-only parts of baseBlock.
1776 -------------------------------------------------- */
1777
1778/* Offsets of addresses of helper functions. A "helper" function is
1779 one which is called from generated code. */
1780
1781extern Int VGOFF_(helper_idiv_64_32);
1782extern Int VGOFF_(helper_div_64_32);
1783extern Int VGOFF_(helper_idiv_32_16);
1784extern Int VGOFF_(helper_div_32_16);
1785extern Int VGOFF_(helper_idiv_16_8);
1786extern Int VGOFF_(helper_div_16_8);
1787
1788extern Int VGOFF_(helper_imul_32_64);
1789extern Int VGOFF_(helper_mul_32_64);
1790extern Int VGOFF_(helper_imul_16_32);
1791extern Int VGOFF_(helper_mul_16_32);
1792extern Int VGOFF_(helper_imul_8_16);
1793extern Int VGOFF_(helper_mul_8_16);
1794
1795extern Int VGOFF_(helper_CLD);
1796extern Int VGOFF_(helper_STD);
1797extern Int VGOFF_(helper_get_dirflag);
1798
1799extern Int VGOFF_(helper_shldl);
1800extern Int VGOFF_(helper_shldw);
1801extern Int VGOFF_(helper_shrdl);
1802extern Int VGOFF_(helper_shrdw);
1803
1804extern Int VGOFF_(helper_RDTSC);
1805extern Int VGOFF_(helper_CPUID);
1806
sewardjde4a1d02002-03-22 01:27:54 +00001807extern Int VGOFF_(helper_bsf);
1808extern Int VGOFF_(helper_bsr);
1809
1810extern Int VGOFF_(helper_fstsw_AX);
1811extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001812extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001813extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001814
1815extern Int VGOFF_(helper_value_check4_fail);
1816extern Int VGOFF_(helper_value_check2_fail);
1817extern Int VGOFF_(helper_value_check1_fail);
1818extern Int VGOFF_(helper_value_check0_fail);
1819
sewardjde4a1d02002-03-22 01:27:54 +00001820extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1821extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1822extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1823
1824extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1825extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1826extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1827
1828extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1829extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1830extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1831
njn4f9c9342002-04-29 16:03:24 +00001832extern Int VGOFF_(cachesim_log_non_mem_instr);
1833extern Int VGOFF_(cachesim_log_mem_instr);
sewardjde4a1d02002-03-22 01:27:54 +00001834
1835#endif /* ndef __VG_INCLUDE_H */
1836
sewardj3b2736a2002-03-24 12:18:35 +00001837
1838/* ---------------------------------------------------------------------
1839 Finally - autoconf-generated settings
1840 ------------------------------------------------------------------ */
1841
1842#include "config.h"
1843
sewardjde4a1d02002-03-22 01:27:54 +00001844/*--------------------------------------------------------------------*/
1845/*--- end vg_include.h ---*/
1846/*--------------------------------------------------------------------*/