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

Side by Side Diff: content/gpu/gpu_main.cc

Issue 10051022: Add an initial Linux GPU sandbox using the seccomp filter framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/rand_util.h"
13 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 #include "base/win/scoped_com_initializer.h" 16 #include "base/win/scoped_com_initializer.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "content/common/gpu/gpu_config.h" 18 #include "content/common/gpu/gpu_config.h"
18 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
19 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
20 #include "content/public/common/main_function_params.h" 21 #include "content/public/common/main_function_params.h"
21 #include "content/gpu/gpu_child_thread.h" 22 #include "content/gpu/gpu_child_thread.h"
22 #include "content/gpu/gpu_info_collector.h" 23 #include "content/gpu/gpu_info_collector.h"
23 #include "content/gpu/gpu_process.h" 24 #include "content/gpu/gpu_process.h"
24 #include "ui/gfx/gl/gl_surface.h" 25 #include "ui/gfx/gl/gl_surface.h"
25 #include "ui/gfx/gl/gl_switches.h" 26 #include "ui/gfx/gl/gl_switches.h"
26 27
27 #if defined(OS_WIN) 28 #if defined(OS_WIN)
28 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" 29 #include "content/common/gpu/media/dxva_video_decode_accelerator.h"
29 #include "sandbox/src/sandbox.h" 30 #include "sandbox/src/sandbox.h"
30 #endif 31 #endif
31 32
32 #if defined(USE_X11) 33 #if defined(USE_X11)
33 #include "ui/base/x/x11_util.h" 34 #include "ui/base/x/x11_util.h"
34 #endif 35 #endif
35 36
36 #if defined(TOOLKIT_GTK) 37 #if defined(TOOLKIT_GTK)
37 #include "ui/gfx/gtk_util.h" 38 #include "ui/gfx/gtk_util.h"
38 #endif 39 #endif
39 40
41 #if defined(OS_LINUX)
42 #include "content/public/common/sandbox_init.h"
43 #endif
44
40 // Main function for starting the Gpu process. 45 // Main function for starting the Gpu process.
41 int GpuMain(const content::MainFunctionParams& parameters) { 46 int GpuMain(const content::MainFunctionParams& parameters) {
42 base::Time start_time = base::Time::Now(); 47 base::Time start_time = base::Time::Now();
43 48
44 const CommandLine& command_line = parameters.command_line; 49 const CommandLine& command_line = parameters.command_line;
45 if (command_line.HasSwitch(switches::kGpuStartupDialog)) { 50 if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
46 ChildProcess::WaitForDebugger("Gpu"); 51 ChildProcess::WaitForDebugger("Gpu");
47 } 52 }
48 53
49 if (!command_line.HasSwitch(switches::kSingleProcess)) { 54 if (!command_line.HasSwitch(switches::kSingleProcess)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 #endif 98 #endif
94 99
95 // Set the GPU info even if it failed. 100 // Set the GPU info even if it failed.
96 content::GetContentClient()->SetGpuInfo(gpu_info); 101 content::GetContentClient()->SetGpuInfo(gpu_info);
97 } else { 102 } else {
98 LOG(INFO) << "gfx::GLSurface::InitializeOneOff failed"; 103 LOG(INFO) << "gfx::GLSurface::InitializeOneOff failed";
99 gpu_info.gpu_accessible = false; 104 gpu_info.gpu_accessible = false;
100 dead_on_arrival = true; 105 dead_on_arrival = true;
101 } 106 }
102 107
108 // Warm up the random subsystem, which needs to done pre-sandbox on all
109 // platforms. The numbers are arbitrary.
110 (void) base::RandInt(0, 1337);
111
112 #if defined(OS_LINUX)
113 // TODO(cevans): eventually this will be removed when we have tested all
114 // cards and drivers.
115 if (gpu_info.vendor_id == 0x1002) // ATI
116 content::InitializeSandbox();
117 #endif
118
103 base::win::ScopedCOMInitializer com_initializer; 119 base::win::ScopedCOMInitializer com_initializer;
104 120
105 #if defined(OS_WIN) 121 #if defined(OS_WIN)
106 // Preload this DLL because the sandbox prevents it from loading. 122 // Preload this DLL because the sandbox prevents it from loading.
107 LoadLibrary(L"setupapi.dll"); 123 LoadLibrary(L"setupapi.dll");
108 124
109 // Cause advapi32 to load before the sandbox is turned on.
110 unsigned int dummy_rand;
111 rand_s(&dummy_rand);
112
113 sandbox::TargetServices* target_services = 125 sandbox::TargetServices* target_services =
114 parameters.sandbox_info->target_services; 126 parameters.sandbox_info->target_services;
115 // Initialize H/W video decoding stuff which fails in the sandbox. 127 // Initialize H/W video decoding stuff which fails in the sandbox.
116 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); 128 DXVAVideoDecodeAccelerator::PreSandboxInitialization();
117 // For windows, if the target_services interface is not zero, the process 129 // For windows, if the target_services interface is not zero, the process
118 // is sandboxed and we must call LowerToken() before rendering untrusted 130 // is sandboxed and we must call LowerToken() before rendering untrusted
119 // content. 131 // content.
120 if (target_services) 132 if (target_services)
121 target_services->LowerToken(); 133 target_services->LowerToken();
122 #endif 134 #endif
(...skipping 21 matching lines...) Expand all
144 child_thread->Init(start_time); 156 child_thread->Init(start_time);
145 157
146 gpu_process.set_main_thread(child_thread); 158 gpu_process.set_main_thread(child_thread);
147 159
148 main_message_loop.Run(); 160 main_message_loop.Run();
149 161
150 child_thread->StopWatchdog(); 162 child_thread->StopWatchdog();
151 163
152 return 0; 164 return 0;
153 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698