Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: third_party/mach_override/mach_override.c

Issue 7492012: Lion x86 compatibility for mach_override (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/mach_override/README.chromium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************************* 1 /*******************************************************************************
2 mach_override.c 2 mach_override.c
3 Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzs ch.com> 3 Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzs ch.com>
4 Some rights reserved: <http://opensource.org/licenses/mit-licens e.php> 4 Some rights reserved: <http://opensource.org/licenses/mit-licens e.php>
5 5
6 ************************************************************************ ***/ 6 ************************************************************************ ***/
7 7
8 #include "mach_override.h" 8 #include "mach_override.h"
9 9
10 #include <mach-o/dyld.h> 10 #include <mach-o/dyld.h>
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 #endif 138 #endif
139 139
140 /******************************************************************************* 140 /*******************************************************************************
141 * 141 *
142 * Interface 142 * Interface
143 * 143 *
144 *******************************************************************************/ 144 *******************************************************************************/
145 #pragma mark - 145 #pragma mark -
146 #pragma mark (Interface) 146 #pragma mark (Interface)
147 147
148 #if defined(__x86_64__) 148 #if defined(__i386__) || defined(__x86_64__)
149 mach_error_t makeIslandExecutable(void *address) { 149 mach_error_t makeIslandExecutable(void *address) {
150 mach_error_t err = err_none; 150 mach_error_t err = err_none;
151 vm_size_t pageSize; 151 vm_size_t pageSize;
152 host_page_size( mach_host_self(), &pageSize ); 152 host_page_size( mach_host_self(), &pageSize );
153 uint64_t page = (uint64_t)address & ~(uint64_t)(pageSize-1); 153 uintptr_t page = (uintptr_t)address & ~(uintptr_t)(pageSize-1);
154 int e = err_none; 154 int e = err_none;
155 e |= mprotect((void *)page, pageSize, PROT_EXEC | PROT_READ | PROT_WRITE); 155 e |= mprotect((void *)page, pageSize, PROT_EXEC | PROT_READ | PROT_WRITE);
156 e |= msync((void *)page, pageSize, MS_INVALIDATE ); 156 e |= msync((void *)page, pageSize, MS_INVALIDATE );
157 if (e) { 157 if (e) {
158 err = err_cannot_override; 158 err = err_cannot_override;
159 } 159 }
160 return err; 160 return err;
161 } 161 }
162 #endif 162 #endif
163 163
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // Note that on i386, we do not support someone else changing the code u nder our feet 294 // Note that on i386, we do not support someone else changing the code u nder our feet
295 if ( !err ) { 295 if ( !err ) {
296 if( reentryIsland ) 296 if( reentryIsland )
297 err = setBranchIslandTarget_i386( reentryIsland, 297 err = setBranchIslandTarget_i386( reentryIsland,
298 (void*) ((char *)originalFunctionPtr+eatenCount), originalInstructions ); 298 (void*) ((char *)originalFunctionPtr+eatenCount), originalInstructions );
299 if ( !err ) 299 if ( !err )
300 atomic_mov64((uint64_t *)originalFunctionPtr, jumpRelati veInstruction); 300 atomic_mov64((uint64_t *)originalFunctionPtr, jumpRelati veInstruction);
301 } 301 }
302 #endif 302 #endif
303 303
304 #if defined(__i386__) || defined(__x86_64__)
305 if ( !err )
306 err = makeIslandExecutable( escapeIsland );
307 if ( !err && reentryIsland )
308 err = makeIslandExecutable( reentryIsland );
309 #endif
310
304 // Clean up on error. 311 // Clean up on error.
305 if( err ) { 312 if( err ) {
306 if( reentryIsland ) 313 if( reentryIsland )
307 freeBranchIsland( reentryIsland ); 314 freeBranchIsland( reentryIsland );
308 if( escapeIsland ) 315 if( escapeIsland )
309 freeBranchIsland( escapeIsland ); 316 freeBranchIsland( escapeIsland );
310 } 317 }
311 318
312 #if defined(__x86_64__)
313 err = makeIslandExecutable(escapeIsland);
314 err = makeIslandExecutable(reentryIsland);
315 #endif
316
317 return err; 319 return err;
318 } 320 }
319 321
320 /******************************************************************************* 322 /*******************************************************************************
321 * 323 *
322 * Implementation 324 * Implementation
323 * 325 *
324 *******************************************************************************/ 326 *******************************************************************************/
325 #pragma mark - 327 #pragma mark -
326 #pragma mark (Implementation) 328 #pragma mark (Implementation)
(...skipping 21 matching lines...) Expand all
348 350
349 if( allocateHigh ) { 351 if( allocateHigh ) {
350 vm_size_t pageSize; 352 vm_size_t pageSize;
351 err = host_page_size( mach_host_self(), &pageSize ); 353 err = host_page_size( mach_host_self(), &pageSize );
352 if( !err ) { 354 if( !err ) {
353 assert( sizeof( BranchIsland ) <= pageSize ); 355 assert( sizeof( BranchIsland ) <= pageSize );
354 #if defined(__x86_64__) 356 #if defined(__x86_64__)
355 vm_address_t first = (uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1) | ((uint64_t)1 << 31); // start in the mid dle of the page? 357 vm_address_t first = (uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1) | ((uint64_t)1 << 31); // start in the mid dle of the page?
356 vm_address_t last = 0x0; 358 vm_address_t last = 0x0;
357 #else 359 #else
358 » » » vm_address_t first = 0xfeffffff; 360 » » » vm_address_t first = 0xffc00000;
359 » » » vm_address_t last = 0xfe000000 + pageSize; 361 » » » vm_address_t last = 0xfffe0000;
360 #endif 362 #endif
361 363
362 vm_address_t page = first; 364 vm_address_t page = first;
363 int allocated = 0; 365 int allocated = 0;
364 vm_map_t task_self = mach_task_self(); 366 vm_map_t task_self = mach_task_self();
365 367
366 while( !err && !allocated && page != last ) { 368 while( !err && !allocated && page != last ) {
367 369
368 err = vm_allocate( task_self, &page, pageSize, 0 ); 370 err = vm_allocate( task_self, &page, pageSize, 0 );
369 if( err == err_none ) 371 if( err == err_none )
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 ); 675 );
674 #elif defined(__x86_64__) 676 #elif defined(__x86_64__)
675 void atomic_mov64( 677 void atomic_mov64(
676 uint64_t *targetAddress, 678 uint64_t *targetAddress,
677 uint64_t value ) 679 uint64_t value )
678 { 680 {
679 *targetAddress = value; 681 *targetAddress = value;
680 } 682 }
681 #endif 683 #endif
682 #endif 684 #endif
OLDNEW
« no previous file with comments | « third_party/mach_override/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698