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

Unified Diff: sandbox/win/src/sandbox_nt_util.cc

Issue 24296002: Sandbox: Update for Windows 8.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/win/src/internal_types.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/win/src/sandbox_nt_util.cc
===================================================================
--- sandbox/win/src/sandbox_nt_util.cc (revision 223979)
+++ sandbox/win/src/sandbox_nt_util.cc (working copy)
@@ -13,7 +13,7 @@
// This is the list of all imported symbols from ntdll.dll.
SANDBOX_INTERCEPT NtExports g_nt = { NULL };
-} // namespace
+} // namespace sandbox
namespace {
@@ -22,26 +22,20 @@
using sandbox::g_nt;
// Start with 1 GB above the source.
- const unsigned int kOneGB = 0x40000000;
+ const size_t kOneGB = 0x40000000;
void* base = reinterpret_cast<char*>(source) + kOneGB;
SIZE_T actual_size = size;
ULONG_PTR zero_bits = 0; // Not the correct type if used.
ULONG type = MEM_RESERVE;
- if (reinterpret_cast<SIZE_T>(source) > 0x7ff80000000) {
- // We are at the top of the address space. Let's try the highest available
- // address.
- base = NULL;
- type |= MEM_TOP_DOWN;
- }
-
NTSTATUS ret;
int attempts = 0;
- for (; attempts < 20; attempts++) {
+ for (; attempts < 41; attempts++) {
cpu_(ooo_6.6-7.5) 2013/09/20 02:40:39 I thought the answer was 42 :p
rvargas (doing something else) 2013/09/20 02:42:24 Better not risk melting down the computer
ret = g_nt.AllocateVirtualMemory(NtCurrentProcess, &base, zero_bits,
&actual_size, type, PAGE_READWRITE);
if (NT_SUCCESS(ret)) {
- if (base < source) {
+ if (base < source ||
+ base >= reinterpret_cast<char*>(source) + 4 * kOneGB) {
// We won't be able to patch this dll.
VERIFY_SUCCESS(g_nt.FreeVirtualMemory(NtCurrentProcess, &base, &size,
MEM_RELEASE));
@@ -50,11 +44,20 @@
break;
}
+ if (attempts == 30) {
+ // Try the first GB.
+ base = reinterpret_cast<char*>(source);
+ } else if (attempts == 40) {
+ // Try the highest available address.
+ base = NULL;
+ type |= MEM_TOP_DOWN;
+ }
+
// Try 100 MB higher.
base = reinterpret_cast<char*>(base) + 100 * 0x100000;
};
- if (attempts == 20)
+ if (attempts == 41)
return NULL;
ret = g_nt.AllocateVirtualMemory(NtCurrentProcess, &base, zero_bits,
« no previous file with comments | « sandbox/win/src/internal_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698