blob: 4794cd0dc5594aed98048c5f1116d7849f0ed620 [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);
265
266
267/* ---------------------------------------------------------------------
268 Debugging and profiling stuff
269 ------------------------------------------------------------------ */
270
271/* No, really. I _am_ that strange. */
272#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
273
274/* Tools for building messages from multiple parts. */
275typedef
276 enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg }
277 VgMsgKind;
278
279extern void VG_(start_msg) ( VgMsgKind kind );
280extern void VG_(add_to_msg) ( Char* format, ... );
281extern void VG_(end_msg) ( void );
282
283/* Send a simple, single-part message. */
284extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
285
286/* Create a logfile into which messages can be dumped. */
287extern void VG_(startup_logging) ( void );
288extern void VG_(shutdown_logging) ( void );
289
290
291/* Profiling stuff */
292#ifdef VG_PROFILE
293
294#define VGP_M_STACK 10
295
sewardj671ff542002-05-07 09:25:30 +0000296#define VGP_M_CCS 26 /* == the # of elems in VGP_LIST */
sewardjde4a1d02002-03-22 01:27:54 +0000297#define VGP_LIST \
sewardj671ff542002-05-07 09:25:30 +0000298 VGP_PAIR(VgpUnc=0, "unclassified"), \
299 VGP_PAIR(VgpRun, "running"), \
300 VGP_PAIR(VgpSched, "scheduler"), \
sewardjde4a1d02002-03-22 01:27:54 +0000301 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
302 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
303 VGP_PAIR(VgpTranslate, "translate-main"), \
304 VGP_PAIR(VgpToUCode, "to-ucode"), \
305 VGP_PAIR(VgpFromUcode, "from-ucode"), \
306 VGP_PAIR(VgpImprove, "improve"), \
307 VGP_PAIR(VgpInstrument, "instrument"), \
308 VGP_PAIR(VgpCleanup, "cleanup"), \
309 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
310 VGP_PAIR(VgpDoLRU, "do-lru"), \
311 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
312 VGP_PAIR(VgpInitAudit, "init-mem-audit"), \
313 VGP_PAIR(VgpExeContext, "exe-context"), \
314 VGP_PAIR(VgpReadSyms, "read-syms"), \
315 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
316 VGP_PAIR(VgpSARP, "set-addr-range-perms"), \
317 VGP_PAIR(VgpSyscall, "syscall wrapper"), \
njn4f9c9342002-04-29 16:03:24 +0000318 VGP_PAIR(VgpCacheInstrument, "cache instrument"), \
319 VGP_PAIR(VgpCacheGetBBCC,"cache get BBCC"), \
320 VGP_PAIR(VgpCacheSimulate, "cache simulate"), \
321 VGP_PAIR(VgpCacheDump, "cache stats dump"), \
sewardjde4a1d02002-03-22 01:27:54 +0000322 VGP_PAIR(VgpSpare1, "spare 1"), \
323 VGP_PAIR(VgpSpare2, "spare 2")
324
325#define VGP_PAIR(enumname,str) enumname
326typedef enum { VGP_LIST } VgpCC;
327#undef VGP_PAIR
328
329extern void VGP_(init_profiling) ( void );
330extern void VGP_(done_profiling) ( void );
331extern void VGP_(pushcc) ( VgpCC );
332extern void VGP_(popcc) ( void );
333
334#define VGP_PUSHCC(cc) VGP_(pushcc)(cc)
335#define VGP_POPCC VGP_(popcc)()
336
337#else
338
339#define VGP_PUSHCC(cc) /* */
340#define VGP_POPCC /* */
341
342#endif /* VG_PROFILE */
343
344
345/* ---------------------------------------------------------------------
346 Exports of vg_malloc2.c
347 ------------------------------------------------------------------ */
348
349/* Allocation arenas.
350 SYMTAB is for Valgrind's symbol table storage.
351 CLIENT is for the client's mallocs/frees.
352 DEMANGLE is for the C++ demangler.
353 EXECTXT is for storing ExeContexts.
354 ERRCTXT is for storing ErrContexts.
355 PRIVATE is for Valgrind general stuff.
356 TRANSIENT is for very short-term use. It should be empty
357 in between uses.
358 When adding a new arena, remember also to add it
359 to ensure_mm_init().
360*/
361typedef Int ArenaId;
362
363#define VG_N_ARENAS 7
364
365#define VG_AR_PRIVATE 0 /* :: ArenaId */
366#define VG_AR_SYMTAB 1 /* :: ArenaId */
367#define VG_AR_CLIENT 2 /* :: ArenaId */
368#define VG_AR_DEMANGLE 3 /* :: ArenaId */
369#define VG_AR_EXECTXT 4 /* :: ArenaId */
370#define VG_AR_ERRCTXT 5 /* :: ArenaId */
371#define VG_AR_TRANSIENT 6 /* :: ArenaId */
372
373extern void* VG_(malloc) ( ArenaId arena, Int nbytes );
374extern void VG_(free) ( ArenaId arena, void* ptr );
375extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes );
376extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size );
377extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB,
378 Int req_pszB );
379
380extern void VG_(mallocSanityCheckArena) ( ArenaId arena );
381extern void VG_(mallocSanityCheckAll) ( void );
382
383extern void VG_(show_all_arena_stats) ( void );
384extern Bool VG_(is_empty_arena) ( ArenaId aid );
385
386
387/* The red-zone size for the client. This can be arbitrary, but
388 unfortunately must be set at compile time. */
389#define VG_AR_CLIENT_REDZONE_SZW 4
390
391#define VG_AR_CLIENT_REDZONE_SZB \
392 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
393
394
395/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000396 Exports of vg_clientfuns.c
397 ------------------------------------------------------------------ */
398
399/* This doesn't export code or data that valgrind.so needs to link
400 against. However, the scheduler does need to know the following
401 request codes. A few, publically-visible, request codes are also
402 defined in valgrind.h. */
403
404#define VG_USERREQ__MALLOC 0x2001
405#define VG_USERREQ__BUILTIN_NEW 0x2002
406#define VG_USERREQ__BUILTIN_VEC_NEW 0x2003
407
408#define VG_USERREQ__FREE 0x2004
409#define VG_USERREQ__BUILTIN_DELETE 0x2005
410#define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006
411
412#define VG_USERREQ__CALLOC 0x2007
413#define VG_USERREQ__REALLOC 0x2008
414#define VG_USERREQ__MEMALIGN 0x2009
415
416
417#define VG_USERREQ__PTHREAD_CREATE 0x3001
sewardjbc5b99f2002-04-13 00:08:51 +0000418#define VG_USERREQ__PTHREAD_JOIN 0x3002
419#define VG_USERREQ__PTHREAD_GET_THREADID 0x3003
sewardj3b5d8862002-04-20 13:53:23 +0000420#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x3004
sewardj30671ff2002-04-21 00:13:57 +0000421#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x3005
422#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x3006
423#define VG_USERREQ__PTHREAD_CANCEL 0x3007
424#define VG_USERREQ__PTHREAD_EXIT 0x3008
425#define VG_USERREQ__PTHREAD_COND_WAIT 0x3009
sewardj5f07b662002-04-23 16:52:51 +0000426#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x300A
427#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x300B
428#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x300C
429#define VG_USERREQ__PTHREAD_KEY_CREATE 0x300D
430#define VG_USERREQ__PTHREAD_KEY_DELETE 0x300E
431#define VG_USERREQ__PTHREAD_SETSPECIFIC 0x300F
432#define VG_USERREQ__PTHREAD_GETSPECIFIC 0x3010
sewardj56fc53d2002-04-24 01:17:42 +0000433#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3011
sewardj2e93c502002-04-12 11:12:52 +0000434
sewardj45b4b372002-04-16 22:50:32 +0000435/* Cosmetic ... */
436#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
437
sewardj54cacf02002-04-12 23:24:59 +0000438/*
439In vg_constants.h:
440#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardjbc5b99f2002-04-13 00:08:51 +0000441#define VG_USERREQ__PTHREAD_RETURNS 0x4002
sewardj54cacf02002-04-12 23:24:59 +0000442*/
443
444
sewardj2e93c502002-04-12 11:12:52 +0000445/* ---------------------------------------------------------------------
446 Constants pertaining to the simulated CPU state, VG_(baseBlock),
447 which need to go here to avoid ugly circularities.
448 ------------------------------------------------------------------ */
449
450/* How big is the saved FPU state? */
451#define VG_SIZE_OF_FPUSTATE 108
452/* ... and in words ... */
453#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
454
455
456/* ---------------------------------------------------------------------
457 Exports of vg_scheduler.c
458 ------------------------------------------------------------------ */
459
460/* ThreadIds are simply indices into the vg_threads[] array. */
461typedef
462 UInt
463 ThreadId;
464
sewardj6072c362002-04-19 14:40:57 +0000465/* Special magic value for an invalid ThreadId. It corresponds to
466 LinuxThreads using zero as the initial value for
467 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
468#define VG_INVALID_THREADID ((ThreadId)(0))
sewardj2e93c502002-04-12 11:12:52 +0000469
470typedef
471 enum {
472 VgTs_Empty, /* this slot is not in use */
473 VgTs_Runnable, /* waiting to be scheduled */
474 VgTs_WaitJoiner, /* waiting for someone to do join on me */
475 VgTs_WaitJoinee, /* waiting for the thread I did join on */
476 VgTs_WaitFD, /* waiting for I/O completion on a fd */
477 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000478 VgTs_WaitCV, /* waiting on a condition variable */
sewardj2e93c502002-04-12 11:12:52 +0000479 VgTs_Sleeping /* sleeping for a while */
480 }
481 ThreadStatus;
482
483typedef
484 struct {
sewardj6072c362002-04-19 14:40:57 +0000485 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
486 The thread identity is simply the index in vg_threads[].
487 ThreadId == 1 is the root thread and has the special property
sewardj1e8cdc92002-04-18 11:37:52 +0000488 that we don't try and allocate or deallocate its stack. For
489 convenience of generating error message, we also put the
490 ThreadId in this tid field, but be aware that it should
sewardj604ec3c2002-04-18 22:38:41 +0000491 ALWAYS == the index in vg_threads[]. */
sewardj1e8cdc92002-04-18 11:37:52 +0000492 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000493
sewardj5f07b662002-04-23 16:52:51 +0000494 /* Current scheduling status.
495
496 Complications: whenever this is set to VgTs_WaitMX, you
497 should also set .m_edx to whatever the required return value
498 is for pthread_mutex_lock / pthread_cond_timedwait for when
499 the mutex finally gets unblocked. */
sewardj2e93c502002-04-12 11:12:52 +0000500 ThreadStatus status;
501
502 /* Identity of joiner (thread who called join on me), or
503 VG_INVALID_THREADID if no one asked to join yet. */
504 ThreadId joiner;
505
sewardj3b5d8862002-04-20 13:53:23 +0000506 /* When .status == WaitMX, points to the mutex I am waiting for.
507 When .status == WaitCV, points to the mutex associated with
508 the condition variable indicated by the .associated_cv field.
509 In all other cases, should be NULL. */
510 void* /* pthread_mutex_t* */ associated_mx;
511
512 /* When .status == WaitCV, points to the condition variable I am
513 waiting for. In all other cases, should be NULL. */
514 void* /* pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000515
sewardj5f07b662002-04-23 16:52:51 +0000516 /* If VgTs_Sleeping, this is when we should wake up, measured in
517 milliseconds as supplied by VG_(read_millisecond_counter).
518
519 If VgTs_WaitCV, this indicates the time at which
520 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
521 this means infinitely far in the future, viz,
522 pthread_cond_wait. */
523 UInt awaken_at;
sewardj2e93c502002-04-12 11:12:52 +0000524
525 /* return value */
526 void* retval;
527
sewardj5f07b662002-04-23 16:52:51 +0000528 /* thread-specific data */
529 void* specifics[VG_N_THREAD_KEYS];
530
sewardj2e93c502002-04-12 11:12:52 +0000531 /* Stacks. When a thread slot is freed, we don't deallocate its
532 stack; we just leave it lying around for the next use of the
533 slot. If the next use of the slot requires a larger stack,
534 only then is the old one deallocated and a new one
535 allocated.
536
537 For the main thread (threadid == 0), this mechanism doesn't
538 apply. We don't know the size of the stack since we didn't
539 allocate it, and furthermore we never reallocate it. */
540
541 /* The allocated size of this thread's stack (permanently zero
542 if this is ThreadId == 0, since we didn't allocate its stack) */
543 UInt stack_size;
544
545 /* Address of the lowest word in this thread's stack. NULL means
546 not allocated yet.
547 */
548 Addr stack_base;
549
sewardj1e8cdc92002-04-18 11:37:52 +0000550 /* Address of the highest legitimate word in this stack. This is
551 used for error messages only -- not critical for execution
552 correctness. Is is set for all stacks, specifically including
553 ThreadId == 0 (the main thread). */
554 Addr stack_highest_word;
555
sewardj2e93c502002-04-12 11:12:52 +0000556 /* Saved machine context. */
557 UInt m_eax;
558 UInt m_ebx;
559 UInt m_ecx;
560 UInt m_edx;
561 UInt m_esi;
562 UInt m_edi;
563 UInt m_ebp;
564 UInt m_esp;
565 UInt m_eflags;
566 UInt m_eip;
567 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
568
569 UInt sh_eax;
570 UInt sh_ebx;
571 UInt sh_ecx;
572 UInt sh_edx;
573 UInt sh_esi;
574 UInt sh_edi;
575 UInt sh_ebp;
576 UInt sh_esp;
577 UInt sh_eflags;
578 }
579 ThreadState;
580
581
582/* Copy the specified thread's state into VG_(baseBlock) in
583 preparation for running it. */
584extern void VG_(load_thread_state)( ThreadId );
585
586/* Save the specified thread's state back in VG_(baseBlock), and fill
587 VG_(baseBlock) with junk, for sanity-check reasons. */
588extern void VG_(save_thread_state)( ThreadId );
589
590/* Get the thread state block for the specified thread. */
591extern ThreadState* VG_(get_thread_state)( ThreadId );
592
sewardj1e8cdc92002-04-18 11:37:52 +0000593/* And for the currently running one, if valid. */
594extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000595
sewardj1e8cdc92002-04-18 11:37:52 +0000596/* Similarly ... */
597extern ThreadId VG_(get_current_tid) ( void );
598
599/* Which thread is this address in the stack of, if any? Used for
600 error message generation. */
601extern ThreadId VG_(identify_stack_addr)( Addr a );
602
sewardj2e93c502002-04-12 11:12:52 +0000603
604/* Return codes from the scheduler. */
605typedef
sewardj7e87e382002-05-03 19:09:05 +0000606 enum {
607 VgSrc_Deadlock, /* no runnable threads and no prospect of any
608 even if we wait for a long time */
609 VgSrc_ExitSyscall, /* client called exit(). This is the normal
610 route out. */
611 VgSrc_BbsDone /* In a debugging run, the specified number of
612 bbs has been completed. */
613 }
sewardj2e93c502002-04-12 11:12:52 +0000614 VgSchedReturnCode;
615
sewardj7e87e382002-05-03 19:09:05 +0000616
sewardj2e93c502002-04-12 11:12:52 +0000617/* The scheduler. */
618extern VgSchedReturnCode VG_(scheduler) ( void );
619
620extern void VG_(scheduler_init) ( void );
621
sewardj15a43e12002-04-17 19:35:12 +0000622extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000623
624/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
625extern jmp_buf VG_(scheduler_jmpbuf);
626/* ... and if so, here's the signal which caused it to do so. */
627extern Int VG_(longjmpd_on_signal);
628
629
630/* We check that the initial stack, which we can't move, is allocated
631 here. VG_(scheduler_init) checks this.
632*/
sewardjebc82332002-04-24 14:44:23 +0000633#define VG_STARTUP_STACK_MASK (Addr)0xBFF80000
sewardj2e93c502002-04-12 11:12:52 +0000634
635
636/* The red-zone size which we put at the bottom (highest address) of
637 thread stacks, for paranoia reasons. This can be arbitrary, and
638 doesn't really need to be set at compile time. */
639#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
640
641#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
642 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
643
644
645
646/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000647 Exports of vg_signals.c
648 ------------------------------------------------------------------ */
649
sewardjde4a1d02002-03-22 01:27:54 +0000650extern void VG_(sigstartup_actions) ( void );
651
sewardj14e03422002-04-24 19:51:31 +0000652extern Bool VG_(deliver_signals) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000653extern void VG_(unblock_host_signal) ( Int sigNo );
654
655
656/* Fake system calls for signal handling. */
sewardj2e93c502002-04-12 11:12:52 +0000657extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +0000658extern void VG_(do__NR_sigprocmask) ( Int how, vki_ksigset_t* set );
659
sewardj2e93c502002-04-12 11:12:52 +0000660/* Modify the current thread's state once we have detected it is
661 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +0000662extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000663
sewardj2e93c502002-04-12 11:12:52 +0000664/* Handy utilities to block/restore all host signals. */
665extern void VG_(block_all_host_signals)
666 ( /* OUT */ vki_ksigset_t* saved_mask );
667extern void VG_(restore_host_signals)
668 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000669
670/* ---------------------------------------------------------------------
671 Exports of vg_mylibc.c
672 ------------------------------------------------------------------ */
673
674
675#define NULL ((void*)0)
676
677extern void VG_(exit)( Int status )
678 __attribute__ ((__noreturn__));
679
680extern void VG_(printf) ( const char *format, ... );
681/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
682
683extern void VG_(sprintf) ( Char* buf, Char *format, ... );
684
685extern void VG_(vprintf) ( void(*send)(Char),
686 const Char *format, va_list vargs );
687
688extern Bool VG_(isspace) ( Char c );
689
690extern Int VG_(strlen) ( const Char* str );
691
692extern Long VG_(atoll) ( Char* str );
693
694extern Char* VG_(strcat) ( Char* dest, const Char* src );
695extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
696extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
697
698extern Char* VG_(strcpy) ( Char* dest, const Char* src );
699
700extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
701extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
702
703extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
704extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
705
706extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
707extern Char* VG_(strchr) ( const Char* s, Char c );
708extern Char* VG_(strdup) ( ArenaId aid, const Char* s);
709
710extern Char* VG_(getenv) ( Char* name );
711extern Int VG_(getpid) ( void );
sewardj5f07b662002-04-23 16:52:51 +0000712
713extern void VG_(start_rdtsc_calibration) ( void );
714extern void VG_(end_rdtsc_calibration) ( void );
715extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000716
717
718extern Char VG_(toupper) ( Char c );
719
720extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
721
722extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
723
724extern Bool VG_(stringMatch) ( Char* pat, Char* str );
725
726
727#define __STRING(x) #x
728
729/* Asserts are permanently enabled. Hurrah! */
730#define vg_assert(expr) \
731 ((void) ((expr) ? 0 : \
732 (VG_(assert_fail) (__STRING(expr), \
733 __FILE__, __LINE__, \
734 __PRETTY_FUNCTION__), 0)))
735
736extern void VG_(assert_fail) ( Char* expr, Char* file,
737 Int line, Char* fn )
738 __attribute__ ((__noreturn__));
739
njn4f9c9342002-04-29 16:03:24 +0000740/* Reading and writing files. */
sewardjde4a1d02002-03-22 01:27:54 +0000741extern Int VG_(open_read) ( Char* pathname );
njn4f9c9342002-04-29 16:03:24 +0000742extern Int VG_(open_write) ( Char* pathname );
743extern Int VG_(create_and_write) ( Char* pathname );
sewardjde4a1d02002-03-22 01:27:54 +0000744extern void VG_(close) ( Int fd );
745extern Int VG_(read) ( Int fd, void* buf, Int count);
746extern Int VG_(write) ( Int fd, void* buf, Int count);
747
sewardj2e93c502002-04-12 11:12:52 +0000748extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
749
750extern Int VG_(select)( Int n,
751 vki_fd_set* readfds,
752 vki_fd_set* writefds,
753 vki_fd_set* exceptfds,
754 struct vki_timeval * timeout );
755extern Int VG_(nanosleep)( const struct vki_timespec *req,
756 struct vki_timespec *rem );
757
758
sewardjde4a1d02002-03-22 01:27:54 +0000759/* mmap-ery ... */
760extern void* VG_(mmap)( void* start, UInt length,
761 UInt prot, UInt flags, UInt fd, UInt offset );
762
sewardj2e93c502002-04-12 11:12:52 +0000763extern Int VG_(munmap)( void* start, Int length );
sewardjde4a1d02002-03-22 01:27:54 +0000764
765
766/* Print a (panic) message, and abort. */
767extern void VG_(panic) ( Char* str )
768 __attribute__ ((__noreturn__));
769
770/* Get memory by anonymous mmap. */
sewardje6a25242002-04-21 22:03:07 +0000771extern void* VG_(get_memory_from_mmap) ( Int nBytes );
772
773/* Crude stand-in for the glibc system() call. */
774extern Int VG_(system) ( Char* cmd );
775
sewardjde4a1d02002-03-22 01:27:54 +0000776
777/* Signal stuff. Note that these use the vk_ (kernel) structure
778 definitions, which are different in places from those that glibc
779 defines. Since we're operating right at the kernel interface,
780 glibc's view of the world is entirely irrelevant. */
781extern Int VG_(ksigfillset)( vki_ksigset_t* set );
782extern Int VG_(ksigemptyset)( vki_ksigset_t* set );
783extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum );
784
785extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set,
786 vki_ksigset_t* oldset );
787extern Int VG_(ksigaction) ( Int signum,
788 const vki_ksigaction* act,
789 vki_ksigaction* oldact );
790extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
791
792extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int));
793
794extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss );
795
796
797
798/* ---------------------------------------------------------------------
799 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
800 vg_from_ucode.c).
801 ------------------------------------------------------------------ */
802
803/* Tags which describe what operands are. */
804typedef
805 enum { TempReg=0, ArchReg=1, RealReg=2,
806 SpillNo=3, Literal=4, Lit16=5,
807 NoValue=6 }
808 Tag;
809
810
811/* Microinstruction opcodes. */
812typedef
813 enum {
814 NOP,
815 GET,
816 PUT,
817 LOAD,
818 STORE,
819 MOV,
820 CMOV, /* Used for cmpxchg and cmov */
821 WIDEN,
822 JMP,
823
824 /* Read/write the %EFLAGS register into a TempReg. */
825 GETF, PUTF,
826
827 ADD, ADC, AND, OR, XOR, SUB, SBB,
828 SHL, SHR, SAR, ROL, ROR, RCL, RCR,
829 NOT, NEG, INC, DEC, BSWAP,
830 CC2VAL,
831
832 /* Not strictly needed, but useful for making better
833 translations of address calculations. */
834 LEA1, /* reg2 := const + reg1 */
835 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
836
837 /* not for translating x86 calls -- only to call helpers */
838 CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences
839 for CALLM. */
840 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */
841 CALLM, /* call to a machine-code helper */
842
843 /* Hack for translating string (REP-) insns. Jump to literal if
844 TempReg/RealReg is zero. */
845 JIFZ,
846
847 /* FPU ops which read/write mem or don't touch mem at all. */
848 FPU_R,
849 FPU_W,
850 FPU,
851
852 /* Advance the simulated %eip by some small (< 128) number. */
853 INCEIP,
854
855 /* uinstrs which are not needed for mere translation of x86 code,
856 only for instrumentation of it. */
857 LOADV,
858 STOREV,
859 GETV,
860 PUTV,
861 TESTV,
862 SETV,
863 /* Get/set the v-bit (and it is only one bit) for the simulated
864 %eflags register. */
865 GETVF,
866 PUTVF,
867
868 /* Do a unary or binary tag op. Only for post-instrumented
869 code. For TAG1, first and only arg is a TempReg, and is both
870 arg and result reg. For TAG2, first arg is src, second is
871 dst, in the normal way; both are TempRegs. In both cases,
872 3rd arg is a RiCHelper with a Lit16 tag. This indicates
873 which tag op to do. */
874 TAG1,
875 TAG2
876 }
877 Opcode;
878
879
880/* Condition codes, observing the Intel encoding. CondAlways is an
881 extra. */
882typedef
883 enum {
884 CondO = 0, /* overflow */
885 CondNO = 1, /* no overflow */
886 CondB = 2, /* below */
887 CondNB = 3, /* not below */
888 CondZ = 4, /* zero */
889 CondNZ = 5, /* not zero */
890 CondBE = 6, /* below or equal */
891 CondNBE = 7, /* not below or equal */
892 CondS = 8, /* negative */
893 ConsNS = 9, /* not negative */
894 CondP = 10, /* parity even */
895 CondNP = 11, /* not parity even */
896 CondL = 12, /* jump less */
897 CondNL = 13, /* not less */
898 CondLE = 14, /* less or equal */
899 CondNLE = 15, /* not less or equal */
900 CondAlways = 16 /* Jump always */
901 }
902 Condcode;
903
904
sewardj2e93c502002-04-12 11:12:52 +0000905/* Descriptions of additional properties of *unconditional* jumps. */
906typedef
907 enum {
908 JmpBoring=0, /* boring unconditional jump */
909 JmpCall=1, /* jump due to an x86 call insn */
910 JmpRet=2, /* jump due to an x86 ret insn */
911 JmpSyscall=3, /* do a system call, then jump */
912 JmpClientReq=4 /* do a client request, then jump */
913 }
914 JmpKind;
915
916
sewardjde4a1d02002-03-22 01:27:54 +0000917/* Flags. User-level code can only read/write O(verflow), S(ign),
918 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
919 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
920 thusly:
921 76543210
922 DOSZACP
923 and bit 7 must always be zero since it is unused.
924*/
925typedef UChar FlagSet;
926
927#define FlagD (1<<6)
928#define FlagO (1<<5)
929#define FlagS (1<<4)
930#define FlagZ (1<<3)
931#define FlagA (1<<2)
932#define FlagC (1<<1)
933#define FlagP (1<<0)
934
935#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
936#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
937#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
938#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
939#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
940#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
sewardj4a7456e2002-03-24 13:52:19 +0000941#define FlagsZCP ( FlagZ | FlagC | FlagP)
sewardjde4a1d02002-03-22 01:27:54 +0000942#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000943#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000944
945#define FlagsALL (FlagsOSZACP | FlagD)
946#define FlagsEmpty (FlagSet)0
947
948#define VG_IS_FLAG_SUBSET(set1,set2) \
949 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
950
951#define VG_UNION_FLAG_SETS(set1,set2) \
952 ( ((FlagSet)set1) | ((FlagSet)set2) )
953
954
955
956/* A Micro (u)-instruction. */
957typedef
958 struct {
959 /* word 1 */
960 UInt lit32; /* 32-bit literal */
961
962 /* word 2 */
963 UShort val1; /* first operand */
964 UShort val2; /* second operand */
965
966 /* word 3 */
967 UShort val3; /* third operand */
968 UChar opcode; /* opcode */
969 UChar size; /* data transfer size */
970
971 /* word 4 */
972 FlagSet flags_r; /* :: FlagSet */
973 FlagSet flags_w; /* :: FlagSet */
974 UChar tag1:4; /* first operand tag */
975 UChar tag2:4; /* second operand tag */
976 UChar tag3:4; /* third operand tag */
977 UChar extra4b:4; /* Spare field, used by WIDEN for src
978 -size, and by LEA2 for scale
njn4f9c9342002-04-29 16:03:24 +0000979 (1,2,4 or 8), and by unconditional JMPs for
980 orig x86 instr size if --cachesim=yes */
981
sewardjde4a1d02002-03-22 01:27:54 +0000982
983 /* word 5 */
984 UChar cond; /* condition, for jumps */
985 Bool smc_check:1; /* do a smc test, if writes memory. */
986 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
sewardj2e93c502002-04-12 11:12:52 +0000987 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
sewardjde4a1d02002-03-22 01:27:54 +0000988 }
989 UInstr;
990
991
992/* Expandable arrays of uinstrs. */
993typedef
994 struct {
995 Int used;
996 Int size;
997 UInstr* instrs;
998 Int nextTemp;
999 }
1000 UCodeBlock;
1001
1002/* Refer to `the last instruction stuffed in', including as an
1003 lvalue. */
1004#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
1005
1006/* An invalid temporary number :-) */
1007#define INVALID_TEMPREG 999999999
1008
1009
1010/* ---------------------------------------------------------------------
1011 Exports of vg_demangle.c
1012 ------------------------------------------------------------------ */
1013
1014extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
1015
1016
1017/* ---------------------------------------------------------------------
1018 Exports of vg_from_ucode.c
1019 ------------------------------------------------------------------ */
1020
1021extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
1022
1023
1024/* ---------------------------------------------------------------------
1025 Exports of vg_to_ucode.c
1026 ------------------------------------------------------------------ */
1027
1028extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
1029extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
1030extern Char VG_(nameOfIntSize) ( Int size );
1031extern UInt VG_(extend_s_8to32) ( UInt x );
1032extern Int VG_(getNewTemp) ( UCodeBlock* cb );
1033extern Int VG_(getNewShadow) ( UCodeBlock* cb );
1034
1035#define SHADOW(tempreg) ((tempreg)+1)
1036
1037
1038/* ---------------------------------------------------------------------
1039 Exports of vg_translate.c
1040 ------------------------------------------------------------------ */
1041
sewardj1e8cdc92002-04-18 11:37:52 +00001042extern void VG_(translate) ( ThreadState* tst,
1043 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001044 UInt* orig_size,
1045 Addr* trans_addr,
1046 UInt* trans_size );
1047
1048extern void VG_(emptyUInstr) ( UInstr* u );
1049extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
1050extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
1051 Tag tag1, UInt val1 );
1052extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
1053 Tag tag1, UInt val1,
1054 Tag tag2, UInt val2 );
1055extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
1056 Tag tag1, UInt val1,
1057 Tag tag2, UInt val2,
1058 Tag tag3, UInt val3 );
1059extern void VG_(setFlagRW) ( UInstr* u,
1060 FlagSet fr, FlagSet fw );
1061
1062extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
1063extern Bool VG_(anyFlagUse) ( UInstr* u );
1064
1065
1066
1067extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
1068extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
1069
njn4f9c9342002-04-29 16:03:24 +00001070extern UCodeBlock* VG_(allocCodeBlock) ( void );
1071extern void VG_(freeCodeBlock) ( UCodeBlock* cb );
1072extern void VG_(copyUInstr) ( UCodeBlock* cb, UInstr* instr );
1073
sewardjde4a1d02002-03-22 01:27:54 +00001074extern Char* VG_(nameCondcode) ( Condcode cond );
1075extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
1076extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
1077extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
1078extern Int VG_(rankToRealRegNo) ( Int rank );
1079
1080extern void* VG_(jitmalloc) ( Int nbytes );
1081extern void VG_(jitfree) ( void* ptr );
1082
1083
1084/* ---------------------------------------------------------------------
1085 Exports of vg_execontext.c.
1086 ------------------------------------------------------------------ */
1087
1088/* Records the PC and a bit of the call chain. The first 4 %eip
1089 values are used in comparisons do remove duplicate errors, and for
1090 comparing against suppression specifications. The rest are purely
1091 informational (but often important). */
1092
1093typedef
1094 struct _ExeContextRec {
1095 struct _ExeContextRec * next;
1096 /* The size of this array is VG_(clo_backtrace_size); at least
1097 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1098 [1] is its caller, [2] is the caller of [1], etc. */
1099 Addr eips[0];
1100 }
1101 ExeContext;
1102
1103
1104/* Initialise the ExeContext storage mechanism. */
1105extern void VG_(init_ExeContext_storage) ( void );
1106
1107/* Print stats (informational only). */
1108extern void VG_(show_ExeContext_stats) ( void );
1109
1110
1111/* Take a snapshot of the client's stack. Search our collection of
1112 ExeContexts to see if we already have it, and if not, allocate a
1113 new one. Either way, return a pointer to the context. */
sewardj8c824512002-04-14 04:16:48 +00001114extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame,
1115 Addr eip, Addr ebp );
sewardjde4a1d02002-03-22 01:27:54 +00001116
1117/* Print an ExeContext. */
1118extern void VG_(pp_ExeContext) ( ExeContext* );
1119
1120/* Compare two ExeContexts, just comparing the top two callers. */
1121extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
1122
1123/* Compare two ExeContexts, just comparing the top four callers. */
1124extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
1125
1126/* Compare two ExeContexts, comparing all callers. */
1127extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
1128
1129
1130
1131/* ---------------------------------------------------------------------
1132 Exports of vg_errcontext.c.
1133 ------------------------------------------------------------------ */
1134
1135extern void VG_(load_suppressions) ( void );
1136extern void VG_(show_all_errors) ( void );
1137extern void VG_(record_value_error) ( Int size );
sewardjaabd5ad2002-04-19 15:43:37 +00001138extern void VG_(record_free_error) ( ThreadState* tst, Addr a );
1139extern void VG_(record_freemismatch_error) ( ThreadState* tst, Addr a );
sewardjde4a1d02002-03-22 01:27:54 +00001140extern void VG_(record_address_error) ( Addr a, Int size,
1141 Bool isWrite );
sewardj1e8cdc92002-04-18 11:37:52 +00001142
1143extern void VG_(record_jump_error) ( ThreadState* tst, Addr a );
sewardj8c824512002-04-14 04:16:48 +00001144
1145extern void VG_(record_param_err) ( ThreadState* tst,
1146 Addr a,
sewardjde4a1d02002-03-22 01:27:54 +00001147 Bool isWriteLack,
1148 Char* msg );
sewardj8c824512002-04-14 04:16:48 +00001149extern void VG_(record_user_err) ( ThreadState* tst,
1150 Addr a, Bool isWriteLack );
sewardjde4a1d02002-03-22 01:27:54 +00001151
1152
1153/* The classification of a faulting address. */
1154typedef
sewardjb581a132002-05-08 00:32:50 +00001155 enum { Undescribed, /* as-yet unclassified */
1156 Stack,
1157 Unknown, /* classification yielded nothing useful */
1158 Freed, Mallocd,
1159 UserG, UserS }
sewardjde4a1d02002-03-22 01:27:54 +00001160 AddrKind;
1161
1162/* Records info about a faulting address. */
1163typedef
1164 struct {
1165 /* ALL */
1166 AddrKind akind;
1167 /* Freed, Mallocd */
1168 Int blksize;
1169 /* Freed, Mallocd */
1170 Int rwoffset;
1171 /* Freed, Mallocd */
1172 ExeContext* lastchange;
sewardj1e8cdc92002-04-18 11:37:52 +00001173 /* Stack */
1174 ThreadId stack_tid;
sewardjb581a132002-05-08 00:32:50 +00001175 /* True if is just-below %esp -- could be a gcc bug. */
1176 Bool maybe_gcc;
sewardjde4a1d02002-03-22 01:27:54 +00001177 }
1178 AddrInfo;
1179
1180
1181/* ---------------------------------------------------------------------
1182 Exports of vg_clientperms.c
1183 ------------------------------------------------------------------ */
1184
1185extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
1186
sewardj8c824512002-04-14 04:16:48 +00001187extern UInt VG_(handle_client_request) ( ThreadState* tst, UInt* arg_block );
sewardjde4a1d02002-03-22 01:27:54 +00001188
1189extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
1190
1191extern void VG_(show_client_block_stats) ( void );
1192
1193
1194/* ---------------------------------------------------------------------
1195 Exports of vg_procselfmaps.c
1196 ------------------------------------------------------------------ */
1197
1198extern
1199void VG_(read_procselfmaps) (
1200 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
1201);
1202
1203
1204/* ---------------------------------------------------------------------
1205 Exports of vg_symtab2.c
1206 ------------------------------------------------------------------ */
1207
1208/* We assume the executable is loaded here ... can't really find
1209 out. There is a hacky sanity check in vg_init_memory_audit()
1210 which should trip up most stupidities.
1211*/
1212#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
1213
1214extern void VG_(read_symbols) ( void );
1215extern void VG_(mini_stack_dump) ( ExeContext* ec );
1216extern void VG_(what_obj_and_fun_is_this)
1217 ( Addr a,
1218 Char* obj_buf, Int n_obj_buf,
1219 Char* fun_buf, Int n_fun_buf );
njn4f9c9342002-04-29 16:03:24 +00001220extern Bool VG_(what_line_is_this) ( Addr a,
1221 UChar* filename, Int n_filename,
1222 UInt* lineno );
1223extern Bool VG_(what_fn_is_this) ( Bool no_demangle, Addr a,
1224 Char* fn_name, Int n_fn_name);
sewardjde4a1d02002-03-22 01:27:54 +00001225
1226extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
1227
1228
1229/* ---------------------------------------------------------------------
1230 Exports of vg_clientmalloc.c
1231 ------------------------------------------------------------------ */
1232
sewardjde4a1d02002-03-22 01:27:54 +00001233typedef
1234 enum {
1235 Vg_AllocMalloc = 0,
sewardj2e93c502002-04-12 11:12:52 +00001236 Vg_AllocNew = 1,
sewardjde4a1d02002-03-22 01:27:54 +00001237 Vg_AllocNewVec = 2
1238 }
1239 VgAllocKind;
1240
1241/* Description of a malloc'd chunk. */
1242typedef
1243 struct _ShadowChunk {
1244 struct _ShadowChunk* next;
1245 ExeContext* where; /* where malloc'd/free'd */
1246 UInt size : 30; /* size requested. */
1247 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1248 Addr data; /* ptr to actual block. */
1249 }
1250 ShadowChunk;
1251
1252extern void VG_(clientmalloc_done) ( void );
1253extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
1254extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1255
sewardj2e93c502002-04-12 11:12:52 +00001256/* These are called from the scheduler, when it intercepts a user
1257 request. */
sewardj8c824512002-04-14 04:16:48 +00001258extern void* VG_(client_malloc) ( ThreadState* tst,
1259 UInt size, VgAllocKind kind );
1260extern void* VG_(client_memalign) ( ThreadState* tst,
1261 UInt align, UInt size );
1262extern void VG_(client_free) ( ThreadState* tst,
1263 void* ptrV, VgAllocKind kind );
1264extern void* VG_(client_calloc) ( ThreadState* tst,
1265 UInt nmemb, UInt size1 );
1266extern void* VG_(client_realloc) ( ThreadState* tst,
1267 void* ptrV, UInt size_new );
sewardjde4a1d02002-03-22 01:27:54 +00001268
1269
1270/* ---------------------------------------------------------------------
1271 Exports of vg_main.c
1272 ------------------------------------------------------------------ */
1273
sewardjde4a1d02002-03-22 01:27:54 +00001274/* A structure used as an intermediary when passing the simulated
1275 CPU's state to some assembly fragments, particularly system calls.
1276 Stuff is copied from baseBlock to here, the assembly magic runs,
1277 and then the inverse copy is done. */
1278
1279extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
1280 + 1 /* %eflags */
1281 + 1 /* %eip */
1282 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1283 ];
1284
1285/* Handy fns for doing the copy back and forth. */
1286extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1287extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1288
sewardjde4a1d02002-03-22 01:27:54 +00001289/* Called when some unhandleable client behaviour is detected.
1290 Prints a msg and aborts. */
1291extern void VG_(unimplemented) ( Char* msg );
sewardjcfc39b22002-05-08 01:58:18 +00001292extern void VG_(nvidia_moan) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001293
1294/* The stack on which Valgrind runs. We can't use the same stack as the
1295 simulatee -- that's an important design decision. */
1296extern UInt VG_(stack)[10000];
1297
1298/* Similarly, we have to ask for signals to be delivered on an
1299 alternative stack, since it is possible, although unlikely, that
1300 we'll have to run client code from inside the Valgrind-installed
1301 signal handler. If this happens it will be done by
1302 vg_deliver_signal_immediately(). */
1303extern UInt VG_(sigstack)[10000];
1304
sewardjde4a1d02002-03-22 01:27:54 +00001305/* Holds client's %esp at the point we gained control. From this the
1306 client's argc, argv and envp are deduced. */
1307extern Addr VG_(esp_at_startup);
1308extern Int VG_(client_argc);
1309extern Char** VG_(client_argv);
1310extern Char** VG_(client_envp);
1311
1312/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
1313 don't get traced into. */
1314extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
1315
1316/* Something of a function looking for a home ... start up GDB. This
1317 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1318 *client's* stack. This is necessary to give GDB the illusion that
1319 the client program really was running on the real cpu. */
1320extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1321
1322/* Spew out vast amounts of junk during JITting? */
1323extern Bool VG_(disassemble);
1324
1325/* 64-bit counter for the number of basic blocks done. */
1326extern ULong VG_(bbs_done);
1327/* 64-bit counter for the number of bbs to go before a debug exit. */
1328extern ULong VG_(bbs_to_go);
1329
1330/* Counts downwards in vg_run_innerloop. */
1331extern UInt VG_(dispatch_ctr);
1332
sewardjde4a1d02002-03-22 01:27:54 +00001333/* Is the client running on the simulated CPU or the real one? */
1334extern Bool VG_(running_on_simd_CPU); /* Initially False */
1335
1336/* The current LRU epoch. */
1337extern UInt VG_(current_epoch);
1338
sewardj7e87e382002-05-03 19:09:05 +00001339/* This is the ThreadId of the last thread the scheduler ran. */
1340extern ThreadId VG_(last_run_tid);
1341
sewardjde4a1d02002-03-22 01:27:54 +00001342
1343/* --- Counters, for informational purposes only. --- */
1344
1345/* Number of lookups which miss the fast tt helper. */
1346extern UInt VG_(tt_fast_misses);
1347
1348/* Counts for LRU informational messages. */
1349
1350/* Number and total o/t size of new translations this epoch. */
1351extern UInt VG_(this_epoch_in_count);
1352extern UInt VG_(this_epoch_in_osize);
1353extern UInt VG_(this_epoch_in_tsize);
1354/* Number and total o/t size of discarded translations this epoch. */
1355extern UInt VG_(this_epoch_out_count);
1356extern UInt VG_(this_epoch_out_osize);
1357extern UInt VG_(this_epoch_out_tsize);
1358/* Number and total o/t size of translations overall. */
1359extern UInt VG_(overall_in_count);
1360extern UInt VG_(overall_in_osize);
1361extern UInt VG_(overall_in_tsize);
1362/* Number and total o/t size of discards overall. */
1363extern UInt VG_(overall_out_count);
1364extern UInt VG_(overall_out_osize);
1365extern UInt VG_(overall_out_tsize);
1366
1367/* The number of LRU-clearings of TT/TC. */
1368extern UInt VG_(number_of_lrus);
1369
1370/* Counts pertaining to the register allocator. */
1371
1372/* total number of uinstrs input to reg-alloc */
1373extern UInt VG_(uinstrs_prealloc);
1374
1375/* total number of uinstrs added due to spill code */
1376extern UInt VG_(uinstrs_spill);
1377
1378/* number of bbs requiring spill code */
1379extern UInt VG_(translations_needing_spill);
1380
1381/* total of register ranks over all translations */
1382extern UInt VG_(total_reg_rank);
1383
1384/* Counts pertaining to the self-modifying-code detection machinery. */
1385
1386/* Total number of writes checked. */
1387//extern UInt VG_(smc_total_check4s);
1388
1389/* Number of writes which the fast smc check couldn't show were
1390 harmless. */
1391extern UInt VG_(smc_cache_passed);
1392
1393/* Numnber of writes which really did write on original code. */
1394extern UInt VG_(smc_fancy_passed);
1395
1396/* Number of translations discarded as a result. */
1397//extern UInt VG_(smc_discard_count);
1398
1399/* Counts pertaining to internal sanity checking. */
1400extern UInt VG_(sanity_fast_count);
1401extern UInt VG_(sanity_slow_count);
1402
sewardj2e93c502002-04-12 11:12:52 +00001403/* Counts pertaining to the scheduler. */
1404extern UInt VG_(num_scheduling_events_MINOR);
1405extern UInt VG_(num_scheduling_events_MAJOR);
1406
sewardjde4a1d02002-03-22 01:27:54 +00001407
1408/* ---------------------------------------------------------------------
1409 Exports of vg_memory.c
1410 ------------------------------------------------------------------ */
1411
1412extern void VGM_(init_memory_audit) ( void );
1413extern Addr VGM_(curr_dataseg_end);
1414extern void VG_(show_reg_tags) ( void );
1415extern void VG_(detect_memory_leaks) ( void );
1416extern void VG_(done_prof_mem) ( void );
1417
1418/* Set permissions for an address range. Not speed-critical. */
1419extern void VGM_(make_noaccess) ( Addr a, UInt len );
1420extern void VGM_(make_writable) ( Addr a, UInt len );
1421extern void VGM_(make_readable) ( Addr a, UInt len );
1422/* Use with care! (read: use for shmat only) */
1423extern void VGM_(make_readwritable) ( Addr a, UInt len );
1424extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1425 UInt len );
1426
1427/* Check permissions for an address range. Not speed-critical. */
1428extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1429extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1430extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1431
sewardj0c3b53f2002-05-01 01:58:35 +00001432/* Sanity checks which may be done at any time. The scheduler decides
1433 when. */
1434extern void VG_(do_sanity_checks) ( Bool force_expensive );
sewardjde4a1d02002-03-22 01:27:54 +00001435/* Very cheap ... */
1436extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1437
1438/* These functions are called from generated code. */
1439extern void VG_(helperc_STOREV4) ( UInt, Addr );
1440extern void VG_(helperc_STOREV2) ( UInt, Addr );
1441extern void VG_(helperc_STOREV1) ( UInt, Addr );
1442
1443extern UInt VG_(helperc_LOADV1) ( Addr );
1444extern UInt VG_(helperc_LOADV2) ( Addr );
1445extern UInt VG_(helperc_LOADV4) ( Addr );
1446
1447extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1448extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1449extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1450
1451/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1452 space and pass the addresses and values of all addressible,
1453 defined, aligned words to notify_word. This is the basis for the
1454 leak detector. Returns the number of calls made to notify_word. */
1455UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1456
1457/* Is this address within some small distance below %ESP? Used only
1458 for the --workaround-gcc296-bugs kludge. */
sewardj8c824512002-04-14 04:16:48 +00001459extern Bool VG_(is_just_below_ESP)( Addr esp, Addr aa );
sewardjde4a1d02002-03-22 01:27:54 +00001460
1461/* Nasty kludgery to deal with applications which switch stacks,
1462 like netscape. */
sewardjde4a1d02002-03-22 01:27:54 +00001463#define VG_PLAUSIBLE_STACK_SIZE 8000000
1464
sewardjc3bd5f52002-05-01 03:24:23 +00001465/* Needed by the pthreads implementation. */
1466#define VGM_WORD_VALID 0
1467#define VGM_WORD_INVALID 0xFFFFFFFF
1468
sewardjde4a1d02002-03-22 01:27:54 +00001469
1470/* ---------------------------------------------------------------------
1471 Exports of vg_syscall_mem.c
1472 ------------------------------------------------------------------ */
1473
sewardj2e93c502002-04-12 11:12:52 +00001474extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001475
sewardj2e93c502002-04-12 11:12:52 +00001476extern void VG_(check_known_blocking_syscall) ( ThreadId tid,
1477 Int syscallno,
1478 Int* /*IN*/ res );
sewardjde4a1d02002-03-22 01:27:54 +00001479
1480extern Bool VG_(is_kerror) ( Int res );
1481
sewardj2e93c502002-04-12 11:12:52 +00001482#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1483 VG_(load_thread_state)(thread_id); \
sewardjde4a1d02002-03-22 01:27:54 +00001484 VG_(copy_baseBlock_to_m_state_static)(); \
1485 VG_(do_syscall)(); \
1486 VG_(copy_m_state_static_to_baseBlock)(); \
sewardj2e93c502002-04-12 11:12:52 +00001487 VG_(save_thread_state)(thread_id); \
1488 result_lvalue = VG_(get_thread_state)(thread_id)->m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001489
1490
1491/* ---------------------------------------------------------------------
1492 Exports of vg_transtab.c
1493 ------------------------------------------------------------------ */
1494
1495/* An entry in the translation table (TT). */
1496typedef
1497 struct {
1498 /* +0 */ Addr orig_addr;
1499 /* +4 */ Addr trans_addr;
1500 /* +8 */ UInt mru_epoch;
1501 /* +12 */ UShort orig_size;
1502 /* +14 */ UShort trans_size;
1503 }
1504 TTEntry;
1505
1506/* The number of basic blocks in an epoch (one age-step). */
1507#define VG_BBS_PER_EPOCH 20000
1508
1509extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1510extern void VG_(maybe_do_lru_pass) ( void );
1511extern void VG_(flush_transtab) ( void );
1512extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1513extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1514
1515extern void VG_(smc_mark_original) ( Addr original_addr,
1516 Int original_len );
1517
1518extern void VG_(init_transtab_and_SMC) ( void );
1519
1520extern void VG_(sanity_check_tc_tt) ( void );
1521extern Addr VG_(search_transtab) ( Addr original_addr );
1522
1523extern void VG_(invalidate_tt_fast)( void );
1524
1525
1526/* ---------------------------------------------------------------------
1527 Exports of vg_vtagops.c
1528 ------------------------------------------------------------------ */
1529
1530/* Lists the names of value-tag operations used in instrumented
1531 code. These are the third argument to TAG1 and TAG2 uinsns. */
1532
1533typedef
1534 enum {
1535 /* Unary. */
1536 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1537 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1538
1539 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1540
1541 VgT_Left4, VgT_Left2, VgT_Left1,
1542
1543 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1544 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1545
1546 /* Binary; 1st is rd; 2nd is rd+wr */
1547 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1548 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1549
1550 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1551 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1552 VgT_DebugFn
1553 }
1554 VgTagOp;
1555
1556extern Char* VG_(nameOfTagOp) ( VgTagOp );
1557extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1558
1559
1560/* ---------------------------------------------------------------------
1561 Exports of vg_syscall.S
1562 ------------------------------------------------------------------ */
1563
1564extern void VG_(do_syscall) ( void );
1565
1566
1567/* ---------------------------------------------------------------------
1568 Exports of vg_startup.S
1569 ------------------------------------------------------------------ */
1570
sewardjde4a1d02002-03-22 01:27:54 +00001571extern void VG_(switch_to_real_CPU) ( void );
1572
sewardj35805422002-04-21 13:05:34 +00001573extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1574 Addr m_esp_at_error,
1575 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001576
1577
1578/* ---------------------------------------------------------------------
1579 Exports of vg_dispatch.S
1580 ------------------------------------------------------------------ */
1581
sewardj2e93c502002-04-12 11:12:52 +00001582/* Run a thread for a (very short) while, until some event happens
1583 which means we need to defer to the scheduler. */
1584extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001585
1586
1587/* ---------------------------------------------------------------------
1588 Exports of vg_helpers.S
1589 ------------------------------------------------------------------ */
1590
sewardjde4a1d02002-03-22 01:27:54 +00001591/* SMC fast checks. */
1592extern void VG_(helper_smc_check4);
1593
1594/* Mul, div, etc, -- we don't codegen these directly. */
1595extern void VG_(helper_idiv_64_32);
1596extern void VG_(helper_div_64_32);
1597extern void VG_(helper_idiv_32_16);
1598extern void VG_(helper_div_32_16);
1599extern void VG_(helper_idiv_16_8);
1600extern void VG_(helper_div_16_8);
1601
1602extern void VG_(helper_imul_32_64);
1603extern void VG_(helper_mul_32_64);
1604extern void VG_(helper_imul_16_32);
1605extern void VG_(helper_mul_16_32);
1606extern void VG_(helper_imul_8_16);
1607extern void VG_(helper_mul_8_16);
1608
1609extern void VG_(helper_CLD);
1610extern void VG_(helper_STD);
1611extern void VG_(helper_get_dirflag);
1612
1613extern void VG_(helper_shldl);
1614extern void VG_(helper_shldw);
1615extern void VG_(helper_shrdl);
1616extern void VG_(helper_shrdw);
1617
1618extern void VG_(helper_RDTSC);
1619extern void VG_(helper_CPUID);
1620
sewardjde4a1d02002-03-22 01:27:54 +00001621extern void VG_(helper_bsf);
1622extern void VG_(helper_bsr);
1623
1624extern void VG_(helper_fstsw_AX);
1625extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001626extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001627extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001628
1629extern void VG_(helper_value_check4_fail);
1630extern void VG_(helper_value_check2_fail);
1631extern void VG_(helper_value_check1_fail);
1632extern void VG_(helper_value_check0_fail);
1633
sewardjbc5b99f2002-04-13 00:08:51 +00001634/* NOT FUNCTIONS; these are bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001635extern void VG_(signalreturn_bogusRA)( void );
sewardjbc5b99f2002-04-13 00:08:51 +00001636extern void VG_(pthreadreturn_bogusRA)( void );
sewardj54cacf02002-04-12 23:24:59 +00001637
njn4f9c9342002-04-29 16:03:24 +00001638/* ---------------------------------------------------------------------
1639 Exports of vg_cachesim.c
1640 ------------------------------------------------------------------ */
1641
1642extern UCodeBlock* VG_(cachesim_instrument)(UCodeBlock* cb_in, Addr orig_addr);
1643
1644typedef struct _iCC iCC;
1645typedef struct _idCC idCC;
1646
1647extern void VG_(init_cachesim) ( void );
1648extern void VG_(show_cachesim_results)( Int client_argc, Char** client_argv );
1649
1650extern void VG_(cachesim_log_non_mem_instr)( iCC* cc );
1651extern void VG_(cachesim_log_mem_instr) ( idCC* cc, Addr data_addr );
sewardjde4a1d02002-03-22 01:27:54 +00001652
1653/* ---------------------------------------------------------------------
1654 The state of the simulated CPU.
1655 ------------------------------------------------------------------ */
1656
1657/* This is the Intel register encoding. */
1658#define R_EAX 0
1659#define R_ECX 1
1660#define R_EDX 2
1661#define R_EBX 3
1662#define R_ESP 4
1663#define R_EBP 5
1664#define R_ESI 6
1665#define R_EDI 7
1666
1667#define R_AL (0+R_EAX)
1668#define R_CL (0+R_ECX)
1669#define R_DL (0+R_EDX)
1670#define R_BL (0+R_EBX)
1671#define R_AH (4+R_EAX)
1672#define R_CH (4+R_ECX)
1673#define R_DH (4+R_EDX)
1674#define R_BH (4+R_EBX)
1675
1676
1677/* ---------------------------------------------------------------------
1678 Offsets into baseBlock for everything which needs to referred to
1679 from generated code. The order of these decls does not imply
1680 what the order of the actual offsets is. The latter is important
1681 and is set up in vg_main.c.
1682 ------------------------------------------------------------------ */
1683
1684/* An array of words. In generated code, %ebp always points to the
1685 start of this array. Useful stuff, like the simulated CPU state,
1686 and the addresses of helper functions, can then be found by
1687 indexing off %ebp. The following declares variables which, at
1688 startup time, are given values denoting offsets into baseBlock.
1689 These offsets are in *words* from the start of baseBlock. */
1690
1691#define VG_BASEBLOCK_WORDS 200
1692
1693extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1694
1695
1696/* -----------------------------------------------------
1697 Read-write parts of baseBlock.
1698 -------------------------------------------------- */
1699
1700/* State of the simulated CPU. */
1701extern Int VGOFF_(m_eax);
1702extern Int VGOFF_(m_ecx);
1703extern Int VGOFF_(m_edx);
1704extern Int VGOFF_(m_ebx);
1705extern Int VGOFF_(m_esp);
1706extern Int VGOFF_(m_ebp);
1707extern Int VGOFF_(m_esi);
1708extern Int VGOFF_(m_edi);
1709extern Int VGOFF_(m_eflags);
1710extern Int VGOFF_(m_fpustate);
1711extern Int VGOFF_(m_eip);
1712
1713/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1714extern Int VGOFF_(spillslots);
1715
1716/* Records the valid bits for the 8 integer regs & flags reg. */
1717extern Int VGOFF_(sh_eax);
1718extern Int VGOFF_(sh_ecx);
1719extern Int VGOFF_(sh_edx);
1720extern Int VGOFF_(sh_ebx);
1721extern Int VGOFF_(sh_esp);
1722extern Int VGOFF_(sh_ebp);
1723extern Int VGOFF_(sh_esi);
1724extern Int VGOFF_(sh_edi);
1725extern Int VGOFF_(sh_eflags);
1726
1727
1728/* -----------------------------------------------------
1729 Read-only parts of baseBlock.
1730 -------------------------------------------------- */
1731
1732/* Offsets of addresses of helper functions. A "helper" function is
1733 one which is called from generated code. */
1734
1735extern Int VGOFF_(helper_idiv_64_32);
1736extern Int VGOFF_(helper_div_64_32);
1737extern Int VGOFF_(helper_idiv_32_16);
1738extern Int VGOFF_(helper_div_32_16);
1739extern Int VGOFF_(helper_idiv_16_8);
1740extern Int VGOFF_(helper_div_16_8);
1741
1742extern Int VGOFF_(helper_imul_32_64);
1743extern Int VGOFF_(helper_mul_32_64);
1744extern Int VGOFF_(helper_imul_16_32);
1745extern Int VGOFF_(helper_mul_16_32);
1746extern Int VGOFF_(helper_imul_8_16);
1747extern Int VGOFF_(helper_mul_8_16);
1748
1749extern Int VGOFF_(helper_CLD);
1750extern Int VGOFF_(helper_STD);
1751extern Int VGOFF_(helper_get_dirflag);
1752
1753extern Int VGOFF_(helper_shldl);
1754extern Int VGOFF_(helper_shldw);
1755extern Int VGOFF_(helper_shrdl);
1756extern Int VGOFF_(helper_shrdw);
1757
1758extern Int VGOFF_(helper_RDTSC);
1759extern Int VGOFF_(helper_CPUID);
1760
sewardjde4a1d02002-03-22 01:27:54 +00001761extern Int VGOFF_(helper_bsf);
1762extern Int VGOFF_(helper_bsr);
1763
1764extern Int VGOFF_(helper_fstsw_AX);
1765extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001766extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001767extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001768
1769extern Int VGOFF_(helper_value_check4_fail);
1770extern Int VGOFF_(helper_value_check2_fail);
1771extern Int VGOFF_(helper_value_check1_fail);
1772extern Int VGOFF_(helper_value_check0_fail);
1773
sewardjde4a1d02002-03-22 01:27:54 +00001774extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1775extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1776extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1777
1778extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1779extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1780extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1781
1782extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1783extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1784extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1785
njn4f9c9342002-04-29 16:03:24 +00001786extern Int VGOFF_(cachesim_log_non_mem_instr);
1787extern Int VGOFF_(cachesim_log_mem_instr);
sewardjde4a1d02002-03-22 01:27:54 +00001788
1789#endif /* ndef __VG_INCLUDE_H */
1790
sewardj3b2736a2002-03-24 12:18:35 +00001791
1792/* ---------------------------------------------------------------------
1793 Finally - autoconf-generated settings
1794 ------------------------------------------------------------------ */
1795
1796#include "config.h"
1797
sewardjde4a1d02002-03-22 01:27:54 +00001798/*--------------------------------------------------------------------*/
1799/*--- end vg_include.h ---*/
1800/*--------------------------------------------------------------------*/