Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mach_override.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <respindola@mozilla.com>2012-07-20 20:03:20 +0400
committerRafael Ávila de Espíndola <respindola@mozilla.com>2012-07-20 20:03:20 +0400
commit00ae6473f94dd343968fb05f0b8cfa290dd10e4c (patch)
tree8ecee6d06974f1be5f421910190e9fcb9738809b
parent4112f60a1c446f1dcec5b63c98deda73f36ac11b (diff)
Constant propagate kAllocateHigh.
-rw-r--r--mach_override/mach_override.c85
1 files changed, 31 insertions, 54 deletions
diff --git a/mach_override/mach_override.c b/mach_override/mach_override.c
index faaff77..bab278a 100644
--- a/mach_override/mach_override.c
+++ b/mach_override/mach_override.c
@@ -77,9 +77,6 @@ char kIslandTemplate[] = {
#endif
-#define kAllocateHigh 1
-#define kAllocateNormal 0
-
/**************************
*
* Data Types
@@ -90,7 +87,6 @@ char kIslandTemplate[] = {
typedef struct {
char instructions[sizeof(kIslandTemplate)];
- int allocatedHigh;
} BranchIsland;
/**************************
@@ -104,7 +100,6 @@ typedef struct {
mach_error_t
allocateBranchIsland(
BranchIsland **island,
- int allocateHigh,
void *originalFunctionAddress);
mach_error_t
@@ -240,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__);
@@ -282,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;
}
@@ -366,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
***************************************************************************/
@@ -376,60 +368,49 @@ mach_override_ptr(
mach_error_t
allocateBranchIsland(
BranchIsland **island,
- int allocateHigh,
void *originalFunctionAddress)
{
assert( island );
mach_error_t err = err_none;
- if( allocateHigh ) {
- if( !err ) {
- assert( sizeof( BranchIsland ) <= kPageSize );
+ if( !err ) {
+ assert( sizeof( BranchIsland ) <= kPageSize );
#if defined(__ppc__) || defined(__POWERPC__)
- vm_address_t first = 0xfeffffff;
- vm_address_t last = 0xfe000000 + kPageSize;
+ 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();
+ vm_address_t page = first;
+ int allocated = 0;
+ vm_map_t task_self = mach_task_self();
- while( !err && !allocated && page != last ) {
+ while( !err && !allocated && page != last ) {
- err = vm_allocate( task_self, &page, kPageSize, 0 );
- if( err == err_none )
- allocated = 1;
- else if( err == KERN_NO_SPACE ) {
+ err = vm_allocate( task_self, &page, kPageSize, 0 );
+ if( err == err_none )
+ allocated = 1;
+ else if( err == KERN_NO_SPACE ) {
#if defined(__x86_64__)
- page -= kPageSize;
+ page -= kPageSize;
#else
- page += kPageSize;
+ page += kPageSize;
#endif
- err = err_none;
- }
+ 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
+ if( allocated )
+ *island = (BranchIsland*) page;
+ else if( !allocated && !err )
err = KERN_NO_SPACE;
}
- if( !err )
- (**island).allocatedHigh = allocateHigh;
-
+
return err;
}
@@ -447,19 +428,15 @@ freeBranchIsland(
{
assert( island );
assert( (*(long*)&island->instructions[0]) == kIslandTemplate[0] );
- assert( island->allocatedHigh );
mach_error_t err = err_none;
- if( island->allocatedHigh ) {
- if( !err ) {
- assert( sizeof( BranchIsland ) <= kPageSize );
- err = vm_deallocate(
- mach_task_self(),
- (vm_address_t) island, kPageSize );
- }
- } else {
- free( island );
+
+ if( !err ) {
+ assert( sizeof( BranchIsland ) <= kPageSize );
+ err = vm_deallocate(
+ mach_task_self(),
+ (vm_address_t) island, kPageSize );
}
return err;