njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 1 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Default panicky definitions of template functions that skins ---*/ |
| 4 | /*--- should override. ---*/ |
| 5 | /*--- vg_defaults.c ---*/ |
| 6 | /*--------------------------------------------------------------------*/ |
| 7 | |
| 8 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | This file is part of Valgrind, an extensible x86 protected-mode |
| 10 | emulator for monitoring program execution on x86-Unixes. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 11 | |
| 12 | Copyright (C) 2000-2002 Nicholas Nethercote |
| 13 | njn25@cam.ac.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 | |
| 33 | |
| 34 | /* These functions aren't intended to be run. Replacement functions used by |
| 35 | * the chosen skin are substituted by compiling the skin into a .so and |
| 36 | * LD_PRELOADing it. Nasty :) */ |
| 37 | |
| 38 | #include "vg_include.h" |
| 39 | |
| 40 | /* --------------------------------------------------------------------- |
| 41 | Error messages (for malformed skins) |
| 42 | ------------------------------------------------------------------ */ |
| 43 | |
| 44 | /* If the skin fails to define one or more of the required functions, |
| 45 | * make it very clear what went wrong! */ |
| 46 | |
| 47 | static __attribute__ ((noreturn)) |
| 48 | void fund_panic ( Char* fn ) |
| 49 | { |
| 50 | VG_(printf)( |
| 51 | "\nSkin error:\n" |
| 52 | " The skin you have selected is missing the function `%s',\n" |
| 53 | " which is required.\n\n", |
| 54 | fn); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 55 | VG_(skin_panic)("Missing skin function"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static __attribute__ ((noreturn)) |
| 59 | void non_fund_panic ( Char* fn ) |
| 60 | { |
| 61 | VG_(printf)( |
| 62 | "\nSkin error:\n" |
| 63 | " The skin you have selected is missing the function `%s'\n" |
| 64 | " required by one of its needs.\n\n", |
| 65 | fn); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 66 | VG_(skin_panic)("Missing skin function"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* --------------------------------------------------------------------- |
| 70 | Fundamental template functions |
| 71 | ------------------------------------------------------------------ */ |
| 72 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 73 | __attribute__ ((weak)) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 74 | void SK_(pre_clo_init)( void ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 75 | { |
| 76 | fund_panic("SK_(pre_clo_init)"); |
| 77 | } |
| 78 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 79 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 80 | void SK_(post_clo_init)(void) |
| 81 | { |
| 82 | fund_panic("SK_(post_clo_init)"); |
| 83 | } |
| 84 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 85 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 86 | UCodeBlock* SK_(instrument)(UCodeBlock* cb, Addr not_used) |
| 87 | { |
| 88 | fund_panic("SK_(instrument)"); |
| 89 | } |
| 90 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 91 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 92 | void SK_(fini)(void) |
| 93 | { |
| 94 | fund_panic("SK_(fini)"); |
| 95 | } |
| 96 | |
| 97 | /* --------------------------------------------------------------------- |
| 98 | For error reporting and suppression handling |
| 99 | ------------------------------------------------------------------ */ |
| 100 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 101 | __attribute__ ((weak)) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 102 | Bool SK_(eq_SkinError)(VgRes res, Error* e1, Error* e2) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 103 | { |
| 104 | non_fund_panic("SK_(eq_SkinError)"); |
| 105 | } |
| 106 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 107 | __attribute__ ((weak)) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 108 | void SK_(pp_SkinError)(Error* err) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 109 | { |
| 110 | non_fund_panic("SK_(pp_SkinError)"); |
| 111 | } |
| 112 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 113 | __attribute__ ((weak)) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 114 | UInt SK_(update_extra)(Error* err) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 115 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 116 | non_fund_panic("SK_(update_extra)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 117 | } |
| 118 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 119 | __attribute__ ((weak)) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 120 | Bool SK_(recognised_suppression)(Char* name, Supp* su) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 121 | { |
| 122 | non_fund_panic("SK_(recognised_suppression)"); |
| 123 | } |
| 124 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 125 | __attribute__ ((weak)) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 126 | Bool SK_(read_extra_suppression_info)(Int fd, Char* buf, Int nBuf, Supp* su) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 127 | { |
| 128 | non_fund_panic("SK_(read_extra_suppression_info)"); |
| 129 | } |
| 130 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 131 | __attribute__ ((weak)) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 132 | Bool SK_(error_matches_suppression)(Error* err, Supp* su) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 133 | { |
| 134 | non_fund_panic("SK_(error_matches_suppression)"); |
| 135 | } |
| 136 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 137 | __attribute__ ((weak)) |
| 138 | Char* SK_(get_error_name)(Error* err) |
| 139 | { |
| 140 | non_fund_panic("SK_(get_error_name)"); |
| 141 | } |
| 142 | |
| 143 | __attribute__ ((weak)) |
| 144 | void SK_(print_extra_suppression_info)(Error* err) |
| 145 | { |
| 146 | non_fund_panic("SK_(print_extra_suppression_info)"); |
| 147 | } |
| 148 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 149 | |
| 150 | /* --------------------------------------------------------------------- |
| 151 | For throwing out basic block level info when code is invalidated |
| 152 | ------------------------------------------------------------------ */ |
| 153 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 154 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 155 | void SK_(discard_basic_block_info)(Addr a, UInt size) |
| 156 | { |
| 157 | non_fund_panic("SK_(discard_basic_block_info)"); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /* --------------------------------------------------------------------- |
| 162 | For throwing out basic block level info when code is invalidated |
| 163 | ------------------------------------------------------------------ */ |
| 164 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 165 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 166 | void SK_(written_shadow_regs_values)(UInt* gen_reg, UInt* eflags) |
| 167 | { |
| 168 | non_fund_panic("SK_(written_shadow_regs_values)"); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /* --------------------------------------------------------------------- |
| 173 | Command line arg template function |
| 174 | ------------------------------------------------------------------ */ |
| 175 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 176 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 177 | Bool SK_(process_cmd_line_option)(Char* argv) |
| 178 | { |
| 179 | non_fund_panic("SK_(process_cmd_line_option)"); |
| 180 | } |
| 181 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 182 | __attribute__ ((weak)) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 183 | void SK_(print_usage)(void) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 184 | { |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 185 | non_fund_panic("SK_(print_usage)"); |
| 186 | } |
| 187 | |
| 188 | __attribute__ ((weak)) |
| 189 | void SK_(print_debug_usage)(void) |
| 190 | { |
| 191 | non_fund_panic("SK_(print_debug_usage)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* --------------------------------------------------------------------- |
| 195 | Client request template function |
| 196 | ------------------------------------------------------------------ */ |
| 197 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 198 | __attribute__ ((weak)) |
sewardj | 3404251 | 2002-10-22 04:14:35 +0000 | [diff] [blame] | 199 | Bool SK_(handle_client_request)(ThreadState* tst, UInt* arg_block, UInt *ret) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 200 | { |
| 201 | non_fund_panic("SK_(handle_client_request)"); |
| 202 | } |
| 203 | |
| 204 | /* --------------------------------------------------------------------- |
| 205 | UCode extension |
| 206 | ------------------------------------------------------------------ */ |
| 207 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 208 | __attribute__ ((weak)) |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 209 | void SK_(emit_XUInstr)(UInstr* u, RRegSet regs_live_before) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 210 | { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 211 | non_fund_panic("SK_(emit_XUInstr)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 212 | } |
| 213 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 214 | __attribute__ ((weak)) |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 215 | Bool SK_(sane_XUInstr)(Bool beforeRA, Bool beforeLiveness, UInstr* u) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 216 | { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 217 | non_fund_panic("SK_(sane_XUInstr)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 218 | } |
| 219 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 220 | __attribute__ ((weak)) |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 221 | Char* SK_(name_XUOpcode)(Opcode opc) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 222 | { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 223 | non_fund_panic("SK_(name_XUOpcode)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 224 | } |
| 225 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 226 | __attribute__ ((weak)) |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 227 | void SK_(pp_XUInstr)(UInstr* u) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 228 | { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 229 | non_fund_panic("SK_(pp_XUInstr)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 230 | } |
| 231 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 232 | __attribute__ ((weak)) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 233 | Int SK_(get_Xreg_usage)(UInstr* u, Tag tag, Int* regs, Bool* isWrites) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 234 | { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 235 | non_fund_panic("SK_(get_Xreg_usage)"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* --------------------------------------------------------------------- |
| 239 | Syscall wrapping |
| 240 | ------------------------------------------------------------------ */ |
| 241 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 242 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 243 | void* SK_(pre_syscall)(ThreadId tid, UInt syscallno, Bool is_blocking) |
| 244 | { |
| 245 | non_fund_panic("SK_(pre_syscall)"); |
| 246 | } |
| 247 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 248 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 249 | void SK_(post_syscall)(ThreadId tid, UInt syscallno, |
| 250 | void* pre_result, Int res, Bool is_blocking) |
| 251 | { |
| 252 | non_fund_panic("SK_(post_syscall)"); |
| 253 | } |
| 254 | |
| 255 | /* --------------------------------------------------------------------- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 256 | Sanity checks |
| 257 | ------------------------------------------------------------------ */ |
| 258 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 259 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 260 | Bool SK_(cheap_sanity_check)(void) |
| 261 | { |
| 262 | non_fund_panic("SK_(cheap_sanity_check)"); |
| 263 | } |
| 264 | |
sewardj | c9b8252 | 2002-09-30 23:17:49 +0000 | [diff] [blame] | 265 | __attribute__ ((weak)) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 266 | Bool SK_(expensive_sanity_check)(void) |
| 267 | { |
| 268 | non_fund_panic("SK_(expensive_sanity_check)"); |
| 269 | } |
| 270 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 271 | /*------------------------------------------------------------*/ |
| 272 | /*--- Replacing malloc et al ---*/ |
| 273 | /*------------------------------------------------------------*/ |
| 274 | |
| 275 | /* Default redzone for CLIENT arena of Valgrind's malloc() is 4 bytes */ |
| 276 | __attribute__ ((weak)) |
| 277 | UInt VG_(vg_malloc_redzone_szB) = 4; |
| 278 | |
| 279 | Bool VG_(sk_malloc_called_by_scheduler) = False; |
| 280 | |
| 281 | static __attribute__ ((noreturn)) |
| 282 | void malloc_panic ( Char* fn ) |
| 283 | { |
| 284 | VG_(printf)( |
| 285 | "\nSkin error:\n" |
| 286 | " The skin you have selected is missing the function `%s'\n" |
| 287 | " required because it is replacing malloc() et al.\n\n", |
| 288 | fn); |
| 289 | VG_(skin_panic)("Missing skin function"); |
| 290 | } |
| 291 | |
| 292 | /* If the skin hasn't replaced malloc(), this one can be called from the |
| 293 | scheduler, for the USERREQ__MALLOC user request used by vg_libpthread.c. |
| 294 | (Nb: it cannot call glibc's malloc().) The lock variable ensures that the |
| 295 | scheduler is the only place this can be called from; this ensures that a |
| 296 | malloc()-replacing skin cannot forget to implement SK_(malloc)() or |
| 297 | SK_(free)(). */ |
| 298 | __attribute__ ((weak)) |
| 299 | void* SK_(malloc) ( ThreadState* tst, Int size ) |
| 300 | { |
| 301 | if (VG_(sk_malloc_called_by_scheduler)) |
| 302 | return VG_(cli_malloc)(4, size); |
| 303 | else |
| 304 | malloc_panic("SK_(malloc)"); |
| 305 | } |
| 306 | |
| 307 | __attribute__ ((weak)) |
| 308 | void* SK_(__builtin_new) ( ThreadState* tst, Int size ) |
| 309 | { |
| 310 | malloc_panic("SK_(__builtin_new)"); |
| 311 | } |
| 312 | |
| 313 | __attribute__ ((weak)) |
| 314 | void* SK_(__builtin_vec_new) ( ThreadState* tst, Int size ) |
| 315 | { |
| 316 | malloc_panic("SK_(__builtin_vec_new)"); |
| 317 | } |
| 318 | |
| 319 | __attribute__ ((weak)) |
| 320 | void* SK_(memalign) ( ThreadState* tst, Int align, Int size ) |
| 321 | { |
| 322 | malloc_panic("SK_(memalign)"); |
| 323 | } |
| 324 | |
| 325 | __attribute__ ((weak)) |
| 326 | void* SK_(calloc) ( ThreadState* tst, Int nmemb, Int size ) |
| 327 | { |
| 328 | malloc_panic("SK_(calloc)"); |
| 329 | } |
| 330 | |
| 331 | __attribute__ ((weak)) |
| 332 | void SK_(free) ( ThreadState* tst, void* p ) |
| 333 | { |
| 334 | /* see comment for SK_(malloc)() above */ |
| 335 | if (VG_(sk_malloc_called_by_scheduler)) |
| 336 | VG_(cli_free)(p); |
| 337 | else |
| 338 | malloc_panic("SK_(free)"); |
| 339 | } |
| 340 | |
| 341 | __attribute__ ((weak)) |
| 342 | void SK_(__builtin_delete) ( ThreadState* tst, void* p ) |
| 343 | { |
| 344 | malloc_panic("SK_(__builtin_delete)"); |
| 345 | } |
| 346 | |
| 347 | __attribute__ ((weak)) |
| 348 | void SK_(__builtin_vec_delete) ( ThreadState* tst, void* p ) |
| 349 | { |
| 350 | malloc_panic("SK_(__builtin_vec_delete)"); |
| 351 | } |
| 352 | |
| 353 | __attribute__ ((weak)) |
| 354 | void* SK_(realloc) ( ThreadState* tst, void* p, Int new_size ) |
| 355 | { |
| 356 | malloc_panic("SK_(realloc)"); |
| 357 | } |
| 358 | |
| 359 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 360 | /*--------------------------------------------------------------------*/ |
| 361 | /*--- end vg_defaults.c ---*/ |
| 362 | /*--------------------------------------------------------------------*/ |