blob: 8b81b6d364b476cc6a5656054368b10b56bf9cc0 [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)
619#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000620#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000621
622#define FlagsALL (FlagsOSZACP | FlagD)
623#define FlagsEmpty (FlagSet)0
624
625#define VG_IS_FLAG_SUBSET(set1,set2) \
626 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
627
628#define VG_UNION_FLAG_SETS(set1,set2) \
629 ( ((FlagSet)set1) | ((FlagSet)set2) )
630
631
632
633/* A Micro (u)-instruction. */
634typedef
635 struct {
636 /* word 1 */
637 UInt lit32; /* 32-bit literal */
638
639 /* word 2 */
640 UShort val1; /* first operand */
641 UShort val2; /* second operand */
642
643 /* word 3 */
644 UShort val3; /* third operand */
645 UChar opcode; /* opcode */
646 UChar size; /* data transfer size */
647
648 /* word 4 */
649 FlagSet flags_r; /* :: FlagSet */
650 FlagSet flags_w; /* :: FlagSet */
651 UChar tag1:4; /* first operand tag */
652 UChar tag2:4; /* second operand tag */
653 UChar tag3:4; /* third operand tag */
654 UChar extra4b:4; /* Spare field, used by WIDEN for src
655 -size, and by LEA2 for scale
656 (1,2,4 or 8) */
657
658 /* word 5 */
659 UChar cond; /* condition, for jumps */
660 Bool smc_check:1; /* do a smc test, if writes memory. */
661 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
662 Bool ret_dispatch:1; /* Is this jump as a result of RET ? */
663 Bool call_dispatch:1; /* Is this jump as a result of CALL ? */
664 }
665 UInstr;
666
667
668/* Expandable arrays of uinstrs. */
669typedef
670 struct {
671 Int used;
672 Int size;
673 UInstr* instrs;
674 Int nextTemp;
675 }
676 UCodeBlock;
677
678/* Refer to `the last instruction stuffed in', including as an
679 lvalue. */
680#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
681
682/* An invalid temporary number :-) */
683#define INVALID_TEMPREG 999999999
684
685
686/* ---------------------------------------------------------------------
687 Exports of vg_demangle.c
688 ------------------------------------------------------------------ */
689
690extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
691
692
693/* ---------------------------------------------------------------------
694 Exports of vg_from_ucode.c
695 ------------------------------------------------------------------ */
696
697extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
698
699
700/* ---------------------------------------------------------------------
701 Exports of vg_to_ucode.c
702 ------------------------------------------------------------------ */
703
704extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
705extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
706extern Char VG_(nameOfIntSize) ( Int size );
707extern UInt VG_(extend_s_8to32) ( UInt x );
708extern Int VG_(getNewTemp) ( UCodeBlock* cb );
709extern Int VG_(getNewShadow) ( UCodeBlock* cb );
710
711#define SHADOW(tempreg) ((tempreg)+1)
712
713
714/* ---------------------------------------------------------------------
715 Exports of vg_translate.c
716 ------------------------------------------------------------------ */
717
718extern void VG_(translate) ( Addr orig_addr,
719 UInt* orig_size,
720 Addr* trans_addr,
721 UInt* trans_size );
722
723extern void VG_(emptyUInstr) ( UInstr* u );
724extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
725extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
726 Tag tag1, UInt val1 );
727extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
728 Tag tag1, UInt val1,
729 Tag tag2, UInt val2 );
730extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
731 Tag tag1, UInt val1,
732 Tag tag2, UInt val2,
733 Tag tag3, UInt val3 );
734extern void VG_(setFlagRW) ( UInstr* u,
735 FlagSet fr, FlagSet fw );
736
737extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
738extern Bool VG_(anyFlagUse) ( UInstr* u );
739
740
741
742extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
743extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
744
745extern Char* VG_(nameCondcode) ( Condcode cond );
746extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
747extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
748extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
749extern Int VG_(rankToRealRegNo) ( Int rank );
750
751extern void* VG_(jitmalloc) ( Int nbytes );
752extern void VG_(jitfree) ( void* ptr );
753
754
755/* ---------------------------------------------------------------------
756 Exports of vg_execontext.c.
757 ------------------------------------------------------------------ */
758
759/* Records the PC and a bit of the call chain. The first 4 %eip
760 values are used in comparisons do remove duplicate errors, and for
761 comparing against suppression specifications. The rest are purely
762 informational (but often important). */
763
764typedef
765 struct _ExeContextRec {
766 struct _ExeContextRec * next;
767 /* The size of this array is VG_(clo_backtrace_size); at least
768 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
769 [1] is its caller, [2] is the caller of [1], etc. */
770 Addr eips[0];
771 }
772 ExeContext;
773
774
775/* Initialise the ExeContext storage mechanism. */
776extern void VG_(init_ExeContext_storage) ( void );
777
778/* Print stats (informational only). */
779extern void VG_(show_ExeContext_stats) ( void );
780
781
782/* Take a snapshot of the client's stack. Search our collection of
783 ExeContexts to see if we already have it, and if not, allocate a
784 new one. Either way, return a pointer to the context. */
785extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame );
786
787/* Print an ExeContext. */
788extern void VG_(pp_ExeContext) ( ExeContext* );
789
790/* Compare two ExeContexts, just comparing the top two callers. */
791extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
792
793/* Compare two ExeContexts, just comparing the top four callers. */
794extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
795
796/* Compare two ExeContexts, comparing all callers. */
797extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
798
799
800
801/* ---------------------------------------------------------------------
802 Exports of vg_errcontext.c.
803 ------------------------------------------------------------------ */
804
805extern void VG_(load_suppressions) ( void );
806extern void VG_(show_all_errors) ( void );
807extern void VG_(record_value_error) ( Int size );
808extern void VG_(record_free_error) ( Addr a );
809extern void VG_(record_freemismatch_error) ( Addr a );
810extern void VG_(record_address_error) ( Addr a, Int size,
811 Bool isWrite );
812extern void VG_(record_jump_error) ( Addr a );
813extern void VG_(record_param_err) ( Addr a,
814 Bool isWriteLack,
815 Char* msg );
816extern void VG_(record_user_err) ( Addr a, Bool isWriteLack );
817
818
819/* The classification of a faulting address. */
820typedef
821 enum { Stack, Unknown, Freed, Mallocd, UserG, UserS }
822 AddrKind;
823
824/* Records info about a faulting address. */
825typedef
826 struct {
827 /* ALL */
828 AddrKind akind;
829 /* Freed, Mallocd */
830 Int blksize;
831 /* Freed, Mallocd */
832 Int rwoffset;
833 /* Freed, Mallocd */
834 ExeContext* lastchange;
835 }
836 AddrInfo;
837
838
839/* ---------------------------------------------------------------------
840 Exports of vg_clientperms.c
841 ------------------------------------------------------------------ */
842
843extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
844
845extern UInt VG_(handle_client_request) ( UInt code, Addr aa, UInt nn );
846
847extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
848
849extern void VG_(show_client_block_stats) ( void );
850
851
852/* ---------------------------------------------------------------------
853 Exports of vg_procselfmaps.c
854 ------------------------------------------------------------------ */
855
856extern
857void VG_(read_procselfmaps) (
858 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
859);
860
861
862/* ---------------------------------------------------------------------
863 Exports of vg_symtab2.c
864 ------------------------------------------------------------------ */
865
866/* We assume the executable is loaded here ... can't really find
867 out. There is a hacky sanity check in vg_init_memory_audit()
868 which should trip up most stupidities.
869*/
870#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
871
872extern void VG_(read_symbols) ( void );
873extern void VG_(mini_stack_dump) ( ExeContext* ec );
874extern void VG_(what_obj_and_fun_is_this)
875 ( Addr a,
876 Char* obj_buf, Int n_obj_buf,
877 Char* fun_buf, Int n_fun_buf );
878
879extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
880
881
882/* ---------------------------------------------------------------------
883 Exports of vg_clientmalloc.c
884 ------------------------------------------------------------------ */
885
886/* these numbers are not arbitary. if you change them,
887 adjust vg_dispatch.S as well */
888
889typedef
890 enum {
891 Vg_AllocMalloc = 0,
892 Vg_AllocNew = 1,
893 Vg_AllocNewVec = 2
894 }
895 VgAllocKind;
896
897/* Description of a malloc'd chunk. */
898typedef
899 struct _ShadowChunk {
900 struct _ShadowChunk* next;
901 ExeContext* where; /* where malloc'd/free'd */
902 UInt size : 30; /* size requested. */
903 VgAllocKind allockind : 2; /* which wrapper did the allocation */
904 Addr data; /* ptr to actual block. */
905 }
906 ShadowChunk;
907
908extern void VG_(clientmalloc_done) ( void );
909extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
910extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
911
912/* This should never be called; if it is, something's seriously
913 wrong. */
914extern UInt VG_(trap_here) ( UInt arg1, UInt arg2, UInt what_to_do );
915
916
917/* ---------------------------------------------------------------------
918 Exports of vg_main.c
919 ------------------------------------------------------------------ */
920
921/* How big is the saved FPU state? */
922#define VG_SIZE_OF_FPUSTATE 108
923/* ... and in words ... */
924#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
925
926/* A structure used as an intermediary when passing the simulated
927 CPU's state to some assembly fragments, particularly system calls.
928 Stuff is copied from baseBlock to here, the assembly magic runs,
929 and then the inverse copy is done. */
930
931extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
932 + 1 /* %eflags */
933 + 1 /* %eip */
934 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
935 ];
936
937/* Handy fns for doing the copy back and forth. */
938extern void VG_(copy_baseBlock_to_m_state_static) ( void );
939extern void VG_(copy_m_state_static_to_baseBlock) ( void );
940
941/* Create, and add to TT/TC, the translation of a client basic
942 block. */
943extern void VG_(create_translation_for) ( Addr orig_addr );
944
945/* Called when some unhandleable client behaviour is detected.
946 Prints a msg and aborts. */
947extern void VG_(unimplemented) ( Char* msg );
948
949/* The stack on which Valgrind runs. We can't use the same stack as the
950 simulatee -- that's an important design decision. */
951extern UInt VG_(stack)[10000];
952
953/* Similarly, we have to ask for signals to be delivered on an
954 alternative stack, since it is possible, although unlikely, that
955 we'll have to run client code from inside the Valgrind-installed
956 signal handler. If this happens it will be done by
957 vg_deliver_signal_immediately(). */
958extern UInt VG_(sigstack)[10000];
959
960
961/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
962extern jmp_buf VG_(toploop_jmpbuf);
963/* ... and if so, here's the signal which caused it to do so. */
964extern Int VG_(longjmpd_on_signal);
965
966/* Holds client's %esp at the point we gained control. From this the
967 client's argc, argv and envp are deduced. */
968extern Addr VG_(esp_at_startup);
969extern Int VG_(client_argc);
970extern Char** VG_(client_argv);
971extern Char** VG_(client_envp);
972
973/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
974 don't get traced into. */
975extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
976
977/* Something of a function looking for a home ... start up GDB. This
978 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
979 *client's* stack. This is necessary to give GDB the illusion that
980 the client program really was running on the real cpu. */
981extern void VG_(start_GDB_whilst_on_client_stack) ( void );
982
983/* Spew out vast amounts of junk during JITting? */
984extern Bool VG_(disassemble);
985
986/* 64-bit counter for the number of basic blocks done. */
987extern ULong VG_(bbs_done);
988/* 64-bit counter for the number of bbs to go before a debug exit. */
989extern ULong VG_(bbs_to_go);
990
991/* Counts downwards in vg_run_innerloop. */
992extern UInt VG_(dispatch_ctr);
993
994/* If vg_dispatch_ctr is set to 1 to force a stop, its
995 previous value is saved here. */
996extern UInt VG_(dispatch_ctr_SAVED);
997
998/* This is why vg_run_innerloop() exited. */
999extern UInt VG_(interrupt_reason);
1000
1001/* Is the client running on the simulated CPU or the real one? */
1002extern Bool VG_(running_on_simd_CPU); /* Initially False */
1003
1004/* The current LRU epoch. */
1005extern UInt VG_(current_epoch);
1006
1007
1008/* --- Counters, for informational purposes only. --- */
1009
1010/* Number of lookups which miss the fast tt helper. */
1011extern UInt VG_(tt_fast_misses);
1012
1013/* Counts for LRU informational messages. */
1014
1015/* Number and total o/t size of new translations this epoch. */
1016extern UInt VG_(this_epoch_in_count);
1017extern UInt VG_(this_epoch_in_osize);
1018extern UInt VG_(this_epoch_in_tsize);
1019/* Number and total o/t size of discarded translations this epoch. */
1020extern UInt VG_(this_epoch_out_count);
1021extern UInt VG_(this_epoch_out_osize);
1022extern UInt VG_(this_epoch_out_tsize);
1023/* Number and total o/t size of translations overall. */
1024extern UInt VG_(overall_in_count);
1025extern UInt VG_(overall_in_osize);
1026extern UInt VG_(overall_in_tsize);
1027/* Number and total o/t size of discards overall. */
1028extern UInt VG_(overall_out_count);
1029extern UInt VG_(overall_out_osize);
1030extern UInt VG_(overall_out_tsize);
1031
1032/* The number of LRU-clearings of TT/TC. */
1033extern UInt VG_(number_of_lrus);
1034
1035/* Counts pertaining to the register allocator. */
1036
1037/* total number of uinstrs input to reg-alloc */
1038extern UInt VG_(uinstrs_prealloc);
1039
1040/* total number of uinstrs added due to spill code */
1041extern UInt VG_(uinstrs_spill);
1042
1043/* number of bbs requiring spill code */
1044extern UInt VG_(translations_needing_spill);
1045
1046/* total of register ranks over all translations */
1047extern UInt VG_(total_reg_rank);
1048
1049/* Counts pertaining to the self-modifying-code detection machinery. */
1050
1051/* Total number of writes checked. */
1052//extern UInt VG_(smc_total_check4s);
1053
1054/* Number of writes which the fast smc check couldn't show were
1055 harmless. */
1056extern UInt VG_(smc_cache_passed);
1057
1058/* Numnber of writes which really did write on original code. */
1059extern UInt VG_(smc_fancy_passed);
1060
1061/* Number of translations discarded as a result. */
1062//extern UInt VG_(smc_discard_count);
1063
1064/* Counts pertaining to internal sanity checking. */
1065extern UInt VG_(sanity_fast_count);
1066extern UInt VG_(sanity_slow_count);
1067
1068
1069/* ---------------------------------------------------------------------
1070 Exports of vg_memory.c
1071 ------------------------------------------------------------------ */
1072
1073extern void VGM_(init_memory_audit) ( void );
1074extern Addr VGM_(curr_dataseg_end);
1075extern void VG_(show_reg_tags) ( void );
1076extern void VG_(detect_memory_leaks) ( void );
1077extern void VG_(done_prof_mem) ( void );
1078
1079/* Set permissions for an address range. Not speed-critical. */
1080extern void VGM_(make_noaccess) ( Addr a, UInt len );
1081extern void VGM_(make_writable) ( Addr a, UInt len );
1082extern void VGM_(make_readable) ( Addr a, UInt len );
1083/* Use with care! (read: use for shmat only) */
1084extern void VGM_(make_readwritable) ( Addr a, UInt len );
1085extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1086 UInt len );
1087
1088/* Check permissions for an address range. Not speed-critical. */
1089extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1090extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1091extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1092
1093/* Sanity checks which may be done at any time. Doing them at
1094 signal-delivery time turns out to be convenient. */
1095extern void VG_(do_sanity_checks) ( Bool force_expensive );
1096/* Very cheap ... */
1097extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1098
1099/* These functions are called from generated code. */
1100extern void VG_(helperc_STOREV4) ( UInt, Addr );
1101extern void VG_(helperc_STOREV2) ( UInt, Addr );
1102extern void VG_(helperc_STOREV1) ( UInt, Addr );
1103
1104extern UInt VG_(helperc_LOADV1) ( Addr );
1105extern UInt VG_(helperc_LOADV2) ( Addr );
1106extern UInt VG_(helperc_LOADV4) ( Addr );
1107
1108extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1109extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1110extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1111
1112/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1113 space and pass the addresses and values of all addressible,
1114 defined, aligned words to notify_word. This is the basis for the
1115 leak detector. Returns the number of calls made to notify_word. */
1116UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1117
1118/* Is this address within some small distance below %ESP? Used only
1119 for the --workaround-gcc296-bugs kludge. */
1120extern Bool VG_(is_just_below_ESP)( Addr aa );
1121
1122/* Nasty kludgery to deal with applications which switch stacks,
1123 like netscape. */
1124#define VG_STACK_STARTS_AT 0xC0000000
1125#define VG_PLAUSIBLE_STACK_SIZE 8000000
1126
1127extern Bool VG_(is_plausible_stack_addr) ( Addr );
1128
1129
1130/* ---------------------------------------------------------------------
1131 Exports of vg_syscall_mem.c
1132 ------------------------------------------------------------------ */
1133
1134/* Counts the depth of nested syscalls. Is used in
1135 VG_(deliver_signals) do discover whether or not the client is in a
1136 syscall (presumably _blocked_ in a syscall) when a signal is
1137 delivered. If so, the signal delivery mechanism needs to behave
1138 differently from normal. */
1139extern Int VG_(syscall_depth);
1140
1141extern void VG_(wrap_syscall) ( void );
1142
1143extern Bool VG_(is_kerror) ( Int res );
1144
1145#define KERNEL_DO_SYSCALL(result_lvalue) \
1146 VG_(copy_baseBlock_to_m_state_static)(); \
1147 VG_(do_syscall)(); \
1148 VG_(copy_m_state_static_to_baseBlock)(); \
1149 result_lvalue = VG_(baseBlock)[VGOFF_(m_eax)];
1150
1151
1152/* ---------------------------------------------------------------------
1153 Exports of vg_transtab.c
1154 ------------------------------------------------------------------ */
1155
1156/* An entry in the translation table (TT). */
1157typedef
1158 struct {
1159 /* +0 */ Addr orig_addr;
1160 /* +4 */ Addr trans_addr;
1161 /* +8 */ UInt mru_epoch;
1162 /* +12 */ UShort orig_size;
1163 /* +14 */ UShort trans_size;
1164 }
1165 TTEntry;
1166
1167/* The number of basic blocks in an epoch (one age-step). */
1168#define VG_BBS_PER_EPOCH 20000
1169
1170extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1171extern void VG_(maybe_do_lru_pass) ( void );
1172extern void VG_(flush_transtab) ( void );
1173extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1174extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1175
1176extern void VG_(smc_mark_original) ( Addr original_addr,
1177 Int original_len );
1178
1179extern void VG_(init_transtab_and_SMC) ( void );
1180
1181extern void VG_(sanity_check_tc_tt) ( void );
1182extern Addr VG_(search_transtab) ( Addr original_addr );
1183
1184extern void VG_(invalidate_tt_fast)( void );
1185
1186
1187/* ---------------------------------------------------------------------
1188 Exports of vg_vtagops.c
1189 ------------------------------------------------------------------ */
1190
1191/* Lists the names of value-tag operations used in instrumented
1192 code. These are the third argument to TAG1 and TAG2 uinsns. */
1193
1194typedef
1195 enum {
1196 /* Unary. */
1197 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1198 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1199
1200 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1201
1202 VgT_Left4, VgT_Left2, VgT_Left1,
1203
1204 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1205 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1206
1207 /* Binary; 1st is rd; 2nd is rd+wr */
1208 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1209 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1210
1211 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1212 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1213 VgT_DebugFn
1214 }
1215 VgTagOp;
1216
1217extern Char* VG_(nameOfTagOp) ( VgTagOp );
1218extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1219
1220
1221/* ---------------------------------------------------------------------
1222 Exports of vg_syscall.S
1223 ------------------------------------------------------------------ */
1224
1225extern void VG_(do_syscall) ( void );
1226
1227
1228/* ---------------------------------------------------------------------
1229 Exports of vg_startup.S
1230 ------------------------------------------------------------------ */
1231
1232extern void VG_(shutdown);
1233extern void VG_(switch_to_real_CPU) ( void );
1234
1235extern void VG_(swizzle_esp_then_start_GDB) ( void );
1236
1237
1238/* ---------------------------------------------------------------------
1239 Exports of vg_dispatch.S
1240 ------------------------------------------------------------------ */
1241
1242extern void VG_(dispatch);
1243extern void VG_(run_innerloop) ( void );
1244
1245/* Returns the next orig_addr to run. */
1246extern Addr VG_(run_singleton_translation) ( Addr trans_addr );
1247
1248
1249/* ---------------------------------------------------------------------
1250 Exports of vg_helpers.S
1251 ------------------------------------------------------------------ */
1252
1253/* For doing exits ... */
1254extern void VG_(helper_request_normal_exit);
1255
1256/* SMC fast checks. */
1257extern void VG_(helper_smc_check4);
1258
1259/* Mul, div, etc, -- we don't codegen these directly. */
1260extern void VG_(helper_idiv_64_32);
1261extern void VG_(helper_div_64_32);
1262extern void VG_(helper_idiv_32_16);
1263extern void VG_(helper_div_32_16);
1264extern void VG_(helper_idiv_16_8);
1265extern void VG_(helper_div_16_8);
1266
1267extern void VG_(helper_imul_32_64);
1268extern void VG_(helper_mul_32_64);
1269extern void VG_(helper_imul_16_32);
1270extern void VG_(helper_mul_16_32);
1271extern void VG_(helper_imul_8_16);
1272extern void VG_(helper_mul_8_16);
1273
1274extern void VG_(helper_CLD);
1275extern void VG_(helper_STD);
1276extern void VG_(helper_get_dirflag);
1277
1278extern void VG_(helper_shldl);
1279extern void VG_(helper_shldw);
1280extern void VG_(helper_shrdl);
1281extern void VG_(helper_shrdw);
1282
1283extern void VG_(helper_RDTSC);
1284extern void VG_(helper_CPUID);
1285
1286extern void VG_(helper_bt);
1287extern void VG_(helper_bts);
1288extern void VG_(helper_btr);
1289extern void VG_(helper_btc);
1290
1291extern void VG_(helper_bsf);
1292extern void VG_(helper_bsr);
1293
1294extern void VG_(helper_fstsw_AX);
1295extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001296extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001297extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001298
1299extern void VG_(helper_value_check4_fail);
1300extern void VG_(helper_value_check2_fail);
1301extern void VG_(helper_value_check1_fail);
1302extern void VG_(helper_value_check0_fail);
1303
1304extern void VG_(helper_do_syscall);
1305extern void VG_(helper_do_client_request);
1306
1307
1308/* ---------------------------------------------------------------------
1309 The state of the simulated CPU.
1310 ------------------------------------------------------------------ */
1311
1312/* This is the Intel register encoding. */
1313#define R_EAX 0
1314#define R_ECX 1
1315#define R_EDX 2
1316#define R_EBX 3
1317#define R_ESP 4
1318#define R_EBP 5
1319#define R_ESI 6
1320#define R_EDI 7
1321
1322#define R_AL (0+R_EAX)
1323#define R_CL (0+R_ECX)
1324#define R_DL (0+R_EDX)
1325#define R_BL (0+R_EBX)
1326#define R_AH (4+R_EAX)
1327#define R_CH (4+R_ECX)
1328#define R_DH (4+R_EDX)
1329#define R_BH (4+R_EBX)
1330
1331
1332/* ---------------------------------------------------------------------
1333 Offsets into baseBlock for everything which needs to referred to
1334 from generated code. The order of these decls does not imply
1335 what the order of the actual offsets is. The latter is important
1336 and is set up in vg_main.c.
1337 ------------------------------------------------------------------ */
1338
1339/* An array of words. In generated code, %ebp always points to the
1340 start of this array. Useful stuff, like the simulated CPU state,
1341 and the addresses of helper functions, can then be found by
1342 indexing off %ebp. The following declares variables which, at
1343 startup time, are given values denoting offsets into baseBlock.
1344 These offsets are in *words* from the start of baseBlock. */
1345
1346#define VG_BASEBLOCK_WORDS 200
1347
1348extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1349
1350
1351/* -----------------------------------------------------
1352 Read-write parts of baseBlock.
1353 -------------------------------------------------- */
1354
1355/* State of the simulated CPU. */
1356extern Int VGOFF_(m_eax);
1357extern Int VGOFF_(m_ecx);
1358extern Int VGOFF_(m_edx);
1359extern Int VGOFF_(m_ebx);
1360extern Int VGOFF_(m_esp);
1361extern Int VGOFF_(m_ebp);
1362extern Int VGOFF_(m_esi);
1363extern Int VGOFF_(m_edi);
1364extern Int VGOFF_(m_eflags);
1365extern Int VGOFF_(m_fpustate);
1366extern Int VGOFF_(m_eip);
1367
1368/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1369extern Int VGOFF_(spillslots);
1370
1371/* Records the valid bits for the 8 integer regs & flags reg. */
1372extern Int VGOFF_(sh_eax);
1373extern Int VGOFF_(sh_ecx);
1374extern Int VGOFF_(sh_edx);
1375extern Int VGOFF_(sh_ebx);
1376extern Int VGOFF_(sh_esp);
1377extern Int VGOFF_(sh_ebp);
1378extern Int VGOFF_(sh_esi);
1379extern Int VGOFF_(sh_edi);
1380extern Int VGOFF_(sh_eflags);
1381
1382
1383/* -----------------------------------------------------
1384 Read-only parts of baseBlock.
1385 -------------------------------------------------- */
1386
1387/* Offsets of addresses of helper functions. A "helper" function is
1388 one which is called from generated code. */
1389
1390extern Int VGOFF_(helper_idiv_64_32);
1391extern Int VGOFF_(helper_div_64_32);
1392extern Int VGOFF_(helper_idiv_32_16);
1393extern Int VGOFF_(helper_div_32_16);
1394extern Int VGOFF_(helper_idiv_16_8);
1395extern Int VGOFF_(helper_div_16_8);
1396
1397extern Int VGOFF_(helper_imul_32_64);
1398extern Int VGOFF_(helper_mul_32_64);
1399extern Int VGOFF_(helper_imul_16_32);
1400extern Int VGOFF_(helper_mul_16_32);
1401extern Int VGOFF_(helper_imul_8_16);
1402extern Int VGOFF_(helper_mul_8_16);
1403
1404extern Int VGOFF_(helper_CLD);
1405extern Int VGOFF_(helper_STD);
1406extern Int VGOFF_(helper_get_dirflag);
1407
1408extern Int VGOFF_(helper_shldl);
1409extern Int VGOFF_(helper_shldw);
1410extern Int VGOFF_(helper_shrdl);
1411extern Int VGOFF_(helper_shrdw);
1412
1413extern Int VGOFF_(helper_RDTSC);
1414extern Int VGOFF_(helper_CPUID);
1415
1416extern Int VGOFF_(helper_bt);
1417extern Int VGOFF_(helper_bts);
1418extern Int VGOFF_(helper_btr);
1419extern Int VGOFF_(helper_btc);
1420
1421extern Int VGOFF_(helper_bsf);
1422extern Int VGOFF_(helper_bsr);
1423
1424extern Int VGOFF_(helper_fstsw_AX);
1425extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001426extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001427extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001428
1429extern Int VGOFF_(helper_value_check4_fail);
1430extern Int VGOFF_(helper_value_check2_fail);
1431extern Int VGOFF_(helper_value_check1_fail);
1432extern Int VGOFF_(helper_value_check0_fail);
1433
1434extern Int VGOFF_(helper_do_syscall);
1435extern Int VGOFF_(helper_do_client_request);
1436
1437extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1438extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1439extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1440
1441extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1442extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1443extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1444
1445extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1446extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1447extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1448
1449extern Int VGOFF_(helper_request_normal_exit);
1450
1451
1452
1453#endif /* ndef __VG_INCLUDE_H */
1454
sewardj3b2736a2002-03-24 12:18:35 +00001455
1456/* ---------------------------------------------------------------------
1457 Finally - autoconf-generated settings
1458 ------------------------------------------------------------------ */
1459
1460#include "config.h"
1461
sewardjde4a1d02002-03-22 01:27:54 +00001462/*--------------------------------------------------------------------*/
1463/*--- end vg_include.h ---*/
1464/*--------------------------------------------------------------------*/