[email protected] | 2e3d9e4 | 2012-02-14 03:23:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [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 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 5 | #include <stddef.h> |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 6 | #include <stdlib.h> |
| 7 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 8 | #include <memory> |
dcheng | f26eed3 | 2016-01-13 10:58:14 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 11 | #include "base/lazy_instance.h" |
[email protected] | e55f564 | 2013-07-18 00:22:54 | [diff] [blame] | 12 | #include "base/message_loop/message_loop.h" |
[email protected] | 2f2fd9e | 2013-12-05 03:36:30 | [diff] [blame] | 13 | #include "base/metrics/histogram.h" |
jmadill | 29fda863 | 2015-03-18 22:45:22 | [diff] [blame] | 14 | #include "base/metrics/statistics_recorder.h" |
[email protected] | 2436a6b | 2012-04-13 21:08:51 | [diff] [blame] | 15 | #include "base/rand_util.h" |
fdoray | e716a90 | 2016-07-05 16:05:49 | [diff] [blame] | 16 | #include "base/run_loop.h" |
[email protected] | d0ea478 | 2013-06-11 04:58:24 | [diff] [blame] | 17 | #include "base/strings/string_number_conversions.h" |
| 18 | #include "base/strings/stringprintf.h" |
glider | 6b8d75a4 | 2015-02-20 11:44:50 | [diff] [blame] | 19 | #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 20 | #include "base/threading/platform_thread.h" |
primiano | 50b7444c | 2015-01-28 04:17:00 | [diff] [blame] | 21 | #include "base/trace_event/trace_event.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 22 | #include "build/build_config.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 23 | #include "content/child/child_process.h" |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 24 | #include "content/common/content_constants_internal.h" |
fsamuel | 115b5ed4 | 2016-03-22 19:41:58 | [diff] [blame] | 25 | #include "content/common/gpu_host_messages.h" |
[email protected] | 5c9cddd | 2013-12-13 07:03:29 | [diff] [blame] | 26 | #include "content/common/sandbox_linux/sandbox_linux.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 27 | #include "content/gpu/gpu_child_thread.h" |
[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 28 | #include "content/gpu/gpu_process.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 29 | #include "content/public/common/content_client.h" |
| 30 | #include "content/public/common/content_switches.h" |
| 31 | #include "content/public/common/main_function_params.h" |
[email protected] | 40c19e72 | 2013-11-05 23:51:24 | [diff] [blame] | 32 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 33 | #include "gpu/config/gpu_info_collector.h" |
tfarina | 15525c4 | 2015-04-28 19:04:16 | [diff] [blame] | 34 | #include "gpu/config/gpu_switches.h" |
[email protected] | 40c19e72 | 2013-11-05 23:51:24 | [diff] [blame] | 35 | #include "gpu/config/gpu_util.h" |
fsamuel | c277422 | 2016-03-24 00:27:12 | [diff] [blame] | 36 | #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 37 | #include "gpu/ipc/service/gpu_config.h" |
| 38 | #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame^] | 39 | #include "gpu/ipc/service/gpu_watchdog_thread.h" |
[email protected] | c093918 | 2014-05-24 00:09:19 | [diff] [blame] | 40 | #include "ui/events/platform/platform_event_source.h" |
martina.kollarova | a34211d | 2015-06-25 11:49:07 | [diff] [blame] | 41 | #include "ui/gl/gl_context.h" |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 42 | #include "ui/gl/gl_implementation.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 43 | #include "ui/gl/gl_surface.h" |
| 44 | #include "ui/gl/gl_switches.h" |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 45 | #include "ui/gl/gpu_switching_manager.h" |
kylechar | 5b9dec1 | 2016-05-16 15:40:57 | [diff] [blame] | 46 | #include "ui/gl/init/gl_factory.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 47 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 48 | #if defined(OS_WIN) |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 49 | #include <windows.h> |
fdoray | e716a90 | 2016-07-05 16:05:49 | [diff] [blame] | 50 | #include <dwmapi.h> |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 51 | #endif |
| 52 | |
primiano | b3fb641 | 2015-10-14 16:03:51 | [diff] [blame] | 53 | #if defined(OS_ANDROID) |
| 54 | #include "base/trace_event/memory_dump_manager.h" |
primiano | ccb26c6 | 2016-06-01 21:50:02 | [diff] [blame] | 55 | #include "components/tracing/common/graphics_memory_dump_provider_android.h" |
primiano | b3fb641 | 2015-10-14 16:03:51 | [diff] [blame] | 56 | #endif |
| 57 | |
[email protected] | d7de5787 | 2011-12-06 23:32:43 | [diff] [blame] | 58 | #if defined(OS_WIN) |
[email protected] | 5f7e451 | 2012-10-01 20:51:37 | [diff] [blame] | 59 | #include "base/win/scoped_com_initializer.h" |
kylechar | 5b9dec1 | 2016-05-16 15:40:57 | [diff] [blame] | 60 | #include "base/win/windows_version.h" |
markdittmer | 6e70beb8 | 2016-05-02 05:40:47 | [diff] [blame] | 61 | #include "media/gpu/dxva_video_decode_accelerator_win.h" |
emircan | c253d05a | 2016-07-22 23:21:11 | [diff] [blame] | 62 | #include "media/gpu/media_foundation_video_encode_accelerator_win.h" |
[email protected] | 18149178 | 2012-07-18 00:59:15 | [diff] [blame] | 63 | #include "sandbox/win/src/sandbox.h" |
[email protected] | 802a13a0 | 2010-12-02 01:48:37 | [diff] [blame] | 64 | #endif |
| 65 | |
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 66 | #if defined(USE_X11) |
kylechar | fe6518f | 2016-04-29 13:56:50 | [diff] [blame] | 67 | #include "ui/base/x/x11_util.h" // nogncheck |
kylechar | 4abed71f | 2016-04-06 14:46:42 | [diff] [blame] | 68 | #include "ui/gfx/x/x11_switches.h" // nogncheck |
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 69 | #endif |
| 70 | |
[email protected] | 2436a6b | 2012-04-13 21:08:51 | [diff] [blame] | 71 | #if defined(OS_LINUX) |
| 72 | #include "content/public/common/sandbox_init.h" |
| 73 | #endif |
| 74 | |
[email protected] | 826aab0 | 2014-05-14 02:58:59 | [diff] [blame] | 75 | #if defined(OS_MACOSX) |
| 76 | #include "base/message_loop/message_pump_mac.h" |
[email protected] | 6abc808 | 2014-07-11 10:35:46 | [diff] [blame] | 77 | #include "content/common/sandbox_mac.h" |
[email protected] | 826aab0 | 2014-05-14 02:58:59 | [diff] [blame] | 78 | #endif |
| 79 | |
hshi | 9583705 | 2015-05-12 15:39:51 | [diff] [blame] | 80 | #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
markdittmer | 6e70beb8 | 2016-05-02 05:40:47 | [diff] [blame] | 81 | #include "media/gpu/vaapi_wrapper.h" |
hshi | 9583705 | 2015-05-12 15:39:51 | [diff] [blame] | 82 | #endif |
| 83 | |
glider | ddea13b | 2015-02-13 18:01:30 | [diff] [blame] | 84 | #if defined(SANITIZER_COVERAGE) |
| 85 | #include <sanitizer/common_interface_defs.h> |
hans | 832e529 | 2015-03-05 04:02:11 | [diff] [blame] | 86 | #include <sanitizer/coverage_interface.h> |
[email protected] | 655abd52 | 2014-06-02 15:23:43 | [diff] [blame] | 87 | #endif |
| 88 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 89 | namespace content { |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 90 | |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 91 | namespace { |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 92 | |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 93 | void GetGpuInfoFromCommandLine(gpu::GPUInfo& gpu_info, |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 94 | const base::CommandLine& command_line); |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 95 | void WarmUpSandbox(); |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 96 | |
| 97 | #if !defined(OS_MACOSX) |
| 98 | bool CollectGraphicsInfo(gpu::GPUInfo& gpu_info); |
| 99 | #endif |
| 100 | |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 101 | #if defined(OS_LINUX) |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 102 | #if !defined(OS_CHROMEOS) |
| 103 | bool CanAccessNvidiaDeviceFile(); |
| 104 | #endif |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame^] | 105 | bool StartSandboxLinux(const gpu::GPUInfo&, gpu::GpuWatchdogThread*); |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 106 | #elif defined(OS_WIN) |
| 107 | bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*); |
| 108 | #endif |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 109 | |
| 110 | base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages = |
| 111 | LAZY_INSTANCE_INITIALIZER; |
| 112 | |
| 113 | bool GpuProcessLogMessageHandler(int severity, |
| 114 | const char* file, int line, |
| 115 | size_t message_start, |
| 116 | const std::string& str) { |
| 117 | std::string header = str.substr(0, message_start); |
| 118 | std::string message = str.substr(message_start); |
fsamuel | a660ce0 | 2016-02-25 03:56:16 | [diff] [blame] | 119 | deferred_messages.Get().push( |
| 120 | new GpuHostMsg_OnLogMessage(severity, header, message)); |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 121 | return false; |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 122 | } |
| 123 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 124 | } // namespace anonymous |
| 125 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 126 | // Main function for starting the Gpu process. |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 127 | int GpuMain(const MainFunctionParams& parameters) { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 128 | TRACE_EVENT0("gpu", "GpuMain"); |
ssid | b2e3ece | 2015-02-09 16:02:20 | [diff] [blame] | 129 | base::trace_event::TraceLog::GetInstance()->SetProcessName("GPU Process"); |
| 130 | base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex( |
[email protected] | 91a2aea | 2013-07-08 23:14:39 | [diff] [blame] | 131 | kTraceEventGpuProcessSortIndex); |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 132 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 133 | const base::CommandLine& command_line = parameters.command_line; |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 134 | if (command_line.HasSwitch(switches::kGpuStartupDialog)) { |
[email protected] | 75fcc27 | 2011-03-08 20:50:48 | [diff] [blame] | 135 | ChildProcess::WaitForDebugger("Gpu"); |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | ca23992b0 | 2013-06-13 17:25:19 | [diff] [blame] | 138 | base::Time start_time = base::Time::Now(); |
| 139 | |
[email protected] | 23f4656 | 2011-09-07 01:42:39 | [diff] [blame] | 140 | #if defined(OS_WIN) |
[email protected] | 5281947 | 2013-11-24 22:49:55 | [diff] [blame] | 141 | // Prevent Windows from displaying a modal dialog on failures like not being |
| 142 | // able to load a DLL. |
| 143 | SetErrorMode( |
| 144 | SEM_FAILCRITICALERRORS | |
| 145 | SEM_NOGPFAULTERRORBOX | |
| 146 | SEM_NOOPENFILEERRORBOX); |
[email protected] | 23f4656 | 2011-09-07 01:42:39 | [diff] [blame] | 147 | #elif defined(USE_X11) |
[email protected] | 5281947 | 2013-11-24 22:49:55 | [diff] [blame] | 148 | ui::SetDefaultX11ErrorHandlers(); |
j.isorce | 5ade848 | 2015-11-23 16:15:12 | [diff] [blame] | 149 | |
| 150 | #if !defined(OS_CHROMEOS) |
| 151 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 152 | switches::kWindowDepth)); |
j.isorce | a1e4224 | 2016-05-19 05:11:28 | [diff] [blame] | 153 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 154 | switches::kX11VisualID)); |
j.isorce | 5ade848 | 2015-11-23 16:15:12 | [diff] [blame] | 155 | #endif |
| 156 | |
[email protected] | 23f4656 | 2011-09-07 01:42:39 | [diff] [blame] | 157 | #endif |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 158 | |
[email protected] | 5281947 | 2013-11-24 22:49:55 | [diff] [blame] | 159 | logging::SetLogMessageHandler(GpuProcessLogMessageHandler); |
[email protected] | 23f4656 | 2011-09-07 01:42:39 | [diff] [blame] | 160 | |
[email protected] | 40c19e72 | 2013-11-05 23:51:24 | [diff] [blame] | 161 | if (command_line.HasSwitch(switches::kSupportsDualGpus)) { |
| 162 | std::string types = command_line.GetSwitchValueASCII( |
| 163 | switches::kGpuDriverBugWorkarounds); |
| 164 | std::set<int> workarounds; |
| 165 | gpu::StringToFeatureSet(types, &workarounds); |
| 166 | if (workarounds.count(gpu::FORCE_DISCRETE_GPU) == 1) |
[email protected] | a2221e8 | 2012-10-08 22:33:14 | [diff] [blame] | 167 | ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu(); |
[email protected] | 40c19e72 | 2013-11-05 23:51:24 | [diff] [blame] | 168 | else if (workarounds.count(gpu::FORCE_INTEGRATED_GPU) == 1) |
[email protected] | a2221e8 | 2012-10-08 22:33:14 | [diff] [blame] | 169 | ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu(); |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 172 | // Initialization of the OpenGL bindings may fail, in which case we |
| 173 | // will need to tear down this process. However, we can not do so |
| 174 | // safely until the IPC channel is set up, because the detection of |
| 175 | // early return of a child process is implemented using an IPC |
| 176 | // channel error. If the IPC channel is not fully set up between the |
| 177 | // browser and GPU process, and the GPU process crashes or exits |
| 178 | // early, the browser process will never detect it. For this reason |
| 179 | // we defer tearing down the GPU process until receiving the |
| 180 | // GpuMsg_Initialize message from the browser. |
| 181 | bool dead_on_arrival = false; |
| 182 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 183 | #if defined(OS_WIN) |
geofflang | 019d4f3 | 2015-04-27 21:39:39 | [diff] [blame] | 184 | // Use a UI message loop because ANGLE and the desktop GL platform can |
| 185 | // create child windows to render to. |
stanisc | 100d03d | 2016-05-26 18:39:51 | [diff] [blame] | 186 | base::MessagePumpForGpu::InitFactory(); |
jbauman | ca6bfb5 | 2015-07-01 21:17:52 | [diff] [blame] | 187 | base::MessageLoop main_message_loop(base::MessageLoop::TYPE_UI); |
[email protected] | c093918 | 2014-05-24 00:09:19 | [diff] [blame] | 188 | #elif defined(OS_LINUX) && defined(USE_X11) |
| 189 | // We need a UI loop so that we can grab the Expose events. See GLSurfaceGLX |
| 190 | // and https://crbug.com/326995. |
| 191 | base::MessageLoop main_message_loop(base::MessageLoop::TYPE_UI); |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 192 | std::unique_ptr<ui::PlatformEventSource> event_source = |
[email protected] | c093918 | 2014-05-24 00:09:19 | [diff] [blame] | 193 | ui::PlatformEventSource::CreateDefault(); |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 194 | #elif defined(OS_LINUX) |
[email protected] | 826aab0 | 2014-05-14 02:58:59 | [diff] [blame] | 195 | base::MessageLoop main_message_loop(base::MessageLoop::TYPE_DEFAULT); |
| 196 | #elif defined(OS_MACOSX) |
| 197 | // This is necessary for CoreAnimation layers hosted in the GPU process to be |
| 198 | // drawn. See http://crbug.com/312462. |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 199 | std::unique_ptr<base::MessagePump> pump(new base::MessagePumpCFRunLoop()); |
dcheng | f26eed3 | 2016-01-13 10:58:14 | [diff] [blame] | 200 | base::MessageLoop main_message_loop(std::move(pump)); |
[email protected] | 826aab0 | 2014-05-14 02:58:59 | [diff] [blame] | 201 | #else |
| 202 | base::MessageLoop main_message_loop(base::MessageLoop::TYPE_IO); |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 203 | #endif |
| 204 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 205 | base::PlatformThread::SetName("CrGpuMain"); |
| 206 | |
| 207 | // In addition to disabling the watchdog if the command line switch is |
| 208 | // present, disable the watchdog on valgrind because the code is expected |
| 209 | // to run slowly in that case. |
| 210 | bool enable_watchdog = |
[email protected] | ca23992b0 | 2013-06-13 17:25:19 | [diff] [blame] | 211 | !command_line.HasSwitch(switches::kDisableGpuWatchdog) && |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 212 | !RunningOnValgrind(); |
| 213 | |
| 214 | // Disable the watchdog in debug builds because they tend to only be run by |
| 215 | // developers who will not appreciate the watchdog killing the GPU process. |
| 216 | #ifndef NDEBUG |
| 217 | enable_watchdog = false; |
| 218 | #endif |
| 219 | |
[email protected] | 4271960 | 2012-11-08 02:51:12 | [diff] [blame] | 220 | bool delayed_watchdog_enable = false; |
| 221 | |
| 222 | #if defined(OS_CHROMEOS) |
| 223 | // Don't start watchdog immediately, to allow developers to switch to VT2 on |
| 224 | // startup. |
| 225 | delayed_watchdog_enable = true; |
| 226 | #endif |
| 227 | |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame^] | 228 | scoped_refptr<gpu::GpuWatchdogThread> watchdog_thread; |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 229 | |
| 230 | // Start the GPU watchdog only after anything that is expected to be time |
| 231 | // consuming has completed, otherwise the process is liable to be aborted. |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame^] | 232 | if (enable_watchdog && !delayed_watchdog_enable) |
| 233 | watchdog_thread = gpu::GpuWatchdogThread::Create(); |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame] | 234 | |
jmadill | 29fda863 | 2015-03-18 22:45:22 | [diff] [blame] | 235 | // Initializes StatisticsRecorder which tracks UMA histograms. |
| 236 | base::StatisticsRecorder::Initialize(); |
| 237 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 238 | gpu::GPUInfo gpu_info; |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 239 | // Get vendor_id, device_id, driver_version from browser process through |
| 240 | // commandline switches. |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 241 | GetGpuInfoFromCommandLine(gpu_info, command_line); |
bajones | e3677b64 | 2015-07-25 00:41:56 | [diff] [blame] | 242 | gpu_info.in_process_gpu = false; |
[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 243 | |
hshi | 9583705 | 2015-05-12 15:39:51 | [diff] [blame] | 244 | #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
markdittmer | 6e70beb8 | 2016-05-02 05:40:47 | [diff] [blame] | 245 | media::VaapiWrapper::PreSandboxInitialization(); |
hshi | 9583705 | 2015-05-12 15:39:51 | [diff] [blame] | 246 | #endif |
| 247 | |
reveman | e7acf84 | 2016-02-05 08:24:32 | [diff] [blame] | 248 | #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 249 | // Set thread priority before sandbox initialization. |
| 250 | base::PlatformThread::SetCurrentThreadPriority(base::ThreadPriority::DISPLAY); |
| 251 | #endif |
| 252 | |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 253 | // Warm up resources that don't need access to GPUInfo. |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 254 | WarmUpSandbox(); |
| 255 | |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 256 | #if defined(OS_LINUX) |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 257 | bool initialized_sandbox = false; |
| 258 | // On Chrome OS ARM Mali, GPU driver userspace creates threads when |
| 259 | // initializing a GL context, so start the sandbox early. |
| 260 | if (command_line.HasSwitch(switches::kGpuSandboxStartEarly)) { |
| 261 | gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get()); |
| 262 | initialized_sandbox = true; |
| 263 | } |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 264 | #endif // defined(OS_LINUX) |
| 265 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 266 | base::TimeTicks before_initialize_one_off = base::TimeTicks::Now(); |
[email protected] | 2f2fd9e | 2013-12-05 03:36:30 | [diff] [blame] | 267 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 268 | // Determine if we need to initialize GL here or it has already been done. |
| 269 | bool gl_already_initialized = false; |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 270 | #if defined(OS_MACOSX) |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 271 | if (!command_line.HasSwitch(switches::kNoSandbox)) { |
| 272 | // On Mac, if the sandbox is enabled, then gl::init::InitializeGLOneOff() |
| 273 | // is called from the sandbox warmup code before getting here. |
| 274 | gl_already_initialized = true; |
| 275 | } |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 276 | #endif |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 277 | if (command_line.HasSwitch(switches::kInProcessGPU)) { |
| 278 | // With in-process GPU, gl::init::InitializeGLOneOff() is called from |
| 279 | // GpuChildThread before getting here. |
| 280 | gl_already_initialized = true; |
| 281 | } |
[email protected] | af7c5d9 | 2014-02-03 19:53:15 | [diff] [blame] | 282 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 283 | // Load and initialize the GL implementation and locate the GL entry points. |
| 284 | bool gl_initialized = |
| 285 | gl_already_initialized |
| 286 | ? gl::GetGLImplementation() != gl::kGLImplementationNone |
| 287 | : gl::init::InitializeGLOneOff(); |
| 288 | if (gl_initialized) { |
| 289 | // We need to collect GL strings (VENDOR, RENDERER) for blacklisting |
| 290 | // purposes. However, on Mac we don't actually use them. As documented in |
| 291 | // crbug.com/222934, due to some driver issues, glGetString could take |
| 292 | // multiple seconds to finish, which in turn cause the GPU process to |
| 293 | // crash. |
| 294 | // By skipping the following code on Mac, we don't really lose anything, |
| 295 | // because the basic GPU information is passed down from browser process |
| 296 | // and we already registered them through SetGpuInfo() above. |
| 297 | base::TimeTicks before_collect_context_graphics_info = |
| 298 | base::TimeTicks::Now(); |
[email protected] | e9931a4 | 2013-04-11 00:48:41 | [diff] [blame] | 299 | #if !defined(OS_MACOSX) |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 300 | if (!CollectGraphicsInfo(gpu_info)) |
[email protected] | ca23992b0 | 2013-06-13 17:25:19 | [diff] [blame] | 301 | dead_on_arrival = true; |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 302 | |
| 303 | // Recompute gpu driver bug workarounds. |
| 304 | // This is necessary on systems where vendor_id/device_id aren't available |
| 305 | // (Chrome OS, Android) or where workarounds may be dependent on GL_VENDOR |
| 306 | // and GL_RENDERER strings which are lazily computed (Linux). |
| 307 | if (!command_line.HasSwitch(switches::kDisableGpuDriverBugWorkarounds)) { |
| 308 | // TODO: this can not affect disabled extensions, since they're already |
| 309 | // initialized in the bindings. This should be moved before bindings |
| 310 | // initialization. However, populating GPUInfo fully works only on |
| 311 | // Android. Other platforms would need the bindings to query GL strings. |
| 312 | gpu::ApplyGpuDriverBugWorkarounds( |
| 313 | gpu_info, const_cast<base::CommandLine*>(&command_line)); |
[email protected] | ca23992b0 | 2013-06-13 17:25:19 | [diff] [blame] | 314 | } |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 315 | #endif // !defined(OS_MACOSX) |
[email protected] | 4a2a4d2 | 2011-07-25 23:20:34 | [diff] [blame] | 316 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 317 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 318 | if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA |
| 319 | gpu_info.driver_vendor == "NVIDIA" && !CanAccessNvidiaDeviceFile()) |
| 320 | dead_on_arrival = true; |
| 321 | #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
[email protected] | 2f2fd9e | 2013-12-05 03:36:30 | [diff] [blame] | 322 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 323 | base::TimeDelta collect_context_time = |
| 324 | base::TimeTicks::Now() - before_collect_context_graphics_info; |
| 325 | UMA_HISTOGRAM_TIMES("GPU.CollectContextGraphicsInfo", collect_context_time); |
| 326 | } else { // gl_initialized |
| 327 | VLOG(1) << "gl::init::InitializeGLOneOff failed"; |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 328 | dead_on_arrival = true; |
[email protected] | ca23992b0 | 2013-06-13 17:25:19 | [diff] [blame] | 329 | } |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 330 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 331 | base::TimeDelta initialize_one_off_time = |
| 332 | base::TimeTicks::Now() - before_initialize_one_off; |
| 333 | UMA_HISTOGRAM_MEDIUM_TIMES("GPU.InitializeOneOffMediumTime", |
| 334 | initialize_one_off_time); |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame^] | 335 | if (enable_watchdog && delayed_watchdog_enable) |
| 336 | watchdog_thread = gpu::GpuWatchdogThread::Create(); |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 337 | |
| 338 | // OSMesa is expected to run very slowly, so disable the watchdog in that |
| 339 | // case. |
| 340 | if (enable_watchdog && |
| 341 | gl::GetGLImplementation() == gl::kGLImplementationOSMesaGL) { |
| 342 | watchdog_thread->Stop(); |
| 343 | watchdog_thread = NULL; |
| 344 | } |
| 345 | |
| 346 | #if defined(OS_LINUX) |
| 347 | if (!initialized_sandbox) |
| 348 | gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get()); |
| 349 | #elif defined(OS_WIN) |
| 350 | gpu_info.sandboxed = StartSandboxWindows(parameters.sandbox_info); |
| 351 | #elif defined(OS_MACOSX) |
| 352 | gpu_info.sandboxed = Sandbox::SandboxIsCurrentlyActive(); |
| 353 | #endif |
| 354 | |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 355 | logging::SetLogMessageHandler(NULL); |
| 356 | |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 357 | std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory; |
fsamuel | c277422 | 2016-03-24 00:27:12 | [diff] [blame] | 358 | if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) |
markdittmer | d88b835 | 2016-04-08 15:28:45 | [diff] [blame] | 359 | gpu_memory_buffer_factory = gpu::GpuMemoryBufferFactory::CreateNativeType(); |
reveman | fb8c8e10 | 2015-10-07 20:26:32 | [diff] [blame] | 360 | |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame] | 361 | base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL; |
| 362 | #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 363 | io_thread_priority = base::ThreadPriority::DISPLAY; |
| 364 | #endif |
| 365 | |
| 366 | GpuProcess gpu_process(io_thread_priority); |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 367 | |
reveman | 611d024f | 2015-06-25 22:42:40 | [diff] [blame] | 368 | GpuChildThread* child_thread = new GpuChildThread( |
| 369 | watchdog_thread.get(), dead_on_arrival, gpu_info, deferred_messages.Get(), |
boliu | 1384d6d | 2016-04-22 06:38:50 | [diff] [blame] | 370 | gpu_memory_buffer_factory.get()); |
[email protected] | ec4bda6 | 2013-06-14 15:51:03 | [diff] [blame] | 371 | while (!deferred_messages.Get().empty()) |
| 372 | deferred_messages.Get().pop(); |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 373 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 374 | child_thread->Init(start_time); |
[email protected] | 995a7f1 | 2011-02-11 23:07:17 | [diff] [blame] | 375 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 376 | gpu_process.set_main_thread(child_thread); |
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 377 | |
dcheng | 56ddc2f | 2014-08-26 23:01:40 | [diff] [blame] | 378 | if (watchdog_thread.get()) |
[email protected] | 21e2490 | 2013-08-06 20:23:48 | [diff] [blame] | 379 | watchdog_thread->AddPowerObserver(); |
| 380 | |
primiano | b3fb641 | 2015-10-14 16:03:51 | [diff] [blame] | 381 | #if defined(OS_ANDROID) |
| 382 | base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
primiano | 186d6bfe | 2015-10-30 13:21:40 | [diff] [blame] | 383 | tracing::GraphicsMemoryDumpProvider::GetInstance(), "AndroidGraphics", |
| 384 | nullptr); |
primiano | b3fb641 | 2015-10-14 16:03:51 | [diff] [blame] | 385 | #endif |
| 386 | |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 387 | { |
| 388 | TRACE_EVENT0("gpu", "Run Message Loop"); |
fdoray | e716a90 | 2016-07-05 16:05:49 | [diff] [blame] | 389 | base::RunLoop().Run(); |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 390 | } |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 391 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 392 | child_thread->StopWatchdog(); |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 393 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 394 | return 0; |
| 395 | } |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 396 | |
| 397 | namespace { |
| 398 | |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 399 | void GetGpuInfoFromCommandLine(gpu::GPUInfo& gpu_info, |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 400 | const base::CommandLine& command_line) { |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 401 | DCHECK(command_line.HasSwitch(switches::kGpuVendorID) && |
| 402 | command_line.HasSwitch(switches::kGpuDeviceID) && |
| 403 | command_line.HasSwitch(switches::kGpuDriverVersion)); |
| 404 | bool success = base::HexStringToUInt( |
| 405 | command_line.GetSwitchValueASCII(switches::kGpuVendorID), |
| 406 | &gpu_info.gpu.vendor_id); |
| 407 | DCHECK(success); |
| 408 | success = base::HexStringToUInt( |
| 409 | command_line.GetSwitchValueASCII(switches::kGpuDeviceID), |
| 410 | &gpu_info.gpu.device_id); |
| 411 | DCHECK(success); |
| 412 | gpu_info.driver_vendor = |
| 413 | command_line.GetSwitchValueASCII(switches::kGpuDriverVendor); |
| 414 | gpu_info.driver_version = |
| 415 | command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); |
j.isorce | fecf94b | 2016-04-28 05:52:15 | [diff] [blame] | 416 | gpu_info.driver_date = |
| 417 | command_line.GetSwitchValueASCII(switches::kGpuDriverDate); |
j.isorce | 74cae740 | 2016-04-25 20:00:58 | [diff] [blame] | 418 | gpu::ParseSecondaryGpuDevicesFromCommandLine(command_line, &gpu_info); |
| 419 | |
| 420 | // Set active gpu device. |
| 421 | if (command_line.HasSwitch(switches::kGpuActiveVendorID) && |
| 422 | command_line.HasSwitch(switches::kGpuActiveDeviceID)) { |
| 423 | uint32_t active_vendor_id = 0; |
| 424 | uint32_t active_device_id = 0; |
| 425 | success = base::HexStringToUInt( |
| 426 | command_line.GetSwitchValueASCII(switches::kGpuActiveVendorID), |
| 427 | &active_vendor_id); |
| 428 | DCHECK(success); |
| 429 | success = base::HexStringToUInt( |
| 430 | command_line.GetSwitchValueASCII(switches::kGpuActiveDeviceID), |
| 431 | &active_device_id); |
| 432 | DCHECK(success); |
| 433 | if (gpu_info.gpu.vendor_id == active_vendor_id && |
| 434 | gpu_info.gpu.device_id == active_device_id) { |
| 435 | gpu_info.gpu.active = true; |
| 436 | } else { |
| 437 | for (size_t i = 0; i < gpu_info.secondary_gpus.size(); ++i) { |
| 438 | if (gpu_info.secondary_gpus[i].vendor_id == active_vendor_id && |
| 439 | gpu_info.secondary_gpus[i].device_id == active_device_id) { |
| 440 | gpu_info.secondary_gpus[i].active = true; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 447 | GetContentClient()->SetGpuInfo(gpu_info); |
| 448 | } |
| 449 | |
Sadrul Habib Chowdhury | c0a4a9b9 | 2016-08-29 21:43:24 | [diff] [blame] | 450 | void WarmUpSandbox() { |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 451 | { |
| 452 | TRACE_EVENT0("gpu", "Warm up rand"); |
| 453 | // Warm up the random subsystem, which needs to be done pre-sandbox on all |
| 454 | // platforms. |
| 455 | (void) base::RandUint64(); |
| 456 | } |
ananta | b03aa179 | 2015-11-06 01:21:32 | [diff] [blame] | 457 | |
| 458 | #if defined(OS_WIN) |
markdittmer | 6e70beb8 | 2016-05-02 05:40:47 | [diff] [blame] | 459 | media::DXVAVideoDecodeAccelerator::PreSandboxInitialization(); |
emircan | c253d05a | 2016-07-22 23:21:11 | [diff] [blame] | 460 | media::MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); |
ananta | b03aa179 | 2015-11-06 01:21:32 | [diff] [blame] | 461 | #endif |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | #if !defined(OS_MACOSX) |
| 465 | bool CollectGraphicsInfo(gpu::GPUInfo& gpu_info) { |
fdoray | f30bf3a | 2015-10-28 21:47:00 | [diff] [blame] | 466 | TRACE_EVENT0("gpu,startup", "Collect Graphics Info"); |
| 467 | |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 468 | bool res = true; |
| 469 | gpu::CollectInfoResult result = gpu::CollectContextGraphicsInfo(&gpu_info); |
| 470 | switch (result) { |
| 471 | case gpu::kCollectInfoFatalFailure: |
| 472 | LOG(ERROR) << "gpu::CollectGraphicsInfo failed (fatal)."; |
| 473 | res = false; |
| 474 | break; |
| 475 | case gpu::kCollectInfoNonFatalFailure: |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 476 | DVLOG(1) << "gpu::CollectGraphicsInfo failed (non-fatal)."; |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 477 | break; |
zmo | 84eae5e | 2014-09-05 01:36:23 | [diff] [blame] | 478 | case gpu::kCollectInfoNone: |
| 479 | NOTREACHED(); |
| 480 | break; |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 481 | case gpu::kCollectInfoSuccess: |
| 482 | break; |
| 483 | } |
| 484 | GetContentClient()->SetGpuInfo(gpu_info); |
| 485 | return res; |
| 486 | } |
| 487 | #endif |
| 488 | |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 489 | #if defined(OS_LINUX) |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 490 | #if !defined(OS_CHROMEOS) |
| 491 | bool CanAccessNvidiaDeviceFile() { |
| 492 | bool res = true; |
| 493 | base::ThreadRestrictions::AssertIOAllowed(); |
| 494 | if (access("/dev/nvidiactl", R_OK) != 0) { |
anujk.sharma | 98e81a1 | 2014-11-14 04:54:21 | [diff] [blame] | 495 | DVLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; |
[email protected] | b80059f | 2014-06-12 11:00:46 | [diff] [blame] | 496 | res = false; |
| 497 | } |
| 498 | return res; |
| 499 | } |
| 500 | #endif |
| 501 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 502 | bool StartSandboxLinux(const gpu::GPUInfo& gpu_info, |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame^] | 503 | gpu::GpuWatchdogThread* watchdog_thread) { |
fdoray | f30bf3a | 2015-10-28 21:47:00 | [diff] [blame] | 504 | TRACE_EVENT0("gpu,startup", "Initialize sandbox"); |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 505 | |
| 506 | bool res = false; |
| 507 | |
[email protected] | f330b76 | 2014-02-08 04:52:46 | [diff] [blame] | 508 | if (watchdog_thread) { |
| 509 | // LinuxSandbox needs to be able to ensure that the thread |
| 510 | // has really been stopped. |
| 511 | LinuxSandbox::StopThread(watchdog_thread); |
| 512 | } |
[email protected] | 655abd52 | 2014-06-02 15:23:43 | [diff] [blame] | 513 | |
glider | ddea13b | 2015-02-13 18:01:30 | [diff] [blame] | 514 | #if defined(SANITIZER_COVERAGE) |
[email protected] | 356b5202 | 2014-06-03 21:57:38 | [diff] [blame] | 515 | const std::string sancov_file_name = |
| 516 | "gpu." + base::Uint64ToString(base::RandUint64()); |
[email protected] | 655abd52 | 2014-06-02 15:23:43 | [diff] [blame] | 517 | LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); |
| 518 | linux_sandbox->sanitizer_args()->coverage_sandboxed = 1; |
[email protected] | 356b5202 | 2014-06-03 21:57:38 | [diff] [blame] | 519 | linux_sandbox->sanitizer_args()->coverage_fd = |
| 520 | __sanitizer_maybe_open_cov_file(sancov_file_name.c_str()); |
[email protected] | 655abd52 | 2014-06-02 15:23:43 | [diff] [blame] | 521 | linux_sandbox->sanitizer_args()->coverage_max_block_size = 0; |
| 522 | #endif |
| 523 | |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 524 | // LinuxSandbox::InitializeSandbox() must always be called |
| 525 | // with only one thread. |
| 526 | res = LinuxSandbox::InitializeSandbox(); |
[email protected] | f330b76 | 2014-02-08 04:52:46 | [diff] [blame] | 527 | if (watchdog_thread) { |
tonyg | 3f2962f | 2014-09-16 02:14:43 | [diff] [blame] | 528 | base::Thread::Options options; |
| 529 | options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 530 | watchdog_thread->StartWithOptions(options); |
[email protected] | f330b76 | 2014-02-08 04:52:46 | [diff] [blame] | 531 | } |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 532 | |
| 533 | return res; |
| 534 | } |
| 535 | #endif // defined(OS_LINUX) |
| 536 | |
| 537 | #if defined(OS_WIN) |
| 538 | bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) { |
fdoray | f30bf3a | 2015-10-28 21:47:00 | [diff] [blame] | 539 | TRACE_EVENT0("gpu,startup", "Lower token"); |
[email protected] | 663c4b3 | 2013-04-18 05:52:54 | [diff] [blame] | 540 | |
| 541 | // For Windows, if the target_services interface is not zero, the process |
| 542 | // is sandboxed and we must call LowerToken() before rendering untrusted |
| 543 | // content. |
| 544 | sandbox::TargetServices* target_services = sandbox_info->target_services; |
| 545 | if (target_services) { |
| 546 | target_services->LowerToken(); |
| 547 | return true; |
| 548 | } |
| 549 | |
| 550 | return false; |
| 551 | } |
| 552 | #endif // defined(OS_WIN) |
| 553 | |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 554 | } // namespace. |
| 555 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 556 | } // namespace content |