OLD | NEW |
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> |
11 #include <mach/mach_host.h> | 11 #include <mach/mach_host.h> |
12 #include <mach/mach_init.h> | 12 #include <mach/mach_init.h> |
13 #include <mach/vm_map.h> | 13 #include <mach/vm_map.h> |
| 14 #include <mach/vm_statistics.h> |
14 #include <sys/mman.h> | 15 #include <sys/mman.h> |
15 | 16 |
16 #include <CoreServices/CoreServices.h> | 17 #include <CoreServices/CoreServices.h> |
17 | 18 |
18 /************************** | 19 /************************** |
19 * | 20 * |
20 * Constants | 21 * Constants |
21 * | 22 * |
22 **************************/ | 23 **************************/ |
23 #pragma mark - | 24 #pragma mark - |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 ************************************************************************
***/ | 373 ************************************************************************
***/ |
373 | 374 |
374 mach_error_t | 375 mach_error_t |
375 allocateBranchIsland( | 376 allocateBranchIsland( |
376 BranchIsland **island, | 377 BranchIsland **island, |
377 void *originalFunctionAddress) | 378 void *originalFunctionAddress) |
378 { | 379 { |
379 assert( island ); | 380 assert( island ); |
380 | 381 |
381 assert( sizeof( BranchIsland ) <= kPageSize ); | 382 assert( sizeof( BranchIsland ) <= kPageSize ); |
| 383 #if defined(__i386__) |
| 384 vm_address_t page = 0; |
| 385 mach_error_t err = vm_allocate( mach_task_self(), &page, kPageSize, VM_F
LAGS_ANYWHERE ); |
| 386 if( err == err_none ) { |
| 387 *island = (BranchIsland*) page; |
| 388 return err_none; |
| 389 } |
| 390 return err; |
| 391 #else |
| 392 |
382 #if defined(__ppc__) || defined(__POWERPC__) | 393 #if defined(__ppc__) || defined(__POWERPC__) |
383 vm_address_t first = 0xfeffffff; | 394 vm_address_t first = 0xfeffffff; |
384 vm_address_t last = 0xfe000000 + kPageSize; | 395 vm_address_t last = 0xfe000000 + kPageSize; |
385 #elif defined(__x86_64__) | 396 #elif defined(__x86_64__) |
386 vm_address_t first = ((uint64_t)originalFunctionAddress & ~(uint64_t)(((
uint64_t)1 << 31) - 1)) | ((uint64_t)1 << 31); // start in the middle of the pag
e? | 397 vm_address_t first = ((uint64_t)originalFunctionAddress & ~(uint64_t)(((
uint64_t)1 << 31) - 1)) | ((uint64_t)1 << 31); // start in the middle of the pag
e? |
387 vm_address_t last = 0x0; | 398 vm_address_t last = 0x0; |
388 #else | |
389 vm_address_t first = 0xffc00000; | |
390 vm_address_t last = 0xfffe0000; | |
391 #endif | 399 #endif |
392 | 400 |
393 vm_address_t page = first; | 401 vm_address_t page = first; |
394 vm_map_t task_self = mach_task_self(); | 402 vm_map_t task_self = mach_task_self(); |
395 | 403 |
396 while( page != last ) { | 404 while( page != last ) { |
397 mach_error_t err = vm_allocate( task_self, &page, kPageSize, 0 )
; | 405 mach_error_t err = vm_allocate( task_self, &page, kPageSize, 0 )
; |
398 if( err == err_none ) { | 406 if( err == err_none ) { |
399 *island = (BranchIsland*) page; | 407 *island = (BranchIsland*) page; |
400 return err_none; | 408 return err_none; |
401 } | 409 } |
402 if( err != KERN_NO_SPACE ) | 410 if( err != KERN_NO_SPACE ) |
403 return err; | 411 return err; |
404 #if defined(__x86_64__) | 412 #if defined(__x86_64__) |
405 page -= kPageSize; | 413 page -= kPageSize; |
406 #else | 414 #else |
407 page += kPageSize; | 415 page += kPageSize; |
408 #endif | 416 #endif |
409 err = err_none; | 417 err = err_none; |
410 } | 418 } |
411 | 419 |
412 return KERN_NO_SPACE; | 420 return KERN_NO_SPACE; |
| 421 #endif |
413 } | 422 } |
414 | 423 |
415 /***************************************************************************//** | 424 /***************************************************************************//** |
416 Implementation: Deallocates memory for a branch island. | 425 Implementation: Deallocates memory for a branch island. |
417 | 426 |
418 @param island -> The island to deallocate. | 427 @param island -> The island to deallocate. |
419 @result <- mach_error_t | 428 @result <- mach_error_t |
420 | 429 |
421 ************************************************************************
***/ | 430 ************************************************************************
***/ |
422 | 431 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 ); | 728 ); |
720 #elif defined(__x86_64__) | 729 #elif defined(__x86_64__) |
721 void atomic_mov64( | 730 void atomic_mov64( |
722 uint64_t *targetAddress, | 731 uint64_t *targetAddress, |
723 uint64_t value ) | 732 uint64_t value ) |
724 { | 733 { |
725 *targetAddress = value; | 734 *targetAddress = value; |
726 } | 735 } |
727 #endif | 736 #endif |
728 #endif | 737 #endif |
OLD | NEW |