|
From: Nicholas N. <nj...@ca...> - 2004-07-15 16:28:42
|
CVS commit by nethercote:
If new/new[] fails and should throw an exception, abort instead, since we can't
throw exceptions.
M +27 -7 vg_replace_malloc.c.base 1.3
--- valgrind/coregrind/vg_replace_malloc.c.base #1.2:1.3
@@ -64,4 +64,6 @@
ret VG_INTERCEPT(soname:libc.so.6, ##name) args
+extern void _exit(int);
+
/*------------------------------------------------------------*/
/*--- Replacing malloc() et al ---*/
@@ -107,15 +109,35 @@
return v; \
}
+
+#define ALLOC2(fff, vgfff) \
+LIBALIAS(void *, fff, (Int n)) \
+{ \
+ void* v; \
+ \
+ MALLOC_TRACE(#fff "(%d)", n ); \
+ MAYBE_SLOPPIFY(n); \
+ if (!init_done) init(); \
+ \
+ v = (void*)VALGRIND_NON_SIMD_CALL1( info.sk_##vgfff, n ); \
+ MALLOC_TRACE(" = %p", v ); \
+ if (NULL == v) { \
+ VALGRIND_PRINTF_BACKTRACE( \
+ "new/new[] failed and should throw an exception, but Valgrind\n" \
+ " cannot throw exceptions and so is aborting instead. Sorry."); \
+ _exit(1); \
+ } \
+ return v; \
+}
ALLOC( malloc, malloc );
-ALLOC( __builtin_new, __builtin_new );
-ALLOC( _Znwj, __builtin_new );
+ALLOC2(__builtin_new, __builtin_new );
+ALLOC2(_Znwj, __builtin_new );
// operator new(unsigned, std::nothrow_t const&)
ALLOC( _ZnwjRKSt9nothrow_t, __builtin_new );
-ALLOC( __builtin_vec_new, __builtin_vec_new );
-ALLOC( _Znaj, __builtin_vec_new );
+ALLOC2(__builtin_vec_new, __builtin_vec_new );
+ALLOC2(_Znaj, __builtin_vec_new );
-// operator new[](unsigned, std::nothrow_t const&
+// operator new[](unsigned, std::nothrow_t const&)
ALLOC( _ZnajRKSt9nothrow_t, __builtin_vec_new );
@@ -246,6 +268,4 @@
/* Bomb out if we get any of these. */
-extern void _exit(int);
-
static void panic(const char *str)
{
|