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

Side by Side Diff: components/crash/app/breakpad_win.cc

Issue 619543002: Hook up custom Win 64 SEH to v8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates 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 | « chrome/common/v8_breakpad_support_win.cc ('k') | content/content_shell.gypi » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/crash/app/breakpad_win.h" 5 #include "components/crash/app/breakpad_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <tchar.h> 9 #include <tchar.h>
10 #include <userenv.h> 10 #include <userenv.h>
11 #include <winnt.h> 11 #include <winnt.h>
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <map> 14 #include <map>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/base_switches.h" 17 #include "base/base_switches.h"
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/debug/crash_logging.h" 20 #include "base/debug/crash_logging.h"
21 #include "base/debug/dump_without_crashing.h" 21 #include "base/debug/dump_without_crashing.h"
22 #include "base/environment.h" 22 #include "base/environment.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/numerics/safe_conversions.h"
24 #include "base/strings/string16.h" 25 #include "base/strings/string16.h"
25 #include "base/strings/string_split.h" 26 #include "base/strings/string_split.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
28 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
29 #include "base/synchronization/lock.h" 30 #include "base/synchronization/lock.h"
30 #include "base/win/metro.h" 31 #include "base/win/metro.h"
31 #include "base/win/pe_image.h" 32 #include "base/win/pe_image.h"
32 #include "base/win/registry.h" 33 #include "base/win/registry.h"
33 #include "base/win/win_util.h" 34 #include "base/win/win_util.h"
34 #include "breakpad/src/client/windows/handler/exception_handler.h" 35 #include "breakpad/src/client/windows/handler/exception_handler.h"
35 #include "components/crash/app/crash_keys_win.h" 36 #include "components/crash/app/crash_keys_win.h"
36 #include "components/crash/app/crash_reporter_client.h" 37 #include "components/crash/app/crash_reporter_client.h"
37 #include "components/crash/app/hard_error_handler_win.h" 38 #include "components/crash/app/hard_error_handler_win.h"
38 #include "content/public/common/result_codes.h" 39 #include "content/public/common/result_codes.h"
39 #include "sandbox/win/src/nt_internals.h" 40 #include "sandbox/win/src/nt_internals.h"
40 #include "sandbox/win/src/sidestep/preamble_patcher.h" 41 #include "sandbox/win/src/sidestep/preamble_patcher.h"
41 42
42 // userenv.dll is required for GetProfileType(). 43 // userenv.dll is required for GetProfileType().
43 #pragma comment(lib, "userenv.lib") 44 #pragma comment(lib, "userenv.lib")
44 45
45 #pragma intrinsic(_AddressOfReturnAddress) 46 #pragma intrinsic(_AddressOfReturnAddress)
46 #pragma intrinsic(_ReturnAddress) 47 #pragma intrinsic(_ReturnAddress)
47 48
49 #ifdef _WIN64
50 // See http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
51 typedef struct _UNWIND_INFO {
52 unsigned char Version : 3;
53 unsigned char Flags : 5;
54 unsigned char SizeOfProlog;
55 unsigned char CountOfCodes;
56 unsigned char FrameRegister : 4;
57 unsigned char FrameOffset : 4;
58 ULONG ExceptionHandler;
59 } UNWIND_INFO, *PUNWIND_INFO;
60 #endif
61
48 namespace breakpad { 62 namespace breakpad {
49 63
50 using crash_reporter::GetCrashReporterClient; 64 using crash_reporter::GetCrashReporterClient;
51 65
52 namespace { 66 namespace {
53 67
54 // Minidump with stacks, PEB, TEB, and unloaded module list. 68 // Minidump with stacks, PEB, TEB, and unloaded module list.
55 const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>( 69 const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
56 MiniDumpWithProcessThreadData | // Get PEB and TEB. 70 MiniDumpWithProcessThreadData | // Get PEB and TEB.
57 MiniDumpWithUnloadedModules); // Get unloaded modules when available. 71 MiniDumpWithUnloadedModules); // Get unloaded modules when available.
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // restarted instance will still contain the pipe environment variable, which 618 // restarted instance will still contain the pipe environment variable, which
605 // will allow the restarted process to still upload crash reports. This function 619 // will allow the restarted process to still upload crash reports. This function
606 // clears the environment variable, so that the restarted Chrome, which inherits 620 // clears the environment variable, so that the restarted Chrome, which inherits
607 // its environment from the current Chrome, will no longer contain the variable. 621 // its environment from the current Chrome, will no longer contain the variable.
608 extern "C" void __declspec(dllexport) __cdecl 622 extern "C" void __declspec(dllexport) __cdecl
609 ClearBreakpadPipeEnvironmentVariable() { 623 ClearBreakpadPipeEnvironmentVariable() {
610 scoped_ptr<base::Environment> env(base::Environment::Create()); 624 scoped_ptr<base::Environment> env(base::Environment::Create());
611 env->UnSetVar(kPipeNameVar); 625 env->UnSetVar(kPipeNameVar);
612 } 626 }
613 627
628 #ifdef _WIN64
629 int CrashForExceptionInNonABICompliantCodeRange(
630 PEXCEPTION_RECORD ExceptionRecord,
631 ULONG64 EstablisherFrame,
632 PCONTEXT ContextRecord,
633 PDISPATCHER_CONTEXT DispatcherContext) {
634 EXCEPTION_POINTERS info = { ExceptionRecord, ContextRecord };
635 return CrashForException(&info);
636 }
637
638 struct ExceptionHandlerRecord {
639 RUNTIME_FUNCTION runtime_function;
640 UNWIND_INFO unwind_info;
641 unsigned char thunk[12];
642 };
643
644 extern "C" void __declspec(dllexport) __cdecl
645 RegisterNonABICompliantCodeRange(void* start, size_t size_in_bytes) {
646 ExceptionHandlerRecord* record =
647 reinterpret_cast<ExceptionHandlerRecord*>(start);
648
649 // We assume that the first page of the code range is executable and
650 // committed and reserved for breakpad. What could possibly go wrong?
651
652 // All addresses are 32bit relative offsets to start.
653 record->runtime_function.BeginAddress = 0;
654 record->runtime_function.EndAddress =
655 base::checked_cast<DWORD>(size_in_bytes);
656 record->runtime_function.UnwindData =
657 offsetof(ExceptionHandlerRecord, unwind_info);
658
659 // Create unwind info that only specifies an exception handler.
660 record->unwind_info.Version = 1;
661 record->unwind_info.Flags = UNW_FLAG_EHANDLER;
662 record->unwind_info.SizeOfProlog = 0;
663 record->unwind_info.CountOfCodes = 0;
664 record->unwind_info.FrameRegister = 0;
665 record->unwind_info.FrameOffset = 0;
666 record->unwind_info.ExceptionHandler =
667 offsetof(ExceptionHandlerRecord, thunk);
668
669 // Hardcoded thunk.
670 // mov imm64, rax
671 record->thunk[0] = 0x48;
672 record->thunk[1] = 0xb8;
673 void* handler = &CrashForExceptionInNonABICompliantCodeRange;
674 memcpy(&record->thunk[2], &handler, 8);
675
676 // jmp rax
677 record->thunk[10] = 0xff;
678 record->thunk[11] = 0xe0;
679
680 // Protect reserved page against modifications.
681 DWORD old_protect;
682 CHECK(VirtualProtect(
683 start, sizeof(ExceptionHandlerRecord), PAGE_EXECUTE_READ, &old_protect));
684 CHECK(RtlAddFunctionTable(
685 &record->runtime_function, 1, reinterpret_cast<DWORD64>(start)));
686 }
687
688 extern "C" void __declspec(dllexport) __cdecl
689 UnregisterNonABICompliantCodeRange(void* start) {
690 ExceptionHandlerRecord* record =
691 reinterpret_cast<ExceptionHandlerRecord*>(start);
692
693 CHECK(RtlDeleteFunctionTable(&record->runtime_function));
694 }
695 #endif
696
614 } // namespace breakpad 697 } // namespace breakpad
OLDNEW
« no previous file with comments | « chrome/common/v8_breakpad_support_win.cc ('k') | content/content_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698