OLD | NEW |
---|---|
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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #endif | 37 #endif |
38 | 38 |
39 #if defined(USE_X11) | 39 #if defined(USE_X11) |
40 #include "ui/base/x/x11_util.h" | 40 #include "ui/base/x/x11_util.h" |
41 #endif | 41 #endif |
42 | 42 |
43 #if defined(OS_LINUX) | 43 #if defined(OS_LINUX) |
44 #include "content/public/common/sandbox_init.h" | 44 #include "content/public/common/sandbox_init.h" |
45 #endif | 45 #endif |
46 | 46 |
47 namespace { | |
48 void WarmUpSandbox(content::GPUInfo*, bool); | |
49 void CollectGraphicsInfo(content::GPUInfo*); | |
50 } | |
51 | |
47 // Main function for starting the Gpu process. | 52 // Main function for starting the Gpu process. |
48 int GpuMain(const content::MainFunctionParams& parameters) { | 53 int GpuMain(const content::MainFunctionParams& parameters) { |
49 TRACE_EVENT0("gpu", "GpuMain"); | 54 TRACE_EVENT0("gpu", "GpuMain"); |
50 | 55 |
51 base::Time start_time = base::Time::Now(); | 56 base::Time start_time = base::Time::Now(); |
52 | 57 |
53 const CommandLine& command_line = parameters.command_line; | 58 const CommandLine& command_line = parameters.command_line; |
54 if (command_line.HasSwitch(switches::kGpuStartupDialog)) { | 59 if (command_line.HasSwitch(switches::kGpuStartupDialog)) { |
55 ChildProcess::WaitForDebugger("Gpu"); | 60 ChildProcess::WaitForDebugger("Gpu"); |
56 } | 61 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 success = base::HexStringToInt( | 97 success = base::HexStringToInt( |
93 command_line.GetSwitchValueASCII(switches::kGpuDeviceID), | 98 command_line.GetSwitchValueASCII(switches::kGpuDeviceID), |
94 reinterpret_cast<int*>(&(gpu_info.gpu.device_id))); | 99 reinterpret_cast<int*>(&(gpu_info.gpu.device_id))); |
95 DCHECK(success); | 100 DCHECK(success); |
96 gpu_info.driver_vendor = | 101 gpu_info.driver_vendor = |
97 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor); | 102 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor); |
98 gpu_info.driver_version = | 103 gpu_info.driver_version = |
99 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); | 104 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); |
100 content::GetContentClient()->SetGpuInfo(gpu_info); | 105 content::GetContentClient()->SetGpuInfo(gpu_info); |
101 | 106 |
107 // We need to track that information for the sandbox PreWarm function. | |
108 bool collect_graphics_info_called = false; | |
102 // Load and initialize the GL implementation and locate the GL entry points. | 109 // Load and initialize the GL implementation and locate the GL entry points. |
103 if (gfx::GLSurface::InitializeOneOff()) { | 110 if (gfx::GLSurface::InitializeOneOff()) { |
104 #if defined(OS_LINUX) | 111 #if defined(OS_LINUX) |
105 // We collect full GPU info on demand in Win/Mac, i.e., when about:gpu | 112 // We collect full GPU info on demand in Win/Mac, i.e., when about:gpu |
106 // page opens. This is because we can make blacklist decisions based on | 113 // page opens. This is because we can make blacklist decisions based on |
107 // preliminary GPU info. | 114 // preliminary GPU info. |
108 // However, on Linux, we may not have enough info for blacklisting. | 115 // However, on Linux, we may not have enough info for blacklisting. |
109 if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id || | 116 if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id || |
110 gpu_info.driver_vendor.empty() || gpu_info.driver_version.empty()) { | 117 gpu_info.driver_vendor.empty() || gpu_info.driver_version.empty()) { |
111 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info)) | 118 CollectGraphicsInfo(&gpu_info); |
112 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; | 119 collect_graphics_info_called = true; |
113 content::GetContentClient()->SetGpuInfo(gpu_info); | |
114 } | 120 } |
115 | 121 |
116 #if !defined(OS_CHROMEOS) | 122 #if !defined(OS_CHROMEOS) |
117 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA | 123 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA |
118 gpu_info.driver_vendor == "NVIDIA") { | 124 gpu_info.driver_vendor == "NVIDIA") { |
119 base::ThreadRestrictions::AssertIOAllowed(); | 125 base::ThreadRestrictions::AssertIOAllowed(); |
120 if (access("/dev/nvidiactl", R_OK) != 0) { | 126 if (access("/dev/nvidiactl", R_OK) != 0) { |
121 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; | 127 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; |
122 gpu_info.gpu_accessible = false; | 128 gpu_info.gpu_accessible = false; |
123 dead_on_arrival = true; | 129 dead_on_arrival = true; |
124 } | 130 } |
125 } | 131 } |
126 #endif // OS_CHROMEOS | 132 #endif // OS_CHROMEOS |
127 #endif // OS_LINUX | 133 #endif // OS_LINUX |
128 } else { | 134 } else { |
129 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; | 135 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; |
130 gpu_info.gpu_accessible = false; | 136 gpu_info.gpu_accessible = false; |
131 gpu_info.finalized = true; | 137 gpu_info.finalized = true; |
132 dead_on_arrival = true; | 138 dead_on_arrival = true; |
133 } | 139 } |
134 | 140 |
135 { | 141 { |
136 TRACE_EVENT0("gpu", "Warm up rand"); | 142 const bool should_collect_graphics_info = !collect_graphics_info_called && |
137 // Warm up the random subsystem, which needs to be done pre-sandbox on all | 143 !dead_on_arrival; |
138 // platforms. | 144 // Warm up the current process before enabling the sandbox. |
139 (void) base::RandUint64(); | 145 WarmUpSandbox(&gpu_info, should_collect_graphics_info); |
140 } | |
141 { | |
142 TRACE_EVENT0("gpu", "Warm up HMAC"); | |
143 // Warm up the crypto subsystem, which needs to done pre-sandbox on all | |
144 // platforms. | |
145 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
146 unsigned char key = '\0'; | |
147 bool ret = hmac.Init(&key, sizeof(key)); | |
148 (void) ret; | |
149 } | 146 } |
150 | 147 |
151 #if defined(OS_LINUX) | 148 #if defined(OS_LINUX) |
152 { | 149 { |
153 TRACE_EVENT0("gpu", "Initialize sandbox"); | 150 TRACE_EVENT0("gpu", "Initialize sandbox"); |
154 bool do_init_sandbox = true; | 151 bool do_init_sandbox = true; |
155 | 152 |
156 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
157 OmxVideoDecodeAccelerator::PreSandboxInitialization(); | |
158 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
159 VaapiVideoDecodeAccelerator::PreSandboxInitialization(); | |
160 #endif | |
161 | |
162 #if defined(OS_CHROMEOS) && defined(NDEBUG) | 153 #if defined(OS_CHROMEOS) && defined(NDEBUG) |
163 // On Chrome OS and when not on a debug build, initialize | 154 // On Chrome OS and when not on a debug build, initialize |
164 // the GPU process' sandbox only for Intel GPUs. | 155 // the GPU process' sandbox only for Intel GPUs. |
165 do_init_sandbox = gpu_info.gpu.vendor_id == 0x8086; // Intel GPU. | 156 do_init_sandbox = gpu_info.gpu.vendor_id == 0x8086; // Intel GPU. |
166 #endif | 157 #endif |
167 | 158 |
168 if (do_init_sandbox) { | 159 if (do_init_sandbox) { |
169 content::InitializeSandbox(); | 160 content::InitializeSandbox(); |
170 } | 161 } |
171 } | 162 } |
172 #endif | 163 #endif |
173 | 164 |
174 { | |
175 TRACE_EVENT0("gpu", "Initialize COM"); | |
176 base::win::ScopedCOMInitializer com_initializer; | |
177 } | |
178 | |
179 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
180 { | 166 { |
181 TRACE_EVENT0("gpu", "Preload setupapi.dll"); | |
182 // Preload this DLL because the sandbox prevents it from loading. | |
183 LoadLibrary(L"setupapi.dll"); | |
184 } | |
185 | |
186 { | |
187 TRACE_EVENT0("gpu", "Initialize DXVA"); | |
188 // Initialize H/W video decoding stuff which fails in the sandbox. | |
189 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); | |
190 } | |
191 | |
192 { | |
193 TRACE_EVENT0("gpu", "Lower token"); | 167 TRACE_EVENT0("gpu", "Lower token"); |
194 // For windows, if the target_services interface is not zero, the process | 168 // For windows, if the target_services interface is not zero, the process |
195 // is sandboxed and we must call LowerToken() before rendering untrusted | 169 // is sandboxed and we must call LowerToken() before rendering untrusted |
196 // content. | 170 // content. |
197 sandbox::TargetServices* target_services = | 171 sandbox::TargetServices* target_services = |
198 parameters.sandbox_info->target_services; | 172 parameters.sandbox_info->target_services; |
199 if (target_services) | 173 if (target_services) |
200 target_services->LowerToken(); | 174 target_services->LowerToken(); |
201 } | 175 } |
202 #endif | 176 #endif |
(...skipping 25 matching lines...) Expand all Loading... | |
228 | 202 |
229 { | 203 { |
230 TRACE_EVENT0("gpu", "Run Message Loop"); | 204 TRACE_EVENT0("gpu", "Run Message Loop"); |
231 main_message_loop.Run(); | 205 main_message_loop.Run(); |
232 } | 206 } |
233 | 207 |
234 child_thread->StopWatchdog(); | 208 child_thread->StopWatchdog(); |
235 | 209 |
236 return 0; | 210 return 0; |
237 } | 211 } |
212 | |
213 namespace { | |
214 | |
215 void WarmUpSandbox(content::GPUInfo* gpu_info, | |
216 bool should_collect_graphics_info) { | |
217 { | |
218 TRACE_EVENT0("gpu", "Warm up rand"); | |
219 // Warm up the random subsystem, which needs to be done pre-sandbox on all | |
220 // platforms. | |
221 (void) base::RandUint64(); | |
222 } | |
223 { | |
224 TRACE_EVENT0("gpu", "Warm up HMAC"); | |
225 // Warm up the crypto subsystem, which needs to done pre-sandbox on all | |
226 // platforms. | |
227 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
228 unsigned char key = '\0'; | |
229 bool ret = hmac.Init(&key, sizeof(key)); | |
230 (void) ret; | |
231 } | |
232 | |
233 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
234 OmxVideoDecodeAccelerator::PreSandboxInitialization(); | |
235 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
236 VaapiVideoDecodeAccelerator::PreSandboxInitialization(); | |
237 #endif | |
238 | |
239 #if defined(OS_LINUX) | |
240 // On Linux, this is needed to make sure /dev/nvidiactl has | |
241 // been opened and its descriptor cached. | |
242 if (gpu_info->gpu.vendor_id == 0x10de && // NVIDIA | |
243 gpu_info->driver_vendor == "NVIDIA" && | |
244 should_collect_graphics_info) { | |
245 CollectGraphicsInfo(gpu_info); | |
Ken Russell (switch to Gerrit)
2012/08/16 00:45:54
I think you should be more explicit about this. In
jln (very slow on Chromium)
2012/08/16 00:52:53
I refactored the local "CollectGraphicsInfo" at th
| |
246 } | |
247 #endif | |
248 | |
249 { | |
250 TRACE_EVENT0("gpu", "Initialize COM"); | |
251 base::win::ScopedCOMInitializer com_initializer; | |
252 } | |
253 | |
254 #if defined(OS_WIN) | |
255 { | |
256 TRACE_EVENT0("gpu", "Preload setupapi.dll"); | |
257 // Preload this DLL because the sandbox prevents it from loading. | |
258 LoadLibrary(L"setupapi.dll"); | |
259 } | |
260 | |
261 { | |
262 TRACE_EVENT0("gpu", "Initialize DXVA"); | |
263 // Initialize H/W video decoding stuff which fails in the sandbox. | |
264 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); | |
265 } | |
266 #endif | |
267 } | |
268 | |
269 void CollectGraphicsInfo(content::GPUInfo* gpu_info) { | |
270 if (!gpu_info_collector::CollectGraphicsInfo(gpu_info)) | |
271 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; | |
272 content::GetContentClient()->SetGpuInfo(*gpu_info); | |
273 } | |
274 | |
275 } // namespace. | |
276 | |
OLD | NEW |