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 | |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 12 | Copyright (C) 2000-2003 Nicholas Nethercote |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 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)) |
daywalker | 3222e0a | 2003-09-18 01:39:50 +0000 | [diff] [blame] | 48 | void fund_panic ( const Char* fn ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 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)) |
daywalker | 3222e0a | 2003-09-18 01:39:50 +0000 | [diff] [blame] | 59 | void non_fund_panic ( const Char* fn ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 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 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 69 | static __attribute__ ((noreturn)) |
daywalker | 3222e0a | 2003-09-18 01:39:50 +0000 | [diff] [blame] | 70 | void malloc_panic ( const Char* fn ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 71 | { |
| 72 | VG_(printf)( |
| 73 | "\nSkin error:\n" |
| 74 | " The skin you have selected is missing the function `%s'\n" |
| 75 | " required because it is replacing malloc() et al.\n\n", |
| 76 | fn); |
| 77 | VG_(skin_panic)("Missing skin function"); |
| 78 | } |
| 79 | |
njn | 308955f | 2003-05-21 10:48:24 +0000 | [diff] [blame] | 80 | #define FUND(proto) \ |
| 81 | __attribute__((weak)) \ |
| 82 | proto \ |
| 83 | { \ |
| 84 | fund_panic(__PRETTY_FUNCTION__); \ |
| 85 | } |
| 86 | |
| 87 | #define NON_FUND(proto) \ |
| 88 | __attribute__((weak)) \ |
| 89 | proto \ |
| 90 | { \ |
| 91 | non_fund_panic(__PRETTY_FUNCTION__); \ |
| 92 | } |
| 93 | |
| 94 | #define MALLOC(proto) \ |
| 95 | __attribute__((weak)) \ |
| 96 | proto \ |
| 97 | { \ |
| 98 | malloc_panic(__PRETTY_FUNCTION__); \ |
| 99 | } |
| 100 | |
| 101 | /* --------------------------------------------------------------------- |
| 102 | Default functions |
| 103 | ------------------------------------------------------------------ */ |
| 104 | |
| 105 | /* Fundamental template functions */ |
| 106 | FUND( void SK_(pre_clo_init) (void) ); |
| 107 | FUND( void SK_(post_clo_init)(void) ); |
| 108 | FUND( UCodeBlock* SK_(instrument) (UCodeBlock* cb, Addr not_used) ); |
| 109 | FUND( void SK_(fini) (Int exitcode) ); |
| 110 | |
| 111 | /* For error reporting and suppression handling */ |
| 112 | NON_FUND( Bool SK_(eq_SkinError)(VgRes res, Error* e1, Error* e2) ); |
| 113 | NON_FUND( void SK_(pp_SkinError)(Error* err) ); |
| 114 | NON_FUND( UInt SK_(update_extra)(Error* err) ); |
| 115 | NON_FUND( Bool SK_(recognised_suppression)(Char* name, Supp* su) ); |
| 116 | NON_FUND( Bool SK_(read_extra_suppression_info)(Int fd, Char* buf, Int nBuf, |
| 117 | Supp* su) ); |
| 118 | NON_FUND( Bool SK_(error_matches_suppression)(Error* err, Supp* su) ); |
| 119 | NON_FUND( Char* SK_(get_error_name)(Error* err) ); |
| 120 | NON_FUND( void SK_(print_extra_suppression_info)(Error* err) ); |
| 121 | |
| 122 | /* For throwing out basic block level info when code is invalidated */ |
| 123 | NON_FUND( void SK_(discard_basic_block_info)(Addr a, UInt size) ); |
| 124 | |
| 125 | /* For throwing out basic block level info when code is invalidated */ |
| 126 | NON_FUND( void SK_(written_shadow_regs_values)(UInt* gen_reg, UInt* eflags) ); |
| 127 | |
| 128 | /* Command line arg handling functions */ |
| 129 | NON_FUND( Bool SK_(process_cmd_line_option)(Char* argv) ); |
| 130 | NON_FUND( void SK_(print_usage)(void) ); |
| 131 | NON_FUND( void SK_(print_debug_usage)(void) ); |
| 132 | |
| 133 | /* Client request template function */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 134 | NON_FUND( Bool SK_(handle_client_request)(ThreadId tid, UInt* arg_block, |
njn | 308955f | 2003-05-21 10:48:24 +0000 | [diff] [blame] | 135 | UInt *ret) ); |
| 136 | |
| 137 | /* UCode extension */ |
| 138 | NON_FUND( void SK_(emit_XUInstr) (UInstr* u, RRegSet regs_live_before) ); |
| 139 | NON_FUND( Bool SK_(sane_XUInstr) (Bool beforeRA, Bool beforeLiveness, |
| 140 | UInstr* u) ); |
| 141 | NON_FUND( Char* SK_(name_XUOpcode) (Opcode opc) ); |
| 142 | NON_FUND( void SK_(pp_XUInstr) (UInstr* u) ); |
| 143 | NON_FUND( Int SK_(get_Xreg_usage)(UInstr* u, Tag tag, Int* regs, |
| 144 | Bool* isWrites) ); |
| 145 | |
| 146 | /* Syscall wrapping */ |
| 147 | NON_FUND( void* SK_(pre_syscall) (ThreadId tid, UInt syscallno, |
| 148 | Bool is_blocking) ); |
| 149 | NON_FUND( void SK_(post_syscall)(ThreadId tid, UInt syscallno, |
| 150 | void* pre_result, Int res, Bool is_blocking) ); |
| 151 | |
| 152 | /* Sanity checks */ |
| 153 | NON_FUND( Bool SK_(cheap_sanity_check)(void) ); |
| 154 | NON_FUND( Bool SK_(expensive_sanity_check)(void) ); |
| 155 | |
| 156 | /*------------------------------------------------------------*/ |
| 157 | /*--- Replacing malloc et al ---*/ |
| 158 | /*------------------------------------------------------------*/ |
| 159 | |
| 160 | /* Default redzone for CLIENT arena of Valgrind's malloc() is 4 bytes */ |
| 161 | __attribute__ ((weak)) |
| 162 | UInt VG_(vg_malloc_redzone_szB) = 4; |
| 163 | |
| 164 | Bool VG_(sk_malloc_called_by_scheduler) = False; |
| 165 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 166 | /* If the skin hasn't replaced malloc(), this one can be called from the |
| 167 | scheduler, for the USERREQ__MALLOC user request used by vg_libpthread.c. |
| 168 | (Nb: it cannot call glibc's malloc().) The lock variable ensures that the |
| 169 | scheduler is the only place this can be called from; this ensures that a |
| 170 | malloc()-replacing skin cannot forget to implement SK_(malloc)() or |
| 171 | SK_(free)(). */ |
| 172 | __attribute__ ((weak)) |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 173 | void* SK_(malloc)( Int size ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 174 | { |
| 175 | if (VG_(sk_malloc_called_by_scheduler)) |
| 176 | return VG_(cli_malloc)(4, size); |
| 177 | else |
njn | 308955f | 2003-05-21 10:48:24 +0000 | [diff] [blame] | 178 | malloc_panic(__PRETTY_FUNCTION__); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | __attribute__ ((weak)) |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 182 | void SK_(free)( void* p ) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 183 | { |
| 184 | /* see comment for SK_(malloc)() above */ |
| 185 | if (VG_(sk_malloc_called_by_scheduler)) |
| 186 | VG_(cli_free)(p); |
| 187 | else |
njn | 308955f | 2003-05-21 10:48:24 +0000 | [diff] [blame] | 188 | malloc_panic(__PRETTY_FUNCTION__); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 189 | } |
| 190 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 191 | MALLOC( void* SK_(__builtin_new) ( Int size ) ); |
| 192 | MALLOC( void* SK_(__builtin_vec_new)( Int size ) ); |
| 193 | MALLOC( void* SK_(memalign) ( Int align, Int size ) ); |
| 194 | MALLOC( void* SK_(calloc) ( Int nmemb, Int size ) ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 195 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 196 | MALLOC( void SK_(__builtin_delete) ( void* p ) ); |
| 197 | MALLOC( void SK_(__builtin_vec_delete) ( void* p ) ); |
| 198 | MALLOC( void* SK_(realloc) ( void* p, Int new_size ) ); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 199 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 200 | /*--------------------------------------------------------------------*/ |
| 201 | /*--- end vg_defaults.c ---*/ |
| 202 | /*--------------------------------------------------------------------*/ |