diff options
author | badea@adobe.com <badea@adobe.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 17:42:26 +0000 |
---|---|---|
committer | badea@adobe.com <badea@adobe.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 17:42:26 +0000 |
commit | ac0e0898ff5c7dde8f7654db6bdf474601f26f5c (patch) | |
tree | a7e4a9c7df0507844a19702ec5db4cb9d29c5c7a /third_party/mach_override | |
parent | 164494d856e3833b7f9f78014da0f9d86cb470f6 (diff) | |
download | chromium_src-ac0e0898ff5c7dde8f7654db6bdf474601f26f5c.zip chromium_src-ac0e0898ff5c7dde8f7654db6bdf474601f26f5c.tar.gz chromium_src-ac0e0898ff5c7dde8f7654db6bdf474601f26f5c.tar.bz2 |
Roll mach_override to a newer version.
See https://code.google.com/p/chromium/issues/detail?id=138535#c5
Review URL: https://chromiumcodereview.appspot.com/11360250
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/mach_override')
-rw-r--r-- | third_party/mach_override/README.chromium | 6 | ||||
-rw-r--r-- | third_party/mach_override/mach_override.c | 109 |
2 files changed, 35 insertions, 80 deletions
diff --git a/third_party/mach_override/README.chromium b/third_party/mach_override/README.chromium index f13edb9..ae82f29 100644 --- a/third_party/mach_override/README.chromium +++ b/third_party/mach_override/README.chromium @@ -2,15 +2,15 @@ Name: mach_override Short Name: Part of the mach_star project Version: Unknown URL: https://github.com/rentzsch/mach_star -Date: 10/31/2012 -Revision: 34048d938af230c2c801e02d6c312f856ac4150a +Date: 11/14/2012 +Revision: 10860416803280f05cbe20f97a3ec02a7c697bf4 License: MIT Security Critical: Yes Description: This is the mach_override part of mach_star, namely: -https://github.com/rentzsch/mach_star/tree/34048d938af230c2c801e02d6c312f856ac4150a +https://github.com/rentzsch/mach_star/tree/10860416803280f05cbe20f97a3ec02a7c697bf4 This package is used to replace framework functions with different implementations at run time. diff --git a/third_party/mach_override/mach_override.c b/third_party/mach_override/mach_override.c index 64dd0ab..549409d 100644 --- a/third_party/mach_override/mach_override.c +++ b/third_party/mach_override/mach_override.c @@ -23,6 +23,7 @@ #pragma mark - #pragma mark (Constants) +#define kPageSize 4096 #if defined(__ppc__) || defined(__POWERPC__) long kIslandTemplate[] = { @@ -76,9 +77,6 @@ char kIslandTemplate[] = { #endif -#define kAllocateHigh 1 -#define kAllocateNormal 0 - /************************** * * Data Types @@ -89,7 +87,6 @@ char kIslandTemplate[] = { typedef struct { char instructions[sizeof(kIslandTemplate)]; - int allocatedHigh; } BranchIsland; /************************** @@ -103,7 +100,6 @@ typedef struct { mach_error_t allocateBranchIsland( BranchIsland **island, - int allocateHigh, void *originalFunctionAddress); mach_error_t @@ -158,12 +154,10 @@ fixupInstructions( #if defined(__i386__) || defined(__x86_64__) mach_error_t makeIslandExecutable(void *address) { mach_error_t err = err_none; - vm_size_t pageSize; - host_page_size( mach_host_self(), &pageSize ); - uintptr_t page = (uintptr_t)address & ~(uintptr_t)(pageSize-1); + uintptr_t page = (uintptr_t)address & ~(uintptr_t)(kPageSize-1); int e = err_none; - e |= mprotect((void *)page, pageSize, PROT_EXEC | PROT_READ | PROT_WRITE); - e |= msync((void *)page, pageSize, MS_INVALIDATE ); + e |= mprotect((void *)page, kPageSize, PROT_EXEC | PROT_READ | PROT_WRITE); + e |= msync((void *)page, kPageSize, MS_INVALIDATE ); if (e) { err = err_cannot_override; } @@ -241,7 +235,7 @@ mach_override_ptr( // Allocate and target the escape island to the overriding function. BranchIsland *escapeIsland = NULL; if( !err ) - err = allocateBranchIsland( &escapeIsland, kAllocateHigh, originalFunctionAddress ); + err = allocateBranchIsland( &escapeIsland, originalFunctionAddress ); if (err) fprintf(stderr, "err = %x %s:%d\n", err, __FILE__, __LINE__); @@ -283,7 +277,7 @@ mach_override_ptr( // technically our original function. BranchIsland *reentryIsland = NULL; if( !err && originalFunctionReentryIsland ) { - err = allocateBranchIsland( &reentryIsland, kAllocateHigh, escapeIsland); + err = allocateBranchIsland( &reentryIsland, escapeIsland); if( !err ) *originalFunctionReentryIsland = reentryIsland; } @@ -367,9 +361,6 @@ mach_override_ptr( Implementation: Allocates memory for a branch island. @param island <- The allocated island. - @param allocateHigh -> Whether to allocate the island at the end of the - address space (for use with the branch absolute - instruction). @result <- mach_error_t ***************************************************************************/ @@ -377,63 +368,42 @@ mach_override_ptr( mach_error_t allocateBranchIsland( BranchIsland **island, - int allocateHigh, void *originalFunctionAddress) { assert( island ); - mach_error_t err = err_none; - - if( allocateHigh ) { - vm_size_t pageSize; - err = host_page_size( mach_host_self(), &pageSize ); - if( !err ) { - assert( sizeof( BranchIsland ) <= pageSize ); + assert( sizeof( BranchIsland ) <= kPageSize ); #if defined(__ppc__) || defined(__POWERPC__) - vm_address_t first = 0xfeffffff; - vm_address_t last = 0xfe000000 + pageSize; + vm_address_t first = 0xfeffffff; + vm_address_t last = 0xfe000000 + kPageSize; #elif defined(__x86_64__) - vm_address_t first = ((uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1)) | ((uint64_t)1 << 31); // start in the middle of the page? - vm_address_t last = 0x0; + vm_address_t first = ((uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1)) | ((uint64_t)1 << 31); // start in the middle of the page? + vm_address_t last = 0x0; #else - vm_address_t first = 0xffc00000; - vm_address_t last = 0xfffe0000; + vm_address_t first = 0xffc00000; + vm_address_t last = 0xfffe0000; #endif - vm_address_t page = first; - int allocated = 0; - vm_map_t task_self = mach_task_self(); - - while( !err && !allocated && page != last ) { - - err = vm_allocate( task_self, &page, pageSize, 0 ); - if( err == err_none ) - allocated = 1; - else if( err == KERN_NO_SPACE ) { + vm_address_t page = first; + vm_map_t task_self = mach_task_self(); + + while( page != last ) { + mach_error_t err = vm_allocate( task_self, &page, kPageSize, 0 ); + if( err == err_none ) { + *island = (BranchIsland*) page; + return err_none; + } + if( err != KERN_NO_SPACE ) + return err; #if defined(__x86_64__) - page -= pageSize; + page -= kPageSize; #else - page += pageSize; + page += kPageSize; #endif - err = err_none; - } - } - if( allocated ) - *island = (BranchIsland*) page; - else if( !allocated && !err ) - err = KERN_NO_SPACE; - } - } else { - void *block = malloc( sizeof( BranchIsland ) ); - if( block ) - *island = block; - else - err = KERN_NO_SPACE; + err = err_none; } - if( !err ) - (**island).allocatedHigh = allocateHigh; - - return err; + + return KERN_NO_SPACE; } /***************************************************************************//** @@ -450,24 +420,9 @@ freeBranchIsland( { assert( island ); assert( (*(long*)&island->instructions[0]) == kIslandTemplate[0] ); - assert( island->allocatedHigh ); - - mach_error_t err = err_none; - - if( island->allocatedHigh ) { - vm_size_t pageSize; - err = host_page_size( mach_host_self(), &pageSize ); - if( !err ) { - assert( sizeof( BranchIsland ) <= pageSize ); - err = vm_deallocate( - mach_task_self(), - (vm_address_t) island, pageSize ); - } - } else { - free( island ); - } - - return err; + assert( sizeof( BranchIsland ) <= kPageSize ); + return vm_deallocate( mach_task_self(), (vm_address_t) island, + kPageSize ); } /***************************************************************************//** |