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