njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Stuff relating to skin data structures. ---*/ |
| 4 | /*--- vg_needs.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, an extensible x86 protected-mode |
| 9 | emulator for monitoring program execution on x86-Unixes. |
| 10 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2004 Nicholas Nethercote |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 12 | njn25@cam.ac.uk |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 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 | |
| 32 | #include "vg_include.h" |
| 33 | |
| 34 | |
| 35 | /* --------------------------------------------------------------------- |
| 36 | Skin data structure initialisation |
| 37 | ------------------------------------------------------------------ */ |
| 38 | |
| 39 | /* Init with default values. */ |
| 40 | VgDetails VG_(details) = { |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 41 | .name = NULL, |
| 42 | .version = NULL, |
| 43 | .description = NULL, |
| 44 | .copyright_author = NULL, |
| 45 | .bug_reports_to = NULL, |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 46 | .avg_translation_sizeB = VG_DEFAULT_TRANS_SIZEB, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | VgNeeds VG_(needs) = { |
| 50 | .core_errors = False, |
| 51 | .skin_errors = False, |
| 52 | .libc_freeres = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 53 | .basic_block_discards = False, |
| 54 | .shadow_regs = False, |
| 55 | .command_line_options = False, |
| 56 | .client_requests = False, |
| 57 | .extended_UCode = False, |
| 58 | .syscall_wrapper = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 59 | .sanity_checks = False, |
| 60 | .data_syms = False, |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 61 | .shadow_memory = False, |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* static */ |
| 65 | void VG_(sanity_check_needs) ( void) |
| 66 | { |
| 67 | #define CHECK_NOT(var, value) \ |
| 68 | if ((var)==(value)) { \ |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 69 | VG_(printf)("\nTool error: `%s' not initialised\n", \ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 70 | VG__STRING(var)); \ |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 71 | VG_(skin_panic)("Uninitialised details field\n"); \ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 72 | } |
| 73 | |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 74 | /* Ones that must be set */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 75 | CHECK_NOT(VG_(details).name, NULL); |
| 76 | /* Nb: .version can be NULL */ |
| 77 | CHECK_NOT(VG_(details).description, NULL); |
| 78 | CHECK_NOT(VG_(details).copyright_author, NULL); |
| 79 | CHECK_NOT(VG_(details).bug_reports_to, NULL); |
| 80 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 81 | if ( (VG_(defined_new_mem_stack_4)() || |
| 82 | VG_(defined_new_mem_stack_8)() || |
| 83 | VG_(defined_new_mem_stack_12)() || |
| 84 | VG_(defined_new_mem_stack_16)() || |
| 85 | VG_(defined_new_mem_stack_32)()) && |
| 86 | ! VG_(defined_new_mem_stack)()) |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 87 | { |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 88 | VG_(printf)("\nTool error: one of the specialised `new_mem_stack_n'\n" |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 89 | "events tracked, but not the generic `new_mem_stack' one.\n"); |
| 90 | VG_(skin_panic)("`new_mem_stack' should be defined\n"); |
| 91 | } |
| 92 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 93 | if ( (VG_(defined_die_mem_stack_4)() || |
| 94 | VG_(defined_die_mem_stack_8)() || |
| 95 | VG_(defined_die_mem_stack_12)() || |
| 96 | VG_(defined_die_mem_stack_16)() || |
| 97 | VG_(defined_die_mem_stack_32)()) && |
| 98 | ! VG_(defined_die_mem_stack)()) |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 99 | { |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 100 | VG_(printf)("\nTool error: one of the specialised `die_mem_stack_n'\n" |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 101 | "events tracked, but not the generic `die_mem_stack' one.\n"); |
| 102 | VG_(skin_panic)("`die_mem_stack' should be defined\n"); |
| 103 | } |
| 104 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 105 | if ( (VG_(defined_post_reg_write_syscall_return)() || |
| 106 | VG_(defined_post_reg_write_deliver_signal)() || |
| 107 | VG_(defined_post_reg_write_pthread_return)() || |
| 108 | VG_(defined_post_reg_write_clientreq_return)() || |
| 109 | VG_(defined_post_reg_write_clientcall_return)()) && |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 110 | ! VG_(needs).shadow_regs) |
| 111 | { |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 112 | VG_(printf)("\nTool error: one of the `post_reg_write'\n" |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 113 | "events tracked, but `shadow_regs' need not set.\n"); |
| 114 | VG_(skin_panic)("`shadow_regs' should be set\n"); |
| 115 | } |
| 116 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 117 | if (VG_(needs).shadow_memory != (VG_(get_shadow_size)() != 0)) { |
| 118 | if (VG_(get_shadow_size)() != 0) |
| 119 | VG_(printf)("\nTool error: tool allocated shadow memory, but apparently doesn't " |
| 120 | "need it.\n"); |
| 121 | else |
| 122 | VG_(printf)("\nTool error: tool didn't allocated shadow memory, but apparently " |
| 123 | "needs it.\n"); |
| 124 | VG_(skin_panic)("VG_(needs).shadow_memory need should be set to match SK_(shadow_ratio)\n"); |
| 125 | } |
| 126 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 127 | #undef CHECK_NOT |
| 128 | #undef INVALID_Bool |
| 129 | } |
| 130 | |
| 131 | /*--------------------------------------------------------------------*/ |
| 132 | /* Setting details */ |
| 133 | |
| 134 | /* Use macro because they're so repetitive */ |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 135 | #define DETAILS(type, detail) \ |
| 136 | extern void VG_(details_##detail)(type detail) \ |
| 137 | { \ |
| 138 | VG_(details).detail = detail; \ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 139 | } |
| 140 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 141 | DETAILS(Char*, name) |
| 142 | DETAILS(Char*, version) |
| 143 | DETAILS(Char*, description) |
| 144 | DETAILS(Char*, copyright_author) |
| 145 | DETAILS(Char*, bug_reports_to) |
njn | 120281f | 2003-02-03 12:20:07 +0000 | [diff] [blame] | 146 | DETAILS(UInt, avg_translation_sizeB) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 147 | |
| 148 | /*--------------------------------------------------------------------*/ |
| 149 | /* Setting needs */ |
| 150 | |
| 151 | /* Use macro because they're so repetitive */ |
| 152 | #define NEEDS(need) \ |
| 153 | extern void VG_(needs_##need)(void) \ |
| 154 | { \ |
| 155 | VG_(needs).need = True; \ |
| 156 | } |
| 157 | |
| 158 | NEEDS(libc_freeres) |
| 159 | NEEDS(core_errors) |
| 160 | NEEDS(skin_errors) |
| 161 | NEEDS(basic_block_discards) |
| 162 | NEEDS(shadow_regs) |
| 163 | NEEDS(command_line_options) |
| 164 | NEEDS(client_requests) |
| 165 | NEEDS(extended_UCode) |
| 166 | NEEDS(syscall_wrapper) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 167 | NEEDS(sanity_checks) |
| 168 | NEEDS(data_syms) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 169 | NEEDS(shadow_memory) |
njn | fdc28af | 2003-02-24 10:36:48 +0000 | [diff] [blame] | 170 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 171 | /*--------------------------------------------------------------------*/ |
| 172 | /* UCodeBlocks */ |
| 173 | |
| 174 | Int VG_(get_num_instrs) ( UCodeBlock* cb ) |
| 175 | { |
| 176 | return cb->used; |
| 177 | } |
| 178 | |
| 179 | Int VG_(get_num_temps) ( UCodeBlock* cb ) |
| 180 | { |
| 181 | return cb->nextTemp; |
| 182 | } |
| 183 | |
| 184 | UInstr* VG_(get_instr) ( UCodeBlock* cb, Int i ) |
| 185 | { |
| 186 | return & cb->instrs[i]; |
| 187 | } |
| 188 | |
| 189 | UInstr* VG_(get_last_instr) ( UCodeBlock* cb ) |
| 190 | { |
| 191 | return & cb->instrs[cb->used-1]; |
| 192 | } |
| 193 | |
| 194 | /*--------------------------------------------------------------------*/ |
| 195 | /* Suppressions */ |
| 196 | |
| 197 | SuppKind VG_(get_supp_kind) ( Supp* su ) |
| 198 | { |
| 199 | return su->skind; |
| 200 | } |
| 201 | |
| 202 | Char* VG_(get_supp_string) ( Supp* su ) |
| 203 | { |
| 204 | return su->string; |
| 205 | } |
| 206 | |
| 207 | void* VG_(get_supp_extra) ( Supp* su ) |
| 208 | { |
| 209 | return su->extra; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | void VG_(set_supp_kind) ( Supp* su, SuppKind skind ) |
| 214 | { |
| 215 | su->skind = skind; |
| 216 | } |
| 217 | |
| 218 | void VG_(set_supp_string) ( Supp* su, Char* string ) |
| 219 | { |
| 220 | su->string = string; |
| 221 | } |
| 222 | |
| 223 | void VG_(set_supp_extra) ( Supp* su, void* extra ) |
| 224 | { |
| 225 | su->extra = extra; |
| 226 | } |
| 227 | |
| 228 | /*--------------------------------------------------------------------*/ |
| 229 | /* Errors */ |
| 230 | |
njn | ae17bec | 2003-01-28 19:59:38 +0000 | [diff] [blame] | 231 | ExeContext* VG_(get_error_where) ( Error* err ) |
| 232 | { |
njn | 6d57f7d | 2003-02-06 08:17:08 +0000 | [diff] [blame] | 233 | return err->where; |
njn | ae17bec | 2003-01-28 19:59:38 +0000 | [diff] [blame] | 234 | } |
| 235 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 236 | ErrorKind VG_(get_error_kind) ( Error* err ) |
| 237 | { |
| 238 | return err->ekind; |
| 239 | } |
| 240 | |
| 241 | Addr VG_(get_error_address) ( Error* err ) |
| 242 | { |
| 243 | return err->addr; |
| 244 | } |
| 245 | |
| 246 | Char* VG_(get_error_string) ( Error* err ) |
| 247 | { |
| 248 | return err->string; |
| 249 | } |
| 250 | |
| 251 | void* VG_(get_error_extra) ( Error* err ) |
| 252 | { |
| 253 | return err->extra; |
| 254 | } |
| 255 | |
| 256 | /*--------------------------------------------------------------------*/ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 257 | /*--- end vg_needs.c ---*/ |
| 258 | /*--------------------------------------------------------------------*/ |
| 259 | |
| 260 | |