blob: 1249d1148e17b6d5464e03eb6bfe7c58a5ba04c7 [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. */
sewardjd8091eb2002-04-24 02:19:36 +0000109#define VG_GCC296_BUG_STACK_SLOP 256
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
sewardjde4a1d02002-03-22 01:27:54 +0000145
146/* ---------------------------------------------------------------------
147 Basic types
148 ------------------------------------------------------------------ */
149
150typedef unsigned char UChar;
151typedef unsigned short UShort;
152typedef unsigned int UInt;
153typedef unsigned long long int ULong;
154
155typedef signed char Char;
156typedef signed short Short;
157typedef signed int Int;
158typedef signed long long int Long;
159
160typedef unsigned int Addr;
161
162typedef unsigned char Bool;
163#define False ((Bool)0)
164#define True ((Bool)1)
165
166#define mycat_wrk(aaa,bbb) aaa##bbb
167#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
168
169/* Just pray that gcc's constant folding works properly ... */
170#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
171 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
172 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
173
174
175/* ---------------------------------------------------------------------
176 Now the basic types are set up, we can haul in the kernel-interface
177 definitions.
178 ------------------------------------------------------------------ */
179
180#include "./vg_kerneliface.h"
181
182
183/* ---------------------------------------------------------------------
184 Command-line-settable options
185 ------------------------------------------------------------------ */
186
187#define VG_CLO_SMC_NONE 0
188#define VG_CLO_SMC_SOME 1
189#define VG_CLO_SMC_ALL 2
190
191#define VG_CLO_MAX_SFILES 10
192
sewardj97ced732002-03-25 00:07:36 +0000193/* Shall we V-check addrs (they are always A checked too): default: YES */
194extern Bool VG_(clo_check_addrVs);
sewardjde4a1d02002-03-22 01:27:54 +0000195/* Enquire about whether to attach to GDB at errors? default: NO */
196extern Bool VG_(clo_GDB_attach);
197/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
198extern Int VG_(sanity_level);
199/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
200extern Int VG_(clo_verbosity);
201/* Automatically attempt to demangle C++ names? default: YES */
202extern Bool VG_(clo_demangle);
203/* Do leak check at exit? default: NO */
204extern Bool VG_(clo_leak_check);
205/* In leak check, show reachable-but-not-freed blocks? default: NO */
206extern Bool VG_(clo_show_reachable);
207/* How closely should we compare ExeContexts in leak records? default: 2 */
208extern Int VG_(clo_leak_resolution);
209/* Round malloc sizes upwards to integral number of words? default:
210 NO */
211extern Bool VG_(clo_sloppy_malloc);
212/* Allow loads from partially-valid addresses? default: YES */
213extern Bool VG_(clo_partial_loads_ok);
214/* Simulate child processes? default: NO */
215extern Bool VG_(clo_trace_children);
216/* The file id on which we send all messages. default: 2 (stderr). */
217extern Int VG_(clo_logfile_fd);
218/* Max volume of the freed blocks queue. */
219extern Int VG_(clo_freelist_vol);
220/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
221 default: NO */
222extern Bool VG_(clo_workaround_gcc296_bugs);
223
224/* The number of suppression files specified. */
225extern Int VG_(clo_n_suppressions);
226/* The names of the suppression files. */
227extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
228
229/* Single stepping? default: NO */
230extern Bool VG_(clo_single_step);
231/* Code improvement? default: YES */
232extern Bool VG_(clo_optimise);
233/* Memory-check instrumentation? default: YES */
234extern Bool VG_(clo_instrument);
235/* DEBUG: clean up instrumented code? default: YES */
236extern Bool VG_(clo_cleanup);
njn4f9c9342002-04-29 16:03:24 +0000237/* Cache simulation instrumentation? default: NO */
238extern Bool VG_(clo_cachesim);
sewardjde4a1d02002-03-22 01:27:54 +0000239/* SMC write checks? default: SOME (1,2,4 byte movs to mem) */
240extern Int VG_(clo_smc_check);
241/* DEBUG: print system calls? default: NO */
242extern Bool VG_(clo_trace_syscalls);
243/* DEBUG: print signal details? default: NO */
244extern Bool VG_(clo_trace_signals);
245/* DEBUG: print symtab details? default: NO */
246extern Bool VG_(clo_trace_symtab);
247/* DEBUG: print malloc details? default: NO */
248extern Bool VG_(clo_trace_malloc);
sewardj8937c812002-04-12 20:12:20 +0000249/* DEBUG: print thread scheduling events? default: NO */
250extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000251/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
252 (some), 2 (all) */
253extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000254/* Stop after this many basic blocks. default: Infinity. */
255extern ULong VG_(clo_stop_after);
256/* Display gory details for the k'th most popular error. default:
257 Infinity. */
258extern Int VG_(clo_dump_error);
259/* Number of parents of a backtrace. Default: 8. */
260extern Int VG_(clo_backtrace_size);
261
262
263/* ---------------------------------------------------------------------
264 Debugging and profiling stuff
265 ------------------------------------------------------------------ */
266
267/* No, really. I _am_ that strange. */
268#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
269
270/* Tools for building messages from multiple parts. */
271typedef
272 enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg }
273 VgMsgKind;
274
275extern void VG_(start_msg) ( VgMsgKind kind );
276extern void VG_(add_to_msg) ( Char* format, ... );
277extern void VG_(end_msg) ( void );
278
279/* Send a simple, single-part message. */
280extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
281
282/* Create a logfile into which messages can be dumped. */
283extern void VG_(startup_logging) ( void );
284extern void VG_(shutdown_logging) ( void );
285
286
287/* Profiling stuff */
288#ifdef VG_PROFILE
289
290#define VGP_M_STACK 10
291
njn4f9c9342002-04-29 16:03:24 +0000292#define VGP_M_CCS 24 /* == the # of elems in VGP_LIST */
sewardjde4a1d02002-03-22 01:27:54 +0000293#define VGP_LIST \
294 VGP_PAIR(VgpRun=0, "running"), \
295 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
296 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
297 VGP_PAIR(VgpTranslate, "translate-main"), \
298 VGP_PAIR(VgpToUCode, "to-ucode"), \
299 VGP_PAIR(VgpFromUcode, "from-ucode"), \
300 VGP_PAIR(VgpImprove, "improve"), \
301 VGP_PAIR(VgpInstrument, "instrument"), \
302 VGP_PAIR(VgpCleanup, "cleanup"), \
303 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
304 VGP_PAIR(VgpDoLRU, "do-lru"), \
305 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
306 VGP_PAIR(VgpInitAudit, "init-mem-audit"), \
307 VGP_PAIR(VgpExeContext, "exe-context"), \
308 VGP_PAIR(VgpReadSyms, "read-syms"), \
309 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
310 VGP_PAIR(VgpSARP, "set-addr-range-perms"), \
311 VGP_PAIR(VgpSyscall, "syscall wrapper"), \
njn4f9c9342002-04-29 16:03:24 +0000312 VGP_PAIR(VgpCacheInstrument, "cache instrument"), \
313 VGP_PAIR(VgpCacheGetBBCC,"cache get BBCC"), \
314 VGP_PAIR(VgpCacheSimulate, "cache simulate"), \
315 VGP_PAIR(VgpCacheDump, "cache stats dump"), \
sewardjde4a1d02002-03-22 01:27:54 +0000316 VGP_PAIR(VgpSpare1, "spare 1"), \
317 VGP_PAIR(VgpSpare2, "spare 2")
318
319#define VGP_PAIR(enumname,str) enumname
320typedef enum { VGP_LIST } VgpCC;
321#undef VGP_PAIR
322
323extern void VGP_(init_profiling) ( void );
324extern void VGP_(done_profiling) ( void );
325extern void VGP_(pushcc) ( VgpCC );
326extern void VGP_(popcc) ( void );
327
328#define VGP_PUSHCC(cc) VGP_(pushcc)(cc)
329#define VGP_POPCC VGP_(popcc)()
330
331#else
332
333#define VGP_PUSHCC(cc) /* */
334#define VGP_POPCC /* */
335
336#endif /* VG_PROFILE */
337
338
339/* ---------------------------------------------------------------------
340 Exports of vg_malloc2.c
341 ------------------------------------------------------------------ */
342
343/* Allocation arenas.
344 SYMTAB is for Valgrind's symbol table storage.
345 CLIENT is for the client's mallocs/frees.
346 DEMANGLE is for the C++ demangler.
347 EXECTXT is for storing ExeContexts.
348 ERRCTXT is for storing ErrContexts.
349 PRIVATE is for Valgrind general stuff.
350 TRANSIENT is for very short-term use. It should be empty
351 in between uses.
352 When adding a new arena, remember also to add it
353 to ensure_mm_init().
354*/
355typedef Int ArenaId;
356
357#define VG_N_ARENAS 7
358
359#define VG_AR_PRIVATE 0 /* :: ArenaId */
360#define VG_AR_SYMTAB 1 /* :: ArenaId */
361#define VG_AR_CLIENT 2 /* :: ArenaId */
362#define VG_AR_DEMANGLE 3 /* :: ArenaId */
363#define VG_AR_EXECTXT 4 /* :: ArenaId */
364#define VG_AR_ERRCTXT 5 /* :: ArenaId */
365#define VG_AR_TRANSIENT 6 /* :: ArenaId */
366
367extern void* VG_(malloc) ( ArenaId arena, Int nbytes );
368extern void VG_(free) ( ArenaId arena, void* ptr );
369extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes );
370extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size );
371extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB,
372 Int req_pszB );
373
374extern void VG_(mallocSanityCheckArena) ( ArenaId arena );
375extern void VG_(mallocSanityCheckAll) ( void );
376
377extern void VG_(show_all_arena_stats) ( void );
378extern Bool VG_(is_empty_arena) ( ArenaId aid );
379
380
381/* The red-zone size for the client. This can be arbitrary, but
382 unfortunately must be set at compile time. */
383#define VG_AR_CLIENT_REDZONE_SZW 4
384
385#define VG_AR_CLIENT_REDZONE_SZB \
386 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
387
388
389/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000390 Exports of vg_clientfuns.c
391 ------------------------------------------------------------------ */
392
393/* This doesn't export code or data that valgrind.so needs to link
394 against. However, the scheduler does need to know the following
395 request codes. A few, publically-visible, request codes are also
396 defined in valgrind.h. */
397
398#define VG_USERREQ__MALLOC 0x2001
399#define VG_USERREQ__BUILTIN_NEW 0x2002
400#define VG_USERREQ__BUILTIN_VEC_NEW 0x2003
401
402#define VG_USERREQ__FREE 0x2004
403#define VG_USERREQ__BUILTIN_DELETE 0x2005
404#define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006
405
406#define VG_USERREQ__CALLOC 0x2007
407#define VG_USERREQ__REALLOC 0x2008
408#define VG_USERREQ__MEMALIGN 0x2009
409
410
411#define VG_USERREQ__PTHREAD_CREATE 0x3001
sewardjbc5b99f2002-04-13 00:08:51 +0000412#define VG_USERREQ__PTHREAD_JOIN 0x3002
413#define VG_USERREQ__PTHREAD_GET_THREADID 0x3003
sewardj3b5d8862002-04-20 13:53:23 +0000414#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x3004
sewardj30671ff2002-04-21 00:13:57 +0000415#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x3005
416#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x3006
417#define VG_USERREQ__PTHREAD_CANCEL 0x3007
418#define VG_USERREQ__PTHREAD_EXIT 0x3008
419#define VG_USERREQ__PTHREAD_COND_WAIT 0x3009
sewardj5f07b662002-04-23 16:52:51 +0000420#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x300A
421#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x300B
422#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x300C
423#define VG_USERREQ__PTHREAD_KEY_CREATE 0x300D
424#define VG_USERREQ__PTHREAD_KEY_DELETE 0x300E
425#define VG_USERREQ__PTHREAD_SETSPECIFIC 0x300F
426#define VG_USERREQ__PTHREAD_GETSPECIFIC 0x3010
sewardj56fc53d2002-04-24 01:17:42 +0000427#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3011
sewardj2e93c502002-04-12 11:12:52 +0000428
sewardj45b4b372002-04-16 22:50:32 +0000429/* Cosmetic ... */
430#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
431
sewardj54cacf02002-04-12 23:24:59 +0000432/*
433In vg_constants.h:
434#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardjbc5b99f2002-04-13 00:08:51 +0000435#define VG_USERREQ__PTHREAD_RETURNS 0x4002
436#define VG_USERREQ__SHUTDOWN_VALGRIND 0x4003
sewardj54cacf02002-04-12 23:24:59 +0000437*/
438
439
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/* ---------------------------------------------------------------------
452 Exports of vg_scheduler.c
453 ------------------------------------------------------------------ */
454
455/* ThreadIds are simply indices into the vg_threads[] array. */
456typedef
457 UInt
458 ThreadId;
459
sewardj6072c362002-04-19 14:40:57 +0000460/* Special magic value for an invalid ThreadId. It corresponds to
461 LinuxThreads using zero as the initial value for
462 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
463#define VG_INVALID_THREADID ((ThreadId)(0))
sewardj2e93c502002-04-12 11:12:52 +0000464
465typedef
466 enum {
467 VgTs_Empty, /* this slot is not in use */
468 VgTs_Runnable, /* waiting to be scheduled */
469 VgTs_WaitJoiner, /* waiting for someone to do join on me */
470 VgTs_WaitJoinee, /* waiting for the thread I did join on */
471 VgTs_WaitFD, /* waiting for I/O completion on a fd */
472 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000473 VgTs_WaitCV, /* waiting on a condition variable */
sewardj2e93c502002-04-12 11:12:52 +0000474 VgTs_Sleeping /* sleeping for a while */
475 }
476 ThreadStatus;
477
478typedef
479 struct {
sewardj6072c362002-04-19 14:40:57 +0000480 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
481 The thread identity is simply the index in vg_threads[].
482 ThreadId == 1 is the root thread and has the special property
sewardj1e8cdc92002-04-18 11:37:52 +0000483 that we don't try and allocate or deallocate its stack. For
484 convenience of generating error message, we also put the
485 ThreadId in this tid field, but be aware that it should
sewardj604ec3c2002-04-18 22:38:41 +0000486 ALWAYS == the index in vg_threads[]. */
sewardj1e8cdc92002-04-18 11:37:52 +0000487 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000488
sewardj5f07b662002-04-23 16:52:51 +0000489 /* Current scheduling status.
490
491 Complications: whenever this is set to VgTs_WaitMX, you
492 should also set .m_edx to whatever the required return value
493 is for pthread_mutex_lock / pthread_cond_timedwait for when
494 the mutex finally gets unblocked. */
sewardj2e93c502002-04-12 11:12:52 +0000495 ThreadStatus status;
496
497 /* Identity of joiner (thread who called join on me), or
498 VG_INVALID_THREADID if no one asked to join yet. */
499 ThreadId joiner;
500
sewardj3b5d8862002-04-20 13:53:23 +0000501 /* When .status == WaitMX, points to the mutex I am waiting for.
502 When .status == WaitCV, points to the mutex associated with
503 the condition variable indicated by the .associated_cv field.
504 In all other cases, should be NULL. */
505 void* /* pthread_mutex_t* */ associated_mx;
506
507 /* When .status == WaitCV, points to the condition variable I am
508 waiting for. In all other cases, should be NULL. */
509 void* /* pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000510
sewardj5f07b662002-04-23 16:52:51 +0000511 /* If VgTs_Sleeping, this is when we should wake up, measured in
512 milliseconds as supplied by VG_(read_millisecond_counter).
513
514 If VgTs_WaitCV, this indicates the time at which
515 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
516 this means infinitely far in the future, viz,
517 pthread_cond_wait. */
518 UInt awaken_at;
sewardj2e93c502002-04-12 11:12:52 +0000519
520 /* return value */
521 void* retval;
522
sewardj5f07b662002-04-23 16:52:51 +0000523 /* thread-specific data */
524 void* specifics[VG_N_THREAD_KEYS];
525
sewardj2e93c502002-04-12 11:12:52 +0000526 /* Stacks. When a thread slot is freed, we don't deallocate its
527 stack; we just leave it lying around for the next use of the
528 slot. If the next use of the slot requires a larger stack,
529 only then is the old one deallocated and a new one
530 allocated.
531
532 For the main thread (threadid == 0), this mechanism doesn't
533 apply. We don't know the size of the stack since we didn't
534 allocate it, and furthermore we never reallocate it. */
535
536 /* The allocated size of this thread's stack (permanently zero
537 if this is ThreadId == 0, since we didn't allocate its stack) */
538 UInt stack_size;
539
540 /* Address of the lowest word in this thread's stack. NULL means
541 not allocated yet.
542 */
543 Addr stack_base;
544
sewardj1e8cdc92002-04-18 11:37:52 +0000545 /* Address of the highest legitimate word in this stack. This is
546 used for error messages only -- not critical for execution
547 correctness. Is is set for all stacks, specifically including
548 ThreadId == 0 (the main thread). */
549 Addr stack_highest_word;
550
sewardj2e93c502002-04-12 11:12:52 +0000551 /* Saved machine context. */
552 UInt m_eax;
553 UInt m_ebx;
554 UInt m_ecx;
555 UInt m_edx;
556 UInt m_esi;
557 UInt m_edi;
558 UInt m_ebp;
559 UInt m_esp;
560 UInt m_eflags;
561 UInt m_eip;
562 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
563
564 UInt sh_eax;
565 UInt sh_ebx;
566 UInt sh_ecx;
567 UInt sh_edx;
568 UInt sh_esi;
569 UInt sh_edi;
570 UInt sh_ebp;
571 UInt sh_esp;
572 UInt sh_eflags;
573 }
574 ThreadState;
575
576
577/* Copy the specified thread's state into VG_(baseBlock) in
578 preparation for running it. */
579extern void VG_(load_thread_state)( ThreadId );
580
581/* Save the specified thread's state back in VG_(baseBlock), and fill
582 VG_(baseBlock) with junk, for sanity-check reasons. */
583extern void VG_(save_thread_state)( ThreadId );
584
585/* Get the thread state block for the specified thread. */
586extern ThreadState* VG_(get_thread_state)( ThreadId );
587
sewardj1e8cdc92002-04-18 11:37:52 +0000588/* And for the currently running one, if valid. */
589extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000590
sewardj1e8cdc92002-04-18 11:37:52 +0000591/* Similarly ... */
592extern ThreadId VG_(get_current_tid) ( void );
593
594/* Which thread is this address in the stack of, if any? Used for
595 error message generation. */
596extern ThreadId VG_(identify_stack_addr)( Addr a );
597
sewardj2e93c502002-04-12 11:12:52 +0000598
599/* Return codes from the scheduler. */
600typedef
601 enum { VgSrc_Deadlock, VgSrc_Shutdown, VgSrc_BbsDone }
602 VgSchedReturnCode;
603
604/* The scheduler. */
605extern VgSchedReturnCode VG_(scheduler) ( void );
606
607extern void VG_(scheduler_init) ( void );
608
sewardj15a43e12002-04-17 19:35:12 +0000609extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000610
611/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
612extern jmp_buf VG_(scheduler_jmpbuf);
613/* ... and if so, here's the signal which caused it to do so. */
614extern Int VG_(longjmpd_on_signal);
615
616
617/* We check that the initial stack, which we can't move, is allocated
618 here. VG_(scheduler_init) checks this.
619*/
sewardjebc82332002-04-24 14:44:23 +0000620#define VG_STARTUP_STACK_MASK (Addr)0xBFF80000
sewardj2e93c502002-04-12 11:12:52 +0000621
622
623/* The red-zone size which we put at the bottom (highest address) of
624 thread stacks, for paranoia reasons. This can be arbitrary, and
625 doesn't really need to be set at compile time. */
626#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
627
628#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
629 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
630
631
632
633/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000634 Exports of vg_signals.c
635 ------------------------------------------------------------------ */
636
sewardjde4a1d02002-03-22 01:27:54 +0000637extern void VG_(sigstartup_actions) ( void );
638
sewardj14e03422002-04-24 19:51:31 +0000639extern Bool VG_(deliver_signals) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000640extern void VG_(unblock_host_signal) ( Int sigNo );
641
642
643/* Fake system calls for signal handling. */
sewardj2e93c502002-04-12 11:12:52 +0000644extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +0000645extern void VG_(do__NR_sigprocmask) ( Int how, vki_ksigset_t* set );
646
sewardj2e93c502002-04-12 11:12:52 +0000647/* Modify the current thread's state once we have detected it is
648 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +0000649extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000650
sewardj2e93c502002-04-12 11:12:52 +0000651/* Handy utilities to block/restore all host signals. */
652extern void VG_(block_all_host_signals)
653 ( /* OUT */ vki_ksigset_t* saved_mask );
654extern void VG_(restore_host_signals)
655 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000656
657/* ---------------------------------------------------------------------
658 Exports of vg_mylibc.c
659 ------------------------------------------------------------------ */
660
661
662#define NULL ((void*)0)
663
664extern void VG_(exit)( Int status )
665 __attribute__ ((__noreturn__));
666
667extern void VG_(printf) ( const char *format, ... );
668/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
669
670extern void VG_(sprintf) ( Char* buf, Char *format, ... );
671
672extern void VG_(vprintf) ( void(*send)(Char),
673 const Char *format, va_list vargs );
674
675extern Bool VG_(isspace) ( Char c );
676
677extern Int VG_(strlen) ( const Char* str );
678
679extern Long VG_(atoll) ( Char* str );
680
681extern Char* VG_(strcat) ( Char* dest, const Char* src );
682extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
683extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
684
685extern Char* VG_(strcpy) ( Char* dest, const Char* src );
686
687extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
688extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
689
690extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
691extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
692
693extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
694extern Char* VG_(strchr) ( const Char* s, Char c );
695extern Char* VG_(strdup) ( ArenaId aid, const Char* s);
696
697extern Char* VG_(getenv) ( Char* name );
698extern Int VG_(getpid) ( void );
sewardj5f07b662002-04-23 16:52:51 +0000699
700extern void VG_(start_rdtsc_calibration) ( void );
701extern void VG_(end_rdtsc_calibration) ( void );
702extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000703
704
705extern Char VG_(toupper) ( Char c );
706
707extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
708
709extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
710
711extern Bool VG_(stringMatch) ( Char* pat, Char* str );
712
713
714#define __STRING(x) #x
715
716/* Asserts are permanently enabled. Hurrah! */
717#define vg_assert(expr) \
718 ((void) ((expr) ? 0 : \
719 (VG_(assert_fail) (__STRING(expr), \
720 __FILE__, __LINE__, \
721 __PRETTY_FUNCTION__), 0)))
722
723extern void VG_(assert_fail) ( Char* expr, Char* file,
724 Int line, Char* fn )
725 __attribute__ ((__noreturn__));
726
njn4f9c9342002-04-29 16:03:24 +0000727/* Reading and writing files. */
sewardjde4a1d02002-03-22 01:27:54 +0000728extern Int VG_(open_read) ( Char* pathname );
njn4f9c9342002-04-29 16:03:24 +0000729extern Int VG_(open_write) ( Char* pathname );
730extern Int VG_(create_and_write) ( Char* pathname );
sewardjde4a1d02002-03-22 01:27:54 +0000731extern void VG_(close) ( Int fd );
732extern Int VG_(read) ( Int fd, void* buf, Int count);
733extern Int VG_(write) ( Int fd, void* buf, Int count);
734
sewardj2e93c502002-04-12 11:12:52 +0000735extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
736
737extern Int VG_(select)( Int n,
738 vki_fd_set* readfds,
739 vki_fd_set* writefds,
740 vki_fd_set* exceptfds,
741 struct vki_timeval * timeout );
742extern Int VG_(nanosleep)( const struct vki_timespec *req,
743 struct vki_timespec *rem );
744
745
sewardjde4a1d02002-03-22 01:27:54 +0000746/* mmap-ery ... */
747extern void* VG_(mmap)( void* start, UInt length,
748 UInt prot, UInt flags, UInt fd, UInt offset );
749
sewardj2e93c502002-04-12 11:12:52 +0000750extern Int VG_(munmap)( void* start, Int length );
sewardjde4a1d02002-03-22 01:27:54 +0000751
752
753/* Print a (panic) message, and abort. */
754extern void VG_(panic) ( Char* str )
755 __attribute__ ((__noreturn__));
756
757/* Get memory by anonymous mmap. */
sewardje6a25242002-04-21 22:03:07 +0000758extern void* VG_(get_memory_from_mmap) ( Int nBytes );
759
760/* Crude stand-in for the glibc system() call. */
761extern Int VG_(system) ( Char* cmd );
762
sewardjde4a1d02002-03-22 01:27:54 +0000763
764/* Signal stuff. Note that these use the vk_ (kernel) structure
765 definitions, which are different in places from those that glibc
766 defines. Since we're operating right at the kernel interface,
767 glibc's view of the world is entirely irrelevant. */
768extern Int VG_(ksigfillset)( vki_ksigset_t* set );
769extern Int VG_(ksigemptyset)( vki_ksigset_t* set );
770extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum );
771
772extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set,
773 vki_ksigset_t* oldset );
774extern Int VG_(ksigaction) ( Int signum,
775 const vki_ksigaction* act,
776 vki_ksigaction* oldact );
777extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
778
779extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int));
780
781extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss );
782
783
784
785/* ---------------------------------------------------------------------
786 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
787 vg_from_ucode.c).
788 ------------------------------------------------------------------ */
789
790/* Tags which describe what operands are. */
791typedef
792 enum { TempReg=0, ArchReg=1, RealReg=2,
793 SpillNo=3, Literal=4, Lit16=5,
794 NoValue=6 }
795 Tag;
796
797
798/* Microinstruction opcodes. */
799typedef
800 enum {
801 NOP,
802 GET,
803 PUT,
804 LOAD,
805 STORE,
806 MOV,
807 CMOV, /* Used for cmpxchg and cmov */
808 WIDEN,
809 JMP,
810
811 /* Read/write the %EFLAGS register into a TempReg. */
812 GETF, PUTF,
813
814 ADD, ADC, AND, OR, XOR, SUB, SBB,
815 SHL, SHR, SAR, ROL, ROR, RCL, RCR,
816 NOT, NEG, INC, DEC, BSWAP,
817 CC2VAL,
818
819 /* Not strictly needed, but useful for making better
820 translations of address calculations. */
821 LEA1, /* reg2 := const + reg1 */
822 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
823
824 /* not for translating x86 calls -- only to call helpers */
825 CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences
826 for CALLM. */
827 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */
828 CALLM, /* call to a machine-code helper */
829
830 /* Hack for translating string (REP-) insns. Jump to literal if
831 TempReg/RealReg is zero. */
832 JIFZ,
833
834 /* FPU ops which read/write mem or don't touch mem at all. */
835 FPU_R,
836 FPU_W,
837 FPU,
838
839 /* Advance the simulated %eip by some small (< 128) number. */
840 INCEIP,
841
842 /* uinstrs which are not needed for mere translation of x86 code,
843 only for instrumentation of it. */
844 LOADV,
845 STOREV,
846 GETV,
847 PUTV,
848 TESTV,
849 SETV,
850 /* Get/set the v-bit (and it is only one bit) for the simulated
851 %eflags register. */
852 GETVF,
853 PUTVF,
854
855 /* Do a unary or binary tag op. Only for post-instrumented
856 code. For TAG1, first and only arg is a TempReg, and is both
857 arg and result reg. For TAG2, first arg is src, second is
858 dst, in the normal way; both are TempRegs. In both cases,
859 3rd arg is a RiCHelper with a Lit16 tag. This indicates
860 which tag op to do. */
861 TAG1,
862 TAG2
863 }
864 Opcode;
865
866
867/* Condition codes, observing the Intel encoding. CondAlways is an
868 extra. */
869typedef
870 enum {
871 CondO = 0, /* overflow */
872 CondNO = 1, /* no overflow */
873 CondB = 2, /* below */
874 CondNB = 3, /* not below */
875 CondZ = 4, /* zero */
876 CondNZ = 5, /* not zero */
877 CondBE = 6, /* below or equal */
878 CondNBE = 7, /* not below or equal */
879 CondS = 8, /* negative */
880 ConsNS = 9, /* not negative */
881 CondP = 10, /* parity even */
882 CondNP = 11, /* not parity even */
883 CondL = 12, /* jump less */
884 CondNL = 13, /* not less */
885 CondLE = 14, /* less or equal */
886 CondNLE = 15, /* not less or equal */
887 CondAlways = 16 /* Jump always */
888 }
889 Condcode;
890
891
sewardj2e93c502002-04-12 11:12:52 +0000892/* Descriptions of additional properties of *unconditional* jumps. */
893typedef
894 enum {
895 JmpBoring=0, /* boring unconditional jump */
896 JmpCall=1, /* jump due to an x86 call insn */
897 JmpRet=2, /* jump due to an x86 ret insn */
898 JmpSyscall=3, /* do a system call, then jump */
899 JmpClientReq=4 /* do a client request, then jump */
900 }
901 JmpKind;
902
903
sewardjde4a1d02002-03-22 01:27:54 +0000904/* Flags. User-level code can only read/write O(verflow), S(ign),
905 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
906 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
907 thusly:
908 76543210
909 DOSZACP
910 and bit 7 must always be zero since it is unused.
911*/
912typedef UChar FlagSet;
913
914#define FlagD (1<<6)
915#define FlagO (1<<5)
916#define FlagS (1<<4)
917#define FlagZ (1<<3)
918#define FlagA (1<<2)
919#define FlagC (1<<1)
920#define FlagP (1<<0)
921
922#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
923#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
924#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
925#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
926#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
927#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
sewardj4a7456e2002-03-24 13:52:19 +0000928#define FlagsZCP ( FlagZ | FlagC | FlagP)
sewardjde4a1d02002-03-22 01:27:54 +0000929#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000930#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000931
932#define FlagsALL (FlagsOSZACP | FlagD)
933#define FlagsEmpty (FlagSet)0
934
935#define VG_IS_FLAG_SUBSET(set1,set2) \
936 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
937
938#define VG_UNION_FLAG_SETS(set1,set2) \
939 ( ((FlagSet)set1) | ((FlagSet)set2) )
940
941
942
943/* A Micro (u)-instruction. */
944typedef
945 struct {
946 /* word 1 */
947 UInt lit32; /* 32-bit literal */
948
949 /* word 2 */
950 UShort val1; /* first operand */
951 UShort val2; /* second operand */
952
953 /* word 3 */
954 UShort val3; /* third operand */
955 UChar opcode; /* opcode */
956 UChar size; /* data transfer size */
957
958 /* word 4 */
959 FlagSet flags_r; /* :: FlagSet */
960 FlagSet flags_w; /* :: FlagSet */
961 UChar tag1:4; /* first operand tag */
962 UChar tag2:4; /* second operand tag */
963 UChar tag3:4; /* third operand tag */
964 UChar extra4b:4; /* Spare field, used by WIDEN for src
965 -size, and by LEA2 for scale
njn4f9c9342002-04-29 16:03:24 +0000966 (1,2,4 or 8), and by unconditional JMPs for
967 orig x86 instr size if --cachesim=yes */
968
sewardjde4a1d02002-03-22 01:27:54 +0000969
970 /* word 5 */
971 UChar cond; /* condition, for jumps */
972 Bool smc_check:1; /* do a smc test, if writes memory. */
973 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
sewardj2e93c502002-04-12 11:12:52 +0000974 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
sewardjde4a1d02002-03-22 01:27:54 +0000975 }
976 UInstr;
977
978
979/* Expandable arrays of uinstrs. */
980typedef
981 struct {
982 Int used;
983 Int size;
984 UInstr* instrs;
985 Int nextTemp;
986 }
987 UCodeBlock;
988
989/* Refer to `the last instruction stuffed in', including as an
990 lvalue. */
991#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
992
993/* An invalid temporary number :-) */
994#define INVALID_TEMPREG 999999999
995
996
997/* ---------------------------------------------------------------------
998 Exports of vg_demangle.c
999 ------------------------------------------------------------------ */
1000
1001extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
1002
1003
1004/* ---------------------------------------------------------------------
1005 Exports of vg_from_ucode.c
1006 ------------------------------------------------------------------ */
1007
1008extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
1009
1010
1011/* ---------------------------------------------------------------------
1012 Exports of vg_to_ucode.c
1013 ------------------------------------------------------------------ */
1014
1015extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
1016extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
1017extern Char VG_(nameOfIntSize) ( Int size );
1018extern UInt VG_(extend_s_8to32) ( UInt x );
1019extern Int VG_(getNewTemp) ( UCodeBlock* cb );
1020extern Int VG_(getNewShadow) ( UCodeBlock* cb );
1021
1022#define SHADOW(tempreg) ((tempreg)+1)
1023
1024
1025/* ---------------------------------------------------------------------
1026 Exports of vg_translate.c
1027 ------------------------------------------------------------------ */
1028
sewardj1e8cdc92002-04-18 11:37:52 +00001029extern void VG_(translate) ( ThreadState* tst,
1030 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001031 UInt* orig_size,
1032 Addr* trans_addr,
1033 UInt* trans_size );
1034
1035extern void VG_(emptyUInstr) ( UInstr* u );
1036extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
1037extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
1038 Tag tag1, UInt val1 );
1039extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
1040 Tag tag1, UInt val1,
1041 Tag tag2, UInt val2 );
1042extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
1043 Tag tag1, UInt val1,
1044 Tag tag2, UInt val2,
1045 Tag tag3, UInt val3 );
1046extern void VG_(setFlagRW) ( UInstr* u,
1047 FlagSet fr, FlagSet fw );
1048
1049extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
1050extern Bool VG_(anyFlagUse) ( UInstr* u );
1051
1052
1053
1054extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
1055extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
1056
njn4f9c9342002-04-29 16:03:24 +00001057extern UCodeBlock* VG_(allocCodeBlock) ( void );
1058extern void VG_(freeCodeBlock) ( UCodeBlock* cb );
1059extern void VG_(copyUInstr) ( UCodeBlock* cb, UInstr* instr );
1060
sewardjde4a1d02002-03-22 01:27:54 +00001061extern Char* VG_(nameCondcode) ( Condcode cond );
1062extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
1063extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
1064extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
1065extern Int VG_(rankToRealRegNo) ( Int rank );
1066
1067extern void* VG_(jitmalloc) ( Int nbytes );
1068extern void VG_(jitfree) ( void* ptr );
1069
1070
1071/* ---------------------------------------------------------------------
1072 Exports of vg_execontext.c.
1073 ------------------------------------------------------------------ */
1074
1075/* Records the PC and a bit of the call chain. The first 4 %eip
1076 values are used in comparisons do remove duplicate errors, and for
1077 comparing against suppression specifications. The rest are purely
1078 informational (but often important). */
1079
1080typedef
1081 struct _ExeContextRec {
1082 struct _ExeContextRec * next;
1083 /* The size of this array is VG_(clo_backtrace_size); at least
1084 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1085 [1] is its caller, [2] is the caller of [1], etc. */
1086 Addr eips[0];
1087 }
1088 ExeContext;
1089
1090
1091/* Initialise the ExeContext storage mechanism. */
1092extern void VG_(init_ExeContext_storage) ( void );
1093
1094/* Print stats (informational only). */
1095extern void VG_(show_ExeContext_stats) ( void );
1096
1097
1098/* Take a snapshot of the client's stack. Search our collection of
1099 ExeContexts to see if we already have it, and if not, allocate a
1100 new one. Either way, return a pointer to the context. */
sewardj8c824512002-04-14 04:16:48 +00001101extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame,
1102 Addr eip, Addr ebp );
sewardjde4a1d02002-03-22 01:27:54 +00001103
1104/* Print an ExeContext. */
1105extern void VG_(pp_ExeContext) ( ExeContext* );
1106
1107/* Compare two ExeContexts, just comparing the top two callers. */
1108extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
1109
1110/* Compare two ExeContexts, just comparing the top four callers. */
1111extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
1112
1113/* Compare two ExeContexts, comparing all callers. */
1114extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
1115
1116
1117
1118/* ---------------------------------------------------------------------
1119 Exports of vg_errcontext.c.
1120 ------------------------------------------------------------------ */
1121
1122extern void VG_(load_suppressions) ( void );
1123extern void VG_(show_all_errors) ( void );
1124extern void VG_(record_value_error) ( Int size );
sewardjaabd5ad2002-04-19 15:43:37 +00001125extern void VG_(record_free_error) ( ThreadState* tst, Addr a );
1126extern void VG_(record_freemismatch_error) ( ThreadState* tst, Addr a );
sewardjde4a1d02002-03-22 01:27:54 +00001127extern void VG_(record_address_error) ( Addr a, Int size,
1128 Bool isWrite );
sewardj1e8cdc92002-04-18 11:37:52 +00001129
1130extern void VG_(record_jump_error) ( ThreadState* tst, Addr a );
sewardj8c824512002-04-14 04:16:48 +00001131
1132extern void VG_(record_param_err) ( ThreadState* tst,
1133 Addr a,
sewardjde4a1d02002-03-22 01:27:54 +00001134 Bool isWriteLack,
1135 Char* msg );
sewardj8c824512002-04-14 04:16:48 +00001136extern void VG_(record_user_err) ( ThreadState* tst,
1137 Addr a, Bool isWriteLack );
sewardjde4a1d02002-03-22 01:27:54 +00001138
1139
1140/* The classification of a faulting address. */
1141typedef
1142 enum { Stack, Unknown, Freed, Mallocd, UserG, UserS }
1143 AddrKind;
1144
1145/* Records info about a faulting address. */
1146typedef
1147 struct {
1148 /* ALL */
1149 AddrKind akind;
1150 /* Freed, Mallocd */
1151 Int blksize;
1152 /* Freed, Mallocd */
1153 Int rwoffset;
1154 /* Freed, Mallocd */
1155 ExeContext* lastchange;
sewardj1e8cdc92002-04-18 11:37:52 +00001156 /* Stack */
1157 ThreadId stack_tid;
sewardjde4a1d02002-03-22 01:27:54 +00001158 }
1159 AddrInfo;
1160
1161
1162/* ---------------------------------------------------------------------
1163 Exports of vg_clientperms.c
1164 ------------------------------------------------------------------ */
1165
1166extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
1167
sewardj8c824512002-04-14 04:16:48 +00001168extern UInt VG_(handle_client_request) ( ThreadState* tst, UInt* arg_block );
sewardjde4a1d02002-03-22 01:27:54 +00001169
1170extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
1171
1172extern void VG_(show_client_block_stats) ( void );
1173
1174
1175/* ---------------------------------------------------------------------
1176 Exports of vg_procselfmaps.c
1177 ------------------------------------------------------------------ */
1178
1179extern
1180void VG_(read_procselfmaps) (
1181 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
1182);
1183
1184
1185/* ---------------------------------------------------------------------
1186 Exports of vg_symtab2.c
1187 ------------------------------------------------------------------ */
1188
1189/* We assume the executable is loaded here ... can't really find
1190 out. There is a hacky sanity check in vg_init_memory_audit()
1191 which should trip up most stupidities.
1192*/
1193#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
1194
1195extern void VG_(read_symbols) ( void );
1196extern void VG_(mini_stack_dump) ( ExeContext* ec );
1197extern void VG_(what_obj_and_fun_is_this)
1198 ( Addr a,
1199 Char* obj_buf, Int n_obj_buf,
1200 Char* fun_buf, Int n_fun_buf );
njn4f9c9342002-04-29 16:03:24 +00001201extern Bool VG_(what_line_is_this) ( Addr a,
1202 UChar* filename, Int n_filename,
1203 UInt* lineno );
1204extern Bool VG_(what_fn_is_this) ( Bool no_demangle, Addr a,
1205 Char* fn_name, Int n_fn_name);
sewardjde4a1d02002-03-22 01:27:54 +00001206
1207extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
1208
1209
1210/* ---------------------------------------------------------------------
1211 Exports of vg_clientmalloc.c
1212 ------------------------------------------------------------------ */
1213
sewardjde4a1d02002-03-22 01:27:54 +00001214typedef
1215 enum {
1216 Vg_AllocMalloc = 0,
sewardj2e93c502002-04-12 11:12:52 +00001217 Vg_AllocNew = 1,
sewardjde4a1d02002-03-22 01:27:54 +00001218 Vg_AllocNewVec = 2
1219 }
1220 VgAllocKind;
1221
1222/* Description of a malloc'd chunk. */
1223typedef
1224 struct _ShadowChunk {
1225 struct _ShadowChunk* next;
1226 ExeContext* where; /* where malloc'd/free'd */
1227 UInt size : 30; /* size requested. */
1228 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1229 Addr data; /* ptr to actual block. */
1230 }
1231 ShadowChunk;
1232
1233extern void VG_(clientmalloc_done) ( void );
1234extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
1235extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1236
sewardj2e93c502002-04-12 11:12:52 +00001237/* These are called from the scheduler, when it intercepts a user
1238 request. */
sewardj8c824512002-04-14 04:16:48 +00001239extern void* VG_(client_malloc) ( ThreadState* tst,
1240 UInt size, VgAllocKind kind );
1241extern void* VG_(client_memalign) ( ThreadState* tst,
1242 UInt align, UInt size );
1243extern void VG_(client_free) ( ThreadState* tst,
1244 void* ptrV, VgAllocKind kind );
1245extern void* VG_(client_calloc) ( ThreadState* tst,
1246 UInt nmemb, UInt size1 );
1247extern void* VG_(client_realloc) ( ThreadState* tst,
1248 void* ptrV, UInt size_new );
sewardjde4a1d02002-03-22 01:27:54 +00001249
1250
1251/* ---------------------------------------------------------------------
1252 Exports of vg_main.c
1253 ------------------------------------------------------------------ */
1254
sewardjde4a1d02002-03-22 01:27:54 +00001255/* A structure used as an intermediary when passing the simulated
1256 CPU's state to some assembly fragments, particularly system calls.
1257 Stuff is copied from baseBlock to here, the assembly magic runs,
1258 and then the inverse copy is done. */
1259
1260extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
1261 + 1 /* %eflags */
1262 + 1 /* %eip */
1263 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1264 ];
1265
1266/* Handy fns for doing the copy back and forth. */
1267extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1268extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1269
sewardjde4a1d02002-03-22 01:27:54 +00001270/* Called when some unhandleable client behaviour is detected.
1271 Prints a msg and aborts. */
1272extern void VG_(unimplemented) ( Char* msg );
1273
1274/* The stack on which Valgrind runs. We can't use the same stack as the
1275 simulatee -- that's an important design decision. */
1276extern UInt VG_(stack)[10000];
1277
1278/* Similarly, we have to ask for signals to be delivered on an
1279 alternative stack, since it is possible, although unlikely, that
1280 we'll have to run client code from inside the Valgrind-installed
1281 signal handler. If this happens it will be done by
1282 vg_deliver_signal_immediately(). */
1283extern UInt VG_(sigstack)[10000];
1284
sewardjde4a1d02002-03-22 01:27:54 +00001285/* Holds client's %esp at the point we gained control. From this the
1286 client's argc, argv and envp are deduced. */
1287extern Addr VG_(esp_at_startup);
1288extern Int VG_(client_argc);
1289extern Char** VG_(client_argv);
1290extern Char** VG_(client_envp);
1291
1292/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
1293 don't get traced into. */
1294extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
1295
1296/* Something of a function looking for a home ... start up GDB. This
1297 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1298 *client's* stack. This is necessary to give GDB the illusion that
1299 the client program really was running on the real cpu. */
1300extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1301
1302/* Spew out vast amounts of junk during JITting? */
1303extern Bool VG_(disassemble);
1304
1305/* 64-bit counter for the number of basic blocks done. */
1306extern ULong VG_(bbs_done);
1307/* 64-bit counter for the number of bbs to go before a debug exit. */
1308extern ULong VG_(bbs_to_go);
1309
1310/* Counts downwards in vg_run_innerloop. */
1311extern UInt VG_(dispatch_ctr);
1312
sewardjde4a1d02002-03-22 01:27:54 +00001313/* Is the client running on the simulated CPU or the real one? */
1314extern Bool VG_(running_on_simd_CPU); /* Initially False */
1315
1316/* The current LRU epoch. */
1317extern UInt VG_(current_epoch);
1318
1319
1320/* --- Counters, for informational purposes only. --- */
1321
1322/* Number of lookups which miss the fast tt helper. */
1323extern UInt VG_(tt_fast_misses);
1324
1325/* Counts for LRU informational messages. */
1326
1327/* Number and total o/t size of new translations this epoch. */
1328extern UInt VG_(this_epoch_in_count);
1329extern UInt VG_(this_epoch_in_osize);
1330extern UInt VG_(this_epoch_in_tsize);
1331/* Number and total o/t size of discarded translations this epoch. */
1332extern UInt VG_(this_epoch_out_count);
1333extern UInt VG_(this_epoch_out_osize);
1334extern UInt VG_(this_epoch_out_tsize);
1335/* Number and total o/t size of translations overall. */
1336extern UInt VG_(overall_in_count);
1337extern UInt VG_(overall_in_osize);
1338extern UInt VG_(overall_in_tsize);
1339/* Number and total o/t size of discards overall. */
1340extern UInt VG_(overall_out_count);
1341extern UInt VG_(overall_out_osize);
1342extern UInt VG_(overall_out_tsize);
1343
1344/* The number of LRU-clearings of TT/TC. */
1345extern UInt VG_(number_of_lrus);
1346
1347/* Counts pertaining to the register allocator. */
1348
1349/* total number of uinstrs input to reg-alloc */
1350extern UInt VG_(uinstrs_prealloc);
1351
1352/* total number of uinstrs added due to spill code */
1353extern UInt VG_(uinstrs_spill);
1354
1355/* number of bbs requiring spill code */
1356extern UInt VG_(translations_needing_spill);
1357
1358/* total of register ranks over all translations */
1359extern UInt VG_(total_reg_rank);
1360
1361/* Counts pertaining to the self-modifying-code detection machinery. */
1362
1363/* Total number of writes checked. */
1364//extern UInt VG_(smc_total_check4s);
1365
1366/* Number of writes which the fast smc check couldn't show were
1367 harmless. */
1368extern UInt VG_(smc_cache_passed);
1369
1370/* Numnber of writes which really did write on original code. */
1371extern UInt VG_(smc_fancy_passed);
1372
1373/* Number of translations discarded as a result. */
1374//extern UInt VG_(smc_discard_count);
1375
1376/* Counts pertaining to internal sanity checking. */
1377extern UInt VG_(sanity_fast_count);
1378extern UInt VG_(sanity_slow_count);
1379
sewardj2e93c502002-04-12 11:12:52 +00001380/* Counts pertaining to the scheduler. */
1381extern UInt VG_(num_scheduling_events_MINOR);
1382extern UInt VG_(num_scheduling_events_MAJOR);
1383
sewardjde4a1d02002-03-22 01:27:54 +00001384
1385/* ---------------------------------------------------------------------
1386 Exports of vg_memory.c
1387 ------------------------------------------------------------------ */
1388
1389extern void VGM_(init_memory_audit) ( void );
1390extern Addr VGM_(curr_dataseg_end);
1391extern void VG_(show_reg_tags) ( void );
1392extern void VG_(detect_memory_leaks) ( void );
1393extern void VG_(done_prof_mem) ( void );
1394
1395/* Set permissions for an address range. Not speed-critical. */
1396extern void VGM_(make_noaccess) ( Addr a, UInt len );
1397extern void VGM_(make_writable) ( Addr a, UInt len );
1398extern void VGM_(make_readable) ( Addr a, UInt len );
1399/* Use with care! (read: use for shmat only) */
1400extern void VGM_(make_readwritable) ( Addr a, UInt len );
1401extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1402 UInt len );
1403
1404/* Check permissions for an address range. Not speed-critical. */
1405extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1406extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1407extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1408
sewardj0c3b53f2002-05-01 01:58:35 +00001409/* Sanity checks which may be done at any time. The scheduler decides
1410 when. */
1411extern void VG_(do_sanity_checks) ( Bool force_expensive );
sewardjde4a1d02002-03-22 01:27:54 +00001412/* Very cheap ... */
1413extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1414
1415/* These functions are called from generated code. */
1416extern void VG_(helperc_STOREV4) ( UInt, Addr );
1417extern void VG_(helperc_STOREV2) ( UInt, Addr );
1418extern void VG_(helperc_STOREV1) ( UInt, Addr );
1419
1420extern UInt VG_(helperc_LOADV1) ( Addr );
1421extern UInt VG_(helperc_LOADV2) ( Addr );
1422extern UInt VG_(helperc_LOADV4) ( Addr );
1423
1424extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1425extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1426extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1427
1428/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1429 space and pass the addresses and values of all addressible,
1430 defined, aligned words to notify_word. This is the basis for the
1431 leak detector. Returns the number of calls made to notify_word. */
1432UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1433
1434/* Is this address within some small distance below %ESP? Used only
1435 for the --workaround-gcc296-bugs kludge. */
sewardj8c824512002-04-14 04:16:48 +00001436extern Bool VG_(is_just_below_ESP)( Addr esp, Addr aa );
sewardjde4a1d02002-03-22 01:27:54 +00001437
1438/* Nasty kludgery to deal with applications which switch stacks,
1439 like netscape. */
sewardjde4a1d02002-03-22 01:27:54 +00001440#define VG_PLAUSIBLE_STACK_SIZE 8000000
1441
sewardjde4a1d02002-03-22 01:27:54 +00001442
1443/* ---------------------------------------------------------------------
1444 Exports of vg_syscall_mem.c
1445 ------------------------------------------------------------------ */
1446
sewardj2e93c502002-04-12 11:12:52 +00001447extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001448
sewardj2e93c502002-04-12 11:12:52 +00001449extern void VG_(check_known_blocking_syscall) ( ThreadId tid,
1450 Int syscallno,
1451 Int* /*IN*/ res );
sewardjde4a1d02002-03-22 01:27:54 +00001452
1453extern Bool VG_(is_kerror) ( Int res );
1454
sewardj2e93c502002-04-12 11:12:52 +00001455#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1456 VG_(load_thread_state)(thread_id); \
sewardjde4a1d02002-03-22 01:27:54 +00001457 VG_(copy_baseBlock_to_m_state_static)(); \
1458 VG_(do_syscall)(); \
1459 VG_(copy_m_state_static_to_baseBlock)(); \
sewardj2e93c502002-04-12 11:12:52 +00001460 VG_(save_thread_state)(thread_id); \
1461 result_lvalue = VG_(get_thread_state)(thread_id)->m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001462
1463
1464/* ---------------------------------------------------------------------
1465 Exports of vg_transtab.c
1466 ------------------------------------------------------------------ */
1467
1468/* An entry in the translation table (TT). */
1469typedef
1470 struct {
1471 /* +0 */ Addr orig_addr;
1472 /* +4 */ Addr trans_addr;
1473 /* +8 */ UInt mru_epoch;
1474 /* +12 */ UShort orig_size;
1475 /* +14 */ UShort trans_size;
1476 }
1477 TTEntry;
1478
1479/* The number of basic blocks in an epoch (one age-step). */
1480#define VG_BBS_PER_EPOCH 20000
1481
1482extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1483extern void VG_(maybe_do_lru_pass) ( void );
1484extern void VG_(flush_transtab) ( void );
1485extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1486extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1487
1488extern void VG_(smc_mark_original) ( Addr original_addr,
1489 Int original_len );
1490
1491extern void VG_(init_transtab_and_SMC) ( void );
1492
1493extern void VG_(sanity_check_tc_tt) ( void );
1494extern Addr VG_(search_transtab) ( Addr original_addr );
1495
1496extern void VG_(invalidate_tt_fast)( void );
1497
1498
1499/* ---------------------------------------------------------------------
1500 Exports of vg_vtagops.c
1501 ------------------------------------------------------------------ */
1502
1503/* Lists the names of value-tag operations used in instrumented
1504 code. These are the third argument to TAG1 and TAG2 uinsns. */
1505
1506typedef
1507 enum {
1508 /* Unary. */
1509 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1510 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1511
1512 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1513
1514 VgT_Left4, VgT_Left2, VgT_Left1,
1515
1516 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1517 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1518
1519 /* Binary; 1st is rd; 2nd is rd+wr */
1520 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1521 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1522
1523 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1524 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1525 VgT_DebugFn
1526 }
1527 VgTagOp;
1528
1529extern Char* VG_(nameOfTagOp) ( VgTagOp );
1530extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1531
1532
1533/* ---------------------------------------------------------------------
1534 Exports of vg_syscall.S
1535 ------------------------------------------------------------------ */
1536
1537extern void VG_(do_syscall) ( void );
1538
1539
1540/* ---------------------------------------------------------------------
1541 Exports of vg_startup.S
1542 ------------------------------------------------------------------ */
1543
1544extern void VG_(shutdown);
1545extern void VG_(switch_to_real_CPU) ( void );
1546
sewardj35805422002-04-21 13:05:34 +00001547extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1548 Addr m_esp_at_error,
1549 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001550
1551
1552/* ---------------------------------------------------------------------
1553 Exports of vg_dispatch.S
1554 ------------------------------------------------------------------ */
1555
sewardj2e93c502002-04-12 11:12:52 +00001556/* Run a thread for a (very short) while, until some event happens
1557 which means we need to defer to the scheduler. */
1558extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001559
1560
1561/* ---------------------------------------------------------------------
1562 Exports of vg_helpers.S
1563 ------------------------------------------------------------------ */
1564
sewardjde4a1d02002-03-22 01:27:54 +00001565/* SMC fast checks. */
1566extern void VG_(helper_smc_check4);
1567
1568/* Mul, div, etc, -- we don't codegen these directly. */
1569extern void VG_(helper_idiv_64_32);
1570extern void VG_(helper_div_64_32);
1571extern void VG_(helper_idiv_32_16);
1572extern void VG_(helper_div_32_16);
1573extern void VG_(helper_idiv_16_8);
1574extern void VG_(helper_div_16_8);
1575
1576extern void VG_(helper_imul_32_64);
1577extern void VG_(helper_mul_32_64);
1578extern void VG_(helper_imul_16_32);
1579extern void VG_(helper_mul_16_32);
1580extern void VG_(helper_imul_8_16);
1581extern void VG_(helper_mul_8_16);
1582
1583extern void VG_(helper_CLD);
1584extern void VG_(helper_STD);
1585extern void VG_(helper_get_dirflag);
1586
1587extern void VG_(helper_shldl);
1588extern void VG_(helper_shldw);
1589extern void VG_(helper_shrdl);
1590extern void VG_(helper_shrdw);
1591
1592extern void VG_(helper_RDTSC);
1593extern void VG_(helper_CPUID);
1594
sewardjde4a1d02002-03-22 01:27:54 +00001595extern void VG_(helper_bsf);
1596extern void VG_(helper_bsr);
1597
1598extern void VG_(helper_fstsw_AX);
1599extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001600extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001601extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001602
1603extern void VG_(helper_value_check4_fail);
1604extern void VG_(helper_value_check2_fail);
1605extern void VG_(helper_value_check1_fail);
1606extern void VG_(helper_value_check0_fail);
1607
sewardjbc5b99f2002-04-13 00:08:51 +00001608/* NOT FUNCTIONS; these are bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001609extern void VG_(signalreturn_bogusRA)( void );
sewardjbc5b99f2002-04-13 00:08:51 +00001610extern void VG_(pthreadreturn_bogusRA)( void );
sewardj54cacf02002-04-12 23:24:59 +00001611
njn4f9c9342002-04-29 16:03:24 +00001612/* ---------------------------------------------------------------------
1613 Exports of vg_cachesim.c
1614 ------------------------------------------------------------------ */
1615
1616extern UCodeBlock* VG_(cachesim_instrument)(UCodeBlock* cb_in, Addr orig_addr);
1617
1618typedef struct _iCC iCC;
1619typedef struct _idCC idCC;
1620
1621extern void VG_(init_cachesim) ( void );
1622extern void VG_(show_cachesim_results)( Int client_argc, Char** client_argv );
1623
1624extern void VG_(cachesim_log_non_mem_instr)( iCC* cc );
1625extern void VG_(cachesim_log_mem_instr) ( idCC* cc, Addr data_addr );
sewardjde4a1d02002-03-22 01:27:54 +00001626
1627/* ---------------------------------------------------------------------
1628 The state of the simulated CPU.
1629 ------------------------------------------------------------------ */
1630
1631/* This is the Intel register encoding. */
1632#define R_EAX 0
1633#define R_ECX 1
1634#define R_EDX 2
1635#define R_EBX 3
1636#define R_ESP 4
1637#define R_EBP 5
1638#define R_ESI 6
1639#define R_EDI 7
1640
1641#define R_AL (0+R_EAX)
1642#define R_CL (0+R_ECX)
1643#define R_DL (0+R_EDX)
1644#define R_BL (0+R_EBX)
1645#define R_AH (4+R_EAX)
1646#define R_CH (4+R_ECX)
1647#define R_DH (4+R_EDX)
1648#define R_BH (4+R_EBX)
1649
1650
1651/* ---------------------------------------------------------------------
1652 Offsets into baseBlock for everything which needs to referred to
1653 from generated code. The order of these decls does not imply
1654 what the order of the actual offsets is. The latter is important
1655 and is set up in vg_main.c.
1656 ------------------------------------------------------------------ */
1657
1658/* An array of words. In generated code, %ebp always points to the
1659 start of this array. Useful stuff, like the simulated CPU state,
1660 and the addresses of helper functions, can then be found by
1661 indexing off %ebp. The following declares variables which, at
1662 startup time, are given values denoting offsets into baseBlock.
1663 These offsets are in *words* from the start of baseBlock. */
1664
1665#define VG_BASEBLOCK_WORDS 200
1666
1667extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1668
1669
1670/* -----------------------------------------------------
1671 Read-write parts of baseBlock.
1672 -------------------------------------------------- */
1673
1674/* State of the simulated CPU. */
1675extern Int VGOFF_(m_eax);
1676extern Int VGOFF_(m_ecx);
1677extern Int VGOFF_(m_edx);
1678extern Int VGOFF_(m_ebx);
1679extern Int VGOFF_(m_esp);
1680extern Int VGOFF_(m_ebp);
1681extern Int VGOFF_(m_esi);
1682extern Int VGOFF_(m_edi);
1683extern Int VGOFF_(m_eflags);
1684extern Int VGOFF_(m_fpustate);
1685extern Int VGOFF_(m_eip);
1686
1687/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1688extern Int VGOFF_(spillslots);
1689
1690/* Records the valid bits for the 8 integer regs & flags reg. */
1691extern Int VGOFF_(sh_eax);
1692extern Int VGOFF_(sh_ecx);
1693extern Int VGOFF_(sh_edx);
1694extern Int VGOFF_(sh_ebx);
1695extern Int VGOFF_(sh_esp);
1696extern Int VGOFF_(sh_ebp);
1697extern Int VGOFF_(sh_esi);
1698extern Int VGOFF_(sh_edi);
1699extern Int VGOFF_(sh_eflags);
1700
1701
1702/* -----------------------------------------------------
1703 Read-only parts of baseBlock.
1704 -------------------------------------------------- */
1705
1706/* Offsets of addresses of helper functions. A "helper" function is
1707 one which is called from generated code. */
1708
1709extern Int VGOFF_(helper_idiv_64_32);
1710extern Int VGOFF_(helper_div_64_32);
1711extern Int VGOFF_(helper_idiv_32_16);
1712extern Int VGOFF_(helper_div_32_16);
1713extern Int VGOFF_(helper_idiv_16_8);
1714extern Int VGOFF_(helper_div_16_8);
1715
1716extern Int VGOFF_(helper_imul_32_64);
1717extern Int VGOFF_(helper_mul_32_64);
1718extern Int VGOFF_(helper_imul_16_32);
1719extern Int VGOFF_(helper_mul_16_32);
1720extern Int VGOFF_(helper_imul_8_16);
1721extern Int VGOFF_(helper_mul_8_16);
1722
1723extern Int VGOFF_(helper_CLD);
1724extern Int VGOFF_(helper_STD);
1725extern Int VGOFF_(helper_get_dirflag);
1726
1727extern Int VGOFF_(helper_shldl);
1728extern Int VGOFF_(helper_shldw);
1729extern Int VGOFF_(helper_shrdl);
1730extern Int VGOFF_(helper_shrdw);
1731
1732extern Int VGOFF_(helper_RDTSC);
1733extern Int VGOFF_(helper_CPUID);
1734
sewardjde4a1d02002-03-22 01:27:54 +00001735extern Int VGOFF_(helper_bsf);
1736extern Int VGOFF_(helper_bsr);
1737
1738extern Int VGOFF_(helper_fstsw_AX);
1739extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001740extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001741extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001742
1743extern Int VGOFF_(helper_value_check4_fail);
1744extern Int VGOFF_(helper_value_check2_fail);
1745extern Int VGOFF_(helper_value_check1_fail);
1746extern Int VGOFF_(helper_value_check0_fail);
1747
sewardjde4a1d02002-03-22 01:27:54 +00001748extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1749extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1750extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1751
1752extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1753extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1754extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1755
1756extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1757extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1758extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1759
njn4f9c9342002-04-29 16:03:24 +00001760extern Int VGOFF_(cachesim_log_non_mem_instr);
1761extern Int VGOFF_(cachesim_log_mem_instr);
sewardjde4a1d02002-03-22 01:27:54 +00001762
1763#endif /* ndef __VG_INCLUDE_H */
1764
sewardj3b2736a2002-03-24 12:18:35 +00001765
1766/* ---------------------------------------------------------------------
1767 Finally - autoconf-generated settings
1768 ------------------------------------------------------------------ */
1769
1770#include "config.h"
1771
sewardjde4a1d02002-03-22 01:27:54 +00001772/*--------------------------------------------------------------------*/
1773/*--- end vg_include.h ---*/
1774/*--------------------------------------------------------------------*/