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