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

Side by Side Diff: syzygy/agent/common/hot_patcher.cc

Issue 2194383007: Port some more code to x64 (Closed) Base URL: git@github.com:google/syzygy.git@master
Patch Set: Rename the stack_walker unittest and fix the x86-64 implementation of stack_walker Created 4 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
« no previous file with comments | « syzygy/agent/common/common.gyp ('k') | syzygy/agent/common/stack_capture.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 Google Inc. All Rights Reserved. 1 // Copyright 2015 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 reinterpret_cast<uint8_t*>(new_entry_point) - hot_patch_start - 5; 71 reinterpret_cast<uint8_t*>(new_entry_point) - hot_patch_start - 5;
72 72
73 // This is the location where the short jump overwriting the first two bytes 73 // This is the location where the short jump overwriting the first two bytes
74 // of the function should be placed. 74 // of the function should be placed.
75 volatile uint16_t* jump_hook_place = 75 volatile uint16_t* jump_hook_place =
76 reinterpret_cast<uint16_t*>(hot_patch_start + 5); 76 reinterpret_cast<uint16_t*>(hot_patch_start + 5);
77 77
78 // Writes on x86 architecture are atomic within a cross 4-byte boundary. 78 // Writes on x86 architecture are atomic within a cross 4-byte boundary.
79 // NOTE: This can be loosened. Any two bytes starting at an address that meets 79 // NOTE: This can be loosened. Any two bytes starting at an address that meets
80 // the (address % 4 != 3) condition does not cross 4-byte boundary. 80 // the (address % 4 != 3) condition does not cross 4-byte boundary.
81 CHECK_EQ(0, reinterpret_cast<int>(jump_hook_place) % 2); 81 CHECK_EQ(0u, reinterpret_cast<uintptr_t>(jump_hook_place) % 2);
82 82
83 // We write the instruction JMP -5 which is represented as: 0xEB 0xF9 83 // We write the instruction JMP -5 which is represented as: 0xEB 0xF9
84 // We reverse the order of the bytes because of the little endian encoding 84 // We reverse the order of the bytes because of the little endian encoding
85 // to get the final value 0xF9EB. 85 // to get the final value 0xF9EB.
86 *jump_hook_place = 0xF9EB; 86 *jump_hook_place = 0xF9EB;
87 87
88 // Restore the old page protection. 88 // Restore the old page protection.
89 if (!::VirtualProtect(reinterpret_cast<LPVOID>(hot_patch_start), 89 if (!::VirtualProtect(reinterpret_cast<LPVOID>(hot_patch_start),
90 hot_patch_length, 90 hot_patch_length,
91 old_page_protection, 91 old_page_protection,
92 &old_page_protection)) { 92 &old_page_protection)) {
93 // We do not return false if this fails as the hot patching already 93 // We do not return false if this fails as the hot patching already
94 // happened. 94 // happened.
95 LOG(ERROR) << "Could not reset old privileges to page. Error code: " 95 LOG(ERROR) << "Could not reset old privileges to page. Error code: "
96 << ::common::LogWe(); 96 << ::common::LogWe();
97 } 97 }
98 98
99 return true; 99 return true;
100 } 100 }
101 101
102 } // namespace common 102 } // namespace common
103 } // namespace agent 103 } // namespace agent
OLDNEW
« no previous file with comments | « syzygy/agent/common/common.gyp ('k') | syzygy/agent/common/stack_capture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698