| OLD | NEW |
| (Empty) | |
| 1 diff --git a/third_party/mach_override/README.chromium b/third_party/mach_overri
de/README.chromium |
| 2 index 8a7c3fd79e0b..8d1d95ae0037 100644 |
| 3 --- a/third_party/mach_override/README.chromium |
| 4 +++ b/third_party/mach_override/README.chromium |
| 5 @@ -1,6 +1,6 @@ |
| 6 Name: mach_override |
| 7 Short Name: mach_override |
| 8 -Version: Newer than 1.2. HEAD from branch semver-1.x. |
| 9 +Version: unknown |
| 10 URL: https://github.com/rentzsch/mach_override |
| 11 Date: 2014-05-11 |
| 12 Revision: 919148f94db54fc04d287eb6a42c0c36b166bbfa |
| 13 @@ -16,4 +16,5 @@ mach_override includes a copy of libudis86 1.7.1, available se
parately from |
| 14 http://udis86.sourceforge.net/ and https://github.com/vmt/udis86 . |
| 15 |
| 16 |
| 17 -Local Modifications: None. |
| 18 +Local Modifications: Sped up allocation of branch island memory via usage of |
| 19 + vm_region to skip already allocated pages. |
| 20 diff --git a/third_party/mach_override/chromium.patch b/third_party/mach_overrid
e/chromium.patch |
| 21 new file mode 100644 |
| 22 index 000000000000..e69de29bb2d1 |
| 23 diff --git a/third_party/mach_override/mach_override.c b/third_party/mach_overri
de/mach_override.c |
| 24 index 85a75e5c2067..d822520fa00c 100644 |
| 25 --- a/third_party/mach_override/mach_override.c |
| 26 +++ b/third_party/mach_override/mach_override.c |
| 27 @@ -41,7 +41,7 @@ long kIslandTemplate[] = { |
| 28 #define kInstructionHi 10 |
| 29 #define kInstructionLo 11 |
| 30 |
| 31 -#elif defined(__i386__) |
| 32 +#elif defined(__i386__) |
| 33 |
| 34 #define kOriginalInstructionsSize 16 |
| 35 |
| 36 @@ -61,6 +61,7 @@ char kIslandTemplate[] = { |
| 37 #define kOriginalInstructionsSize 32 |
| 38 |
| 39 #define kJumpAddress kOriginalInstructionsSize + 6 |
| 40 +#define kMaxJumpOffset (0x7fffffffUL) |
| 41 |
| 42 char kIslandTemplate[] = { |
| 43 // kOriginalInstructionsSize nop instructions so that we |
| 44 @@ -267,7 +268,13 @@ mach_override_ptr( |
| 45 |
| 46 #if defined(__i386__) || defined(__x86_64__) |
| 47 if (!err) { |
| 48 - uint32_t addressOffset = ((char*)escapeIsland - (char*)originalF
unctionPtr - 5); |
| 49 + // TODO: On 64-bit, move to opcode FF/4 (jmp 64-bit absolute ind
irect) |
| 50 + // instead of E9 (jmp 32-bit relative to RIP). Then we should up
date |
| 51 + // allocateBranchIsland to simply allocate any page in the addre
ss space. |
| 52 + // See the 64-bit version of kIslandTemplate array. |
| 53 + int64_t addressOffset64 = ((char*)escapeIsland - (char*)original
FunctionPtr - 5); |
| 54 + int32_t addressOffset = addressOffset64; |
| 55 + assert(addressOffset64 == addressOffset); |
| 56 addressOffset = OSSwapInt32(addressOffset); |
| 57 |
| 58 jumpRelativeInstruction |= 0xE900000000000000LL; |
| 59 @@ -385,7 +392,7 @@ allocateBranchIsland( |
| 60 void *originalFunctionAddress) |
| 61 { |
| 62 assert( island ); |
| 63 - |
| 64 + |
| 65 mach_error_t err = err_none; |
| 66 |
| 67 if( allocateHigh ) { |
| 68 @@ -401,23 +408,41 @@ allocateBranchIsland( |
| 69 vm_address_t first = 0xfeffffff; |
| 70 vm_address_t last = 0xfe000000 + PAGE_SIZE; |
| 71 #elif defined(__x86_64__) |
| 72 - // 64-bit ASLR is in bits 13-28 |
| 73 - vm_address_t first = ((uint64_t)originalFunctionAddress & ~( (0x
FUL << 28) | (PAGE_SIZE - 1) ) ) | (0x1UL << 31); |
| 74 - vm_address_t last = (uint64_t)originalFunctionAddress & ~((0x1UL
<< 32) - 1); |
| 75 + // This logic is more complex due to the 32-bit limit of the jum
p out |
| 76 + // of the original function. Once that limitation is removed, we
can |
| 77 + // use vm_allocate with VM_FLAGS_ANYWHERE as in the i386 code ab
ove. |
| 78 + const uint64_t kPageMask = ~(PAGE_SIZE - 1); |
| 79 + vm_address_t first = (uint64_t)originalFunctionAddress - kMaxJum
pOffset; |
| 80 + first = (first & kPageMask) + PAGE_SIZE; // Align up to the next
page start |
| 81 + if (first > (uint64_t)originalFunctionAddress) first = 0; |
| 82 + vm_address_t last = (uint64_t)originalFunctionAddress + kMaxJump
Offset; |
| 83 + if (last < (uint64_t)originalFunctionAddress) last = ULONG_MAX; |
| 84 #endif |
| 85 |
| 86 page = first; |
| 87 int allocated = 0; |
| 88 vm_map_t task_self = mach_task_self(); |
| 89 |
| 90 - while( !err && !allocated && page != last ) { |
| 91 + while( !err && !allocated && page < last ) { |
| 92 |
| 93 err = vm_allocate( task_self, &page, PAGE_SIZE, 0 ); |
| 94 if( err == err_none ) |
| 95 allocated = 1; |
| 96 else if( err == KERN_NO_SPACE ) { |
| 97 #if defined(__x86_64__) |
| 98 - page -= PAGE_SIZE; |
| 99 + // This memory region is not suitable, skip it: |
| 100 + vm_size_t region_size; |
| 101 + mach_msg_type_number_t int_count = VM_REGION_BAS
IC_INFO_COUNT_64; |
| 102 + vm_region_basic_info_data_64_t vm_region_info; |
| 103 + mach_port_t object_name; |
| 104 + // The call will move 'page' to the beginning of
the region: |
| 105 + err = vm_region_64(task_self, &page, ®ion_siz
e, |
| 106 + VM_REGION_BASIC_INFO_64,
(vm_region_info_t)&vm_region_info, |
| 107 + &int_count, &object_name
); |
| 108 + if (err == KERN_SUCCESS) |
| 109 + page += region_size; |
| 110 + else |
| 111 + break; |
| 112 #else |
| 113 page += PAGE_SIZE; |
| 114 #endif |
| 115 @@ -438,7 +463,7 @@ allocateBranchIsland( |
| 116 } |
| 117 if( !err ) |
| 118 (**island).allocatedHigh = allocateHigh; |
| 119 - |
| 120 + |
| 121 return err; |
| 122 } |
| 123 |
| OLD | NEW |