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

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

Issue 21208002: Ensure no RWX pages remain after mach_override_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo printing incorrect error code Created 7 years, 4 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 * 149 *
150 *******************************************************************************/ 150 *******************************************************************************/
151 #pragma mark - 151 #pragma mark -
152 #pragma mark (Interface) 152 #pragma mark (Interface)
153 153
154 #if defined(__i386__) || defined(__x86_64__) 154 #if defined(__i386__) || defined(__x86_64__)
155 mach_error_t makeIslandExecutable(void *address) { 155 mach_error_t makeIslandExecutable(void *address) {
156 mach_error_t err = err_none; 156 mach_error_t err = err_none;
157 uintptr_t page = (uintptr_t)address & ~(uintptr_t)(kPageSize-1); 157 uintptr_t page = (uintptr_t)address & ~(uintptr_t)(kPageSize-1);
158 int e = err_none; 158 int e = err_none;
159 e |= mprotect((void *)page, kPageSize, PROT_EXEC | PROT_READ | PROT_WRITE); 159 e |= mprotect((void *)page, kPageSize, PROT_EXEC | PROT_READ);
160 e |= msync((void *)page, kPageSize, MS_INVALIDATE ); 160 e |= msync((void *)page, kPageSize, MS_INVALIDATE );
161 if (e) { 161 if (e) {
162 err = err_cannot_override; 162 err = err_cannot_override;
163 } 163 }
164 return err; 164 return err;
165 } 165 }
166 #endif 166 #endif
167 167
168 mach_error_t 168 mach_error_t
169 mach_override_ptr( 169 mach_override_ptr(
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 (void*) ((char *)originalFunctionPtr+eatenCount), originalInstructions ); 328 (void*) ((char *)originalFunctionPtr+eatenCount), originalInstructions );
329 // try making islands executable before planting the jmp 329 // try making islands executable before planting the jmp
330 #if defined(__x86_64__) || defined(__i386__) 330 #if defined(__x86_64__) || defined(__i386__)
331 if( !err ) 331 if( !err )
332 err = makeIslandExecutable(escapeIsland); 332 err = makeIslandExecutable(escapeIsland);
333 if( !err && reentryIsland ) 333 if( !err && reentryIsland )
334 err = makeIslandExecutable(reentryIsland); 334 err = makeIslandExecutable(reentryIsland);
335 #endif 335 #endif
336 if ( !err ) 336 if ( !err )
337 atomic_mov64((uint64_t *)originalFunctionPtr, jumpRelati veInstruction); 337 atomic_mov64((uint64_t *)originalFunctionPtr, jumpRelati veInstruction);
338
339 mach_error_t prot_err = err_none;
340 prot_err = vm_protect( mach_task_self(),
341 (vm_address_t) originalFunctionPtr, 8, fa lse,
342 (VM_PROT_READ | VM_PROT_EXECUTE) );
343 if (prot_err) fprintf(stderr, "err = %x %s:%d\n", prot_err, __FI LE__, __LINE__);
338 } 344 }
339 #endif 345 #endif
340 346
341 // Clean up on error. 347 // Clean up on error.
342 if( err ) { 348 if( err ) {
343 if( reentryIsland ) 349 if( reentryIsland )
344 freeBranchIsland( reentryIsland ); 350 freeBranchIsland( reentryIsland );
345 if( escapeIsland ) 351 if( escapeIsland )
346 freeBranchIsland( escapeIsland ); 352 freeBranchIsland( escapeIsland );
347 } 353 }
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 ); 719 );
714 #elif defined(__x86_64__) 720 #elif defined(__x86_64__)
715 void atomic_mov64( 721 void atomic_mov64(
716 uint64_t *targetAddress, 722 uint64_t *targetAddress,
717 uint64_t value ) 723 uint64_t value )
718 { 724 {
719 *targetAddress = value; 725 *targetAddress = value;
720 } 726 }
721 #endif 727 #endif
722 #endif 728 #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