The code instrumented with ASan may have its own instance of the

mach_override library.
In this case chances are that functions from it will be called from
mach_override_ptr() during ASan initialization.
This may lead to crashes (if those functions are instrumented) or
incorrect behavior (if the implementations differ).

The attached patch renames mach_override_ptr() into
__asan_mach_override_ptr() and makes the rest of the mach_override
internals hidden.
The corresponding AddressSanitizer bug is
http://code.google.com/p/address-sanitizer/issues/detail?id=22

Patch by glider@google.com

llvm-svn: 147303
This commit is contained in:
Kostya Serebryany 2011-12-28 01:08:14 +00:00
parent 46c70d33d7
commit 8b981c2564
4 changed files with 19 additions and 15 deletions

View File

@ -39,15 +39,15 @@
#define WRAPPER_NAME(x) "wrap_"#x
#define OVERRIDE_FUNCTION(oldfunc, newfunc) \
CHECK(0 == mach_override_ptr((void*)(oldfunc), \
(void*)(newfunc), \
(void**)&real_##oldfunc)); \
CHECK(0 == __asan_mach_override_ptr((void*)(oldfunc), \
(void*)(newfunc), \
(void**)&real_##oldfunc)); \
CHECK(real_##oldfunc != NULL);
#define OVERRIDE_FUNCTION_IF_EXISTS(oldfunc, newfunc) \
do { mach_override_ptr((void*)(oldfunc), \
(void*)(newfunc), \
(void**)&real_##oldfunc); } while (0)
do { __asan_mach_override_ptr((void*)(oldfunc), \
(void*)(newfunc), \
(void**)&real_##oldfunc); } while (0)
#define INTERCEPT_FUNCTION(func) \
OVERRIDE_FUNCTION(func, WRAP(func))

View File

@ -4,4 +4,6 @@
-- The files are guarded with #ifdef __APPLE__
-- some opcodes are added in order to parse the library functions on Lion
-- fixupInstructions() is extended to relocate relative calls, not only jumps
-- mach_override_ptr is renamed to __asan_mach_override_ptr and
other functions are marked as hidden.

View File

@ -108,18 +108,18 @@ typedef struct {
allocateBranchIsland(
BranchIsland **island,
int allocateHigh,
void *originalFunctionAddress);
void *originalFunctionAddress) __attribute__((visibility("hidden")));
mach_error_t
freeBranchIsland(
BranchIsland *island );
BranchIsland *island ) __attribute__((visibility("hidden")));
#if defined(__ppc__) || defined(__POWERPC__)
mach_error_t
setBranchIslandTarget(
BranchIsland *island,
const void *branchTo,
long instruction );
long instruction ) __attribute__((visibility("hidden")));
#endif
#if defined(__i386__) || defined(__x86_64__)
@ -127,11 +127,11 @@ mach_error_t
setBranchIslandTarget_i386(
BranchIsland *island,
const void *branchTo,
char* instructions );
char* instructions ) __attribute__((visibility("hidden")));
void
atomic_mov64(
uint64_t *targetAddress,
uint64_t value );
uint64_t value ) __attribute__((visibility("hidden")));
static Boolean
eatKnownInstructions(
@ -140,7 +140,7 @@ eatKnownInstructions(
int *howManyEaten,
char *originalInstructions,
int *originalInstructionCount,
uint8_t *originalInstructionSizes );
uint8_t *originalInstructionSizes ) __attribute__((visibility("hidden")));
static void
fixupInstructions(
@ -148,7 +148,7 @@ fixupInstructions(
void *escapeIsland,
void *instructionsToFix,
int instructionCount,
uint8_t *instructionSizes );
uint8_t *instructionSizes ) __attribute__((visibility("hidden")));
#endif
/*******************************************************************************
@ -176,7 +176,7 @@ mach_error_t makeIslandExecutable(void *address) {
#endif
mach_error_t
mach_override_ptr(
__asan_mach_override_ptr(
void *originalFunctionAddress,
const void *overrideFunctionAddress,
void **originalFunctionReentryIsland )

View File

@ -77,8 +77,10 @@
************************************************************************************/
// We're prefixing mach_override_ptr() with "__asan_" to avoid name conflicts with other
// mach_override_ptr() implementations that may appear in the client program.
mach_error_t
mach_override_ptr(
__asan_mach_override_ptr(
void *originalFunctionAddress,
const void *overrideFunctionAddress,
void **originalFunctionReentryIsland );