Add Valgrind poison stubs
This commit is contained in:
parent
a02f78a171
commit
07176ece8b
22
SConstruct
22
SConstruct
|
@ -757,6 +757,27 @@ int main(int, char **){{
|
|||
if self.Compile(context, text=text.format(type=','.join(('int',)*count), value=','.join(('0',)*count)), msg='whether compiler handles 2-element tuples'):
|
||||
raise SCons.Errors.StopError("Compiler cannot handle tuples of 20 elements. Raise the template instantiation depth.")
|
||||
raise SCons.Errors.StopError("Compiler cannot handle tuples of 2 elements.")
|
||||
@_implicit_test
|
||||
def check_poison_valgrind(self,context):
|
||||
context.Display('%s: checking %s...' % (self.msgprefix, 'whether to use Valgrind poisoning'))
|
||||
r = self.user_settings.poison == 'valgrind'
|
||||
context.Result(r)
|
||||
if not r:
|
||||
return
|
||||
text = '''
|
||||
#include "poison.h"
|
||||
int main(int argc,char**) {
|
||||
DXX_MAKE_MEM_UNDEFINED(&argc, sizeof(argc));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
if self.Compile(context, text=text, msg='whether Valgrind memcheck header works', successflags={'CPPDEFINES' : ['DXX_HAVE_POISON_VALGRIND']}):
|
||||
return True
|
||||
raise SCons.Errors.StopError("Valgrind poison requested, but <valgrind/memcheck.h> does not work.")
|
||||
@_custom_test
|
||||
def _check_poison_method(self,context):
|
||||
if self.check_poison_valgrind(context):
|
||||
context.sconf.Define('DXX_HAVE_POISON')
|
||||
|
||||
class LazyObjectConstructor:
|
||||
def __lazy_objects(self,name,source):
|
||||
|
@ -943,6 +964,7 @@ class DXXCommon(LazyObjectConstructor):
|
|||
'variable': self._enum_variable,
|
||||
'arguments': (
|
||||
('host_platform', 'linux' if sys.platform == 'linux2' else sys.platform, 'cross-compile to specified platform', {'allowed_values' : ['win32', 'darwin', 'linux']}),
|
||||
('poison', 'none', 'method for poisoning free memory', {'allowed_values' : ('none', 'valgrind')}),
|
||||
),
|
||||
},
|
||||
{
|
||||
|
|
51
common/include/poison.h
Normal file
51
common/include/poison.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef DXX_HAVE_POISON_VALGRIND
|
||||
#include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
static inline void DXX_MAKE_MEM_UNDEFINED(T *b, unsigned long l)
|
||||
{
|
||||
(void)b;(void)l;
|
||||
#ifdef DXX_HAVE_POISON_VALGRIND
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(b, l);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline void DXX_MAKE_MEM_UNDEFINED(T *b, T *e)
|
||||
{
|
||||
DXX_MAKE_MEM_UNDEFINED(b, e - b);
|
||||
}
|
||||
|
||||
template <typename T, typename V>
|
||||
static inline void _DXX_POISON_MEMORY_RANGE(T b, T e, const V &v)
|
||||
{
|
||||
#ifdef DXX_HAVE_POISON
|
||||
int store = 0;
|
||||
#ifdef DXX_HAVE_POISON_VALGRIND
|
||||
store |= RUNNING_ON_VALGRIND;
|
||||
#endif
|
||||
if (!store)
|
||||
return;
|
||||
for (; b != e; ++b)
|
||||
*b = v;
|
||||
#else
|
||||
(void)b;(void)e;(void)v;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T, typename V>
|
||||
static inline void DXX_POISON_MEMORY(T b, unsigned long l, const V &v)
|
||||
{
|
||||
_DXX_POISON_MEMORY_RANGE(b, b + l, v);
|
||||
DXX_MAKE_MEM_UNDEFINED(b, l);
|
||||
}
|
||||
|
||||
template <typename T, typename V>
|
||||
static inline void DXX_POISON_MEMORY(T b, T e, const V &v)
|
||||
{
|
||||
_DXX_POISON_MEMORY_RANGE(b, e, v);
|
||||
DXX_MAKE_MEM_UNDEFINED(b, e);
|
||||
}
|
|
@ -26,6 +26,8 @@
|
|||
#include "strutil.h"
|
||||
#include "ignorecase.h"
|
||||
|
||||
#include "poison.h"
|
||||
|
||||
static const file_extension_t archive_exts[] = { "dxa", "" };
|
||||
|
||||
char *PHYSFSX_fgets(char *buf, size_t n, PHYSFS_file *const fp)
|
||||
|
@ -59,7 +61,8 @@ char *PHYSFSX_fgets(char *buf, size_t n, PHYSFS_file *const fp)
|
|||
++p;
|
||||
}
|
||||
PHYSFS_seek(fp, t + (p - buf) + 1);
|
||||
std::fill(p, buf + n, 0);
|
||||
*p = 0;
|
||||
DXX_POISON_MEMORY(p + 1, buf + n, 0xcc);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue