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-2010 OpenWorks Ltd 13 info (at) 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" 40 #include "pub_tool_libcprint.h" 41 #include "pub_tool_execontext.h" 42 #include "pub_tool_tooliface.h" 43 #include "pub_tool_options.h" 44 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(); 128 # if defined(VGA_x86) || defined(VGA_amd64) 129 /* nothing */ 130 # elif defined(VGA_ppc32) || defined(VGA_ppc64) || defined(VGA_arm) 131 if (VG_(clo_verbosity) >= 1 && sg_clo_enable_sg_checks) { 132 VG_(message)(Vg_UserMsg, 133 "WARNING: exp-ptrcheck on ppc32/ppc64/arm platforms: " 134 "stack and global array\n"); 135 VG_(message)(Vg_UserMsg, 136 "WARNING: checking is not currently supported. " 137 "Only heap checking is\n"); 138 VG_(message)(Vg_UserMsg, 139 "WARNING: supported. Disabling s/g checks " 140 "(like --enable-sg-checks=no).\n"); 141 } 142 sg_clo_enable_sg_checks = False; 143 # else 144 # error "Unsupported architecture" 145 # endif 146 } 147 148 static void pc_pre_clo_init(void) 149 { 150 #if defined(VGO_darwin) 151 // This makes the (all-failing) regtests run much faster. 152 VG_(printf)("Ptrcheck doesn't work on Darwin yet, sorry.\n"); 153 VG_(exit)(1); 154 #endif 155 156 VG_(details_name) ("exp-ptrcheck"); 157 VG_(details_version) (NULL); 158 VG_(details_description) ("a heap, stack and global array " 159 "overrun detector"); 160 VG_(details_copyright_author)( 161 "Copyright (C) 2003-2010, and GNU GPL'd, by OpenWorks Ltd et al."); 162 VG_(details_bug_reports_to) (VG_BUGS_TO); 163 VG_(details_avg_translation_sizeB) ( 496 ); 164 165 VG_(basic_tool_funcs) (pc_post_clo_init, 166 h_instrument, 167 pc_fini); 168 169 VG_(needs_malloc_replacement)( h_replace_malloc, 170 h_replace___builtin_new, 171 h_replace___builtin_vec_new, 172 h_replace_memalign, 173 h_replace_calloc, 174 h_replace_free, 175 h_replace___builtin_delete, 176 h_replace___builtin_vec_delete, 177 h_replace_realloc, 178 h_replace_malloc_usable_size, 179 0 /* no need for client heap redzones */ ); 180 181 VG_(needs_var_info) (); 182 183 VG_(needs_core_errors) (); 184 VG_(needs_tool_errors) (pc_eq_Error, 185 pc_before_pp_Error, 186 pc_pp_Error, 187 True,/*show TIDs for errors*/ 188 pc_update_Error_extra, 189 pc_is_recognised_suppression, 190 pc_read_extra_suppression_info, 191 pc_error_matches_suppression, 192 pc_get_error_name, 193 pc_get_extra_suppression_info); 194 195 VG_(needs_xml_output) (); 196 197 VG_(needs_syscall_wrapper)( h_pre_syscall, 198 h_post_syscall ); 199 200 VG_(needs_command_line_options)( pc_process_cmd_line_options, 201 pc_print_usage, 202 pc_print_debug_usage ); 203 204 VG_(track_die_mem_stack) ( pc_die_mem_stack ); 205 VG_(track_pre_thread_ll_create) ( pc_pre_thread_ll_create ); 206 VG_(track_pre_thread_first_insn)( pc_pre_thread_first_insn ); 207 208 VG_(track_new_mem_mmap) ( pc_new_mem_mmap ); 209 VG_(track_new_mem_startup) ( pc_new_mem_startup); 210 VG_(track_die_mem_munmap) ( pc_die_mem_munmap ); 211 212 VG_(track_pre_mem_read) ( pc_pre_mem_read ); 213 VG_(track_pre_mem_read_asciiz) ( pc_pre_mem_read_asciiz ); 214 VG_(track_pre_mem_write) ( pc_pre_mem_write ); 215 216 VG_(track_post_reg_write_clientcall_return) ( h_post_reg_write_clientcall ); 217 VG_(track_post_reg_write)( h_post_reg_write_demux ); 218 219 h_pre_clo_init(); 220 sg_pre_clo_init(); 221 222 VG_(clo_vex_control).iropt_unroll_thresh = 0; 223 VG_(clo_vex_control).guest_chase_thresh = 0; 224 } 225 226 VG_DETERMINE_INTERFACE_VERSION(pc_pre_clo_init) 227 228 229 /*--------------------------------------------------------------------*/ 230 /*--- end pc_main.c ---*/ 231 /*--------------------------------------------------------------------*/ 232