blob: cf0237ec9ca599e60b2aebe3e833ea53e64368d1 [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
14 Julian_Seward@muraroa.demon.co.uk
15
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation; either version 2 of the
19 License, or (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 02111-1307, USA.
30
31 The GNU General Public License is contained in the file LICENSE.
32*/
33
34#ifndef __VG_INCLUDE_H
35#define __VG_INCLUDE_H
36
37
38#include <stdarg.h> /* ANSI varargs stuff */
39#include <setjmp.h> /* for jmp_buf */
40
41
42/* ---------------------------------------------------------------------
43 Build options and table sizes. You should be able to change these
44 options or sizes, recompile, and still have a working system.
45 ------------------------------------------------------------------ */
46
47#include "vg_constants.h"
48
49
50/* Set to 1 to enable time profiling. Since this uses SIGPROF, we
51 don't want this permanently enabled -- only for profiling
52 builds. */
53#if 0
54# define VG_PROFILE
55#endif
56
57
58/* Total number of integer registers available for allocation. That's
59 all of them except %esp, %edi and %ebp. %edi is a general spare
60 temporary. %ebp permanently points at VG_(baseBlock). Note that
61 it's important that this tie in with what rankToRealRegNo() says.
62 DO NOT CHANGE THIS VALUE FROM 5. ! */
63#define VG_MAX_REALREGS 5
64
65/* Total number of spill slots available for allocation, if a TempReg
66 doesn't make it into a RealReg. Just bomb the entire system if
67 this value is too small; we don't expect it will ever get
68 particularly high. */
69#define VG_MAX_SPILLSLOTS 24
70
71
72/* Constants for the slow translation lookup cache. */
73#define VG_TRANSTAB_SLOW_BITS 11
74#define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS)
75#define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1)
76
77/* Size of a buffer used for creating messages. */
78#define M_VG_MSGBUF 10000
79
80/* Size of a smallish table used to read /proc/self/map entries. */
81#define M_PROCMAP_BUF 20000
82
83/* Max length of pathname to a .so/executable file. */
84#define M_VG_LIBNAMESTR 100
85
86/* Max length of a text fragment used to construct error messages. */
87#define M_VG_ERRTXT 512
88
89/* Max length of the string copied from env var VG_ARGS at startup. */
90#define M_VG_CMDLINE_STRLEN 1000
91
92/* Max number of options for Valgrind which we can handle. */
93#define M_VG_CMDLINE_OPTS 100
94
95/* After this many different unsuppressed errors have been observed,
96 be more conservative about collecting new ones. */
97#define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50
98
99/* After this many different unsuppressed errors have been observed,
100 stop collecting errors at all, and tell the user their program is
101 evidently a steaming pile of camel dung. */
102#define M_VG_COLLECT_NO_ERRORS_AFTER 500
103
104/* These many bytes below %ESP are considered addressible if we're
105 doing the --workaround-gcc296-bugs hack. */
106#define VG_GCC296_BUG_STACK_SLOP 256
107
108/* The maximum number of calls we're prepared to save in a
109 backtrace. */
110#define VG_DEEPEST_BACKTRACE 50
111
112/* Number of lists in which we keep track of malloc'd but not free'd
113 blocks. Should be prime. */
114#define VG_N_MALLOCLISTS 997
115
116/* Number of lists in which we keep track of ExeContexts. Should be
117 prime. */
118#define VG_N_EC_LISTS /*997*/ 4999
119
120
121/* ---------------------------------------------------------------------
122 Basic types
123 ------------------------------------------------------------------ */
124
125typedef unsigned char UChar;
126typedef unsigned short UShort;
127typedef unsigned int UInt;
128typedef unsigned long long int ULong;
129
130typedef signed char Char;
131typedef signed short Short;
132typedef signed int Int;
133typedef signed long long int Long;
134
135typedef unsigned int Addr;
136
137typedef unsigned char Bool;
138#define False ((Bool)0)
139#define True ((Bool)1)
140
141#define mycat_wrk(aaa,bbb) aaa##bbb
142#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
143
144/* Just pray that gcc's constant folding works properly ... */
145#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
146 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
147 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
148
149
150/* ---------------------------------------------------------------------
151 Now the basic types are set up, we can haul in the kernel-interface
152 definitions.
153 ------------------------------------------------------------------ */
154
155#include "./vg_kerneliface.h"
156
157
158/* ---------------------------------------------------------------------
159 Command-line-settable options
160 ------------------------------------------------------------------ */
161
162#define VG_CLO_SMC_NONE 0
163#define VG_CLO_SMC_SOME 1
164#define VG_CLO_SMC_ALL 2
165
166#define VG_CLO_MAX_SFILES 10
167
168/* Enquire about whether to attach to GDB at errors? default: NO */
169extern Bool VG_(clo_GDB_attach);
170/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
171extern Int VG_(sanity_level);
172/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
173extern Int VG_(clo_verbosity);
174/* Automatically attempt to demangle C++ names? default: YES */
175extern Bool VG_(clo_demangle);
176/* Do leak check at exit? default: NO */
177extern Bool VG_(clo_leak_check);
178/* In leak check, show reachable-but-not-freed blocks? default: NO */
179extern Bool VG_(clo_show_reachable);
180/* How closely should we compare ExeContexts in leak records? default: 2 */
181extern Int VG_(clo_leak_resolution);
182/* Round malloc sizes upwards to integral number of words? default:
183 NO */
184extern Bool VG_(clo_sloppy_malloc);
185/* Allow loads from partially-valid addresses? default: YES */
186extern Bool VG_(clo_partial_loads_ok);
187/* Simulate child processes? default: NO */
188extern Bool VG_(clo_trace_children);
189/* The file id on which we send all messages. default: 2 (stderr). */
190extern Int VG_(clo_logfile_fd);
191/* Max volume of the freed blocks queue. */
192extern Int VG_(clo_freelist_vol);
193/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
194 default: NO */
195extern Bool VG_(clo_workaround_gcc296_bugs);
196
197/* The number of suppression files specified. */
198extern Int VG_(clo_n_suppressions);
199/* The names of the suppression files. */
200extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
201
202/* Single stepping? default: NO */
203extern Bool VG_(clo_single_step);
204/* Code improvement? default: YES */
205extern Bool VG_(clo_optimise);
206/* Memory-check instrumentation? default: YES */
207extern Bool VG_(clo_instrument);
208/* DEBUG: clean up instrumented code? default: YES */
209extern Bool VG_(clo_cleanup);
210/* Handle client memory-range-permissions-setting requests? default: NO */
211extern Bool VG_(clo_client_perms);
212/* SMC write checks? default: SOME (1,2,4 byte movs to mem) */
213extern Int VG_(clo_smc_check);
214/* DEBUG: print system calls? default: NO */
215extern Bool VG_(clo_trace_syscalls);
216/* DEBUG: print signal details? default: NO */
217extern Bool VG_(clo_trace_signals);
218/* DEBUG: print symtab details? default: NO */
219extern Bool VG_(clo_trace_symtab);
220/* DEBUG: print malloc details? default: NO */
221extern Bool VG_(clo_trace_malloc);
222/* Stop after this many basic blocks. default: Infinity. */
223extern ULong VG_(clo_stop_after);
224/* Display gory details for the k'th most popular error. default:
225 Infinity. */
226extern Int VG_(clo_dump_error);
227/* Number of parents of a backtrace. Default: 8. */
228extern Int VG_(clo_backtrace_size);
229
230
231/* ---------------------------------------------------------------------
232 Debugging and profiling stuff
233 ------------------------------------------------------------------ */
234
235/* No, really. I _am_ that strange. */
236#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
237
238/* Tools for building messages from multiple parts. */
239typedef
240 enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg }
241 VgMsgKind;
242
243extern void VG_(start_msg) ( VgMsgKind kind );
244extern void VG_(add_to_msg) ( Char* format, ... );
245extern void VG_(end_msg) ( void );
246
247/* Send a simple, single-part message. */
248extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
249
250/* Create a logfile into which messages can be dumped. */
251extern void VG_(startup_logging) ( void );
252extern void VG_(shutdown_logging) ( void );
253
254
255/* Profiling stuff */
256#ifdef VG_PROFILE
257
258#define VGP_M_STACK 10
259
260#define VGP_M_CCS 20 /* == the # of elems in VGP_LIST */
261#define VGP_LIST \
262 VGP_PAIR(VgpRun=0, "running"), \
263 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
264 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
265 VGP_PAIR(VgpTranslate, "translate-main"), \
266 VGP_PAIR(VgpToUCode, "to-ucode"), \
267 VGP_PAIR(VgpFromUcode, "from-ucode"), \
268 VGP_PAIR(VgpImprove, "improve"), \
269 VGP_PAIR(VgpInstrument, "instrument"), \
270 VGP_PAIR(VgpCleanup, "cleanup"), \
271 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
272 VGP_PAIR(VgpDoLRU, "do-lru"), \
273 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
274 VGP_PAIR(VgpInitAudit, "init-mem-audit"), \
275 VGP_PAIR(VgpExeContext, "exe-context"), \
276 VGP_PAIR(VgpReadSyms, "read-syms"), \
277 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
278 VGP_PAIR(VgpSARP, "set-addr-range-perms"), \
279 VGP_PAIR(VgpSyscall, "syscall wrapper"), \
280 VGP_PAIR(VgpSpare1, "spare 1"), \
281 VGP_PAIR(VgpSpare2, "spare 2")
282
283#define VGP_PAIR(enumname,str) enumname
284typedef enum { VGP_LIST } VgpCC;
285#undef VGP_PAIR
286
287extern void VGP_(init_profiling) ( void );
288extern void VGP_(done_profiling) ( void );
289extern void VGP_(pushcc) ( VgpCC );
290extern void VGP_(popcc) ( void );
291
292#define VGP_PUSHCC(cc) VGP_(pushcc)(cc)
293#define VGP_POPCC VGP_(popcc)()
294
295#else
296
297#define VGP_PUSHCC(cc) /* */
298#define VGP_POPCC /* */
299
300#endif /* VG_PROFILE */
301
302
303/* ---------------------------------------------------------------------
304 Exports of vg_malloc2.c
305 ------------------------------------------------------------------ */
306
307/* Allocation arenas.
308 SYMTAB is for Valgrind's symbol table storage.
309 CLIENT is for the client's mallocs/frees.
310 DEMANGLE is for the C++ demangler.
311 EXECTXT is for storing ExeContexts.
312 ERRCTXT is for storing ErrContexts.
313 PRIVATE is for Valgrind general stuff.
314 TRANSIENT is for very short-term use. It should be empty
315 in between uses.
316 When adding a new arena, remember also to add it
317 to ensure_mm_init().
318*/
319typedef Int ArenaId;
320
321#define VG_N_ARENAS 7
322
323#define VG_AR_PRIVATE 0 /* :: ArenaId */
324#define VG_AR_SYMTAB 1 /* :: ArenaId */
325#define VG_AR_CLIENT 2 /* :: ArenaId */
326#define VG_AR_DEMANGLE 3 /* :: ArenaId */
327#define VG_AR_EXECTXT 4 /* :: ArenaId */
328#define VG_AR_ERRCTXT 5 /* :: ArenaId */
329#define VG_AR_TRANSIENT 6 /* :: ArenaId */
330
331extern void* VG_(malloc) ( ArenaId arena, Int nbytes );
332extern void VG_(free) ( ArenaId arena, void* ptr );
333extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes );
334extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size );
335extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB,
336 Int req_pszB );
337
338extern void VG_(mallocSanityCheckArena) ( ArenaId arena );
339extern void VG_(mallocSanityCheckAll) ( void );
340
341extern void VG_(show_all_arena_stats) ( void );
342extern Bool VG_(is_empty_arena) ( ArenaId aid );
343
344
345/* The red-zone size for the client. This can be arbitrary, but
346 unfortunately must be set at compile time. */
347#define VG_AR_CLIENT_REDZONE_SZW 4
348
349#define VG_AR_CLIENT_REDZONE_SZB \
350 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
351
352
353/* ---------------------------------------------------------------------
354 Exports of vg_signals.c
355 ------------------------------------------------------------------ */
356
357/* The maximum number of basic blocks that we're prepared to run in a
358 signal handler which is called when the client is stuck in a
359 blocking system call. The purpose of this is to check that such a
360 signal handler doesn't merely do a longjmp() and keep going
361 forever; it should return instead. NOTE that this doesn't apply to
362 signals delivered under normal conditions, only when they are
363 delivered and the client is already blocked in a system call. */
364#define VG_MAX_BBS_IN_IMMEDIATE_SIGNAL 50000
365
366extern void VG_(sigstartup_actions) ( void );
367
368extern void VG_(deliver_signals) ( void );
369extern void VG_(unblock_host_signal) ( Int sigNo );
370
371
372/* Fake system calls for signal handling. */
373extern void VG_(do__NR_sigaction) ( void );
374extern void VG_(do__NR_sigprocmask) ( Int how, vki_ksigset_t* set );
375
376
377
378
379/* ---------------------------------------------------------------------
380 Exports of vg_mylibc.c
381 ------------------------------------------------------------------ */
382
383
384#define NULL ((void*)0)
385
386extern void VG_(exit)( Int status )
387 __attribute__ ((__noreturn__));
388
389extern void VG_(printf) ( const char *format, ... );
390/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
391
392extern void VG_(sprintf) ( Char* buf, Char *format, ... );
393
394extern void VG_(vprintf) ( void(*send)(Char),
395 const Char *format, va_list vargs );
396
397extern Bool VG_(isspace) ( Char c );
398
399extern Int VG_(strlen) ( const Char* str );
400
401extern Long VG_(atoll) ( Char* str );
402
403extern Char* VG_(strcat) ( Char* dest, const Char* src );
404extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
405extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
406
407extern Char* VG_(strcpy) ( Char* dest, const Char* src );
408
409extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
410extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
411
412extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
413extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
414
415extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
416extern Char* VG_(strchr) ( const Char* s, Char c );
417extern Char* VG_(strdup) ( ArenaId aid, const Char* s);
418
419extern Char* VG_(getenv) ( Char* name );
420extern Int VG_(getpid) ( void );
421
422
423extern Char VG_(toupper) ( Char c );
424
425extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
426
427extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
428
429extern Bool VG_(stringMatch) ( Char* pat, Char* str );
430
431
432#define __STRING(x) #x
433
434/* Asserts are permanently enabled. Hurrah! */
435#define vg_assert(expr) \
436 ((void) ((expr) ? 0 : \
437 (VG_(assert_fail) (__STRING(expr), \
438 __FILE__, __LINE__, \
439 __PRETTY_FUNCTION__), 0)))
440
441extern void VG_(assert_fail) ( Char* expr, Char* file,
442 Int line, Char* fn )
443 __attribute__ ((__noreturn__));
444
445/* Later ... extern void vg_restore_SIGABRT ( void ); */
446
447/* Reading files. */
448extern Int VG_(open_read) ( Char* pathname );
449extern void VG_(close) ( Int fd );
450extern Int VG_(read) ( Int fd, void* buf, Int count);
451extern Int VG_(write) ( Int fd, void* buf, Int count);
452
453/* mmap-ery ... */
454extern void* VG_(mmap)( void* start, UInt length,
455 UInt prot, UInt flags, UInt fd, UInt offset );
456
457extern Int VG_(munmap)( void* start, Int length );
458
459
460/* Print a (panic) message, and abort. */
461extern void VG_(panic) ( Char* str )
462 __attribute__ ((__noreturn__));
463
464/* Get memory by anonymous mmap. */
465void* VG_(get_memory_from_mmap) ( Int nBytes );
466
467/* Signal stuff. Note that these use the vk_ (kernel) structure
468 definitions, which are different in places from those that glibc
469 defines. Since we're operating right at the kernel interface,
470 glibc's view of the world is entirely irrelevant. */
471extern Int VG_(ksigfillset)( vki_ksigset_t* set );
472extern Int VG_(ksigemptyset)( vki_ksigset_t* set );
473extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum );
474
475extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set,
476 vki_ksigset_t* oldset );
477extern Int VG_(ksigaction) ( Int signum,
478 const vki_ksigaction* act,
479 vki_ksigaction* oldact );
480extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
481
482extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int));
483
484extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss );
485
486
487
488/* ---------------------------------------------------------------------
489 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
490 vg_from_ucode.c).
491 ------------------------------------------------------------------ */
492
493/* Tags which describe what operands are. */
494typedef
495 enum { TempReg=0, ArchReg=1, RealReg=2,
496 SpillNo=3, Literal=4, Lit16=5,
497 NoValue=6 }
498 Tag;
499
500
501/* Microinstruction opcodes. */
502typedef
503 enum {
504 NOP,
505 GET,
506 PUT,
507 LOAD,
508 STORE,
509 MOV,
510 CMOV, /* Used for cmpxchg and cmov */
511 WIDEN,
512 JMP,
513
514 /* Read/write the %EFLAGS register into a TempReg. */
515 GETF, PUTF,
516
517 ADD, ADC, AND, OR, XOR, SUB, SBB,
518 SHL, SHR, SAR, ROL, ROR, RCL, RCR,
519 NOT, NEG, INC, DEC, BSWAP,
520 CC2VAL,
521
522 /* Not strictly needed, but useful for making better
523 translations of address calculations. */
524 LEA1, /* reg2 := const + reg1 */
525 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
526
527 /* not for translating x86 calls -- only to call helpers */
528 CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences
529 for CALLM. */
530 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */
531 CALLM, /* call to a machine-code helper */
532
533 /* Hack for translating string (REP-) insns. Jump to literal if
534 TempReg/RealReg is zero. */
535 JIFZ,
536
537 /* FPU ops which read/write mem or don't touch mem at all. */
538 FPU_R,
539 FPU_W,
540 FPU,
541
542 /* Advance the simulated %eip by some small (< 128) number. */
543 INCEIP,
544
545 /* uinstrs which are not needed for mere translation of x86 code,
546 only for instrumentation of it. */
547 LOADV,
548 STOREV,
549 GETV,
550 PUTV,
551 TESTV,
552 SETV,
553 /* Get/set the v-bit (and it is only one bit) for the simulated
554 %eflags register. */
555 GETVF,
556 PUTVF,
557
558 /* Do a unary or binary tag op. Only for post-instrumented
559 code. For TAG1, first and only arg is a TempReg, and is both
560 arg and result reg. For TAG2, first arg is src, second is
561 dst, in the normal way; both are TempRegs. In both cases,
562 3rd arg is a RiCHelper with a Lit16 tag. This indicates
563 which tag op to do. */
564 TAG1,
565 TAG2
566 }
567 Opcode;
568
569
570/* Condition codes, observing the Intel encoding. CondAlways is an
571 extra. */
572typedef
573 enum {
574 CondO = 0, /* overflow */
575 CondNO = 1, /* no overflow */
576 CondB = 2, /* below */
577 CondNB = 3, /* not below */
578 CondZ = 4, /* zero */
579 CondNZ = 5, /* not zero */
580 CondBE = 6, /* below or equal */
581 CondNBE = 7, /* not below or equal */
582 CondS = 8, /* negative */
583 ConsNS = 9, /* not negative */
584 CondP = 10, /* parity even */
585 CondNP = 11, /* not parity even */
586 CondL = 12, /* jump less */
587 CondNL = 13, /* not less */
588 CondLE = 14, /* less or equal */
589 CondNLE = 15, /* not less or equal */
590 CondAlways = 16 /* Jump always */
591 }
592 Condcode;
593
594
595/* Flags. User-level code can only read/write O(verflow), S(ign),
596 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
597 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
598 thusly:
599 76543210
600 DOSZACP
601 and bit 7 must always be zero since it is unused.
602*/
603typedef UChar FlagSet;
604
605#define FlagD (1<<6)
606#define FlagO (1<<5)
607#define FlagS (1<<4)
608#define FlagZ (1<<3)
609#define FlagA (1<<2)
610#define FlagC (1<<1)
611#define FlagP (1<<0)
612
613#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
614#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
615#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
616#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
617#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
618#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
sewardj4a7456e2002-03-24 13:52:19 +0000619#define FlagsZCP ( FlagZ | FlagC | FlagP)
sewardjde4a1d02002-03-22 01:27:54 +0000620#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000621#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000622
623#define FlagsALL (FlagsOSZACP | FlagD)
624#define FlagsEmpty (FlagSet)0
625
626#define VG_IS_FLAG_SUBSET(set1,set2) \
627 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
628
629#define VG_UNION_FLAG_SETS(set1,set2) \
630 ( ((FlagSet)set1) | ((FlagSet)set2) )
631
632
633
634/* A Micro (u)-instruction. */
635typedef
636 struct {
637 /* word 1 */
638 UInt lit32; /* 32-bit literal */
639
640 /* word 2 */
641 UShort val1; /* first operand */
642 UShort val2; /* second operand */
643
644 /* word 3 */
645 UShort val3; /* third operand */
646 UChar opcode; /* opcode */
647 UChar size; /* data transfer size */
648
649 /* word 4 */
650 FlagSet flags_r; /* :: FlagSet */
651 FlagSet flags_w; /* :: FlagSet */
652 UChar tag1:4; /* first operand tag */
653 UChar tag2:4; /* second operand tag */
654 UChar tag3:4; /* third operand tag */
655 UChar extra4b:4; /* Spare field, used by WIDEN for src
656 -size, and by LEA2 for scale
657 (1,2,4 or 8) */
658
659 /* word 5 */
660 UChar cond; /* condition, for jumps */
661 Bool smc_check:1; /* do a smc test, if writes memory. */
662 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
663 Bool ret_dispatch:1; /* Is this jump as a result of RET ? */
664 Bool call_dispatch:1; /* Is this jump as a result of CALL ? */
665 }
666 UInstr;
667
668
669/* Expandable arrays of uinstrs. */
670typedef
671 struct {
672 Int used;
673 Int size;
674 UInstr* instrs;
675 Int nextTemp;
676 }
677 UCodeBlock;
678
679/* Refer to `the last instruction stuffed in', including as an
680 lvalue. */
681#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
682
683/* An invalid temporary number :-) */
684#define INVALID_TEMPREG 999999999
685
686
687/* ---------------------------------------------------------------------
688 Exports of vg_demangle.c
689 ------------------------------------------------------------------ */
690
691extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
692
693
694/* ---------------------------------------------------------------------
695 Exports of vg_from_ucode.c
696 ------------------------------------------------------------------ */
697
698extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
699
700
701/* ---------------------------------------------------------------------
702 Exports of vg_to_ucode.c
703 ------------------------------------------------------------------ */
704
705extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
706extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
707extern Char VG_(nameOfIntSize) ( Int size );
708extern UInt VG_(extend_s_8to32) ( UInt x );
709extern Int VG_(getNewTemp) ( UCodeBlock* cb );
710extern Int VG_(getNewShadow) ( UCodeBlock* cb );
711
712#define SHADOW(tempreg) ((tempreg)+1)
713
714
715/* ---------------------------------------------------------------------
716 Exports of vg_translate.c
717 ------------------------------------------------------------------ */
718
719extern void VG_(translate) ( Addr orig_addr,
720 UInt* orig_size,
721 Addr* trans_addr,
722 UInt* trans_size );
723
724extern void VG_(emptyUInstr) ( UInstr* u );
725extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
726extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
727 Tag tag1, UInt val1 );
728extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
729 Tag tag1, UInt val1,
730 Tag tag2, UInt val2 );
731extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
732 Tag tag1, UInt val1,
733 Tag tag2, UInt val2,
734 Tag tag3, UInt val3 );
735extern void VG_(setFlagRW) ( UInstr* u,
736 FlagSet fr, FlagSet fw );
737
738extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
739extern Bool VG_(anyFlagUse) ( UInstr* u );
740
741
742
743extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
744extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
745
746extern Char* VG_(nameCondcode) ( Condcode cond );
747extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
748extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
749extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
750extern Int VG_(rankToRealRegNo) ( Int rank );
751
752extern void* VG_(jitmalloc) ( Int nbytes );
753extern void VG_(jitfree) ( void* ptr );
754
755
756/* ---------------------------------------------------------------------
757 Exports of vg_execontext.c.
758 ------------------------------------------------------------------ */
759
760/* Records the PC and a bit of the call chain. The first 4 %eip
761 values are used in comparisons do remove duplicate errors, and for
762 comparing against suppression specifications. The rest are purely
763 informational (but often important). */
764
765typedef
766 struct _ExeContextRec {
767 struct _ExeContextRec * next;
768 /* The size of this array is VG_(clo_backtrace_size); at least
769 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
770 [1] is its caller, [2] is the caller of [1], etc. */
771 Addr eips[0];
772 }
773 ExeContext;
774
775
776/* Initialise the ExeContext storage mechanism. */
777extern void VG_(init_ExeContext_storage) ( void );
778
779/* Print stats (informational only). */
780extern void VG_(show_ExeContext_stats) ( void );
781
782
783/* Take a snapshot of the client's stack. Search our collection of
784 ExeContexts to see if we already have it, and if not, allocate a
785 new one. Either way, return a pointer to the context. */
786extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame );
787
788/* Print an ExeContext. */
789extern void VG_(pp_ExeContext) ( ExeContext* );
790
791/* Compare two ExeContexts, just comparing the top two callers. */
792extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
793
794/* Compare two ExeContexts, just comparing the top four callers. */
795extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
796
797/* Compare two ExeContexts, comparing all callers. */
798extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
799
800
801
802/* ---------------------------------------------------------------------
803 Exports of vg_errcontext.c.
804 ------------------------------------------------------------------ */
805
806extern void VG_(load_suppressions) ( void );
807extern void VG_(show_all_errors) ( void );
808extern void VG_(record_value_error) ( Int size );
809extern void VG_(record_free_error) ( Addr a );
810extern void VG_(record_freemismatch_error) ( Addr a );
811extern void VG_(record_address_error) ( Addr a, Int size,
812 Bool isWrite );
813extern void VG_(record_jump_error) ( Addr a );
814extern void VG_(record_param_err) ( Addr a,
815 Bool isWriteLack,
816 Char* msg );
817extern void VG_(record_user_err) ( Addr a, Bool isWriteLack );
818
819
820/* The classification of a faulting address. */
821typedef
822 enum { Stack, Unknown, Freed, Mallocd, UserG, UserS }
823 AddrKind;
824
825/* Records info about a faulting address. */
826typedef
827 struct {
828 /* ALL */
829 AddrKind akind;
830 /* Freed, Mallocd */
831 Int blksize;
832 /* Freed, Mallocd */
833 Int rwoffset;
834 /* Freed, Mallocd */
835 ExeContext* lastchange;
836 }
837 AddrInfo;
838
839
840/* ---------------------------------------------------------------------
841 Exports of vg_clientperms.c
842 ------------------------------------------------------------------ */
843
844extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
845
846extern UInt VG_(handle_client_request) ( UInt code, Addr aa, UInt nn );
847
848extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
849
850extern void VG_(show_client_block_stats) ( void );
851
852
853/* ---------------------------------------------------------------------
854 Exports of vg_procselfmaps.c
855 ------------------------------------------------------------------ */
856
857extern
858void VG_(read_procselfmaps) (
859 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
860);
861
862
863/* ---------------------------------------------------------------------
864 Exports of vg_symtab2.c
865 ------------------------------------------------------------------ */
866
867/* We assume the executable is loaded here ... can't really find
868 out. There is a hacky sanity check in vg_init_memory_audit()
869 which should trip up most stupidities.
870*/
871#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
872
873extern void VG_(read_symbols) ( void );
874extern void VG_(mini_stack_dump) ( ExeContext* ec );
875extern void VG_(what_obj_and_fun_is_this)
876 ( Addr a,
877 Char* obj_buf, Int n_obj_buf,
878 Char* fun_buf, Int n_fun_buf );
879
880extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
881
882
883/* ---------------------------------------------------------------------
884 Exports of vg_clientmalloc.c
885 ------------------------------------------------------------------ */
886
887/* these numbers are not arbitary. if you change them,
888 adjust vg_dispatch.S as well */
889
890typedef
891 enum {
892 Vg_AllocMalloc = 0,
893 Vg_AllocNew = 1,
894 Vg_AllocNewVec = 2
895 }
896 VgAllocKind;
897
898/* Description of a malloc'd chunk. */
899typedef
900 struct _ShadowChunk {
901 struct _ShadowChunk* next;
902 ExeContext* where; /* where malloc'd/free'd */
903 UInt size : 30; /* size requested. */
904 VgAllocKind allockind : 2; /* which wrapper did the allocation */
905 Addr data; /* ptr to actual block. */
906 }
907 ShadowChunk;
908
909extern void VG_(clientmalloc_done) ( void );
910extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
911extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
912
913/* This should never be called; if it is, something's seriously
914 wrong. */
915extern UInt VG_(trap_here) ( UInt arg1, UInt arg2, UInt what_to_do );
916
917
918/* ---------------------------------------------------------------------
919 Exports of vg_main.c
920 ------------------------------------------------------------------ */
921
922/* How big is the saved FPU state? */
923#define VG_SIZE_OF_FPUSTATE 108
924/* ... and in words ... */
925#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
926
927/* A structure used as an intermediary when passing the simulated
928 CPU's state to some assembly fragments, particularly system calls.
929 Stuff is copied from baseBlock to here, the assembly magic runs,
930 and then the inverse copy is done. */
931
932extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
933 + 1 /* %eflags */
934 + 1 /* %eip */
935 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
936 ];
937
938/* Handy fns for doing the copy back and forth. */
939extern void VG_(copy_baseBlock_to_m_state_static) ( void );
940extern void VG_(copy_m_state_static_to_baseBlock) ( void );
941
942/* Create, and add to TT/TC, the translation of a client basic
943 block. */
944extern void VG_(create_translation_for) ( Addr orig_addr );
945
946/* Called when some unhandleable client behaviour is detected.
947 Prints a msg and aborts. */
948extern void VG_(unimplemented) ( Char* msg );
949
950/* The stack on which Valgrind runs. We can't use the same stack as the
951 simulatee -- that's an important design decision. */
952extern UInt VG_(stack)[10000];
953
954/* Similarly, we have to ask for signals to be delivered on an
955 alternative stack, since it is possible, although unlikely, that
956 we'll have to run client code from inside the Valgrind-installed
957 signal handler. If this happens it will be done by
958 vg_deliver_signal_immediately(). */
959extern UInt VG_(sigstack)[10000];
960
961
962/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
963extern jmp_buf VG_(toploop_jmpbuf);
964/* ... and if so, here's the signal which caused it to do so. */
965extern Int VG_(longjmpd_on_signal);
966
967/* Holds client's %esp at the point we gained control. From this the
968 client's argc, argv and envp are deduced. */
969extern Addr VG_(esp_at_startup);
970extern Int VG_(client_argc);
971extern Char** VG_(client_argv);
972extern Char** VG_(client_envp);
973
974/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
975 don't get traced into. */
976extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
977
978/* Something of a function looking for a home ... start up GDB. This
979 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
980 *client's* stack. This is necessary to give GDB the illusion that
981 the client program really was running on the real cpu. */
982extern void VG_(start_GDB_whilst_on_client_stack) ( void );
983
984/* Spew out vast amounts of junk during JITting? */
985extern Bool VG_(disassemble);
986
987/* 64-bit counter for the number of basic blocks done. */
988extern ULong VG_(bbs_done);
989/* 64-bit counter for the number of bbs to go before a debug exit. */
990extern ULong VG_(bbs_to_go);
991
992/* Counts downwards in vg_run_innerloop. */
993extern UInt VG_(dispatch_ctr);
994
995/* If vg_dispatch_ctr is set to 1 to force a stop, its
996 previous value is saved here. */
997extern UInt VG_(dispatch_ctr_SAVED);
998
999/* This is why vg_run_innerloop() exited. */
1000extern UInt VG_(interrupt_reason);
1001
1002/* Is the client running on the simulated CPU or the real one? */
1003extern Bool VG_(running_on_simd_CPU); /* Initially False */
1004
1005/* The current LRU epoch. */
1006extern UInt VG_(current_epoch);
1007
1008
1009/* --- Counters, for informational purposes only. --- */
1010
1011/* Number of lookups which miss the fast tt helper. */
1012extern UInt VG_(tt_fast_misses);
1013
1014/* Counts for LRU informational messages. */
1015
1016/* Number and total o/t size of new translations this epoch. */
1017extern UInt VG_(this_epoch_in_count);
1018extern UInt VG_(this_epoch_in_osize);
1019extern UInt VG_(this_epoch_in_tsize);
1020/* Number and total o/t size of discarded translations this epoch. */
1021extern UInt VG_(this_epoch_out_count);
1022extern UInt VG_(this_epoch_out_osize);
1023extern UInt VG_(this_epoch_out_tsize);
1024/* Number and total o/t size of translations overall. */
1025extern UInt VG_(overall_in_count);
1026extern UInt VG_(overall_in_osize);
1027extern UInt VG_(overall_in_tsize);
1028/* Number and total o/t size of discards overall. */
1029extern UInt VG_(overall_out_count);
1030extern UInt VG_(overall_out_osize);
1031extern UInt VG_(overall_out_tsize);
1032
1033/* The number of LRU-clearings of TT/TC. */
1034extern UInt VG_(number_of_lrus);
1035
1036/* Counts pertaining to the register allocator. */
1037
1038/* total number of uinstrs input to reg-alloc */
1039extern UInt VG_(uinstrs_prealloc);
1040
1041/* total number of uinstrs added due to spill code */
1042extern UInt VG_(uinstrs_spill);
1043
1044/* number of bbs requiring spill code */
1045extern UInt VG_(translations_needing_spill);
1046
1047/* total of register ranks over all translations */
1048extern UInt VG_(total_reg_rank);
1049
1050/* Counts pertaining to the self-modifying-code detection machinery. */
1051
1052/* Total number of writes checked. */
1053//extern UInt VG_(smc_total_check4s);
1054
1055/* Number of writes which the fast smc check couldn't show were
1056 harmless. */
1057extern UInt VG_(smc_cache_passed);
1058
1059/* Numnber of writes which really did write on original code. */
1060extern UInt VG_(smc_fancy_passed);
1061
1062/* Number of translations discarded as a result. */
1063//extern UInt VG_(smc_discard_count);
1064
1065/* Counts pertaining to internal sanity checking. */
1066extern UInt VG_(sanity_fast_count);
1067extern UInt VG_(sanity_slow_count);
1068
1069
1070/* ---------------------------------------------------------------------
1071 Exports of vg_memory.c
1072 ------------------------------------------------------------------ */
1073
1074extern void VGM_(init_memory_audit) ( void );
1075extern Addr VGM_(curr_dataseg_end);
1076extern void VG_(show_reg_tags) ( void );
1077extern void VG_(detect_memory_leaks) ( void );
1078extern void VG_(done_prof_mem) ( void );
1079
1080/* Set permissions for an address range. Not speed-critical. */
1081extern void VGM_(make_noaccess) ( Addr a, UInt len );
1082extern void VGM_(make_writable) ( Addr a, UInt len );
1083extern void VGM_(make_readable) ( Addr a, UInt len );
1084/* Use with care! (read: use for shmat only) */
1085extern void VGM_(make_readwritable) ( Addr a, UInt len );
1086extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1087 UInt len );
1088
1089/* Check permissions for an address range. Not speed-critical. */
1090extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1091extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1092extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1093
1094/* Sanity checks which may be done at any time. Doing them at
1095 signal-delivery time turns out to be convenient. */
1096extern void VG_(do_sanity_checks) ( Bool force_expensive );
1097/* Very cheap ... */
1098extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1099
1100/* These functions are called from generated code. */
1101extern void VG_(helperc_STOREV4) ( UInt, Addr );
1102extern void VG_(helperc_STOREV2) ( UInt, Addr );
1103extern void VG_(helperc_STOREV1) ( UInt, Addr );
1104
1105extern UInt VG_(helperc_LOADV1) ( Addr );
1106extern UInt VG_(helperc_LOADV2) ( Addr );
1107extern UInt VG_(helperc_LOADV4) ( Addr );
1108
1109extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1110extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1111extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1112
1113/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1114 space and pass the addresses and values of all addressible,
1115 defined, aligned words to notify_word. This is the basis for the
1116 leak detector. Returns the number of calls made to notify_word. */
1117UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1118
1119/* Is this address within some small distance below %ESP? Used only
1120 for the --workaround-gcc296-bugs kludge. */
1121extern Bool VG_(is_just_below_ESP)( Addr aa );
1122
1123/* Nasty kludgery to deal with applications which switch stacks,
1124 like netscape. */
1125#define VG_STACK_STARTS_AT 0xC0000000
1126#define VG_PLAUSIBLE_STACK_SIZE 8000000
1127
1128extern Bool VG_(is_plausible_stack_addr) ( Addr );
1129
1130
1131/* ---------------------------------------------------------------------
1132 Exports of vg_syscall_mem.c
1133 ------------------------------------------------------------------ */
1134
1135/* Counts the depth of nested syscalls. Is used in
1136 VG_(deliver_signals) do discover whether or not the client is in a
1137 syscall (presumably _blocked_ in a syscall) when a signal is
1138 delivered. If so, the signal delivery mechanism needs to behave
1139 differently from normal. */
1140extern Int VG_(syscall_depth);
1141
1142extern void VG_(wrap_syscall) ( void );
1143
1144extern Bool VG_(is_kerror) ( Int res );
1145
1146#define KERNEL_DO_SYSCALL(result_lvalue) \
1147 VG_(copy_baseBlock_to_m_state_static)(); \
1148 VG_(do_syscall)(); \
1149 VG_(copy_m_state_static_to_baseBlock)(); \
1150 result_lvalue = VG_(baseBlock)[VGOFF_(m_eax)];
1151
1152
1153/* ---------------------------------------------------------------------
1154 Exports of vg_transtab.c
1155 ------------------------------------------------------------------ */
1156
1157/* An entry in the translation table (TT). */
1158typedef
1159 struct {
1160 /* +0 */ Addr orig_addr;
1161 /* +4 */ Addr trans_addr;
1162 /* +8 */ UInt mru_epoch;
1163 /* +12 */ UShort orig_size;
1164 /* +14 */ UShort trans_size;
1165 }
1166 TTEntry;
1167
1168/* The number of basic blocks in an epoch (one age-step). */
1169#define VG_BBS_PER_EPOCH 20000
1170
1171extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1172extern void VG_(maybe_do_lru_pass) ( void );
1173extern void VG_(flush_transtab) ( void );
1174extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1175extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1176
1177extern void VG_(smc_mark_original) ( Addr original_addr,
1178 Int original_len );
1179
1180extern void VG_(init_transtab_and_SMC) ( void );
1181
1182extern void VG_(sanity_check_tc_tt) ( void );
1183extern Addr VG_(search_transtab) ( Addr original_addr );
1184
1185extern void VG_(invalidate_tt_fast)( void );
1186
1187
1188/* ---------------------------------------------------------------------
1189 Exports of vg_vtagops.c
1190 ------------------------------------------------------------------ */
1191
1192/* Lists the names of value-tag operations used in instrumented
1193 code. These are the third argument to TAG1 and TAG2 uinsns. */
1194
1195typedef
1196 enum {
1197 /* Unary. */
1198 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1199 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1200
1201 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1202
1203 VgT_Left4, VgT_Left2, VgT_Left1,
1204
1205 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1206 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1207
1208 /* Binary; 1st is rd; 2nd is rd+wr */
1209 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1210 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1211
1212 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1213 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1214 VgT_DebugFn
1215 }
1216 VgTagOp;
1217
1218extern Char* VG_(nameOfTagOp) ( VgTagOp );
1219extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1220
1221
1222/* ---------------------------------------------------------------------
1223 Exports of vg_syscall.S
1224 ------------------------------------------------------------------ */
1225
1226extern void VG_(do_syscall) ( void );
1227
1228
1229/* ---------------------------------------------------------------------
1230 Exports of vg_startup.S
1231 ------------------------------------------------------------------ */
1232
1233extern void VG_(shutdown);
1234extern void VG_(switch_to_real_CPU) ( void );
1235
1236extern void VG_(swizzle_esp_then_start_GDB) ( void );
1237
1238
1239/* ---------------------------------------------------------------------
1240 Exports of vg_dispatch.S
1241 ------------------------------------------------------------------ */
1242
1243extern void VG_(dispatch);
1244extern void VG_(run_innerloop) ( void );
1245
1246/* Returns the next orig_addr to run. */
1247extern Addr VG_(run_singleton_translation) ( Addr trans_addr );
1248
1249
1250/* ---------------------------------------------------------------------
1251 Exports of vg_helpers.S
1252 ------------------------------------------------------------------ */
1253
1254/* For doing exits ... */
1255extern void VG_(helper_request_normal_exit);
1256
1257/* SMC fast checks. */
1258extern void VG_(helper_smc_check4);
1259
1260/* Mul, div, etc, -- we don't codegen these directly. */
1261extern void VG_(helper_idiv_64_32);
1262extern void VG_(helper_div_64_32);
1263extern void VG_(helper_idiv_32_16);
1264extern void VG_(helper_div_32_16);
1265extern void VG_(helper_idiv_16_8);
1266extern void VG_(helper_div_16_8);
1267
1268extern void VG_(helper_imul_32_64);
1269extern void VG_(helper_mul_32_64);
1270extern void VG_(helper_imul_16_32);
1271extern void VG_(helper_mul_16_32);
1272extern void VG_(helper_imul_8_16);
1273extern void VG_(helper_mul_8_16);
1274
1275extern void VG_(helper_CLD);
1276extern void VG_(helper_STD);
1277extern void VG_(helper_get_dirflag);
1278
1279extern void VG_(helper_shldl);
1280extern void VG_(helper_shldw);
1281extern void VG_(helper_shrdl);
1282extern void VG_(helper_shrdw);
1283
1284extern void VG_(helper_RDTSC);
1285extern void VG_(helper_CPUID);
1286
1287extern void VG_(helper_bt);
1288extern void VG_(helper_bts);
1289extern void VG_(helper_btr);
1290extern void VG_(helper_btc);
1291
1292extern void VG_(helper_bsf);
1293extern void VG_(helper_bsr);
1294
1295extern void VG_(helper_fstsw_AX);
1296extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001297extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001298extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001299
1300extern void VG_(helper_value_check4_fail);
1301extern void VG_(helper_value_check2_fail);
1302extern void VG_(helper_value_check1_fail);
1303extern void VG_(helper_value_check0_fail);
1304
1305extern void VG_(helper_do_syscall);
1306extern void VG_(helper_do_client_request);
1307
1308
1309/* ---------------------------------------------------------------------
1310 The state of the simulated CPU.
1311 ------------------------------------------------------------------ */
1312
1313/* This is the Intel register encoding. */
1314#define R_EAX 0
1315#define R_ECX 1
1316#define R_EDX 2
1317#define R_EBX 3
1318#define R_ESP 4
1319#define R_EBP 5
1320#define R_ESI 6
1321#define R_EDI 7
1322
1323#define R_AL (0+R_EAX)
1324#define R_CL (0+R_ECX)
1325#define R_DL (0+R_EDX)
1326#define R_BL (0+R_EBX)
1327#define R_AH (4+R_EAX)
1328#define R_CH (4+R_ECX)
1329#define R_DH (4+R_EDX)
1330#define R_BH (4+R_EBX)
1331
1332
1333/* ---------------------------------------------------------------------
1334 Offsets into baseBlock for everything which needs to referred to
1335 from generated code. The order of these decls does not imply
1336 what the order of the actual offsets is. The latter is important
1337 and is set up in vg_main.c.
1338 ------------------------------------------------------------------ */
1339
1340/* An array of words. In generated code, %ebp always points to the
1341 start of this array. Useful stuff, like the simulated CPU state,
1342 and the addresses of helper functions, can then be found by
1343 indexing off %ebp. The following declares variables which, at
1344 startup time, are given values denoting offsets into baseBlock.
1345 These offsets are in *words* from the start of baseBlock. */
1346
1347#define VG_BASEBLOCK_WORDS 200
1348
1349extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1350
1351
1352/* -----------------------------------------------------
1353 Read-write parts of baseBlock.
1354 -------------------------------------------------- */
1355
1356/* State of the simulated CPU. */
1357extern Int VGOFF_(m_eax);
1358extern Int VGOFF_(m_ecx);
1359extern Int VGOFF_(m_edx);
1360extern Int VGOFF_(m_ebx);
1361extern Int VGOFF_(m_esp);
1362extern Int VGOFF_(m_ebp);
1363extern Int VGOFF_(m_esi);
1364extern Int VGOFF_(m_edi);
1365extern Int VGOFF_(m_eflags);
1366extern Int VGOFF_(m_fpustate);
1367extern Int VGOFF_(m_eip);
1368
1369/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1370extern Int VGOFF_(spillslots);
1371
1372/* Records the valid bits for the 8 integer regs & flags reg. */
1373extern Int VGOFF_(sh_eax);
1374extern Int VGOFF_(sh_ecx);
1375extern Int VGOFF_(sh_edx);
1376extern Int VGOFF_(sh_ebx);
1377extern Int VGOFF_(sh_esp);
1378extern Int VGOFF_(sh_ebp);
1379extern Int VGOFF_(sh_esi);
1380extern Int VGOFF_(sh_edi);
1381extern Int VGOFF_(sh_eflags);
1382
1383
1384/* -----------------------------------------------------
1385 Read-only parts of baseBlock.
1386 -------------------------------------------------- */
1387
1388/* Offsets of addresses of helper functions. A "helper" function is
1389 one which is called from generated code. */
1390
1391extern Int VGOFF_(helper_idiv_64_32);
1392extern Int VGOFF_(helper_div_64_32);
1393extern Int VGOFF_(helper_idiv_32_16);
1394extern Int VGOFF_(helper_div_32_16);
1395extern Int VGOFF_(helper_idiv_16_8);
1396extern Int VGOFF_(helper_div_16_8);
1397
1398extern Int VGOFF_(helper_imul_32_64);
1399extern Int VGOFF_(helper_mul_32_64);
1400extern Int VGOFF_(helper_imul_16_32);
1401extern Int VGOFF_(helper_mul_16_32);
1402extern Int VGOFF_(helper_imul_8_16);
1403extern Int VGOFF_(helper_mul_8_16);
1404
1405extern Int VGOFF_(helper_CLD);
1406extern Int VGOFF_(helper_STD);
1407extern Int VGOFF_(helper_get_dirflag);
1408
1409extern Int VGOFF_(helper_shldl);
1410extern Int VGOFF_(helper_shldw);
1411extern Int VGOFF_(helper_shrdl);
1412extern Int VGOFF_(helper_shrdw);
1413
1414extern Int VGOFF_(helper_RDTSC);
1415extern Int VGOFF_(helper_CPUID);
1416
1417extern Int VGOFF_(helper_bt);
1418extern Int VGOFF_(helper_bts);
1419extern Int VGOFF_(helper_btr);
1420extern Int VGOFF_(helper_btc);
1421
1422extern Int VGOFF_(helper_bsf);
1423extern Int VGOFF_(helper_bsr);
1424
1425extern Int VGOFF_(helper_fstsw_AX);
1426extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001427extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001428extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001429
1430extern Int VGOFF_(helper_value_check4_fail);
1431extern Int VGOFF_(helper_value_check2_fail);
1432extern Int VGOFF_(helper_value_check1_fail);
1433extern Int VGOFF_(helper_value_check0_fail);
1434
1435extern Int VGOFF_(helper_do_syscall);
1436extern Int VGOFF_(helper_do_client_request);
1437
1438extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1439extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1440extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1441
1442extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1443extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1444extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1445
1446extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1447extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1448extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1449
1450extern Int VGOFF_(helper_request_normal_exit);
1451
1452
1453
1454#endif /* ndef __VG_INCLUDE_H */
1455
sewardj3b2736a2002-03-24 12:18:35 +00001456
1457/* ---------------------------------------------------------------------
1458 Finally - autoconf-generated settings
1459 ------------------------------------------------------------------ */
1460
1461#include "config.h"
1462
sewardjde4a1d02002-03-22 01:27:54 +00001463/*--------------------------------------------------------------------*/
1464/*--- end vg_include.h ---*/
1465/*--------------------------------------------------------------------*/