Fix up preload code so that on Android it doesn't try to call anything

else -- that seems to give a runtime link failure.  In particular,
avoid calling _exit, getpagesize or __libc_freeres.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11887
This commit is contained in:
Julian Seward 2011-07-12 13:33:00 +00:00
parent 1db7ec42de
commit 5eabf446b4
3 changed files with 58 additions and 24 deletions

View File

@ -83,8 +83,31 @@
executable too.
*/
/* Call here to exit if we can't continue. On Android we can't call
_exit for some reason, so we have to blunt-instrument it. */
__attribute__ ((__noreturn__))
extern void _exit(int);
static inline void my_exit ( int x )
{
# if defined(VGPV_arm_linux_android)
__asm__ __volatile__(".word 0xFFFFFFFF");
while (1) {}
# else
extern void _exit(int status);
_exit(x)
# endif
}
/* Same problem with getpagesize. */
static inline int my_getpagesize ( void ) {
# if defined(VGPV_arm_linux_android)
return 4096; /* kludge - link failure on Android, for some reason */
# else
extern int getpagesize (void);
return getpagesize();
# endif
}
/* Compute the high word of the double-length unsigned product of U
@ -199,7 +222,7 @@ static void init(void);
"new/new[] failed and should throw an exception, but Valgrind\n"); \
VALGRIND_PRINTF_BACKTRACE( \
" cannot throw exceptions and so is aborting instead. Sorry.\n"); \
_exit(1); \
my_exit(1); \
} \
return v; \
}
@ -524,11 +547,6 @@ ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign);
/*---------------------- valloc ----------------------*/
static int local__getpagesize ( void ) {
extern int getpagesize (void);
return getpagesize();
}
#define VALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT size ); \
@ -536,7 +554,7 @@ static int local__getpagesize ( void ) {
{ \
static int pszB = 0; \
if (pszB == 0) \
pszB = local__getpagesize(); \
pszB = my_getpagesize(); \
return VG_REPLACE_FUNCTION_ZU(VG_Z_LIBC_SONAME,memalign) \
((SizeT)pszB, size); \
}
@ -547,9 +565,8 @@ static int local__getpagesize ( void ) {
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( void *zone, SizeT size ) \
{ \
static int pszB = 0; \
extern int getpagesize (void); \
if (pszB == 0) \
pszB = getpagesize(); \
pszB = my_getpagesize(); \
return VG_REPLACE_FUNCTION_ZU(VG_Z_LIBC_SONAME,memalign) \
((SizeT)pszB, size); \
}
@ -674,7 +691,7 @@ MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
static void panic(const char *str)
{
VALGRIND_PRINTF_BACKTRACE("Program aborting because of call to %s\n", str);
_exit(99);
my_exit(99);
*(volatile int *)0 = 'x';
}

View File

@ -56,10 +56,10 @@
void VG_NOTIFY_ON_LOAD(freeres)( void );
void VG_NOTIFY_ON_LOAD(freeres)( void )
{
#if !defined(__UCLIBC__)
# if !defined(__UCLIBC__) && !defined(VGPV_arm_linux_android)
extern void __libc_freeres(void);
__libc_freeres();
#endif
# endif
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default */,
VG_USERREQ__LIBC_FREERES_DONE,
0, 0, 0, 0, 0);

View File

@ -53,6 +53,7 @@
THEY RUN ON THE SIMD CPU!
------------------------------------------------------------------ */
/* Figure out if [dst .. dst+dstlen-1] overlaps with
[src .. src+srclen-1].
We assume that the address ranges do not wrap around
@ -60,7 +61,7 @@
are not accessible and the program will segfault in this
circumstance, presumably).
*/
static __inline__
static inline
Bool is_overlap ( void* dst, const void* src, SizeT dstlen, SizeT srclen )
{
Addr loS, hiS, loD, hiD;
@ -87,6 +88,22 @@ Bool is_overlap ( void* dst, const void* src, SizeT dstlen, SizeT srclen )
}
}
/* Call here to exit if we can't continue. On Android we can't call
_exit for some reason, so we have to blunt-instrument it. */
__attribute__ ((__noreturn__))
static inline void my_exit ( int x )
{
# if defined(VGPV_arm_linux_android)
__asm__ __volatile__(".word 0xFFFFFFFF");
while (1) {}
# else
extern void _exit(int status);
_exit(x)
# endif
}
// This is a macro rather than a function because we don't want to have an
// extra function in the stack trace.
#define RECORD_OVERLAP_ERROR(s, src, dst, len) \
@ -421,8 +438,10 @@ STRNCMP(VG_Z_DYLD, strncmp)
return 0; \
}
#if !defined(VGPV_arm_linux_android)
STRCASECMP(VG_Z_LIBC_SONAME, strcasecmp)
#if defined(VGO_linux)
#endif
#if defined(VGO_linux) && !defined(VGPV_arm_linux_android)
STRCASECMP(VG_Z_LIBC_SONAME, __GI_strcasecmp)
#endif
@ -448,8 +467,10 @@ STRCASECMP(VG_Z_LIBC_SONAME, __GI_strcasecmp)
} \
}
#if !defined(VGPV_arm_linux_android)
STRNCASECMP(VG_Z_LIBC_SONAME, strncasecmp)
#if defined(VGO_linux)
#endif
#if defined(VGO_linux) && !defined(VGPV_arm_linux_android)
STRNCASECMP(VG_Z_LIBC_SONAME, __GI_strncasecmp)
#elif defined(VGO_darwin)
STRNCASECMP(VG_Z_DYLD, strncasecmp)
@ -799,7 +820,6 @@ BCOPY(VG_Z_DYLD, bcopy)
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
(void *dstV, const void *srcV, SizeT n, SizeT destlen) \
{ \
extern void _exit(int status); \
SizeT i; \
Char* dst = (Char*)dstV; \
Char* src = (Char*)srcV; \
@ -819,7 +839,7 @@ BCOPY(VG_Z_DYLD, bcopy)
VALGRIND_PRINTF_BACKTRACE( \
"*** memmove_chk: buffer overflow detected ***: " \
"program terminated\n"); \
_exit(127); \
my_exit(127); \
/*NOTREACHED*/ \
return NULL; \
}
@ -870,7 +890,6 @@ GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, __GI___rawmemchr)
char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
(char* dst, const char* src, SizeT len) \
{ \
extern void _exit(int status); \
char* ret = dst; \
if (! len) \
goto badness; \
@ -882,7 +901,7 @@ GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, __GI___rawmemchr)
VALGRIND_PRINTF_BACKTRACE( \
"*** strcpy_chk: buffer overflow detected ***: " \
"program terminated\n"); \
_exit(127); \
my_exit(127); \
/*NOTREACHED*/ \
return NULL; \
}
@ -898,7 +917,6 @@ GLIBC25___STRCPY_CHK(VG_Z_LIBC_SONAME, __strcpy_chk)
char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
(char* dst, const char* src, SizeT len) \
{ \
extern void _exit(int status); \
if (! len) \
goto badness; \
while ((*dst++ = *src++) != '\0') \
@ -909,7 +927,7 @@ GLIBC25___STRCPY_CHK(VG_Z_LIBC_SONAME, __strcpy_chk)
VALGRIND_PRINTF_BACKTRACE( \
"*** stpcpy_chk: buffer overflow detected ***: " \
"program terminated\n"); \
_exit(127); \
my_exit(127); \
/*NOTREACHED*/ \
return NULL; \
}
@ -962,7 +980,6 @@ GLIBC25_MEMPCPY(VG_Z_LD_SO_1, mempcpy) /* ld.so.1 */
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
(void* dst, const void* src, SizeT len, SizeT dstlen ) \
{ \
extern void _exit(int status); \
register char *d; \
register char *s; \
\
@ -992,7 +1009,7 @@ GLIBC25_MEMPCPY(VG_Z_LD_SO_1, mempcpy) /* ld.so.1 */
VALGRIND_PRINTF_BACKTRACE( \
"*** memcpy_chk: buffer overflow detected ***: " \
"program terminated\n"); \
_exit(127); \
my_exit(127); \
/*NOTREACHED*/ \
return NULL; \
}