sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Ptrcheck: a pointer-use checker. ---*/ |
| 4 | /*--- This file coordinates the h_ and sg_ subtools. ---*/ |
| 5 | /*--- pc_main.c ---*/ |
| 6 | /*--------------------------------------------------------------------*/ |
| 7 | |
| 8 | /* |
| 9 | This file is part of Ptrcheck, a Valgrind tool for checking pointer |
| 10 | use in programs. |
| 11 | |
| 12 | Copyright (C) 2008-2008 OpenWorks Ltd |
| 13 | info@open-works.co.uk |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License as |
| 17 | published by the Free Software Foundation; either version 2 of the |
| 18 | License, or (at your option) any later version. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with this program; if not, write to the Free Software |
| 27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 28 | 02111-1307, USA. |
| 29 | |
| 30 | The GNU General Public License is contained in the file COPYING. |
| 31 | |
| 32 | Neither the names of the U.S. Department of Energy nor the |
| 33 | University of California nor the names of its contributors may be |
| 34 | used to endorse or promote products derived from this software |
| 35 | without prior written permission. |
| 36 | */ |
| 37 | |
| 38 | #include "pub_tool_basics.h" |
| 39 | #include "pub_tool_libcassert.h" |
sewardj | 4815eb5 | 2008-10-20 23:33:49 +0000 | [diff] [blame^] | 40 | #include "pub_tool_libcprint.h" |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 41 | #include "pub_tool_execontext.h" |
| 42 | #include "pub_tool_tooliface.h" |
| 43 | #include "pub_tool_options.h" |
| 44 | |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 45 | #include "sg_main.h" |
| 46 | #include "pc_common.h" |
| 47 | #include "h_main.h" |
| 48 | |
| 49 | |
| 50 | ////////////////////////////////////////////////////////////// |
| 51 | // // |
| 52 | // // |
| 53 | // // |
| 54 | ////////////////////////////////////////////////////////////// |
| 55 | |
| 56 | |
| 57 | ////////////////////////////////////////////////////////////// |
| 58 | // // |
| 59 | // main // |
| 60 | // // |
| 61 | ////////////////////////////////////////////////////////////// |
| 62 | |
| 63 | static void pc_fini ( Int exitcode ) { |
| 64 | h_fini( exitcode ); |
| 65 | sg_fini( exitcode ); |
| 66 | } |
| 67 | |
| 68 | static void pc_die_mem_stack ( Addr old_SP, SizeT len ) { |
| 69 | /* h_die_mem_stack( old_SP, len ); */ |
| 70 | sg_die_mem_stack( old_SP, len ); |
| 71 | } |
| 72 | |
| 73 | static |
| 74 | void pc_pre_thread_ll_create ( ThreadId parent, ThreadId child ) { |
| 75 | /* h_pre_thread_ll_create(); */ |
| 76 | sg_pre_thread_ll_create(parent,child); |
| 77 | } |
| 78 | |
| 79 | static void pc_pre_thread_first_insn ( ThreadId tid ) { |
| 80 | /* h_pre_thread_first_insn(tid); */ |
| 81 | sg_pre_thread_first_insn(tid); |
| 82 | } |
| 83 | |
| 84 | static |
| 85 | void pc_new_mem_mmap ( Addr a, SizeT len, |
| 86 | Bool rr, Bool ww, Bool xx, ULong di_handle ) |
| 87 | { |
| 88 | h_new_mem_mmap(a, len, rr, ww, xx, di_handle); |
| 89 | sg_new_mem_mmap(a, len, rr, ww, xx, di_handle); |
| 90 | } |
| 91 | |
| 92 | static |
| 93 | void pc_new_mem_startup ( Addr a, SizeT len, |
| 94 | Bool rr, Bool ww, Bool xx, ULong di_handle ) |
| 95 | { |
| 96 | h_new_mem_startup(a, len, rr, ww, xx, di_handle); |
| 97 | sg_new_mem_startup(a, len, rr, ww, xx, di_handle); |
| 98 | } |
| 99 | |
| 100 | static void pc_die_mem_munmap ( Addr a, SizeT len ) { |
| 101 | h_die_mem_munmap(a, len); |
| 102 | sg_die_mem_munmap(a, len); |
| 103 | } |
| 104 | |
| 105 | static void pc_pre_mem_read ( CorePart part, ThreadId tid, Char* s, |
| 106 | Addr base, SizeT size ) { |
| 107 | h_pre_mem_access(part, tid, s, base, size ); |
| 108 | /* sg_pre_mem_read(part, tid, s, base, size); */ |
| 109 | } |
| 110 | |
| 111 | static void pc_pre_mem_read_asciiz ( CorePart part, ThreadId tid, |
| 112 | Char* s, Addr lo ) |
| 113 | { |
| 114 | h_pre_mem_read_asciiz(part, tid, s, lo); |
| 115 | /* sg_pre_mem_read_asciiz(part, tid, s, lo); */ |
| 116 | } |
| 117 | |
| 118 | static void pc_pre_mem_write ( CorePart part, ThreadId tid, Char* s, |
| 119 | Addr base, SizeT size ) { |
| 120 | h_pre_mem_access(part, tid, s, base, size); |
| 121 | /* sg_pre_mem_write(part, tid, s, base, size); */ |
| 122 | } |
| 123 | |
| 124 | static void pc_post_clo_init ( void ) |
| 125 | { |
| 126 | h_post_clo_init(); |
| 127 | sg_post_clo_init(); |
sewardj | 4815eb5 | 2008-10-20 23:33:49 +0000 | [diff] [blame^] | 128 | # if defined(VGA_x86) || defined(VGA_amd64) |
| 129 | /* nothing */ |
| 130 | # elif defined(VGA_ppc32) || defined(VGA_ppc64) |
| 131 | if (VG_(clo_verbosity) >= 1 && sg_clo_enable_sg_checks) { |
| 132 | VG_(message)(Vg_UserMsg, |
| 133 | "WARNING: exp-ptrcheck on ppc32/ppc64 platforms: stack and global array"); |
| 134 | VG_(message)(Vg_UserMsg, |
| 135 | "WARNING: checking is not currently supported. Only heap checking is"); |
| 136 | VG_(message)(Vg_UserMsg, |
| 137 | "WARNING: supported. Disabling s/g checks (like --enable-sg-checks=no)."); |
| 138 | } |
| 139 | sg_clo_enable_sg_checks = False; |
| 140 | # else |
| 141 | # error "Unsupported architecture" |
| 142 | # endif |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static void pc_pre_clo_init(void) |
| 146 | { |
| 147 | VG_(details_name) ("exp-ptrcheck"); |
| 148 | VG_(details_version) (NULL); |
| 149 | VG_(details_description) ("a heap, stack & global array " |
| 150 | "overrun detector"); |
| 151 | VG_(details_copyright_author)( |
| 152 | "Copyright (C) 2003-2008, and GNU GPL'd, by OpenWorks Ltd et al."); |
| 153 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | 4b8ce60 | 2008-10-20 10:23:46 +0000 | [diff] [blame] | 154 | VG_(details_avg_translation_sizeB) ( 496 ); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 155 | |
| 156 | VG_(basic_tool_funcs) (pc_post_clo_init, |
| 157 | h_instrument, |
| 158 | pc_fini); |
| 159 | |
| 160 | VG_(needs_malloc_replacement)( h_replace_malloc, |
| 161 | h_replace___builtin_new, |
| 162 | h_replace___builtin_vec_new, |
| 163 | h_replace_memalign, |
| 164 | h_replace_calloc, |
| 165 | h_replace_free, |
| 166 | h_replace___builtin_delete, |
| 167 | h_replace___builtin_vec_delete, |
| 168 | h_replace_realloc, |
| 169 | 0 /* no need for client heap redzones */ ); |
| 170 | |
| 171 | VG_(needs_var_info) (); |
| 172 | |
| 173 | VG_(needs_core_errors) (); |
| 174 | VG_(needs_tool_errors) (pc_eq_Error, |
| 175 | pc_pp_Error, |
| 176 | True,/*show TIDs for errors*/ |
| 177 | pc_update_Error_extra, |
| 178 | pc_is_recognised_suppression, |
| 179 | pc_read_extra_suppression_info, |
| 180 | pc_error_matches_suppression, |
| 181 | pc_get_error_name, |
| 182 | pc_print_extra_suppression_info); |
| 183 | |
| 184 | VG_(needs_syscall_wrapper)( h_pre_syscall, |
| 185 | h_post_syscall ); |
| 186 | |
| 187 | VG_(needs_command_line_options)( pc_process_cmd_line_options, |
| 188 | pc_print_usage, |
| 189 | pc_print_debug_usage ); |
| 190 | |
| 191 | VG_(track_die_mem_stack) ( pc_die_mem_stack ); |
| 192 | VG_(track_pre_thread_ll_create) ( pc_pre_thread_ll_create ); |
| 193 | VG_(track_pre_thread_first_insn)( pc_pre_thread_first_insn ); |
| 194 | |
| 195 | VG_(track_new_mem_mmap) ( pc_new_mem_mmap ); |
| 196 | VG_(track_new_mem_startup) ( pc_new_mem_startup); |
| 197 | VG_(track_die_mem_munmap) ( pc_die_mem_munmap ); |
| 198 | |
| 199 | VG_(track_pre_mem_read) ( pc_pre_mem_read ); |
| 200 | VG_(track_pre_mem_read_asciiz) ( pc_pre_mem_read_asciiz ); |
| 201 | VG_(track_pre_mem_write) ( pc_pre_mem_write ); |
| 202 | |
| 203 | VG_(track_post_reg_write_clientcall_return) ( h_post_reg_write_clientcall ); |
| 204 | VG_(track_post_reg_write)( h_post_reg_write_demux ); |
| 205 | |
| 206 | h_pre_clo_init(); |
| 207 | sg_pre_clo_init(); |
| 208 | |
| 209 | VG_(clo_vex_control).iropt_unroll_thresh = 0; |
| 210 | VG_(clo_vex_control).guest_chase_thresh = 0; |
| 211 | } |
| 212 | |
| 213 | VG_DETERMINE_INTERFACE_VERSION(pc_pre_clo_init) |
| 214 | |
| 215 | |
| 216 | /*--------------------------------------------------------------------*/ |
| 217 | /*--- end pc_main.c ---*/ |
| 218 | /*--------------------------------------------------------------------*/ |