blob: 5d9825f12da7bf0b3f0d04d9e14e11e4f38012ec [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
sewardj2e93c502002-04-12 11:12:52 +0000120/* Defines the thread-scheduling timeslice, in terms of the number of
121 basic blocks we attempt to run each thread for. Smaller values
122 give finer interleaving but much increased scheduling overheads. */
123#define VG_SCHEDULING_QUANTUM 10000
124
125/* The maximum number of pthreads that we support. This is
126 deliberately not very high since our implementation of some of the
127 scheduler algorithms is surely O(N^2) in the number of threads,
128 since that's simple, at least. And (in practice) we hope that most
129 programs do not need many threads. */
130#define VG_N_THREADS 20
131
132/* Number of file descriptors that can simultaneously be waited on for
133 I/O to complete. Perhaps this should be the same as VG_N_THREADS
134 (surely a thread can't wait on more than one fd at once?. Who
135 knows.) */
136#define VG_N_WAITING_FDS 10
137
138/* Maximum number of mutexes allowed. */
139#define VG_N_MUTEXES 10
140
sewardjde4a1d02002-03-22 01:27:54 +0000141
142/* ---------------------------------------------------------------------
143 Basic types
144 ------------------------------------------------------------------ */
145
146typedef unsigned char UChar;
147typedef unsigned short UShort;
148typedef unsigned int UInt;
149typedef unsigned long long int ULong;
150
151typedef signed char Char;
152typedef signed short Short;
153typedef signed int Int;
154typedef signed long long int Long;
155
156typedef unsigned int Addr;
157
158typedef unsigned char Bool;
159#define False ((Bool)0)
160#define True ((Bool)1)
161
162#define mycat_wrk(aaa,bbb) aaa##bbb
163#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
164
165/* Just pray that gcc's constant folding works properly ... */
166#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
167 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
168 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
169
170
171/* ---------------------------------------------------------------------
172 Now the basic types are set up, we can haul in the kernel-interface
173 definitions.
174 ------------------------------------------------------------------ */
175
176#include "./vg_kerneliface.h"
177
178
179/* ---------------------------------------------------------------------
180 Command-line-settable options
181 ------------------------------------------------------------------ */
182
183#define VG_CLO_SMC_NONE 0
184#define VG_CLO_SMC_SOME 1
185#define VG_CLO_SMC_ALL 2
186
187#define VG_CLO_MAX_SFILES 10
188
sewardj97ced732002-03-25 00:07:36 +0000189/* Shall we V-check addrs (they are always A checked too): default: YES */
190extern Bool VG_(clo_check_addrVs);
sewardjde4a1d02002-03-22 01:27:54 +0000191/* Enquire about whether to attach to GDB at errors? default: NO */
192extern Bool VG_(clo_GDB_attach);
193/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
194extern Int VG_(sanity_level);
195/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
196extern Int VG_(clo_verbosity);
197/* Automatically attempt to demangle C++ names? default: YES */
198extern Bool VG_(clo_demangle);
199/* Do leak check at exit? default: NO */
200extern Bool VG_(clo_leak_check);
201/* In leak check, show reachable-but-not-freed blocks? default: NO */
202extern Bool VG_(clo_show_reachable);
203/* How closely should we compare ExeContexts in leak records? default: 2 */
204extern Int VG_(clo_leak_resolution);
205/* Round malloc sizes upwards to integral number of words? default:
206 NO */
207extern Bool VG_(clo_sloppy_malloc);
208/* Allow loads from partially-valid addresses? default: YES */
209extern Bool VG_(clo_partial_loads_ok);
210/* Simulate child processes? default: NO */
211extern Bool VG_(clo_trace_children);
212/* The file id on which we send all messages. default: 2 (stderr). */
213extern Int VG_(clo_logfile_fd);
214/* Max volume of the freed blocks queue. */
215extern Int VG_(clo_freelist_vol);
216/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
217 default: NO */
218extern Bool VG_(clo_workaround_gcc296_bugs);
219
220/* The number of suppression files specified. */
221extern Int VG_(clo_n_suppressions);
222/* The names of the suppression files. */
223extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
224
225/* Single stepping? default: NO */
226extern Bool VG_(clo_single_step);
227/* Code improvement? default: YES */
228extern Bool VG_(clo_optimise);
229/* Memory-check instrumentation? default: YES */
230extern Bool VG_(clo_instrument);
231/* DEBUG: clean up instrumented code? default: YES */
232extern Bool VG_(clo_cleanup);
233/* Handle client memory-range-permissions-setting requests? default: NO */
234extern Bool VG_(clo_client_perms);
235/* SMC write checks? default: SOME (1,2,4 byte movs to mem) */
236extern Int VG_(clo_smc_check);
237/* DEBUG: print system calls? default: NO */
238extern Bool VG_(clo_trace_syscalls);
239/* DEBUG: print signal details? default: NO */
240extern Bool VG_(clo_trace_signals);
241/* DEBUG: print symtab details? default: NO */
242extern Bool VG_(clo_trace_symtab);
243/* DEBUG: print malloc details? default: NO */
244extern Bool VG_(clo_trace_malloc);
245/* Stop after this many basic blocks. default: Infinity. */
246extern ULong VG_(clo_stop_after);
247/* Display gory details for the k'th most popular error. default:
248 Infinity. */
249extern Int VG_(clo_dump_error);
250/* Number of parents of a backtrace. Default: 8. */
251extern Int VG_(clo_backtrace_size);
252
253
254/* ---------------------------------------------------------------------
255 Debugging and profiling stuff
256 ------------------------------------------------------------------ */
257
258/* No, really. I _am_ that strange. */
259#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
260
261/* Tools for building messages from multiple parts. */
262typedef
263 enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg }
264 VgMsgKind;
265
266extern void VG_(start_msg) ( VgMsgKind kind );
267extern void VG_(add_to_msg) ( Char* format, ... );
268extern void VG_(end_msg) ( void );
269
270/* Send a simple, single-part message. */
271extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
272
273/* Create a logfile into which messages can be dumped. */
274extern void VG_(startup_logging) ( void );
275extern void VG_(shutdown_logging) ( void );
276
277
278/* Profiling stuff */
279#ifdef VG_PROFILE
280
281#define VGP_M_STACK 10
282
283#define VGP_M_CCS 20 /* == the # of elems in VGP_LIST */
284#define VGP_LIST \
285 VGP_PAIR(VgpRun=0, "running"), \
286 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
287 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
288 VGP_PAIR(VgpTranslate, "translate-main"), \
289 VGP_PAIR(VgpToUCode, "to-ucode"), \
290 VGP_PAIR(VgpFromUcode, "from-ucode"), \
291 VGP_PAIR(VgpImprove, "improve"), \
292 VGP_PAIR(VgpInstrument, "instrument"), \
293 VGP_PAIR(VgpCleanup, "cleanup"), \
294 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
295 VGP_PAIR(VgpDoLRU, "do-lru"), \
296 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
297 VGP_PAIR(VgpInitAudit, "init-mem-audit"), \
298 VGP_PAIR(VgpExeContext, "exe-context"), \
299 VGP_PAIR(VgpReadSyms, "read-syms"), \
300 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
301 VGP_PAIR(VgpSARP, "set-addr-range-perms"), \
302 VGP_PAIR(VgpSyscall, "syscall wrapper"), \
303 VGP_PAIR(VgpSpare1, "spare 1"), \
304 VGP_PAIR(VgpSpare2, "spare 2")
305
306#define VGP_PAIR(enumname,str) enumname
307typedef enum { VGP_LIST } VgpCC;
308#undef VGP_PAIR
309
310extern void VGP_(init_profiling) ( void );
311extern void VGP_(done_profiling) ( void );
312extern void VGP_(pushcc) ( VgpCC );
313extern void VGP_(popcc) ( void );
314
315#define VGP_PUSHCC(cc) VGP_(pushcc)(cc)
316#define VGP_POPCC VGP_(popcc)()
317
318#else
319
320#define VGP_PUSHCC(cc) /* */
321#define VGP_POPCC /* */
322
323#endif /* VG_PROFILE */
324
325
326/* ---------------------------------------------------------------------
327 Exports of vg_malloc2.c
328 ------------------------------------------------------------------ */
329
330/* Allocation arenas.
331 SYMTAB is for Valgrind's symbol table storage.
332 CLIENT is for the client's mallocs/frees.
333 DEMANGLE is for the C++ demangler.
334 EXECTXT is for storing ExeContexts.
335 ERRCTXT is for storing ErrContexts.
336 PRIVATE is for Valgrind general stuff.
337 TRANSIENT is for very short-term use. It should be empty
338 in between uses.
339 When adding a new arena, remember also to add it
340 to ensure_mm_init().
341*/
342typedef Int ArenaId;
343
344#define VG_N_ARENAS 7
345
346#define VG_AR_PRIVATE 0 /* :: ArenaId */
347#define VG_AR_SYMTAB 1 /* :: ArenaId */
348#define VG_AR_CLIENT 2 /* :: ArenaId */
349#define VG_AR_DEMANGLE 3 /* :: ArenaId */
350#define VG_AR_EXECTXT 4 /* :: ArenaId */
351#define VG_AR_ERRCTXT 5 /* :: ArenaId */
352#define VG_AR_TRANSIENT 6 /* :: ArenaId */
353
354extern void* VG_(malloc) ( ArenaId arena, Int nbytes );
355extern void VG_(free) ( ArenaId arena, void* ptr );
356extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes );
357extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size );
358extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB,
359 Int req_pszB );
360
361extern void VG_(mallocSanityCheckArena) ( ArenaId arena );
362extern void VG_(mallocSanityCheckAll) ( void );
363
364extern void VG_(show_all_arena_stats) ( void );
365extern Bool VG_(is_empty_arena) ( ArenaId aid );
366
367
368/* The red-zone size for the client. This can be arbitrary, but
369 unfortunately must be set at compile time. */
370#define VG_AR_CLIENT_REDZONE_SZW 4
371
372#define VG_AR_CLIENT_REDZONE_SZB \
373 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
374
375
376/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000377 Exports of vg_clientfuns.c
378 ------------------------------------------------------------------ */
379
380/* This doesn't export code or data that valgrind.so needs to link
381 against. However, the scheduler does need to know the following
382 request codes. A few, publically-visible, request codes are also
383 defined in valgrind.h. */
384
385#define VG_USERREQ__MALLOC 0x2001
386#define VG_USERREQ__BUILTIN_NEW 0x2002
387#define VG_USERREQ__BUILTIN_VEC_NEW 0x2003
388
389#define VG_USERREQ__FREE 0x2004
390#define VG_USERREQ__BUILTIN_DELETE 0x2005
391#define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006
392
393#define VG_USERREQ__CALLOC 0x2007
394#define VG_USERREQ__REALLOC 0x2008
395#define VG_USERREQ__MEMALIGN 0x2009
396
397
398#define VG_USERREQ__PTHREAD_CREATE 0x3001
399#define VG_USERREQ__PTHREAD_CREATE_BOGUSRA 0x3002
400#define VG_USERREQ__PTHREAD_JOIN 0x3003
401#define VG_USERREQ__PTHREAD_GET_THREADID 0x3004
402#define VG_USERREQ__PTHREAD_MUTEX_INIT 0x3005
403#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x3006
404#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x3007
405#define VG_USERREQ__PTHREAD_MUTEX_DESTROY 0x3008
406#define VG_USERREQ__PTHREAD_CANCEL 0x3009
407
408/* ---------------------------------------------------------------------
409 Constants pertaining to the simulated CPU state, VG_(baseBlock),
410 which need to go here to avoid ugly circularities.
411 ------------------------------------------------------------------ */
412
413/* How big is the saved FPU state? */
414#define VG_SIZE_OF_FPUSTATE 108
415/* ... and in words ... */
416#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
417
418
419/* ---------------------------------------------------------------------
420 Exports of vg_scheduler.c
421 ------------------------------------------------------------------ */
422
423/* ThreadIds are simply indices into the vg_threads[] array. */
424typedef
425 UInt
426 ThreadId;
427
428/* MutexIds are simply indices into the vg_mutexes[] array. */
429typedef
430 UInt
431 MutexId;
432
433
434#define VG_INVALID_THREADID ((ThreadId)(-1))
435
436typedef
437 enum {
438 VgTs_Empty, /* this slot is not in use */
439 VgTs_Runnable, /* waiting to be scheduled */
440 VgTs_WaitJoiner, /* waiting for someone to do join on me */
441 VgTs_WaitJoinee, /* waiting for the thread I did join on */
442 VgTs_WaitFD, /* waiting for I/O completion on a fd */
443 VgTs_WaitMX, /* waiting on a mutex */
444 VgTs_Sleeping /* sleeping for a while */
445 }
446 ThreadStatus;
447
448typedef
449 struct {
450 /* The thread identity is simply the index in vg_threads[].
451 ThreadId == 0 is the root thread and has the special property
452 that we don't try and allocate or deallocate its stack. */
453
454 /* Current scheduling status. */
455 ThreadStatus status;
456
457 /* Identity of joiner (thread who called join on me), or
458 VG_INVALID_THREADID if no one asked to join yet. */
459 ThreadId joiner;
460
461 /* Identity of mutex we are waiting on, if .status == WaitMX. */
462 MutexId waited_on_mid;
463
464 /* If VgTs_Sleeping, this is when we should wake up. */
465 ULong awaken_at;
466
467 /* return value */
468 void* retval;
469
470 /* Stacks. When a thread slot is freed, we don't deallocate its
471 stack; we just leave it lying around for the next use of the
472 slot. If the next use of the slot requires a larger stack,
473 only then is the old one deallocated and a new one
474 allocated.
475
476 For the main thread (threadid == 0), this mechanism doesn't
477 apply. We don't know the size of the stack since we didn't
478 allocate it, and furthermore we never reallocate it. */
479
480 /* The allocated size of this thread's stack (permanently zero
481 if this is ThreadId == 0, since we didn't allocate its stack) */
482 UInt stack_size;
483
484 /* Address of the lowest word in this thread's stack. NULL means
485 not allocated yet.
486 */
487 Addr stack_base;
488
489 /* Saved machine context. */
490 UInt m_eax;
491 UInt m_ebx;
492 UInt m_ecx;
493 UInt m_edx;
494 UInt m_esi;
495 UInt m_edi;
496 UInt m_ebp;
497 UInt m_esp;
498 UInt m_eflags;
499 UInt m_eip;
500 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
501
502 UInt sh_eax;
503 UInt sh_ebx;
504 UInt sh_ecx;
505 UInt sh_edx;
506 UInt sh_esi;
507 UInt sh_edi;
508 UInt sh_ebp;
509 UInt sh_esp;
510 UInt sh_eflags;
511 }
512 ThreadState;
513
514
515/* Copy the specified thread's state into VG_(baseBlock) in
516 preparation for running it. */
517extern void VG_(load_thread_state)( ThreadId );
518
519/* Save the specified thread's state back in VG_(baseBlock), and fill
520 VG_(baseBlock) with junk, for sanity-check reasons. */
521extern void VG_(save_thread_state)( ThreadId );
522
523/* Get the thread state block for the specified thread. */
524extern ThreadState* VG_(get_thread_state)( ThreadId );
525
526
527/* Create, and add to TT/TC, the translation of a client basic
528 block. */
529extern void VG_(create_translation_for) ( Addr orig_addr );
530
531/* Return codes from the scheduler. */
532typedef
533 enum { VgSrc_Deadlock, VgSrc_Shutdown, VgSrc_BbsDone }
534 VgSchedReturnCode;
535
536/* The scheduler. */
537extern VgSchedReturnCode VG_(scheduler) ( void );
538
539extern void VG_(scheduler_init) ( void );
540
541
542/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
543extern jmp_buf VG_(scheduler_jmpbuf);
544/* ... and if so, here's the signal which caused it to do so. */
545extern Int VG_(longjmpd_on_signal);
546
547
548/* We check that the initial stack, which we can't move, is allocated
549 here. VG_(scheduler_init) checks this.
550*/
551#define VG_STARTUP_STACK_MASK (Addr)0xBFFF8000
552
553
554/* The red-zone size which we put at the bottom (highest address) of
555 thread stacks, for paranoia reasons. This can be arbitrary, and
556 doesn't really need to be set at compile time. */
557#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
558
559#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
560 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
561
562
563
564/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000565 Exports of vg_signals.c
566 ------------------------------------------------------------------ */
567
sewardjde4a1d02002-03-22 01:27:54 +0000568extern void VG_(sigstartup_actions) ( void );
569
sewardj2e93c502002-04-12 11:12:52 +0000570extern void VG_(deliver_signals) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000571extern void VG_(unblock_host_signal) ( Int sigNo );
572
573
574/* Fake system calls for signal handling. */
sewardj2e93c502002-04-12 11:12:52 +0000575extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +0000576extern void VG_(do__NR_sigprocmask) ( Int how, vki_ksigset_t* set );
577
sewardj2e93c502002-04-12 11:12:52 +0000578/* Bogus return address for signal handlers. Is never executed. */
579extern void VG_(signalreturn_bogusRA) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000580
sewardj2e93c502002-04-12 11:12:52 +0000581/* Modify the current thread's state once we have detected it is
582 returning from a signal handler. */
583extern void VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000584
sewardj2e93c502002-04-12 11:12:52 +0000585/* Handy utilities to block/restore all host signals. */
586extern void VG_(block_all_host_signals)
587 ( /* OUT */ vki_ksigset_t* saved_mask );
588extern void VG_(restore_host_signals)
589 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000590
591/* ---------------------------------------------------------------------
592 Exports of vg_mylibc.c
593 ------------------------------------------------------------------ */
594
595
596#define NULL ((void*)0)
597
598extern void VG_(exit)( Int status )
599 __attribute__ ((__noreturn__));
600
601extern void VG_(printf) ( const char *format, ... );
602/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
603
604extern void VG_(sprintf) ( Char* buf, Char *format, ... );
605
606extern void VG_(vprintf) ( void(*send)(Char),
607 const Char *format, va_list vargs );
608
609extern Bool VG_(isspace) ( Char c );
610
611extern Int VG_(strlen) ( const Char* str );
612
613extern Long VG_(atoll) ( Char* str );
614
615extern Char* VG_(strcat) ( Char* dest, const Char* src );
616extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
617extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
618
619extern Char* VG_(strcpy) ( Char* dest, const Char* src );
620
621extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
622extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
623
624extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
625extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
626
627extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
628extern Char* VG_(strchr) ( const Char* s, Char c );
629extern Char* VG_(strdup) ( ArenaId aid, const Char* s);
630
631extern Char* VG_(getenv) ( Char* name );
632extern Int VG_(getpid) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000633extern ULong VG_(read_microsecond_timer)( void );
sewardjde4a1d02002-03-22 01:27:54 +0000634
635
636extern Char VG_(toupper) ( Char c );
637
638extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
639
640extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
641
642extern Bool VG_(stringMatch) ( Char* pat, Char* str );
643
644
645#define __STRING(x) #x
646
647/* Asserts are permanently enabled. Hurrah! */
648#define vg_assert(expr) \
649 ((void) ((expr) ? 0 : \
650 (VG_(assert_fail) (__STRING(expr), \
651 __FILE__, __LINE__, \
652 __PRETTY_FUNCTION__), 0)))
653
654extern void VG_(assert_fail) ( Char* expr, Char* file,
655 Int line, Char* fn )
656 __attribute__ ((__noreturn__));
657
sewardjde4a1d02002-03-22 01:27:54 +0000658/* Reading files. */
659extern Int VG_(open_read) ( Char* pathname );
660extern void VG_(close) ( Int fd );
661extern Int VG_(read) ( Int fd, void* buf, Int count);
662extern Int VG_(write) ( Int fd, void* buf, Int count);
663
sewardj2e93c502002-04-12 11:12:52 +0000664extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
665
666extern Int VG_(select)( Int n,
667 vki_fd_set* readfds,
668 vki_fd_set* writefds,
669 vki_fd_set* exceptfds,
670 struct vki_timeval * timeout );
671extern Int VG_(nanosleep)( const struct vki_timespec *req,
672 struct vki_timespec *rem );
673
674
sewardjde4a1d02002-03-22 01:27:54 +0000675/* mmap-ery ... */
676extern void* VG_(mmap)( void* start, UInt length,
677 UInt prot, UInt flags, UInt fd, UInt offset );
678
sewardj2e93c502002-04-12 11:12:52 +0000679extern Int VG_(munmap)( void* start, Int length );
sewardjde4a1d02002-03-22 01:27:54 +0000680
681
682/* Print a (panic) message, and abort. */
683extern void VG_(panic) ( Char* str )
684 __attribute__ ((__noreturn__));
685
686/* Get memory by anonymous mmap. */
687void* VG_(get_memory_from_mmap) ( Int nBytes );
688
689/* Signal stuff. Note that these use the vk_ (kernel) structure
690 definitions, which are different in places from those that glibc
691 defines. Since we're operating right at the kernel interface,
692 glibc's view of the world is entirely irrelevant. */
693extern Int VG_(ksigfillset)( vki_ksigset_t* set );
694extern Int VG_(ksigemptyset)( vki_ksigset_t* set );
695extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum );
696
697extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set,
698 vki_ksigset_t* oldset );
699extern Int VG_(ksigaction) ( Int signum,
700 const vki_ksigaction* act,
701 vki_ksigaction* oldact );
702extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
703
704extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int));
705
706extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss );
707
708
709
710/* ---------------------------------------------------------------------
711 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
712 vg_from_ucode.c).
713 ------------------------------------------------------------------ */
714
715/* Tags which describe what operands are. */
716typedef
717 enum { TempReg=0, ArchReg=1, RealReg=2,
718 SpillNo=3, Literal=4, Lit16=5,
719 NoValue=6 }
720 Tag;
721
722
723/* Microinstruction opcodes. */
724typedef
725 enum {
726 NOP,
727 GET,
728 PUT,
729 LOAD,
730 STORE,
731 MOV,
732 CMOV, /* Used for cmpxchg and cmov */
733 WIDEN,
734 JMP,
735
736 /* Read/write the %EFLAGS register into a TempReg. */
737 GETF, PUTF,
738
739 ADD, ADC, AND, OR, XOR, SUB, SBB,
740 SHL, SHR, SAR, ROL, ROR, RCL, RCR,
741 NOT, NEG, INC, DEC, BSWAP,
742 CC2VAL,
743
744 /* Not strictly needed, but useful for making better
745 translations of address calculations. */
746 LEA1, /* reg2 := const + reg1 */
747 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
748
749 /* not for translating x86 calls -- only to call helpers */
750 CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences
751 for CALLM. */
752 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */
753 CALLM, /* call to a machine-code helper */
754
755 /* Hack for translating string (REP-) insns. Jump to literal if
756 TempReg/RealReg is zero. */
757 JIFZ,
758
759 /* FPU ops which read/write mem or don't touch mem at all. */
760 FPU_R,
761 FPU_W,
762 FPU,
763
764 /* Advance the simulated %eip by some small (< 128) number. */
765 INCEIP,
766
767 /* uinstrs which are not needed for mere translation of x86 code,
768 only for instrumentation of it. */
769 LOADV,
770 STOREV,
771 GETV,
772 PUTV,
773 TESTV,
774 SETV,
775 /* Get/set the v-bit (and it is only one bit) for the simulated
776 %eflags register. */
777 GETVF,
778 PUTVF,
779
780 /* Do a unary or binary tag op. Only for post-instrumented
781 code. For TAG1, first and only arg is a TempReg, and is both
782 arg and result reg. For TAG2, first arg is src, second is
783 dst, in the normal way; both are TempRegs. In both cases,
784 3rd arg is a RiCHelper with a Lit16 tag. This indicates
785 which tag op to do. */
786 TAG1,
787 TAG2
788 }
789 Opcode;
790
791
792/* Condition codes, observing the Intel encoding. CondAlways is an
793 extra. */
794typedef
795 enum {
796 CondO = 0, /* overflow */
797 CondNO = 1, /* no overflow */
798 CondB = 2, /* below */
799 CondNB = 3, /* not below */
800 CondZ = 4, /* zero */
801 CondNZ = 5, /* not zero */
802 CondBE = 6, /* below or equal */
803 CondNBE = 7, /* not below or equal */
804 CondS = 8, /* negative */
805 ConsNS = 9, /* not negative */
806 CondP = 10, /* parity even */
807 CondNP = 11, /* not parity even */
808 CondL = 12, /* jump less */
809 CondNL = 13, /* not less */
810 CondLE = 14, /* less or equal */
811 CondNLE = 15, /* not less or equal */
812 CondAlways = 16 /* Jump always */
813 }
814 Condcode;
815
816
sewardj2e93c502002-04-12 11:12:52 +0000817/* Descriptions of additional properties of *unconditional* jumps. */
818typedef
819 enum {
820 JmpBoring=0, /* boring unconditional jump */
821 JmpCall=1, /* jump due to an x86 call insn */
822 JmpRet=2, /* jump due to an x86 ret insn */
823 JmpSyscall=3, /* do a system call, then jump */
824 JmpClientReq=4 /* do a client request, then jump */
825 }
826 JmpKind;
827
828
sewardjde4a1d02002-03-22 01:27:54 +0000829/* Flags. User-level code can only read/write O(verflow), S(ign),
830 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
831 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
832 thusly:
833 76543210
834 DOSZACP
835 and bit 7 must always be zero since it is unused.
836*/
837typedef UChar FlagSet;
838
839#define FlagD (1<<6)
840#define FlagO (1<<5)
841#define FlagS (1<<4)
842#define FlagZ (1<<3)
843#define FlagA (1<<2)
844#define FlagC (1<<1)
845#define FlagP (1<<0)
846
847#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
848#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
849#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
850#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
851#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
852#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
sewardj4a7456e2002-03-24 13:52:19 +0000853#define FlagsZCP ( FlagZ | FlagC | FlagP)
sewardjde4a1d02002-03-22 01:27:54 +0000854#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000855#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000856
857#define FlagsALL (FlagsOSZACP | FlagD)
858#define FlagsEmpty (FlagSet)0
859
860#define VG_IS_FLAG_SUBSET(set1,set2) \
861 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
862
863#define VG_UNION_FLAG_SETS(set1,set2) \
864 ( ((FlagSet)set1) | ((FlagSet)set2) )
865
866
867
868/* A Micro (u)-instruction. */
869typedef
870 struct {
871 /* word 1 */
872 UInt lit32; /* 32-bit literal */
873
874 /* word 2 */
875 UShort val1; /* first operand */
876 UShort val2; /* second operand */
877
878 /* word 3 */
879 UShort val3; /* third operand */
880 UChar opcode; /* opcode */
881 UChar size; /* data transfer size */
882
883 /* word 4 */
884 FlagSet flags_r; /* :: FlagSet */
885 FlagSet flags_w; /* :: FlagSet */
886 UChar tag1:4; /* first operand tag */
887 UChar tag2:4; /* second operand tag */
888 UChar tag3:4; /* third operand tag */
889 UChar extra4b:4; /* Spare field, used by WIDEN for src
890 -size, and by LEA2 for scale
891 (1,2,4 or 8) */
892
893 /* word 5 */
894 UChar cond; /* condition, for jumps */
895 Bool smc_check:1; /* do a smc test, if writes memory. */
896 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
sewardj2e93c502002-04-12 11:12:52 +0000897 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
sewardjde4a1d02002-03-22 01:27:54 +0000898 }
899 UInstr;
900
901
902/* Expandable arrays of uinstrs. */
903typedef
904 struct {
905 Int used;
906 Int size;
907 UInstr* instrs;
908 Int nextTemp;
909 }
910 UCodeBlock;
911
912/* Refer to `the last instruction stuffed in', including as an
913 lvalue. */
914#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
915
916/* An invalid temporary number :-) */
917#define INVALID_TEMPREG 999999999
918
919
920/* ---------------------------------------------------------------------
921 Exports of vg_demangle.c
922 ------------------------------------------------------------------ */
923
924extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
925
926
927/* ---------------------------------------------------------------------
928 Exports of vg_from_ucode.c
929 ------------------------------------------------------------------ */
930
931extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
932
933
934/* ---------------------------------------------------------------------
935 Exports of vg_to_ucode.c
936 ------------------------------------------------------------------ */
937
938extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
939extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
940extern Char VG_(nameOfIntSize) ( Int size );
941extern UInt VG_(extend_s_8to32) ( UInt x );
942extern Int VG_(getNewTemp) ( UCodeBlock* cb );
943extern Int VG_(getNewShadow) ( UCodeBlock* cb );
944
945#define SHADOW(tempreg) ((tempreg)+1)
946
947
948/* ---------------------------------------------------------------------
949 Exports of vg_translate.c
950 ------------------------------------------------------------------ */
951
952extern void VG_(translate) ( Addr orig_addr,
953 UInt* orig_size,
954 Addr* trans_addr,
955 UInt* trans_size );
956
957extern void VG_(emptyUInstr) ( UInstr* u );
958extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
959extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
960 Tag tag1, UInt val1 );
961extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
962 Tag tag1, UInt val1,
963 Tag tag2, UInt val2 );
964extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
965 Tag tag1, UInt val1,
966 Tag tag2, UInt val2,
967 Tag tag3, UInt val3 );
968extern void VG_(setFlagRW) ( UInstr* u,
969 FlagSet fr, FlagSet fw );
970
971extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
972extern Bool VG_(anyFlagUse) ( UInstr* u );
973
974
975
976extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
977extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
978
979extern Char* VG_(nameCondcode) ( Condcode cond );
980extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
981extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
982extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
983extern Int VG_(rankToRealRegNo) ( Int rank );
984
985extern void* VG_(jitmalloc) ( Int nbytes );
986extern void VG_(jitfree) ( void* ptr );
987
988
989/* ---------------------------------------------------------------------
990 Exports of vg_execontext.c.
991 ------------------------------------------------------------------ */
992
993/* Records the PC and a bit of the call chain. The first 4 %eip
994 values are used in comparisons do remove duplicate errors, and for
995 comparing against suppression specifications. The rest are purely
996 informational (but often important). */
997
998typedef
999 struct _ExeContextRec {
1000 struct _ExeContextRec * next;
1001 /* The size of this array is VG_(clo_backtrace_size); at least
1002 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1003 [1] is its caller, [2] is the caller of [1], etc. */
1004 Addr eips[0];
1005 }
1006 ExeContext;
1007
1008
1009/* Initialise the ExeContext storage mechanism. */
1010extern void VG_(init_ExeContext_storage) ( void );
1011
1012/* Print stats (informational only). */
1013extern void VG_(show_ExeContext_stats) ( void );
1014
1015
1016/* Take a snapshot of the client's stack. Search our collection of
1017 ExeContexts to see if we already have it, and if not, allocate a
1018 new one. Either way, return a pointer to the context. */
1019extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame );
1020
1021/* Print an ExeContext. */
1022extern void VG_(pp_ExeContext) ( ExeContext* );
1023
1024/* Compare two ExeContexts, just comparing the top two callers. */
1025extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
1026
1027/* Compare two ExeContexts, just comparing the top four callers. */
1028extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
1029
1030/* Compare two ExeContexts, comparing all callers. */
1031extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
1032
1033
1034
1035/* ---------------------------------------------------------------------
1036 Exports of vg_errcontext.c.
1037 ------------------------------------------------------------------ */
1038
1039extern void VG_(load_suppressions) ( void );
1040extern void VG_(show_all_errors) ( void );
1041extern void VG_(record_value_error) ( Int size );
1042extern void VG_(record_free_error) ( Addr a );
1043extern void VG_(record_freemismatch_error) ( Addr a );
1044extern void VG_(record_address_error) ( Addr a, Int size,
1045 Bool isWrite );
1046extern void VG_(record_jump_error) ( Addr a );
1047extern void VG_(record_param_err) ( Addr a,
1048 Bool isWriteLack,
1049 Char* msg );
1050extern void VG_(record_user_err) ( Addr a, Bool isWriteLack );
1051
1052
1053/* The classification of a faulting address. */
1054typedef
1055 enum { Stack, Unknown, Freed, Mallocd, UserG, UserS }
1056 AddrKind;
1057
1058/* Records info about a faulting address. */
1059typedef
1060 struct {
1061 /* ALL */
1062 AddrKind akind;
1063 /* Freed, Mallocd */
1064 Int blksize;
1065 /* Freed, Mallocd */
1066 Int rwoffset;
1067 /* Freed, Mallocd */
1068 ExeContext* lastchange;
1069 }
1070 AddrInfo;
1071
1072
1073/* ---------------------------------------------------------------------
1074 Exports of vg_clientperms.c
1075 ------------------------------------------------------------------ */
1076
1077extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
1078
sewardj2e93c502002-04-12 11:12:52 +00001079extern UInt VG_(handle_client_request) ( UInt* arg_block );
sewardjde4a1d02002-03-22 01:27:54 +00001080
1081extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
1082
1083extern void VG_(show_client_block_stats) ( void );
1084
1085
1086/* ---------------------------------------------------------------------
1087 Exports of vg_procselfmaps.c
1088 ------------------------------------------------------------------ */
1089
1090extern
1091void VG_(read_procselfmaps) (
1092 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
1093);
1094
1095
1096/* ---------------------------------------------------------------------
1097 Exports of vg_symtab2.c
1098 ------------------------------------------------------------------ */
1099
1100/* We assume the executable is loaded here ... can't really find
1101 out. There is a hacky sanity check in vg_init_memory_audit()
1102 which should trip up most stupidities.
1103*/
1104#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
1105
1106extern void VG_(read_symbols) ( void );
1107extern void VG_(mini_stack_dump) ( ExeContext* ec );
1108extern void VG_(what_obj_and_fun_is_this)
1109 ( Addr a,
1110 Char* obj_buf, Int n_obj_buf,
1111 Char* fun_buf, Int n_fun_buf );
1112
1113extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
1114
1115
1116/* ---------------------------------------------------------------------
1117 Exports of vg_clientmalloc.c
1118 ------------------------------------------------------------------ */
1119
sewardjde4a1d02002-03-22 01:27:54 +00001120typedef
1121 enum {
1122 Vg_AllocMalloc = 0,
sewardj2e93c502002-04-12 11:12:52 +00001123 Vg_AllocNew = 1,
sewardjde4a1d02002-03-22 01:27:54 +00001124 Vg_AllocNewVec = 2
1125 }
1126 VgAllocKind;
1127
1128/* Description of a malloc'd chunk. */
1129typedef
1130 struct _ShadowChunk {
1131 struct _ShadowChunk* next;
1132 ExeContext* where; /* where malloc'd/free'd */
1133 UInt size : 30; /* size requested. */
1134 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1135 Addr data; /* ptr to actual block. */
1136 }
1137 ShadowChunk;
1138
1139extern void VG_(clientmalloc_done) ( void );
1140extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
1141extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1142
sewardj2e93c502002-04-12 11:12:52 +00001143/* These are called from the scheduler, when it intercepts a user
1144 request. */
1145extern void* VG_(client_malloc) ( UInt size, VgAllocKind kind );
1146extern void* VG_(client_memalign) ( UInt align, UInt size );
1147extern void VG_(client_free) ( void* ptrV, VgAllocKind kind );
1148extern void* VG_(client_calloc) ( UInt nmemb, UInt size1 );
1149extern void* VG_(client_realloc) ( void* ptrV, UInt size_new );
sewardjde4a1d02002-03-22 01:27:54 +00001150
1151
1152/* ---------------------------------------------------------------------
1153 Exports of vg_main.c
1154 ------------------------------------------------------------------ */
1155
sewardjde4a1d02002-03-22 01:27:54 +00001156/* A structure used as an intermediary when passing the simulated
1157 CPU's state to some assembly fragments, particularly system calls.
1158 Stuff is copied from baseBlock to here, the assembly magic runs,
1159 and then the inverse copy is done. */
1160
1161extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
1162 + 1 /* %eflags */
1163 + 1 /* %eip */
1164 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1165 ];
1166
1167/* Handy fns for doing the copy back and forth. */
1168extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1169extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1170
sewardjde4a1d02002-03-22 01:27:54 +00001171/* Called when some unhandleable client behaviour is detected.
1172 Prints a msg and aborts. */
1173extern void VG_(unimplemented) ( Char* msg );
1174
1175/* The stack on which Valgrind runs. We can't use the same stack as the
1176 simulatee -- that's an important design decision. */
1177extern UInt VG_(stack)[10000];
1178
1179/* Similarly, we have to ask for signals to be delivered on an
1180 alternative stack, since it is possible, although unlikely, that
1181 we'll have to run client code from inside the Valgrind-installed
1182 signal handler. If this happens it will be done by
1183 vg_deliver_signal_immediately(). */
1184extern UInt VG_(sigstack)[10000];
1185
sewardjde4a1d02002-03-22 01:27:54 +00001186/* Holds client's %esp at the point we gained control. From this the
1187 client's argc, argv and envp are deduced. */
1188extern Addr VG_(esp_at_startup);
1189extern Int VG_(client_argc);
1190extern Char** VG_(client_argv);
1191extern Char** VG_(client_envp);
1192
1193/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
1194 don't get traced into. */
1195extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
1196
1197/* Something of a function looking for a home ... start up GDB. This
1198 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1199 *client's* stack. This is necessary to give GDB the illusion that
1200 the client program really was running on the real cpu. */
1201extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1202
1203/* Spew out vast amounts of junk during JITting? */
1204extern Bool VG_(disassemble);
1205
1206/* 64-bit counter for the number of basic blocks done. */
1207extern ULong VG_(bbs_done);
1208/* 64-bit counter for the number of bbs to go before a debug exit. */
1209extern ULong VG_(bbs_to_go);
1210
1211/* Counts downwards in vg_run_innerloop. */
1212extern UInt VG_(dispatch_ctr);
1213
sewardjde4a1d02002-03-22 01:27:54 +00001214/* Is the client running on the simulated CPU or the real one? */
1215extern Bool VG_(running_on_simd_CPU); /* Initially False */
1216
1217/* The current LRU epoch. */
1218extern UInt VG_(current_epoch);
1219
1220
1221/* --- Counters, for informational purposes only. --- */
1222
1223/* Number of lookups which miss the fast tt helper. */
1224extern UInt VG_(tt_fast_misses);
1225
1226/* Counts for LRU informational messages. */
1227
1228/* Number and total o/t size of new translations this epoch. */
1229extern UInt VG_(this_epoch_in_count);
1230extern UInt VG_(this_epoch_in_osize);
1231extern UInt VG_(this_epoch_in_tsize);
1232/* Number and total o/t size of discarded translations this epoch. */
1233extern UInt VG_(this_epoch_out_count);
1234extern UInt VG_(this_epoch_out_osize);
1235extern UInt VG_(this_epoch_out_tsize);
1236/* Number and total o/t size of translations overall. */
1237extern UInt VG_(overall_in_count);
1238extern UInt VG_(overall_in_osize);
1239extern UInt VG_(overall_in_tsize);
1240/* Number and total o/t size of discards overall. */
1241extern UInt VG_(overall_out_count);
1242extern UInt VG_(overall_out_osize);
1243extern UInt VG_(overall_out_tsize);
1244
1245/* The number of LRU-clearings of TT/TC. */
1246extern UInt VG_(number_of_lrus);
1247
1248/* Counts pertaining to the register allocator. */
1249
1250/* total number of uinstrs input to reg-alloc */
1251extern UInt VG_(uinstrs_prealloc);
1252
1253/* total number of uinstrs added due to spill code */
1254extern UInt VG_(uinstrs_spill);
1255
1256/* number of bbs requiring spill code */
1257extern UInt VG_(translations_needing_spill);
1258
1259/* total of register ranks over all translations */
1260extern UInt VG_(total_reg_rank);
1261
1262/* Counts pertaining to the self-modifying-code detection machinery. */
1263
1264/* Total number of writes checked. */
1265//extern UInt VG_(smc_total_check4s);
1266
1267/* Number of writes which the fast smc check couldn't show were
1268 harmless. */
1269extern UInt VG_(smc_cache_passed);
1270
1271/* Numnber of writes which really did write on original code. */
1272extern UInt VG_(smc_fancy_passed);
1273
1274/* Number of translations discarded as a result. */
1275//extern UInt VG_(smc_discard_count);
1276
1277/* Counts pertaining to internal sanity checking. */
1278extern UInt VG_(sanity_fast_count);
1279extern UInt VG_(sanity_slow_count);
1280
sewardj2e93c502002-04-12 11:12:52 +00001281/* Counts pertaining to the scheduler. */
1282extern UInt VG_(num_scheduling_events_MINOR);
1283extern UInt VG_(num_scheduling_events_MAJOR);
1284
sewardjde4a1d02002-03-22 01:27:54 +00001285
1286/* ---------------------------------------------------------------------
1287 Exports of vg_memory.c
1288 ------------------------------------------------------------------ */
1289
1290extern void VGM_(init_memory_audit) ( void );
1291extern Addr VGM_(curr_dataseg_end);
1292extern void VG_(show_reg_tags) ( void );
1293extern void VG_(detect_memory_leaks) ( void );
1294extern void VG_(done_prof_mem) ( void );
1295
1296/* Set permissions for an address range. Not speed-critical. */
1297extern void VGM_(make_noaccess) ( Addr a, UInt len );
1298extern void VGM_(make_writable) ( Addr a, UInt len );
1299extern void VGM_(make_readable) ( Addr a, UInt len );
1300/* Use with care! (read: use for shmat only) */
1301extern void VGM_(make_readwritable) ( Addr a, UInt len );
1302extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1303 UInt len );
1304
1305/* Check permissions for an address range. Not speed-critical. */
1306extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1307extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1308extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1309
1310/* Sanity checks which may be done at any time. Doing them at
1311 signal-delivery time turns out to be convenient. */
sewardj2e93c502002-04-12 11:12:52 +00001312extern void VG_(do_sanity_checks) ( ThreadId tid, Bool force_expensive );
sewardjde4a1d02002-03-22 01:27:54 +00001313/* Very cheap ... */
1314extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1315
1316/* These functions are called from generated code. */
1317extern void VG_(helperc_STOREV4) ( UInt, Addr );
1318extern void VG_(helperc_STOREV2) ( UInt, Addr );
1319extern void VG_(helperc_STOREV1) ( UInt, Addr );
1320
1321extern UInt VG_(helperc_LOADV1) ( Addr );
1322extern UInt VG_(helperc_LOADV2) ( Addr );
1323extern UInt VG_(helperc_LOADV4) ( Addr );
1324
1325extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1326extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1327extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1328
1329/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1330 space and pass the addresses and values of all addressible,
1331 defined, aligned words to notify_word. This is the basis for the
1332 leak detector. Returns the number of calls made to notify_word. */
1333UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1334
1335/* Is this address within some small distance below %ESP? Used only
1336 for the --workaround-gcc296-bugs kludge. */
1337extern Bool VG_(is_just_below_ESP)( Addr aa );
1338
1339/* Nasty kludgery to deal with applications which switch stacks,
1340 like netscape. */
1341#define VG_STACK_STARTS_AT 0xC0000000
1342#define VG_PLAUSIBLE_STACK_SIZE 8000000
1343
1344extern Bool VG_(is_plausible_stack_addr) ( Addr );
1345
1346
1347/* ---------------------------------------------------------------------
1348 Exports of vg_syscall_mem.c
1349 ------------------------------------------------------------------ */
1350
sewardj2e93c502002-04-12 11:12:52 +00001351extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001352
sewardj2e93c502002-04-12 11:12:52 +00001353extern void VG_(check_known_blocking_syscall) ( ThreadId tid,
1354 Int syscallno,
1355 Int* /*IN*/ res );
sewardjde4a1d02002-03-22 01:27:54 +00001356
1357extern Bool VG_(is_kerror) ( Int res );
1358
sewardj2e93c502002-04-12 11:12:52 +00001359#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1360 VG_(load_thread_state)(thread_id); \
sewardjde4a1d02002-03-22 01:27:54 +00001361 VG_(copy_baseBlock_to_m_state_static)(); \
1362 VG_(do_syscall)(); \
1363 VG_(copy_m_state_static_to_baseBlock)(); \
sewardj2e93c502002-04-12 11:12:52 +00001364 VG_(save_thread_state)(thread_id); \
1365 result_lvalue = VG_(get_thread_state)(thread_id)->m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001366
1367
1368/* ---------------------------------------------------------------------
1369 Exports of vg_transtab.c
1370 ------------------------------------------------------------------ */
1371
1372/* An entry in the translation table (TT). */
1373typedef
1374 struct {
1375 /* +0 */ Addr orig_addr;
1376 /* +4 */ Addr trans_addr;
1377 /* +8 */ UInt mru_epoch;
1378 /* +12 */ UShort orig_size;
1379 /* +14 */ UShort trans_size;
1380 }
1381 TTEntry;
1382
1383/* The number of basic blocks in an epoch (one age-step). */
1384#define VG_BBS_PER_EPOCH 20000
1385
1386extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1387extern void VG_(maybe_do_lru_pass) ( void );
1388extern void VG_(flush_transtab) ( void );
1389extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1390extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1391
1392extern void VG_(smc_mark_original) ( Addr original_addr,
1393 Int original_len );
1394
1395extern void VG_(init_transtab_and_SMC) ( void );
1396
1397extern void VG_(sanity_check_tc_tt) ( void );
1398extern Addr VG_(search_transtab) ( Addr original_addr );
1399
1400extern void VG_(invalidate_tt_fast)( void );
1401
1402
1403/* ---------------------------------------------------------------------
1404 Exports of vg_vtagops.c
1405 ------------------------------------------------------------------ */
1406
1407/* Lists the names of value-tag operations used in instrumented
1408 code. These are the third argument to TAG1 and TAG2 uinsns. */
1409
1410typedef
1411 enum {
1412 /* Unary. */
1413 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1414 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1415
1416 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1417
1418 VgT_Left4, VgT_Left2, VgT_Left1,
1419
1420 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1421 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1422
1423 /* Binary; 1st is rd; 2nd is rd+wr */
1424 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1425 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1426
1427 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1428 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1429 VgT_DebugFn
1430 }
1431 VgTagOp;
1432
1433extern Char* VG_(nameOfTagOp) ( VgTagOp );
1434extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1435
1436
1437/* ---------------------------------------------------------------------
1438 Exports of vg_syscall.S
1439 ------------------------------------------------------------------ */
1440
1441extern void VG_(do_syscall) ( void );
1442
1443
1444/* ---------------------------------------------------------------------
1445 Exports of vg_startup.S
1446 ------------------------------------------------------------------ */
1447
1448extern void VG_(shutdown);
1449extern void VG_(switch_to_real_CPU) ( void );
1450
1451extern void VG_(swizzle_esp_then_start_GDB) ( void );
1452
1453
1454/* ---------------------------------------------------------------------
1455 Exports of vg_dispatch.S
1456 ------------------------------------------------------------------ */
1457
sewardj2e93c502002-04-12 11:12:52 +00001458/* Run a thread for a (very short) while, until some event happens
1459 which means we need to defer to the scheduler. */
1460extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001461
1462
1463/* ---------------------------------------------------------------------
1464 Exports of vg_helpers.S
1465 ------------------------------------------------------------------ */
1466
sewardjde4a1d02002-03-22 01:27:54 +00001467/* SMC fast checks. */
1468extern void VG_(helper_smc_check4);
1469
1470/* Mul, div, etc, -- we don't codegen these directly. */
1471extern void VG_(helper_idiv_64_32);
1472extern void VG_(helper_div_64_32);
1473extern void VG_(helper_idiv_32_16);
1474extern void VG_(helper_div_32_16);
1475extern void VG_(helper_idiv_16_8);
1476extern void VG_(helper_div_16_8);
1477
1478extern void VG_(helper_imul_32_64);
1479extern void VG_(helper_mul_32_64);
1480extern void VG_(helper_imul_16_32);
1481extern void VG_(helper_mul_16_32);
1482extern void VG_(helper_imul_8_16);
1483extern void VG_(helper_mul_8_16);
1484
1485extern void VG_(helper_CLD);
1486extern void VG_(helper_STD);
1487extern void VG_(helper_get_dirflag);
1488
1489extern void VG_(helper_shldl);
1490extern void VG_(helper_shldw);
1491extern void VG_(helper_shrdl);
1492extern void VG_(helper_shrdw);
1493
1494extern void VG_(helper_RDTSC);
1495extern void VG_(helper_CPUID);
1496
1497extern void VG_(helper_bt);
1498extern void VG_(helper_bts);
1499extern void VG_(helper_btr);
1500extern void VG_(helper_btc);
1501
1502extern void VG_(helper_bsf);
1503extern void VG_(helper_bsr);
1504
1505extern void VG_(helper_fstsw_AX);
1506extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001507extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001508extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001509
1510extern void VG_(helper_value_check4_fail);
1511extern void VG_(helper_value_check2_fail);
1512extern void VG_(helper_value_check1_fail);
1513extern void VG_(helper_value_check0_fail);
1514
sewardjde4a1d02002-03-22 01:27:54 +00001515
1516/* ---------------------------------------------------------------------
1517 The state of the simulated CPU.
1518 ------------------------------------------------------------------ */
1519
1520/* This is the Intel register encoding. */
1521#define R_EAX 0
1522#define R_ECX 1
1523#define R_EDX 2
1524#define R_EBX 3
1525#define R_ESP 4
1526#define R_EBP 5
1527#define R_ESI 6
1528#define R_EDI 7
1529
1530#define R_AL (0+R_EAX)
1531#define R_CL (0+R_ECX)
1532#define R_DL (0+R_EDX)
1533#define R_BL (0+R_EBX)
1534#define R_AH (4+R_EAX)
1535#define R_CH (4+R_ECX)
1536#define R_DH (4+R_EDX)
1537#define R_BH (4+R_EBX)
1538
1539
1540/* ---------------------------------------------------------------------
1541 Offsets into baseBlock for everything which needs to referred to
1542 from generated code. The order of these decls does not imply
1543 what the order of the actual offsets is. The latter is important
1544 and is set up in vg_main.c.
1545 ------------------------------------------------------------------ */
1546
1547/* An array of words. In generated code, %ebp always points to the
1548 start of this array. Useful stuff, like the simulated CPU state,
1549 and the addresses of helper functions, can then be found by
1550 indexing off %ebp. The following declares variables which, at
1551 startup time, are given values denoting offsets into baseBlock.
1552 These offsets are in *words* from the start of baseBlock. */
1553
1554#define VG_BASEBLOCK_WORDS 200
1555
1556extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1557
1558
1559/* -----------------------------------------------------
1560 Read-write parts of baseBlock.
1561 -------------------------------------------------- */
1562
1563/* State of the simulated CPU. */
1564extern Int VGOFF_(m_eax);
1565extern Int VGOFF_(m_ecx);
1566extern Int VGOFF_(m_edx);
1567extern Int VGOFF_(m_ebx);
1568extern Int VGOFF_(m_esp);
1569extern Int VGOFF_(m_ebp);
1570extern Int VGOFF_(m_esi);
1571extern Int VGOFF_(m_edi);
1572extern Int VGOFF_(m_eflags);
1573extern Int VGOFF_(m_fpustate);
1574extern Int VGOFF_(m_eip);
1575
1576/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1577extern Int VGOFF_(spillslots);
1578
1579/* Records the valid bits for the 8 integer regs & flags reg. */
1580extern Int VGOFF_(sh_eax);
1581extern Int VGOFF_(sh_ecx);
1582extern Int VGOFF_(sh_edx);
1583extern Int VGOFF_(sh_ebx);
1584extern Int VGOFF_(sh_esp);
1585extern Int VGOFF_(sh_ebp);
1586extern Int VGOFF_(sh_esi);
1587extern Int VGOFF_(sh_edi);
1588extern Int VGOFF_(sh_eflags);
1589
1590
1591/* -----------------------------------------------------
1592 Read-only parts of baseBlock.
1593 -------------------------------------------------- */
1594
1595/* Offsets of addresses of helper functions. A "helper" function is
1596 one which is called from generated code. */
1597
1598extern Int VGOFF_(helper_idiv_64_32);
1599extern Int VGOFF_(helper_div_64_32);
1600extern Int VGOFF_(helper_idiv_32_16);
1601extern Int VGOFF_(helper_div_32_16);
1602extern Int VGOFF_(helper_idiv_16_8);
1603extern Int VGOFF_(helper_div_16_8);
1604
1605extern Int VGOFF_(helper_imul_32_64);
1606extern Int VGOFF_(helper_mul_32_64);
1607extern Int VGOFF_(helper_imul_16_32);
1608extern Int VGOFF_(helper_mul_16_32);
1609extern Int VGOFF_(helper_imul_8_16);
1610extern Int VGOFF_(helper_mul_8_16);
1611
1612extern Int VGOFF_(helper_CLD);
1613extern Int VGOFF_(helper_STD);
1614extern Int VGOFF_(helper_get_dirflag);
1615
1616extern Int VGOFF_(helper_shldl);
1617extern Int VGOFF_(helper_shldw);
1618extern Int VGOFF_(helper_shrdl);
1619extern Int VGOFF_(helper_shrdw);
1620
1621extern Int VGOFF_(helper_RDTSC);
1622extern Int VGOFF_(helper_CPUID);
1623
1624extern Int VGOFF_(helper_bt);
1625extern Int VGOFF_(helper_bts);
1626extern Int VGOFF_(helper_btr);
1627extern Int VGOFF_(helper_btc);
1628
1629extern Int VGOFF_(helper_bsf);
1630extern Int VGOFF_(helper_bsr);
1631
1632extern Int VGOFF_(helper_fstsw_AX);
1633extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001634extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001635extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001636
1637extern Int VGOFF_(helper_value_check4_fail);
1638extern Int VGOFF_(helper_value_check2_fail);
1639extern Int VGOFF_(helper_value_check1_fail);
1640extern Int VGOFF_(helper_value_check0_fail);
1641
sewardjde4a1d02002-03-22 01:27:54 +00001642extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1643extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1644extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1645
1646extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1647extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1648extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1649
1650extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1651extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1652extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1653
sewardjde4a1d02002-03-22 01:27:54 +00001654
1655
1656#endif /* ndef __VG_INCLUDE_H */
1657
sewardj3b2736a2002-03-24 12:18:35 +00001658
1659/* ---------------------------------------------------------------------
1660 Finally - autoconf-generated settings
1661 ------------------------------------------------------------------ */
1662
1663#include "config.h"
1664
sewardjde4a1d02002-03-22 01:27:54 +00001665/*--------------------------------------------------------------------*/
1666/*--- end vg_include.h ---*/
1667/*--------------------------------------------------------------------*/