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

Side by Side Diff: sandbox/win/src/sandbox_nt_util.cc

Issue 667573009: Give PEImage a virtual destructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress the SEH warning instead Created 6 years, 2 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 | « base/win/pe_image.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "sandbox/win/src/sandbox_nt_util.h" 5 #include "sandbox/win/src/sandbox_nt_util.h"
6 6
7 #include "base/win/pe_image.h" 7 #include "base/win/pe_image.h"
8 #include "sandbox/win/src/sandbox_factory.h" 8 #include "sandbox/win/src/sandbox_factory.h"
9 #include "sandbox/win/src/target_services.h" 9 #include "sandbox/win/src/target_services.h"
10 10
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 DCHECK_NT(STATUS_BUFFER_OVERFLOW != ret); 354 DCHECK_NT(STATUS_BUFFER_OVERFLOW != ret);
355 if (!NT_SUCCESS(ret)) { 355 if (!NT_SUCCESS(ret)) {
356 operator delete(out_string, NT_ALLOC); 356 operator delete(out_string, NT_ALLOC);
357 return NULL; 357 return NULL;
358 } 358 }
359 359
360 return out_string; 360 return out_string;
361 } 361 }
362 362
363 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags) { 363 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags) {
364 // PEImage's dtor won't be run during SEH unwinding, but that's OK.
365 #pragma warning(push)
366 #pragma warning(disable: 4509)
364 UNICODE_STRING* out_name = NULL; 367 UNICODE_STRING* out_name = NULL;
365 __try { 368 __try {
366 do { 369 do {
367 *flags = 0; 370 *flags = 0;
368 base::win::PEImage pe(module); 371 base::win::PEImage pe(module);
369 372
370 if (!pe.VerifyMagic()) 373 if (!pe.VerifyMagic())
371 break; 374 break;
372 *flags |= MODULE_IS_PE_IMAGE; 375 *flags |= MODULE_IS_PE_IMAGE;
373 376
374 PIMAGE_EXPORT_DIRECTORY exports = pe.GetExportDirectory(); 377 PIMAGE_EXPORT_DIRECTORY exports = pe.GetExportDirectory();
375 if (exports) { 378 if (exports) {
376 char* name = reinterpret_cast<char*>(pe.RVAToAddr(exports->Name)); 379 char* name = reinterpret_cast<char*>(pe.RVAToAddr(exports->Name));
377 out_name = AnsiToUnicode(name); 380 out_name = AnsiToUnicode(name);
378 } 381 }
379 382
380 PIMAGE_NT_HEADERS headers = pe.GetNTHeaders(); 383 PIMAGE_NT_HEADERS headers = pe.GetNTHeaders();
381 if (headers) { 384 if (headers) {
382 if (headers->OptionalHeader.AddressOfEntryPoint) 385 if (headers->OptionalHeader.AddressOfEntryPoint)
383 *flags |= MODULE_HAS_ENTRY_POINT; 386 *flags |= MODULE_HAS_ENTRY_POINT;
384 if (headers->OptionalHeader.SizeOfCode) 387 if (headers->OptionalHeader.SizeOfCode)
385 *flags |= MODULE_HAS_CODE; 388 *flags |= MODULE_HAS_CODE;
386 } 389 }
387 } while (false); 390 } while (false);
388 } __except(EXCEPTION_EXECUTE_HANDLER) { 391 } __except(EXCEPTION_EXECUTE_HANDLER) {
389 } 392 }
390 393
391 return out_name; 394 return out_name;
395 #pragma warning(pop)
392 } 396 }
393 397
394 UNICODE_STRING* GetBackingFilePath(PVOID address) { 398 UNICODE_STRING* GetBackingFilePath(PVOID address) {
395 // We'll start with something close to max_path charactes for the name. 399 // We'll start with something close to max_path charactes for the name.
396 ULONG buffer_bytes = MAX_PATH * 2; 400 ULONG buffer_bytes = MAX_PATH * 2;
397 401
398 for (;;) { 402 for (;;) {
399 MEMORY_SECTION_NAME* section_name = reinterpret_cast<MEMORY_SECTION_NAME*>( 403 MEMORY_SECTION_NAME* section_name = reinterpret_cast<MEMORY_SECTION_NAME*>(
400 new(NT_ALLOC) char[buffer_bytes]); 404 new(NT_ALLOC) char[buffer_bytes]);
401 405
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 UNREFERENCED_PARAMETER(type); 598 UNREFERENCED_PARAMETER(type);
595 return buffer; 599 return buffer;
596 } 600 }
597 601
598 void __cdecl operator delete(void* memory, void* buffer, 602 void __cdecl operator delete(void* memory, void* buffer,
599 sandbox::AllocationType type) { 603 sandbox::AllocationType type) {
600 UNREFERENCED_PARAMETER(memory); 604 UNREFERENCED_PARAMETER(memory);
601 UNREFERENCED_PARAMETER(buffer); 605 UNREFERENCED_PARAMETER(buffer);
602 UNREFERENCED_PARAMETER(type); 606 UNREFERENCED_PARAMETER(type);
603 } 607 }
OLDNEW
« no previous file with comments | « base/win/pe_image.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698