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 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 12 | Copyright (C) 2008-2017 OpenWorks Ltd |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 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 | // // |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 52 | // main // |
| 53 | // // |
| 54 | ////////////////////////////////////////////////////////////// |
| 55 | |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 56 | static void pc_pre_clo_init(void) |
| 57 | { |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 58 | #if defined(VGO_darwin) |
| 59 | // This makes the (all-failing) regtests run much faster. |
sewardj | d2f95a0 | 2011-05-11 16:04:28 +0000 | [diff] [blame] | 60 | VG_(printf)("SGCheck doesn't work on Darwin yet, sorry.\n"); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 61 | VG_(exit)(1); |
| 62 | #endif |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 63 | #if defined(VGA_s390x) |
| 64 | /* fixs390: to be done. */ |
florian | 4ced797 | 2014-02-22 22:03:09 +0000 | [diff] [blame] | 65 | VG_(printf)("SGCheck doesn't work on s390x yet, sorry.\n"); |
| 66 | VG_(exit)(1); |
| 67 | #endif |
philippe | 0533405 | 2014-08-28 21:02:11 +0000 | [diff] [blame] | 68 | #if defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le) |
florian | 4ced797 | 2014-02-22 22:03:09 +0000 | [diff] [blame] | 69 | VG_(printf)("SGCheck doesn't work on PPC yet, sorry.\n"); |
| 70 | VG_(exit)(1); |
| 71 | #endif |
| 72 | #if defined(VGA_arm) || defined(VGA_arm64) |
| 73 | VG_(printf)("SGCheck doesn't work on ARM yet, sorry.\n"); |
| 74 | VG_(exit)(1); |
| 75 | #endif |
| 76 | #if defined(VGA_mips32) || defined(VGA_mips64) |
| 77 | VG_(printf)("SGCheck doesn't work on MIPS yet, sorry.\n"); |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 78 | VG_(exit)(1); |
| 79 | #endif |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 80 | |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 81 | // Can't change the name until we change the names in suppressions |
| 82 | // too. |
sewardj | d2f95a0 | 2011-05-11 16:04:28 +0000 | [diff] [blame] | 83 | VG_(details_name) ("exp-sgcheck"); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 84 | VG_(details_version) (NULL); |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 85 | VG_(details_description) ("a stack and global array " |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 86 | "overrun detector"); |
| 87 | VG_(details_copyright_author)( |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 88 | "Copyright (C) 2003-2017, and GNU GPL'd, by OpenWorks Ltd et al."); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 89 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | 4b8ce60 | 2008-10-20 10:23:46 +0000 | [diff] [blame] | 90 | VG_(details_avg_translation_sizeB) ( 496 ); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 91 | |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 92 | VG_(basic_tool_funcs) (sg_post_clo_init, |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 93 | h_instrument, |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 94 | sg_fini); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 95 | |
| 96 | VG_(needs_malloc_replacement)( h_replace_malloc, |
| 97 | h_replace___builtin_new, |
| 98 | h_replace___builtin_vec_new, |
| 99 | h_replace_memalign, |
| 100 | h_replace_calloc, |
| 101 | h_replace_free, |
| 102 | h_replace___builtin_delete, |
| 103 | h_replace___builtin_vec_delete, |
| 104 | h_replace_realloc, |
njn | 8b140de | 2009-02-17 04:31:18 +0000 | [diff] [blame] | 105 | h_replace_malloc_usable_size, |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 106 | 0 /* no need for client heap redzones */ ); |
| 107 | |
| 108 | VG_(needs_var_info) (); |
| 109 | |
| 110 | VG_(needs_core_errors) (); |
| 111 | VG_(needs_tool_errors) (pc_eq_Error, |
sewardj | c1bc9d1 | 2009-07-15 14:50:22 +0000 | [diff] [blame] | 112 | pc_before_pp_Error, |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 113 | pc_pp_Error, |
| 114 | True,/*show TIDs for errors*/ |
| 115 | pc_update_Error_extra, |
| 116 | pc_is_recognised_suppression, |
| 117 | pc_read_extra_suppression_info, |
| 118 | pc_error_matches_suppression, |
| 119 | pc_get_error_name, |
philippe | 4e32d67 | 2013-10-17 22:10:41 +0000 | [diff] [blame] | 120 | pc_get_extra_suppression_info, |
| 121 | pc_print_extra_suppression_use, |
| 122 | pc_update_extra_suppression_use); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 123 | |
sewardj | c1bc9d1 | 2009-07-15 14:50:22 +0000 | [diff] [blame] | 124 | VG_(needs_xml_output) (); |
| 125 | |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 126 | //VG_(needs_syscall_wrapper)( h_pre_syscall, |
| 127 | // h_post_syscall ); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 128 | |
| 129 | VG_(needs_command_line_options)( pc_process_cmd_line_options, |
| 130 | pc_print_usage, |
| 131 | pc_print_debug_usage ); |
| 132 | |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 133 | VG_(track_die_mem_stack) ( sg_die_mem_stack ); |
| 134 | VG_(track_pre_thread_ll_create) ( sg_pre_thread_ll_create ); |
| 135 | VG_(track_pre_thread_first_insn)( sg_pre_thread_first_insn ); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 136 | |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 137 | VG_(track_new_mem_mmap) ( sg_new_mem_mmap ); |
| 138 | VG_(track_new_mem_startup) ( sg_new_mem_startup); |
| 139 | VG_(track_die_mem_munmap) ( sg_die_mem_munmap ); |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 140 | |
sewardj | f5b019f | 2011-05-11 12:01:37 +0000 | [diff] [blame] | 141 | /* Really we ought to give handlers for these, to |
| 142 | check that syscalls don't read across array boundaries. */ |
| 143 | /* |
| 144 | VG_(track_pre_mem_read) ( NULL ); |
| 145 | VG_(track_pre_mem_read_asciiz) ( NULL ); |
| 146 | VG_(track_pre_mem_write) ( NULL ); |
| 147 | */ |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 148 | |
sewardj | 024598e | 2008-09-18 14:43:05 +0000 | [diff] [blame] | 149 | sg_pre_clo_init(); |
| 150 | |
| 151 | VG_(clo_vex_control).iropt_unroll_thresh = 0; |
| 152 | VG_(clo_vex_control).guest_chase_thresh = 0; |
| 153 | } |
| 154 | |
| 155 | VG_DETERMINE_INTERFACE_VERSION(pc_pre_clo_init) |
| 156 | |
| 157 | |
| 158 | /*--------------------------------------------------------------------*/ |
| 159 | /*--- end pc_main.c ---*/ |
| 160 | /*--------------------------------------------------------------------*/ |