| OLD | NEW |
| 1 /* Copyright (c) 2007, Google Inc. | 1 /* Copyright (c) 2007, Google Inc. |
| 2 * All rights reserved. | 2 * All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 | 310 |
| 311 // Replace the first few bytes of the original function with the bytes we | 311 // Replace the first few bytes of the original function with the bytes we |
| 312 // previously moved to the preamble stub. | 312 // previously moved to the preamble stub. |
| 313 memcpy(reinterpret_cast<void*>(target), | 313 memcpy(reinterpret_cast<void*>(target), |
| 314 original_function_stub, preamble_bytes); | 314 original_function_stub, preamble_bytes); |
| 315 | 315 |
| 316 // Stub is now useless so delete it. | 316 // Stub is now useless so delete it. |
| 317 // [csilvers: Commented out for perftools because it causes big problems | 317 // [csilvers: Commented out for perftools because it causes big problems |
| 318 // when we're unpatching malloc. We just let this live on as a leak.] | 318 // when we're unpatching malloc. We just let this live on as a leak.] |
| 319 //delete original_function_stub; | 319 //delete [] reinterpret_cast<unsigned char*>(original_function_stub); |
| 320 | 320 |
| 321 // Restore the protection of the first MAX_PREAMBLE_STUB_SIZE bytes of | 321 // Restore the protection of the first MAX_PREAMBLE_STUB_SIZE bytes of |
| 322 // target to what they were before we started goofing around. | 322 // target to what they were before we started goofing around. |
| 323 succeeded = ::VirtualProtect(reinterpret_cast<void*>(target), | 323 succeeded = ::VirtualProtect(reinterpret_cast<void*>(target), |
| 324 MAX_PREAMBLE_STUB_SIZE, | 324 MAX_PREAMBLE_STUB_SIZE, |
| 325 old_target_function_protect, | 325 old_target_function_protect, |
| 326 &old_target_function_protect); | 326 &old_target_function_protect); |
| 327 | 327 |
| 328 // Flush the instruction cache to make sure the processor doesn't execute the | 328 // Flush the instruction cache to make sure the processor doesn't execute the |
| 329 // old version of the instructions (before our patch). | 329 // old version of the instructions (before our patch). |
| 330 // | 330 // |
| 331 // See comment on FlushInstructionCache elsewhere in this file. | 331 // See comment on FlushInstructionCache elsewhere in this file. |
| 332 succeeded = ::FlushInstructionCache(::GetCurrentProcess(), | 332 succeeded = ::FlushInstructionCache(::GetCurrentProcess(), |
| 333 target, | 333 target, |
| 334 MAX_PREAMBLE_STUB_SIZE); | 334 MAX_PREAMBLE_STUB_SIZE); |
| 335 if (!succeeded) { | 335 if (!succeeded) { |
| 336 SIDESTEP_ASSERT(false && "Failed to flush instruction cache."); | 336 SIDESTEP_ASSERT(false && "Failed to flush instruction cache."); |
| 337 return SIDESTEP_UNEXPECTED; | 337 return SIDESTEP_UNEXPECTED; |
| 338 } | 338 } |
| 339 | 339 |
| 340 SIDESTEP_LOG("PreamblePatcher::Unpatch successfully unpatched."); | 340 SIDESTEP_LOG("PreamblePatcher::Unpatch successfully unpatched."); |
| 341 return SIDESTEP_SUCCESS; | 341 return SIDESTEP_SUCCESS; |
| 342 } | 342 } |
| 343 | 343 |
| 344 }; // namespace sidestep | 344 }; // namespace sidestep |
| OLD | NEW |