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