[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 5 | #include "content/browser/frame_host/debug_urls.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 6 | |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 7 | #if defined(SYZYASAN) |
| 8 | #include <windows.h> |
| 9 | #endif |
| 10 | |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 14 | #include "base/debug/asan_invalid_access.h" |
| 15 | #include "base/debug/profiler.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
erikwright | 811f1b0 | 2015-04-17 18:58:36 | [diff] [blame] | 17 | #include "base/synchronization/waitable_event.h" |
erikwright | cf61cd79 | 2015-04-23 14:35:20 | [diff] [blame] | 18 | #include "base/threading/thread_restrictions.h" |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 19 | #include "cc/base/switches.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 20 | #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 21 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7327029 | 2013-08-09 03:48:07 | [diff] [blame] | 22 | #include "content/public/common/content_constants.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 23 | #include "content/public/common/url_constants.h" |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 24 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 25 | #include "url/gurl.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 26 | |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 27 | #if defined(ENABLE_PLUGINS) |
| 28 | #include "content/browser/ppapi_plugin_process_host.h" |
| 29 | #endif |
| 30 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 31 | namespace content { |
| 32 | |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 33 | namespace { |
| 34 | |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 35 | // Define the Asan debug URLs. |
| 36 | const char kAsanCrashDomain[] = "crash"; |
| 37 | const char kAsanHeapOverflow[] = "/browser-heap-overflow"; |
| 38 | const char kAsanHeapUnderflow[] = "/browser-heap-underflow"; |
| 39 | const char kAsanUseAfterFree[] = "/browser-use-after-free"; |
| 40 | #if defined(SYZYASAN) |
| 41 | const char kAsanCorruptHeapBlock[] = "/browser-corrupt-heap-block"; |
| 42 | const char kAsanCorruptHeap[] = "/browser-corrupt-heap"; |
erikwright | 3d48305 | 2015-03-06 13:14:44 | [diff] [blame] | 43 | #endif |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 44 | |
erikwright | 3d48305 | 2015-03-06 13:14:44 | [diff] [blame] | 45 | #if defined(KASKO) |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 46 | // Define the Kasko debug URLs. |
| 47 | const char kKaskoCrashDomain[] = "kasko"; |
| 48 | const char kKaskoSendReport[] = "/send-report"; |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 49 | #endif |
| 50 | |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 51 | void HandlePpapiFlashDebugURL(const GURL& url) { |
| 52 | #if defined(ENABLE_PLUGINS) |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 53 | bool crash = url == GURL(kChromeUIPpapiFlashCrashURL); |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 54 | |
| 55 | std::vector<PpapiPluginProcessHost*> hosts; |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 56 | PpapiPluginProcessHost::FindByName( |
| 57 | base::UTF8ToUTF16(kFlashPluginName), &hosts); |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 58 | for (std::vector<PpapiPluginProcessHost*>::iterator iter = hosts.begin(); |
| 59 | iter != hosts.end(); ++iter) { |
| 60 | if (crash) |
| 61 | (*iter)->Send(new PpapiMsg_Crash()); |
| 62 | else |
| 63 | (*iter)->Send(new PpapiMsg_Hang()); |
| 64 | } |
| 65 | #endif |
| 66 | } |
| 67 | |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 68 | bool IsKaskoDebugURL(const GURL& url) { |
erikwright | 3d48305 | 2015-03-06 13:14:44 | [diff] [blame] | 69 | #if defined(KASKO) |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 70 | return (url.is_valid() && url.SchemeIs(kChromeUIScheme) && |
qyearsley | 7ffaa68 | 2015-08-03 07:03:49 | [diff] [blame] | 71 | url.DomainIs(kKaskoCrashDomain) && |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 72 | url.path() == kKaskoSendReport); |
| 73 | #else |
| 74 | return false; |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | void HandleKaskoDebugURL() { |
erikwright | 3d48305 | 2015-03-06 13:14:44 | [diff] [blame] | 79 | #if defined(KASKO) |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 80 | // Signature of an enhanced crash reporting function. |
| 81 | typedef void(__cdecl * ReportCrashWithProtobufPtr)(EXCEPTION_POINTERS*, |
| 82 | const char*); |
| 83 | |
| 84 | HMODULE exe_hmodule = ::GetModuleHandle(NULL); |
| 85 | ReportCrashWithProtobufPtr report_crash_with_protobuf = |
| 86 | reinterpret_cast<ReportCrashWithProtobufPtr>( |
| 87 | ::GetProcAddress(exe_hmodule, "ReportCrashWithProtobuf")); |
| 88 | if (report_crash_with_protobuf) |
| 89 | report_crash_with_protobuf(NULL, "Invoked from debug url."); |
| 90 | else |
| 91 | NOTREACHED(); |
| 92 | #else |
| 93 | NOTIMPLEMENTED(); |
| 94 | #endif |
| 95 | } |
| 96 | |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 97 | bool IsAsanDebugURL(const GURL& url) { |
| 98 | #if defined(SYZYASAN) |
| 99 | if (!base::debug::IsBinaryInstrumented()) |
| 100 | return false; |
| 101 | #endif |
| 102 | |
| 103 | if (!(url.is_valid() && url.SchemeIs(kChromeUIScheme) && |
qyearsley | 7ffaa68 | 2015-08-03 07:03:49 | [diff] [blame] | 104 | url.DomainIs(kAsanCrashDomain) && |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 105 | url.has_path())) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (url.path() == kAsanHeapOverflow || url.path() == kAsanHeapUnderflow || |
| 110 | url.path() == kAsanUseAfterFree) { |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | #if defined(SYZYASAN) |
| 115 | if (url.path() == kAsanCorruptHeapBlock || url.path() == kAsanCorruptHeap) |
| 116 | return true; |
| 117 | #endif |
| 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | bool HandleAsanDebugURL(const GURL& url) { |
| 123 | #if defined(SYZYASAN) |
| 124 | if (!base::debug::IsBinaryInstrumented()) |
| 125 | return false; |
| 126 | |
| 127 | if (url.path() == kAsanCorruptHeapBlock) { |
| 128 | base::debug::AsanCorruptHeapBlock(); |
| 129 | return true; |
| 130 | } else if (url.path() == kAsanCorruptHeap) { |
| 131 | base::debug::AsanCorruptHeap(); |
| 132 | return true; |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | #if defined(ADDRESS_SANITIZER) || defined(SYZYASAN) |
| 137 | if (url.path() == kAsanHeapOverflow) { |
| 138 | base::debug::AsanHeapOverflow(); |
| 139 | } else if (url.path() == kAsanHeapUnderflow) { |
| 140 | base::debug::AsanHeapUnderflow(); |
| 141 | } else if (url.path() == kAsanUseAfterFree) { |
| 142 | base::debug::AsanHeapUseAfterFree(); |
| 143 | } else { |
| 144 | return false; |
| 145 | } |
| 146 | #endif |
| 147 | |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 152 | } // namespace |
| 153 | |
erikwright | cf61cd79 | 2015-04-23 14:35:20 | [diff] [blame] | 154 | class ScopedAllowWaitForDebugURL { |
| 155 | private: |
| 156 | base::ThreadRestrictions::ScopedAllowWait wait; |
| 157 | }; |
| 158 | |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 159 | bool HandleDebugURL(const GURL& url, ui::PageTransition transition) { |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 160 | // Ensure that the user explicitly navigated to this URL, unless |
| 161 | // kEnableGpuBenchmarking is enabled by Telemetry. |
[email protected] | 47927870 | 2014-08-11 20:32:09 | [diff] [blame] | 162 | bool is_telemetry_navigation = |
| 163 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 164 | cc::switches::kEnableGpuBenchmarking) && |
vmiura | 20fa51a3 | 2015-10-27 21:39:34 | [diff] [blame^] | 165 | (PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED)); |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 166 | |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 167 | if (!(transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 168 | !is_telemetry_navigation) |
| 169 | return false; |
[email protected] | eabfe191 | 2014-05-12 10:07:28 | [diff] [blame] | 170 | |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 171 | if (IsAsanDebugURL(url)) |
| 172 | return HandleAsanDebugURL(url); |
| 173 | |
erikwright | 420a090 | 2015-02-26 21:16:17 | [diff] [blame] | 174 | if (IsKaskoDebugURL(url)) { |
| 175 | HandleKaskoDebugURL(); |
| 176 | return true; |
| 177 | } |
| 178 | |
avi | 861ff75 | 2014-09-23 22:55:33 | [diff] [blame] | 179 | if (url == GURL(kChromeUIBrowserCrashURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 180 | // Induce an intentional crash in the browser process. |
| 181 | CHECK(false); |
| 182 | return true; |
| 183 | } |
| 184 | |
erikwright | 811f1b0 | 2015-04-17 18:58:36 | [diff] [blame] | 185 | if (url == GURL(kChromeUIBrowserUIHang)) { |
erikwright | cf61cd79 | 2015-04-23 14:35:20 | [diff] [blame] | 186 | ScopedAllowWaitForDebugURL allow_wait; |
erikwright | 811f1b0 | 2015-04-17 18:58:36 | [diff] [blame] | 187 | base::WaitableEvent(false, false).Wait(); |
| 188 | return true; |
| 189 | } |
| 190 | |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 191 | if (url == GURL(kChromeUIGpuCleanURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 192 | GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
| 193 | if (shim) |
| 194 | shim->SimulateRemoveAllContext(); |
| 195 | return true; |
| 196 | } |
| 197 | |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 198 | if (url == GURL(kChromeUIGpuCrashURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 199 | GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
| 200 | if (shim) |
| 201 | shim->SimulateCrash(); |
| 202 | return true; |
| 203 | } |
| 204 | |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 205 | if (url == GURL(kChromeUIGpuHangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 206 | GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
| 207 | if (shim) |
| 208 | shim->SimulateHang(); |
| 209 | return true; |
| 210 | } |
| 211 | |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 212 | if (url == GURL(kChromeUIPpapiFlashCrashURL) || |
| 213 | url == GURL(kChromeUIPpapiFlashHangURL)) { |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 214 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 215 | base::Bind(&HandlePpapiFlashDebugURL, url)); |
| 216 | return true; |
| 217 | } |
| 218 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 219 | return false; |
| 220 | } |
| 221 | |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 222 | bool IsRendererDebugURL(const GURL& url) { |
| 223 | if (!url.is_valid()) |
| 224 | return false; |
| 225 | |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 226 | if (url.SchemeIs(url::kJavaScriptScheme)) |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 227 | return true; |
| 228 | |
pcc | 3184322 | 2015-07-31 00:46:30 | [diff] [blame] | 229 | return url == GURL(kChromeUIBadCastCrashURL) || |
| 230 | url == GURL(kChromeUICrashURL) || |
[email protected] | f0e90cf9 | 2014-07-21 17:13:58 | [diff] [blame] | 231 | url == GURL(kChromeUIDumpURL) || |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 232 | url == GURL(kChromeUIKillURL) || |
| 233 | url == GURL(kChromeUIHangURL) || |
| 234 | url == GURL(kChromeUIShorthangURL); |
| 235 | } |
| 236 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 237 | } // namespace content |