[llvm-commits] [compiler-rt] r148115 - in /compiler-rt/trunk/lib/asan/mach_override: mach_override.c mach_override.h
Alexander Potapenko
glider at google.com
Fri Jan 13 07:31:38 PST 2012
Author: glider
Date: Fri Jan 13 09:31:37 2012
New Revision: 148115
URL: http://llvm.org/viewvc/llvm-project?rev=148115&view=rev
Log:
Add __asan_mach_override_ptr_custom, which allows to inject a custom memory allocator into mach_override_ptr().
Modified:
compiler-rt/trunk/lib/asan/mach_override/mach_override.c
compiler-rt/trunk/lib/asan/mach_override/mach_override.h
Modified: compiler-rt/trunk/lib/asan/mach_override/mach_override.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/mach_override.c?rev=148115&r1=148114&r2=148115&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/mach_override/mach_override.c (original)
+++ compiler-rt/trunk/lib/asan/mach_override/mach_override.c Fri Jan 13 09:31:37 2012
@@ -114,6 +114,14 @@
freeBranchIsland(
BranchIsland *island ) __attribute__((visibility("hidden")));
+ mach_error_t
+defaultIslandMalloc(
+ void **ptr, size_t unused_size, void *hint) __attribute__((visibility("hidden")));
+
+ mach_error_t
+defaultIslandFree(
+ void *ptr) __attribute__((visibility("hidden")));
+
#if defined(__ppc__) || defined(__POWERPC__)
mach_error_t
setBranchIslandTarget(
@@ -175,12 +183,38 @@
}
#endif
+ mach_error_t
+defaultIslandMalloc(
+ void **ptr, size_t unused_size, void *hint) {
+ return allocateBranchIsland( (BranchIsland**)ptr, kAllocateHigh, hint );
+}
+ mach_error_t
+defaultIslandFree(
+ void *ptr) {
+ return freeBranchIsland(ptr);
+}
+
mach_error_t
__asan_mach_override_ptr(
void *originalFunctionAddress,
const void *overrideFunctionAddress,
void **originalFunctionReentryIsland )
{
+ return __asan_mach_override_ptr_custom(originalFunctionAddress,
+ overrideFunctionAddress,
+ originalFunctionReentryIsland,
+ defaultIslandMalloc,
+ defaultIslandFree);
+}
+
+ mach_error_t
+__asan_mach_override_ptr_custom(
+ void *originalFunctionAddress,
+ const void *overrideFunctionAddress,
+ void **originalFunctionReentryIsland,
+ island_malloc *alloc,
+ island_free *dealloc)
+{
assert( originalFunctionAddress );
assert( overrideFunctionAddress );
@@ -276,10 +310,9 @@
// Allocate and target the escape island to the overriding function.
BranchIsland *escapeIsland = NULL;
- if( !err )
- err = allocateBranchIsland( &escapeIsland, kAllocateHigh, originalFunctionAddress );
- if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__);
-
+ if( !err )
+ err = alloc( (void**)&escapeIsland, sizeof(BranchIsland), originalFunctionAddress );
+ if ( err ) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__);
#if defined(__ppc__) || defined(__POWERPC__)
if( !err )
@@ -319,7 +352,7 @@
// technically our original function.
BranchIsland *reentryIsland = NULL;
if( !err && originalFunctionReentryIsland ) {
- err = allocateBranchIsland( &reentryIsland, kAllocateHigh, escapeIsland);
+ err = alloc( (void**)&reentryIsland, sizeof(BranchIsland), escapeIsland);
if( !err )
*originalFunctionReentryIsland = reentryIsland;
}
@@ -383,9 +416,9 @@
// Clean up on error.
if( err ) {
if( reentryIsland )
- freeBranchIsland( reentryIsland );
+ dealloc( reentryIsland );
if( escapeIsland )
- freeBranchIsland( escapeIsland );
+ dealloc( escapeIsland );
}
#ifdef DEBUG_DISASM
Modified: compiler-rt/trunk/lib/asan/mach_override/mach_override.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/mach_override.h?rev=148115&r1=148114&r2=148115&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/mach_override/mach_override.h (original)
+++ compiler-rt/trunk/lib/asan/mach_override/mach_override.h Fri Jan 13 09:31:37 2012
@@ -85,6 +85,19 @@
const void *overrideFunctionAddress,
void **originalFunctionReentryIsland );
+// Allow to use custom allocation and deallocation routines with mach_override_ptr().
+// This should help to speed up the things on x86_64.
+typedef mach_error_t island_malloc( void **ptr, size_t size, void *hint );
+typedef mach_error_t island_free( void *ptr );
+
+ mach_error_t
+__asan_mach_override_ptr_custom(
+ void *originalFunctionAddress,
+ const void *overrideFunctionAddress,
+ void **originalFunctionReentryIsland,
+ island_malloc *alloc,
+ island_free *dealloc );
+
/************************************************************************************//**
More information about the llvm-commits
mailing list