mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-07 12:44:45 +00:00
lot to one. This required two basic changes. 1. Tools are responsible for telling the tool about any functions they provide that the tool may call. This includes basic functions like TL_(instrument)(), functions that assist core services such as TL_(pp_Error)(), and malloc-replacement-related functions like TL_(malloc)(). 2. Tools that replace malloc now specify the size of the heap block redzones through an arg to the VG_(malloc_funcs)() function, rather than with a variable VG_(vg_malloc_redzone_szB). One consequence of these changes is that VG_(tool_init_dlsym)() no longer needs to be generated by gen_toolint.pl. There are a number of further improvements that could follow on from this one. - Avoid the confusingly different definitions of the TL_() macro in the core vs. for tools. Indeed, the functions provided by the tools now don't need to use the TL_() macro at all, as they can have arbitrary names. - Remove a lot of the auto-generated stuff in vg_toolint.c and vg_toolint.h (indeed, it might be possible to not auto-generate these at all, which would be nice). - The handling of VgToolInterface is currently split across vg_needs.c and vg_toolint.c, which isn't nice. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3487
97 lines
3.3 KiB
C
97 lines
3.3 KiB
C
|
|
/*--------------------------------------------------------------------*/
|
|
/*--- Default panicky definitions of template functions that tools ---*/
|
|
/*--- should override. ---*/
|
|
/*--- vg_defaults.c ---*/
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
/*
|
|
This file is part of Valgrind, a dynamic binary instrumentation
|
|
framework.
|
|
|
|
Copyright (C) 2000-2005 Nicholas Nethercote
|
|
njn25@cam.ac.uk
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307, USA.
|
|
|
|
The GNU General Public License is contained in the file COPYING.
|
|
*/
|
|
|
|
|
|
#include "core.h"
|
|
|
|
/* ---------------------------------------------------------------------
|
|
Error messages (for malformed tools)
|
|
------------------------------------------------------------------ */
|
|
|
|
/* If the tool fails to define one or more of the required functions,
|
|
* make it very clear what went wrong! */
|
|
|
|
__attribute__ ((noreturn))
|
|
void VG_(missing_tool_func) ( const Char* fn )
|
|
{
|
|
VG_(printf)(
|
|
"\nTool error:\n"
|
|
" The tool you have selected is missing the function `%s',\n"
|
|
" which is required.\n\n",
|
|
fn);
|
|
VG_(tool_panic)("Missing tool function");
|
|
}
|
|
|
|
static __attribute__ ((noreturn))
|
|
void malloc_panic ( const Char* fn )
|
|
{
|
|
VG_(printf)(
|
|
"\nTool error:\n"
|
|
" The tool you have selected is missing the function `%s'\n"
|
|
" required because it is replacing malloc() et al.\n\n",
|
|
fn);
|
|
VG_(tool_panic)("Missing tool function");
|
|
}
|
|
|
|
/*------------------------------------------------------------*/
|
|
/*--- Replacing malloc et al ---*/
|
|
/*------------------------------------------------------------*/
|
|
|
|
Bool VG_(tl_malloc_called_deliberately) = False;
|
|
|
|
/* If the tool hasn't replaced malloc(), this one can be called
|
|
deliberately. The lock variable ensures that this isn't called by
|
|
accident, which could happen if a malloc()-replacing tool forgot to
|
|
implement TL_(malloc)() or TL_(free)(). */
|
|
__attribute__ ((weak))
|
|
void* TL_(malloc)( ThreadId tid, SizeT size )
|
|
{
|
|
if (VG_(tl_malloc_called_deliberately))
|
|
return VG_(cli_malloc)(VG_MIN_MALLOC_SZB, size);
|
|
else
|
|
malloc_panic(__PRETTY_FUNCTION__);
|
|
}
|
|
|
|
__attribute__ ((weak))
|
|
void TL_(free)( ThreadId tid, void* p )
|
|
{
|
|
/* see comment for TL_(malloc)() above */
|
|
if (VG_(tl_malloc_called_deliberately))
|
|
VG_(cli_free)(p);
|
|
else
|
|
malloc_panic(__PRETTY_FUNCTION__);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
/*--- end vg_defaults.c ---*/
|
|
/*--------------------------------------------------------------------*/
|