OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/win/src/win_utils.h" | 5 #include "sandbox/win/src/win_utils.h" |
6 | 6 |
7 #include <psapi.h> | 7 #include <psapi.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 EqualPath(process_path, image_path)) { | 482 EqualPath(process_path, image_path)) { |
483 return mem_info.BaseAddress; | 483 return mem_info.BaseAddress; |
484 } | 484 } |
485 // VirtualQueryEx should fail before overflow, but just in case we'll check | 485 // VirtualQueryEx should fail before overflow, but just in case we'll check |
486 // to prevent an infinite loop. | 486 // to prevent an infinite loop. |
487 base::CheckedNumeric<uintptr_t> next_base = | 487 base::CheckedNumeric<uintptr_t> next_base = |
488 reinterpret_cast<uintptr_t>(mem_info.BaseAddress); | 488 reinterpret_cast<uintptr_t>(mem_info.BaseAddress); |
489 next_base += mem_info.RegionSize; | 489 next_base += mem_info.RegionSize; |
490 if (!next_base.IsValid()) | 490 if (!next_base.IsValid()) |
491 return nullptr; | 491 return nullptr; |
492 current = reinterpret_cast<void*>(next_base.ValueOrDie()); | 492 current = |
| 493 reinterpret_cast<void*>(static_cast<uintptr_t>(next_base.ValueOrDie())); |
493 } | 494 } |
494 | 495 |
495 return nullptr; | 496 return nullptr; |
496 } | 497 } |
497 | 498 |
498 }; // namespace sandbox | 499 }; // namespace sandbox |
499 | 500 |
500 void ResolveNTFunctionPtr(const char* name, void* ptr) { | 501 void ResolveNTFunctionPtr(const char* name, void* ptr) { |
501 static volatile HMODULE ntdll = NULL; | 502 static volatile HMODULE ntdll = NULL; |
502 | 503 |
503 if (!ntdll) { | 504 if (!ntdll) { |
504 HMODULE ntdll_local = ::GetModuleHandle(sandbox::kNtdllName); | 505 HMODULE ntdll_local = ::GetModuleHandle(sandbox::kNtdllName); |
505 // Use PEImage to sanity-check that we have a valid ntdll handle. | 506 // Use PEImage to sanity-check that we have a valid ntdll handle. |
506 base::win::PEImage ntdll_peimage(ntdll_local); | 507 base::win::PEImage ntdll_peimage(ntdll_local); |
507 CHECK_NT(ntdll_peimage.VerifyMagic()); | 508 CHECK_NT(ntdll_peimage.VerifyMagic()); |
508 // Race-safe way to set static ntdll. | 509 // Race-safe way to set static ntdll. |
509 ::InterlockedCompareExchangePointer( | 510 ::InterlockedCompareExchangePointer( |
510 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); | 511 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); |
511 } | 512 } |
512 | 513 |
513 CHECK_NT(ntdll); | 514 CHECK_NT(ntdll); |
514 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 515 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
515 *function_ptr = ::GetProcAddress(ntdll, name); | 516 *function_ptr = ::GetProcAddress(ntdll, name); |
516 CHECK_NT(*function_ptr); | 517 CHECK_NT(*function_ptr); |
517 } | 518 } |
OLD | NEW |