blob: 8eeb6ee69e7e194b38db769eee75cb2c17fd6be7 [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
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
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
69/* ---------------------------------------------------------------------
70 Fundamental template functions
71 ------------------------------------------------------------------ */
72
sewardjc9b82522002-09-30 23:17:49 +000073__attribute__ ((weak))
njn810086f2002-11-14 12:42:47 +000074void SK_(pre_clo_init)( void )
njn25e49d8e72002-09-23 09:36:25 +000075{
76 fund_panic("SK_(pre_clo_init)");
77}
78
sewardjc9b82522002-09-30 23:17:49 +000079__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +000080void SK_(post_clo_init)(void)
81{
82 fund_panic("SK_(post_clo_init)");
83}
84
sewardjc9b82522002-09-30 23:17:49 +000085__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +000086UCodeBlock* SK_(instrument)(UCodeBlock* cb, Addr not_used)
87{
88 fund_panic("SK_(instrument)");
89}
90
sewardjc9b82522002-09-30 23:17:49 +000091__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +000092void SK_(fini)(void)
93{
94 fund_panic("SK_(fini)");
95}
96
97/* ---------------------------------------------------------------------
98 For error reporting and suppression handling
99 ------------------------------------------------------------------ */
100
sewardjc9b82522002-09-30 23:17:49 +0000101__attribute__ ((weak))
njn810086f2002-11-14 12:42:47 +0000102Bool SK_(eq_SkinError)(VgRes res, Error* e1, Error* e2)
njn25e49d8e72002-09-23 09:36:25 +0000103{
104 non_fund_panic("SK_(eq_SkinError)");
105}
106
sewardjc9b82522002-09-30 23:17:49 +0000107__attribute__ ((weak))
njn43c799e2003-04-08 00:08:52 +0000108void SK_(pp_SkinError)(Error* err)
njn25e49d8e72002-09-23 09:36:25 +0000109{
110 non_fund_panic("SK_(pp_SkinError)");
111}
112
sewardjc9b82522002-09-30 23:17:49 +0000113__attribute__ ((weak))
njn43c799e2003-04-08 00:08:52 +0000114UInt SK_(update_extra)(Error* err)
njn25e49d8e72002-09-23 09:36:25 +0000115{
njn43c799e2003-04-08 00:08:52 +0000116 non_fund_panic("SK_(update_extra)");
njn25e49d8e72002-09-23 09:36:25 +0000117}
118
sewardjc9b82522002-09-30 23:17:49 +0000119__attribute__ ((weak))
njn810086f2002-11-14 12:42:47 +0000120Bool SK_(recognised_suppression)(Char* name, Supp* su)
njn25e49d8e72002-09-23 09:36:25 +0000121{
122 non_fund_panic("SK_(recognised_suppression)");
123}
124
sewardjc9b82522002-09-30 23:17:49 +0000125__attribute__ ((weak))
njn810086f2002-11-14 12:42:47 +0000126Bool SK_(read_extra_suppression_info)(Int fd, Char* buf, Int nBuf, Supp* su)
njn25e49d8e72002-09-23 09:36:25 +0000127{
128 non_fund_panic("SK_(read_extra_suppression_info)");
129}
130
sewardjc9b82522002-09-30 23:17:49 +0000131__attribute__ ((weak))
njn810086f2002-11-14 12:42:47 +0000132Bool SK_(error_matches_suppression)(Error* err, Supp* su)
njn25e49d8e72002-09-23 09:36:25 +0000133{
134 non_fund_panic("SK_(error_matches_suppression)");
135}
136
njn43c799e2003-04-08 00:08:52 +0000137__attribute__ ((weak))
138Char* SK_(get_error_name)(Error* err)
139{
140 non_fund_panic("SK_(get_error_name)");
141}
142
143__attribute__ ((weak))
144void SK_(print_extra_suppression_info)(Error* err)
145{
146 non_fund_panic("SK_(print_extra_suppression_info)");
147}
148
njn25e49d8e72002-09-23 09:36:25 +0000149
150/* ---------------------------------------------------------------------
151 For throwing out basic block level info when code is invalidated
152 ------------------------------------------------------------------ */
153
sewardjc9b82522002-09-30 23:17:49 +0000154__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000155void 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
sewardjc9b82522002-09-30 23:17:49 +0000165__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000166void 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
sewardjc9b82522002-09-30 23:17:49 +0000176__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000177Bool SK_(process_cmd_line_option)(Char* argv)
178{
179 non_fund_panic("SK_(process_cmd_line_option)");
180}
181
sewardjc9b82522002-09-30 23:17:49 +0000182__attribute__ ((weak))
njn3e884182003-04-15 13:03:23 +0000183void SK_(print_usage)(void)
njn25e49d8e72002-09-23 09:36:25 +0000184{
njn3e884182003-04-15 13:03:23 +0000185 non_fund_panic("SK_(print_usage)");
186}
187
188__attribute__ ((weak))
189void SK_(print_debug_usage)(void)
190{
191 non_fund_panic("SK_(print_debug_usage)");
njn25e49d8e72002-09-23 09:36:25 +0000192}
193
194/* ---------------------------------------------------------------------
195 Client request template function
196 ------------------------------------------------------------------ */
197
sewardjc9b82522002-09-30 23:17:49 +0000198__attribute__ ((weak))
sewardj34042512002-10-22 04:14:35 +0000199Bool SK_(handle_client_request)(ThreadState* tst, UInt* arg_block, UInt *ret)
njn25e49d8e72002-09-23 09:36:25 +0000200{
201 non_fund_panic("SK_(handle_client_request)");
202}
203
204/* ---------------------------------------------------------------------
205 UCode extension
206 ------------------------------------------------------------------ */
207
sewardjc9b82522002-09-30 23:17:49 +0000208__attribute__ ((weak))
njn4ba5a792002-09-30 10:23:54 +0000209void SK_(emit_XUInstr)(UInstr* u, RRegSet regs_live_before)
njn25e49d8e72002-09-23 09:36:25 +0000210{
njn4ba5a792002-09-30 10:23:54 +0000211 non_fund_panic("SK_(emit_XUInstr)");
njn25e49d8e72002-09-23 09:36:25 +0000212}
213
sewardjc9b82522002-09-30 23:17:49 +0000214__attribute__ ((weak))
njn4ba5a792002-09-30 10:23:54 +0000215Bool SK_(sane_XUInstr)(Bool beforeRA, Bool beforeLiveness, UInstr* u)
njn25e49d8e72002-09-23 09:36:25 +0000216{
njn4ba5a792002-09-30 10:23:54 +0000217 non_fund_panic("SK_(sane_XUInstr)");
njn25e49d8e72002-09-23 09:36:25 +0000218}
219
sewardjc9b82522002-09-30 23:17:49 +0000220__attribute__ ((weak))
njn4ba5a792002-09-30 10:23:54 +0000221Char* SK_(name_XUOpcode)(Opcode opc)
njn25e49d8e72002-09-23 09:36:25 +0000222{
njn4ba5a792002-09-30 10:23:54 +0000223 non_fund_panic("SK_(name_XUOpcode)");
njn25e49d8e72002-09-23 09:36:25 +0000224}
225
sewardjc9b82522002-09-30 23:17:49 +0000226__attribute__ ((weak))
njn4ba5a792002-09-30 10:23:54 +0000227void SK_(pp_XUInstr)(UInstr* u)
njn25e49d8e72002-09-23 09:36:25 +0000228{
njn4ba5a792002-09-30 10:23:54 +0000229 non_fund_panic("SK_(pp_XUInstr)");
njn25e49d8e72002-09-23 09:36:25 +0000230}
231
sewardjc9b82522002-09-30 23:17:49 +0000232__attribute__ ((weak))
njn810086f2002-11-14 12:42:47 +0000233Int SK_(get_Xreg_usage)(UInstr* u, Tag tag, Int* regs, Bool* isWrites)
njn25e49d8e72002-09-23 09:36:25 +0000234{
njn4ba5a792002-09-30 10:23:54 +0000235 non_fund_panic("SK_(get_Xreg_usage)");
njn25e49d8e72002-09-23 09:36:25 +0000236}
237
238/* ---------------------------------------------------------------------
239 Syscall wrapping
240 ------------------------------------------------------------------ */
241
sewardjc9b82522002-09-30 23:17:49 +0000242__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000243void* SK_(pre_syscall)(ThreadId tid, UInt syscallno, Bool is_blocking)
244{
245 non_fund_panic("SK_(pre_syscall)");
246}
247
sewardjc9b82522002-09-30 23:17:49 +0000248__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000249void 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/* ---------------------------------------------------------------------
njn25e49d8e72002-09-23 09:36:25 +0000256 Sanity checks
257 ------------------------------------------------------------------ */
258
sewardjc9b82522002-09-30 23:17:49 +0000259__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000260Bool SK_(cheap_sanity_check)(void)
261{
262 non_fund_panic("SK_(cheap_sanity_check)");
263}
264
sewardjc9b82522002-09-30 23:17:49 +0000265__attribute__ ((weak))
njn25e49d8e72002-09-23 09:36:25 +0000266Bool SK_(expensive_sanity_check)(void)
267{
268 non_fund_panic("SK_(expensive_sanity_check)");
269}
270
njn3e884182003-04-15 13:03:23 +0000271/*------------------------------------------------------------*/
272/*--- Replacing malloc et al ---*/
273/*------------------------------------------------------------*/
274
275/* Default redzone for CLIENT arena of Valgrind's malloc() is 4 bytes */
276__attribute__ ((weak))
277UInt VG_(vg_malloc_redzone_szB) = 4;
278
279Bool VG_(sk_malloc_called_by_scheduler) = False;
280
281static __attribute__ ((noreturn))
282void 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))
299void* 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))
308void* SK_(__builtin_new) ( ThreadState* tst, Int size )
309{
310 malloc_panic("SK_(__builtin_new)");
311}
312
313__attribute__ ((weak))
314void* SK_(__builtin_vec_new) ( ThreadState* tst, Int size )
315{
316 malloc_panic("SK_(__builtin_vec_new)");
317}
318
319__attribute__ ((weak))
320void* SK_(memalign) ( ThreadState* tst, Int align, Int size )
321{
322 malloc_panic("SK_(memalign)");
323}
324
325__attribute__ ((weak))
326void* SK_(calloc) ( ThreadState* tst, Int nmemb, Int size )
327{
328 malloc_panic("SK_(calloc)");
329}
330
331__attribute__ ((weak))
332void 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))
342void SK_(__builtin_delete) ( ThreadState* tst, void* p )
343{
344 malloc_panic("SK_(__builtin_delete)");
345}
346
347__attribute__ ((weak))
348void SK_(__builtin_vec_delete) ( ThreadState* tst, void* p )
349{
350 malloc_panic("SK_(__builtin_vec_delete)");
351}
352
353__attribute__ ((weak))
354void* SK_(realloc) ( ThreadState* tst, void* p, Int new_size )
355{
356 malloc_panic("SK_(realloc)");
357}
358
359
njn25e49d8e72002-09-23 09:36:25 +0000360/*--------------------------------------------------------------------*/
361/*--- end vg_defaults.c ---*/
362/*--------------------------------------------------------------------*/