| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // For information about interceptions as a whole see | 5 // For information about interceptions as a whole see |
| 6 // http://dev.chromium.org/developers/design-documents/sandbox . | 6 // http://dev.chromium.org/developers/design-documents/sandbox . |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "sandbox/win/src/interception.h" | 10 #include "sandbox/win/src/interception.h" |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // Find an aligned, random location within the reserved range. | 392 // Find an aligned, random location within the reserved range. |
| 393 size_t thunk_bytes = interceptions_.size() * sizeof(ThunkData) + | 393 size_t thunk_bytes = interceptions_.size() * sizeof(ThunkData) + |
| 394 sizeof(DllInterceptionData); | 394 sizeof(DllInterceptionData); |
| 395 size_t thunk_offset = GetGranularAlignedRandomOffset(thunk_bytes); | 395 size_t thunk_offset = GetGranularAlignedRandomOffset(thunk_bytes); |
| 396 | 396 |
| 397 // Split the base and offset along page boundaries. | 397 // Split the base and offset along page boundaries. |
| 398 thunk_base += thunk_offset & ~(kPageSize - 1); | 398 thunk_base += thunk_offset & ~(kPageSize - 1); |
| 399 thunk_offset &= kPageSize - 1; | 399 thunk_offset &= kPageSize - 1; |
| 400 | 400 |
| 401 // Make an aligned, padded allocation, and move the pointer to our chunk. | 401 // Make an aligned, padded allocation, and move the pointer to our chunk. |
| 402 size_t thunk_bytes_padded = (thunk_bytes + kPageSize - 1) & kPageSize; | 402 size_t thunk_bytes_padded = (thunk_bytes + kPageSize - 1) & ~(kPageSize - 1); |
| 403 thunk_base = reinterpret_cast<BYTE*>( | 403 thunk_base = reinterpret_cast<BYTE*>( |
| 404 ::VirtualAllocEx(child, thunk_base, thunk_bytes_padded, | 404 ::VirtualAllocEx(child, thunk_base, thunk_bytes_padded, |
| 405 MEM_COMMIT, PAGE_EXECUTE_READWRITE)); | 405 MEM_COMMIT, PAGE_EXECUTE_READWRITE)); |
| 406 CHECK(thunk_base); // If this fails we'd crash anyway on an invalid access. | 406 CHECK(thunk_base); // If this fails we'd crash anyway on an invalid access. |
| 407 DllInterceptionData* thunks = reinterpret_cast<DllInterceptionData*>( | 407 DllInterceptionData* thunks = reinterpret_cast<DllInterceptionData*>( |
| 408 thunk_base + thunk_offset); | 408 thunk_base + thunk_offset); |
| 409 | 409 |
| 410 DllInterceptionData dll_data; | 410 DllInterceptionData dll_data; |
| 411 dll_data.data_bytes = thunk_bytes; | 411 dll_data.data_bytes = thunk_bytes; |
| 412 dll_data.num_thunks = 0; | 412 dll_data.num_thunks = 0; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 ::FreeLibrary(local_interceptor); | 542 ::FreeLibrary(local_interceptor); |
| 543 #endif | 543 #endif |
| 544 | 544 |
| 545 if (it != interceptions_.end()) | 545 if (it != interceptions_.end()) |
| 546 return false; | 546 return false; |
| 547 | 547 |
| 548 return true; | 548 return true; |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace sandbox | 551 } // namespace sandbox |
| OLD | NEW |