mc_include.h revision e49d8e7dfd3a9c96feb9935b5920973dfc0b170a
1/*--------------------------------------------------------------------*/
2/*--- A header file for all parts of the MemCheck skin.            ---*/
3/*---                                        vg_memcheck_include.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7   This file is part of Valgrind, an x86 protected-mode emulator
8   designed for debugging and profiling binaries on x86-Unixes.
9
10   Copyright (C) 2000-2002 Julian Seward
11      jseward@acm.org
12
13   This program is free software; you can redistribute it and/or
14   modify it under the terms of the GNU General Public License as
15   published by the Free Software Foundation; either version 2 of the
16   License, or (at your option) any later version.
17
18   This program is distributed in the hope that it will be useful, but
19   WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21   General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program; if not, write to the Free Software
25   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26   02111-1307, USA.
27
28   The GNU General Public License is contained in the file COPYING.
29*/
30
31#ifndef __VG_MEMCHECK_INCLUDE_H
32#define __VG_MEMCHECK_INCLUDE_H
33
34#include "vg_skin.h"
35
36/* UCode extension for efficient memory checking operations */
37typedef
38   enum {
39      /* uinstrs which are not needed for mere translation of x86 code,
40         only for instrumentation of it. */
41      LOADV = DUMMY_FINAL_UOPCODE + 1,
42      STOREV,
43      GETV,
44      PUTV,
45      TESTV,
46      SETV,
47      /* Get/set the v-bit (and it is only one bit) for the simulated
48         %eflags register. */
49      GETVF,
50      PUTVF,
51
52      /* Do a unary or binary tag op.  Only for post-instrumented
53         code.  For TAG1, first and only arg is a TempReg, and is both
54         arg and result reg.  For TAG2, first arg is src, second is
55         dst, in the normal way; both are TempRegs.  In both cases,
56         3rd arg is a RiCHelper with a Lit16 tag.  This indicates
57         which tag op to do. */
58      TAG1,
59      TAG2
60   }
61   MemCheckOpcode;
62
63
64/* Lists the names of value-tag operations used in instrumented
65   code.  These are the third argument to TAG1 and TAG2 uinsns. */
66typedef
67   enum {
68     /* Unary. */
69     Tag_PCast40, Tag_PCast20, Tag_PCast10,
70     Tag_PCast01, Tag_PCast02, Tag_PCast04,
71
72     Tag_PCast14, Tag_PCast12, Tag_PCast11,
73
74     Tag_Left4, Tag_Left2, Tag_Left1,
75
76     Tag_SWiden14, Tag_SWiden24, Tag_SWiden12,
77     Tag_ZWiden14, Tag_ZWiden24, Tag_ZWiden12,
78
79     /* Binary; 1st is rd; 2nd is rd+wr */
80     Tag_UifU4, Tag_UifU2, Tag_UifU1, Tag_UifU0,
81     Tag_DifD4, Tag_DifD2, Tag_DifD1,
82
83     Tag_ImproveAND4_TQ, Tag_ImproveAND2_TQ, Tag_ImproveAND1_TQ,
84     Tag_ImproveOR4_TQ, Tag_ImproveOR2_TQ, Tag_ImproveOR1_TQ,
85     Tag_DebugFn
86   }
87   TagOp;
88
89/* The classification of a faulting address. */
90typedef
91   enum { Undescribed, /* as-yet unclassified */
92          Stack,
93          Unknown, /* classification yielded nothing useful */
94          Freed, Mallocd,
95          UserG, UserS
96   }
97   AddrKind;
98
99/* Records info about a faulting address. */
100typedef
101   struct {
102      /* ALL */
103      AddrKind akind;
104      /* Freed, Mallocd */
105      Int blksize;
106      /* Freed, Mallocd */
107      Int rwoffset;
108      /* Freed, Mallocd */
109      ExeContext* lastchange;
110      /* Stack */
111      ThreadId stack_tid;
112      /* True if is just-below %esp -- could be a gcc bug. */
113      Bool maybe_gcc;
114   }
115   AddrInfo;
116
117
118/*------------------------------------------------------------*/
119/*--- Skin-specific command line options + defaults        ---*/
120/*------------------------------------------------------------*/
121
122/* Allow loads from partially-valid addresses?  default: YES */
123extern Bool SK_(clo_partial_loads_ok);
124
125/* Max volume of the freed blocks queue. */
126extern Int SK_(clo_freelist_vol);
127
128/* Do leak check at exit?  default: NO */
129extern Bool SK_(clo_leak_check);
130
131/* How closely should we compare ExeContexts in leak records? default: 2 */
132extern VgRes SK_(clo_leak_resolution);
133
134/* In leak check, show reachable-but-not-freed blocks?  default: NO */
135extern Bool SK_(clo_show_reachable);
136
137/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
138 * default: NO*/
139extern Bool SK_(clo_workaround_gcc296_bugs);
140
141/* Shall we V-check addrs? (they are always A checked too)   default: YES */
142extern Bool SK_(clo_check_addrVs);
143
144/* DEBUG: clean up instrumented code?  default: YES */
145extern Bool SK_(clo_cleanup);
146
147
148/*------------------------------------------------------------*/
149/*--- Functions                                            ---*/
150/*------------------------------------------------------------*/
151
152// SSS: work out a consistent prefix convention here
153
154/* Functions defined in vg_memcheck_helpers.S */
155extern void SK_(helper_value_check4_fail) ( void );
156extern void SK_(helper_value_check2_fail) ( void );
157extern void SK_(helper_value_check1_fail) ( void );
158extern void SK_(helper_value_check0_fail) ( void );
159
160/* Functions defined in vg_memcheck.c */
161extern void SK_(helperc_STOREV4) ( UInt, Addr );
162extern void SK_(helperc_STOREV2) ( UInt, Addr );
163extern void SK_(helperc_STOREV1) ( UInt, Addr );
164
165extern UInt SK_(helperc_LOADV1) ( Addr );
166extern UInt SK_(helperc_LOADV2) ( Addr );
167extern UInt SK_(helperc_LOADV4) ( Addr );
168
169extern void SK_(fpu_write_check) ( Addr addr, Int size );
170extern void SK_(fpu_read_check)  ( Addr addr, Int size );
171
172extern ShadowChunk* SK_(any_matching_freed_ShadowChunks)
173                        ( Bool (*p) ( ShadowChunk* ) );
174
175/* For client requests */
176extern void SK_(make_noaccess) ( Addr a, UInt len );
177extern void SK_(make_readable) ( Addr a, UInt len );
178extern void SK_(make_writable) ( Addr a, UInt len );
179
180extern Bool SK_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
181extern Bool SK_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
182
183extern void SK_(detect_memory_leaks) ( void );
184
185
186/* Functions defined in vg_memcheck_clientreqs.c */
187extern Bool SK_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
188extern void SK_(delete_client_stack_blocks_following_ESP_change) ( void );
189extern void SK_(show_client_block_stats) ( void );
190
191/* Functions defined in vg_memcheck_errcontext.c */
192extern void SK_(record_value_error)       ( Int size );
193extern void SK_(record_address_error)     ( Addr a, Int size, Bool isWrite );
194extern void SK_(record_core_mem_error)    ( ThreadState* tst, Bool isWrite,
195                                            Char* s );
196extern void SK_(record_param_error)       ( ThreadState* tst, Addr a,
197                                            Bool isWriteLack, Char* msg );
198extern void SK_(record_jump_error)        ( ThreadState* tst, Addr a );
199extern void SK_(record_free_error)        ( ThreadState* tst, Addr a );
200extern void SK_(record_freemismatch_error)( ThreadState* tst, Addr a );
201extern void SK_(record_user_error)        ( ThreadState* tst, Addr a,
202                                            Bool isWrite );
203
204#endif
205
206/*--------------------------------------------------------------------*/
207/*--- end                                    vg_memcheck_include.h ---*/
208/*--------------------------------------------------------------------*/
209
210