OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "content/public/app/startup_helper_win.h" | 5 #include "base/win/process_startup_helper.h" |
6 | 6 |
7 #include <crtdbg.h> | 7 #include <crtdbg.h> |
8 #include <new.h> | 8 #include <new.h> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/win/windows_version.h" | |
13 #include "sandbox/win/src/process_mitigations.h" | |
14 #include "sandbox/win/src/sandbox_factory.h" | |
15 | 12 |
16 namespace { | 13 namespace { |
17 | 14 |
18 #pragma optimize("", off) | 15 #pragma optimize("", off) |
19 // Handlers for invalid parameter and pure call. They generate a breakpoint to | 16 // Handlers for invalid parameter and pure call. They generate a breakpoint to |
20 // tell breakpad that it needs to dump the process. | 17 // tell breakpad that it needs to dump the process. |
21 void InvalidParameter(const wchar_t* expression, const wchar_t* function, | 18 void InvalidParameter(const wchar_t* expression, const wchar_t* function, |
22 const wchar_t* file, unsigned int line, | 19 const wchar_t* file, unsigned int line, |
23 uintptr_t reserved) { | 20 uintptr_t reserved) { |
24 __debugbreak(); | 21 __debugbreak(); |
25 _exit(1); | 22 _exit(1); |
26 } | 23 } |
27 | 24 |
28 void PureCall() { | 25 void PureCall() { |
29 __debugbreak(); | 26 __debugbreak(); |
30 _exit(1); | 27 _exit(1); |
31 } | 28 } |
32 #pragma optimize("", on) | 29 #pragma optimize("", on) |
33 | 30 |
34 } // namespace | 31 } // namespace |
35 | 32 |
36 namespace content { | 33 namespace base { |
37 | 34 namespace win { |
38 void InitializeSandboxInfo(sandbox::SandboxInterfaceInfo* info) { | |
39 info->broker_services = sandbox::SandboxFactory::GetBrokerServices(); | |
40 if (!info->broker_services) { | |
41 info->target_services = sandbox::SandboxFactory::GetTargetServices(); | |
42 } else { | |
43 // Ensure the proper mitigations are enforced for the browser process. | |
44 sandbox::ApplyProcessMitigationsToCurrentProcess( | |
45 sandbox::MITIGATION_DEP | | |
46 sandbox::MITIGATION_DEP_NO_ATL_THUNK | | |
47 sandbox::MITIGATION_HARDEN_TOKEN_IL_POLICY); | |
48 } | |
49 } | |
50 | 35 |
51 // Register the invalid param handler and pure call handler to be able to | 36 // Register the invalid param handler and pure call handler to be able to |
52 // notify breakpad when it happens. | 37 // notify breakpad when it happens. |
53 void RegisterInvalidParamHandler() { | 38 void RegisterInvalidParamHandler() { |
54 _set_invalid_parameter_handler(InvalidParameter); | 39 _set_invalid_parameter_handler(InvalidParameter); |
55 _set_purecall_handler(PureCall); | 40 _set_purecall_handler(PureCall); |
56 } | 41 } |
57 | 42 |
58 void SetupCRT(const base::CommandLine& command_line) { | 43 void SetupCRT(const CommandLine& command_line) { |
59 #if defined(_CRTDBG_MAP_ALLOC) | 44 #if defined(_CRTDBG_MAP_ALLOC) |
60 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | 45 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
61 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); | 46 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); |
62 #else | 47 #else |
63 if (!command_line.HasSwitch(switches::kDisableBreakpad)) { | 48 if (!command_line.HasSwitch(switches::kDisableBreakpad)) { |
64 _CrtSetReportMode(_CRT_ASSERT, 0); | 49 _CrtSetReportMode(_CRT_ASSERT, 0); |
65 } | 50 } |
66 #endif | 51 #endif |
67 } | 52 } |
68 | 53 |
69 } // namespace content | 54 } // namespace win |
| 55 } // namespace base |
OLD | NEW |