blob: 1bb54085fdbac5fc9565981c6b63b260d8d20a71 [file] [log] [blame]
njnc9539842002-10-02 13:26:35 +00001
njn25e49d8e72002-09-23 09:36:25 +00002/*--------------------------------------------------------------------*/
3/*--- Default panicky definitions of template functions that skins ---*/
4/*--- should override. ---*/
5/*--- vg_defaults.c ---*/
6/*--------------------------------------------------------------------*/
7
8/*
njnc9539842002-10-02 13:26:35 +00009 This file is part of Valgrind, an extensible x86 protected-mode
10 emulator for monitoring program execution on x86-Unixes.
njn25e49d8e72002-09-23 09:36:25 +000011
njn0e1b5142003-04-15 14:58:06 +000012 Copyright (C) 2000-2003 Nicholas Nethercote
njn25e49d8e72002-09-23 09:36:25 +000013 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
47static __attribute__ ((noreturn))
48void 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);
njne427a662002-10-02 11:08:25 +000055 VG_(skin_panic)("Missing skin function");
njn25e49d8e72002-09-23 09:36:25 +000056}
57
58static __attribute__ ((noreturn))
59void 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);
njne427a662002-10-02 11:08:25 +000066 VG_(skin_panic)("Missing skin function");
njn25e49d8e72002-09-23 09:36:25 +000067}
68
njn3e884182003-04-15 13:03:23 +000069static __attribute__ ((noreturn))
70void malloc_panic ( Char* fn )
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
njn308955f2003-05-21 10:48:24 +000080#define FUND(proto) \
81__attribute__((weak)) \
82proto \
83{ \
84 fund_panic(__PRETTY_FUNCTION__); \
85}
86
87#define NON_FUND(proto) \
88__attribute__((weak)) \
89proto \
90{ \
91 non_fund_panic(__PRETTY_FUNCTION__); \
92}
93
94#define MALLOC(proto) \
95__attribute__((weak)) \
96proto \
97{ \
98 malloc_panic(__PRETTY_FUNCTION__); \
99}
100
101/* ---------------------------------------------------------------------
102 Default functions
103 ------------------------------------------------------------------ */
104
105/* Fundamental template functions */
106FUND( void SK_(pre_clo_init) (void) );
107FUND( void SK_(post_clo_init)(void) );
108FUND( UCodeBlock* SK_(instrument) (UCodeBlock* cb, Addr not_used) );
109FUND( void SK_(fini) (Int exitcode) );
110
111/* For error reporting and suppression handling */
112NON_FUND( Bool SK_(eq_SkinError)(VgRes res, Error* e1, Error* e2) );
113NON_FUND( void SK_(pp_SkinError)(Error* err) );
114NON_FUND( UInt SK_(update_extra)(Error* err) );
115NON_FUND( Bool SK_(recognised_suppression)(Char* name, Supp* su) );
116NON_FUND( Bool SK_(read_extra_suppression_info)(Int fd, Char* buf, Int nBuf,
117 Supp* su) );
118NON_FUND( Bool SK_(error_matches_suppression)(Error* err, Supp* su) );
119NON_FUND( Char* SK_(get_error_name)(Error* err) );
120NON_FUND( void SK_(print_extra_suppression_info)(Error* err) );
121
122/* For throwing out basic block level info when code is invalidated */
123NON_FUND( void SK_(discard_basic_block_info)(Addr a, UInt size) );
124
125/* For throwing out basic block level info when code is invalidated */
126NON_FUND( void SK_(written_shadow_regs_values)(UInt* gen_reg, UInt* eflags) );
127
128/* Command line arg handling functions */
129NON_FUND( Bool SK_(process_cmd_line_option)(Char* argv) );
130NON_FUND( void SK_(print_usage)(void) );
131NON_FUND( void SK_(print_debug_usage)(void) );
132
133/* Client request template function */
njn72718642003-07-24 08:45:32 +0000134NON_FUND( Bool SK_(handle_client_request)(ThreadId tid, UInt* arg_block,
njn308955f2003-05-21 10:48:24 +0000135 UInt *ret) );
136
137/* UCode extension */
138NON_FUND( void SK_(emit_XUInstr) (UInstr* u, RRegSet regs_live_before) );
139NON_FUND( Bool SK_(sane_XUInstr) (Bool beforeRA, Bool beforeLiveness,
140 UInstr* u) );
141NON_FUND( Char* SK_(name_XUOpcode) (Opcode opc) );
142NON_FUND( void SK_(pp_XUInstr) (UInstr* u) );
143NON_FUND( Int SK_(get_Xreg_usage)(UInstr* u, Tag tag, Int* regs,
144 Bool* isWrites) );
145
146/* Syscall wrapping */
147NON_FUND( void* SK_(pre_syscall) (ThreadId tid, UInt syscallno,
148 Bool is_blocking) );
149NON_FUND( void SK_(post_syscall)(ThreadId tid, UInt syscallno,
150 void* pre_result, Int res, Bool is_blocking) );
151
152/* Sanity checks */
153NON_FUND( Bool SK_(cheap_sanity_check)(void) );
154NON_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))
162UInt VG_(vg_malloc_redzone_szB) = 4;
163
164Bool VG_(sk_malloc_called_by_scheduler) = False;
165
njn3e884182003-04-15 13:03:23 +0000166/* 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))
njn72718642003-07-24 08:45:32 +0000173void* SK_(malloc)( Int size )
njn3e884182003-04-15 13:03:23 +0000174{
175 if (VG_(sk_malloc_called_by_scheduler))
176 return VG_(cli_malloc)(4, size);
177 else
njn308955f2003-05-21 10:48:24 +0000178 malloc_panic(__PRETTY_FUNCTION__);
njn3e884182003-04-15 13:03:23 +0000179}
180
181__attribute__ ((weak))
njn72718642003-07-24 08:45:32 +0000182void SK_(free)( void* p )
njn3e884182003-04-15 13:03:23 +0000183{
184 /* see comment for SK_(malloc)() above */
185 if (VG_(sk_malloc_called_by_scheduler))
186 VG_(cli_free)(p);
187 else
njn308955f2003-05-21 10:48:24 +0000188 malloc_panic(__PRETTY_FUNCTION__);
njn3e884182003-04-15 13:03:23 +0000189}
190
njn72718642003-07-24 08:45:32 +0000191MALLOC( void* SK_(__builtin_new) ( Int size ) );
192MALLOC( void* SK_(__builtin_vec_new)( Int size ) );
193MALLOC( void* SK_(memalign) ( Int align, Int size ) );
194MALLOC( void* SK_(calloc) ( Int nmemb, Int size ) );
njn3e884182003-04-15 13:03:23 +0000195
njn72718642003-07-24 08:45:32 +0000196MALLOC( void SK_(__builtin_delete) ( void* p ) );
197MALLOC( void SK_(__builtin_vec_delete) ( void* p ) );
198MALLOC( void* SK_(realloc) ( void* p, Int new_size ) );
njn3e884182003-04-15 13:03:23 +0000199
njn25e49d8e72002-09-23 09:36:25 +0000200/*--------------------------------------------------------------------*/
201/*--- end vg_defaults.c ---*/
202/*--------------------------------------------------------------------*/