blob: ee5d6300e16e01d8c1a251b45beedd5498c98c83 [file] [log] [blame]
njnc9539842002-10-02 13:26:35 +00001
njn25e49d8e72002-09-23 09:36:25 +00002/*--------------------------------------------------------------------*/
nethercote137bc552003-11-14 17:47:54 +00003/*--- Default panicky definitions of template functions that tools ---*/
njn25e49d8e72002-09-23 09:36:25 +00004/*--- should override. ---*/
5/*--- vg_defaults.c ---*/
6/*--------------------------------------------------------------------*/
7
8/*
njnb9c427c2004-12-01 14:14:42 +00009 This file is part of Valgrind, a dynamic binary instrumentation
10 framework.
njn25e49d8e72002-09-23 09:36:25 +000011
njn53612422005-03-12 16:22:54 +000012 Copyright (C) 2000-2005 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
nethercotef1e5e152004-09-01 23:58:16 +000034#include "core.h"
njn25e49d8e72002-09-23 09:36:25 +000035
36/* ---------------------------------------------------------------------
nethercote137bc552003-11-14 17:47:54 +000037 Error messages (for malformed tools)
njn25e49d8e72002-09-23 09:36:25 +000038 ------------------------------------------------------------------ */
39
nethercote137bc552003-11-14 17:47:54 +000040/* If the tool fails to define one or more of the required functions,
njn25e49d8e72002-09-23 09:36:25 +000041 * make it very clear what went wrong! */
42
fitzhardinge98abfc72003-12-16 02:05:15 +000043__attribute__ ((noreturn))
44void VG_(missing_tool_func) ( const Char* fn )
njn25e49d8e72002-09-23 09:36:25 +000045{
46 VG_(printf)(
nethercote137bc552003-11-14 17:47:54 +000047 "\nTool error:\n"
48 " The tool you have selected is missing the function `%s',\n"
njn25e49d8e72002-09-23 09:36:25 +000049 " which is required.\n\n",
50 fn);
njn67993252004-11-22 18:02:32 +000051 VG_(tool_panic)("Missing tool function");
njn25e49d8e72002-09-23 09:36:25 +000052}
53
54static __attribute__ ((noreturn))
daywalker3222e0a2003-09-18 01:39:50 +000055void malloc_panic ( const Char* fn )
njn3e884182003-04-15 13:03:23 +000056{
57 VG_(printf)(
nethercote137bc552003-11-14 17:47:54 +000058 "\nTool error:\n"
59 " The tool you have selected is missing the function `%s'\n"
njn3e884182003-04-15 13:03:23 +000060 " required because it is replacing malloc() et al.\n\n",
61 fn);
njn67993252004-11-22 18:02:32 +000062 VG_(tool_panic)("Missing tool function");
njn3e884182003-04-15 13:03:23 +000063}
64
njn308955f2003-05-21 10:48:24 +000065/*------------------------------------------------------------*/
66/*--- Replacing malloc et al ---*/
67/*------------------------------------------------------------*/
68
nethercotee1efb922004-07-10 16:01:52 +000069/* Default redzone size for CLIENT arena of Valgrind's malloc() */
njn308955f2003-05-21 10:48:24 +000070__attribute__ ((weak))
njn0e742df2004-11-30 13:26:29 +000071SizeT VG_(vg_malloc_redzone_szB) = 8;
njn308955f2003-05-21 10:48:24 +000072
njnd2252832004-11-26 10:53:33 +000073Bool VG_(tl_malloc_called_by_scheduler) = False;
njn308955f2003-05-21 10:48:24 +000074
nethercote137bc552003-11-14 17:47:54 +000075/* If the tool hasn't replaced malloc(), this one can be called from the
njn3e884182003-04-15 13:03:23 +000076 scheduler, for the USERREQ__MALLOC user request used by vg_libpthread.c.
77 (Nb: it cannot call glibc's malloc().) The lock variable ensures that the
78 scheduler is the only place this can be called from; this ensures that a
njn26f02512004-11-22 18:33:15 +000079 malloc()-replacing tool cannot forget to implement TL_(malloc)() or
80 TL_(free)(). */
njn3e884182003-04-15 13:03:23 +000081__attribute__ ((weak))
sewardj2a99cf62004-11-24 10:44:19 +000082void* TL_(malloc)( ThreadId tid, SizeT size )
njn3e884182003-04-15 13:03:23 +000083{
njnd2252832004-11-26 10:53:33 +000084 if (VG_(tl_malloc_called_by_scheduler))
nethercote2d5b8162004-08-11 09:40:52 +000085 return VG_(cli_malloc)(VG_MIN_MALLOC_SZB, size);
njn3e884182003-04-15 13:03:23 +000086 else
njn308955f2003-05-21 10:48:24 +000087 malloc_panic(__PRETTY_FUNCTION__);
njn3e884182003-04-15 13:03:23 +000088}
89
90__attribute__ ((weak))
sewardjb5f6f512005-03-10 23:59:00 +000091void TL_(free)( ThreadId tid, void* p )
njn3e884182003-04-15 13:03:23 +000092{
njn26f02512004-11-22 18:33:15 +000093 /* see comment for TL_(malloc)() above */
njnd2252832004-11-26 10:53:33 +000094 if (VG_(tl_malloc_called_by_scheduler))
njn3e884182003-04-15 13:03:23 +000095 VG_(cli_free)(p);
96 else
njn308955f2003-05-21 10:48:24 +000097 malloc_panic(__PRETTY_FUNCTION__);
njn3e884182003-04-15 13:03:23 +000098}
99
njn25e49d8e72002-09-23 09:36:25 +0000100/*--------------------------------------------------------------------*/
101/*--- end vg_defaults.c ---*/
102/*--------------------------------------------------------------------*/