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

Side by Side Diff: chrome/nacl/nacl_exe_win_64.cc

Issue 8414020: Expose the sandbox related code through the content API. I did a bit of cleanup while I was doing... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/system_monitor/system_monitor.h" 11 #include "base/system_monitor/system_monitor.h"
12 #include "chrome/app/breakpad_win.h" 12 #include "chrome/app/breakpad_win.h"
13 #include "chrome/common/chrome_result_codes.h" 13 #include "chrome/common/chrome_result_codes.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/logging_chrome.h" 15 #include "chrome/common/logging_chrome.h"
16 #include "chrome/nacl/nacl_broker_listener.h" 16 #include "chrome/nacl/nacl_broker_listener.h"
17 #include "chrome/nacl/nacl_listener.h" 17 #include "chrome/nacl/nacl_listener.h"
18 #include "chrome/nacl/nacl_main_platform_delegate.h" 18 #include "chrome/nacl/nacl_main_platform_delegate.h"
19 #include "content/app/startup_helper_win.h"
20 #include "content/common/hi_res_timer_manager.h" 19 #include "content/common/hi_res_timer_manager.h"
21 #include "content/common/main_function_params.h" 20 #include "content/common/main_function_params.h"
22 #include "content/common/sandbox_init_wrapper.h" 21 #include "content/public/app/startup_helper_win.h"
23 #include "content/common/sandbox_policy.h" 22 #include "content/public/common/sandbox_init.h"
24 #include "sandbox/src/sandbox.h"
25 #include "sandbox/src/sandbox_types.h" 23 #include "sandbox/src/sandbox_types.h"
26 24
27 extern int NaClMain(const MainFunctionParams&); 25 extern int NaClMain(const MainFunctionParams&);
28 26
29 // main() routine for the NaCl broker process. 27 // main() routine for the NaCl broker process.
30 // This is necessary for supporting NaCl in Chrome on Win64. 28 // This is necessary for supporting NaCl in Chrome on Win64.
31 int NaClBrokerMain(const MainFunctionParams& parameters) { 29 int NaClBrokerMain(const MainFunctionParams& parameters) {
32 const CommandLine& parsed_command_line = parameters.command_line_; 30 const CommandLine& parsed_command_line = parameters.command_line;
33 31
34 MessageLoopForIO main_message_loop; 32 MessageLoopForIO main_message_loop;
35 base::PlatformThread::SetName("CrNaClBrokerMain"); 33 base::PlatformThread::SetName("CrNaClBrokerMain");
36 34
37 base::SystemMonitor system_monitor; 35 base::SystemMonitor system_monitor;
38 HighResolutionTimerManager hi_res_timer_manager; 36 HighResolutionTimerManager hi_res_timer_manager;
39 37
40 // NOTE: this code is duplicated from browser_main.cc
41 // IMPORTANT: This piece of code needs to run as early as possible in the
42 // process because it will initialize the sandbox broker, which requires the
43 // process to swap its window station. During this time all the UI will be
44 // broken. This has to run before threads and windows are created.
45 sandbox::BrokerServices* broker_services =
46 parameters.sandbox_info_.BrokerServices();
47 if (broker_services) {
48 sandbox::InitBrokerServices(broker_services);
49 if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) {
50 bool use_winsta = !parsed_command_line.HasSwitch(
51 switches::kDisableAltWinstation);
52 // Precreate the desktop and window station used by the renderers.
53 sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
54 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
55 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
56 policy->Release();
57 }
58 }
59
60 NaClBrokerListener listener; 38 NaClBrokerListener listener;
61 listener.Listen(); 39 listener.Listen();
62 40
63 return 0; 41 return 0;
64 } 42 }
65 43
66 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { 44 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
67 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 45 sandbox::SandboxInterfaceInfo sandbox_info = {0};
68 content::InitializeSandboxInfo(&sandbox_info); 46 content::InitializeSandboxInfo(&sandbox_info);
69 47
70 base::AtExitManager exit_manager; 48 base::AtExitManager exit_manager;
71 CommandLine::Init(0, NULL); 49 CommandLine::Init(0, NULL);
72 50
73 wchar_t path[MAX_PATH]; 51 wchar_t path[MAX_PATH];
74 ::GetModuleFileNameW(NULL, path, MAX_PATH); 52 ::GetModuleFileNameW(NULL, path, MAX_PATH);
75 InitCrashReporterWithDllPath(std::wstring(path)); 53 InitCrashReporterWithDllPath(std::wstring(path));
76 54
77 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 55 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
78 std::string process_type = 56 std::string process_type =
79 command_line.GetSwitchValueASCII(switches::kProcessType); 57 command_line.GetSwitchValueASCII(switches::kProcessType);
80 58
81 // Copy what ContentMain() does. 59 // Copy what ContentMain() does.
82 base::EnableTerminationOnHeapCorruption(); 60 base::EnableTerminationOnHeapCorruption();
83 base::EnableTerminationOnOutOfMemory(); 61 base::EnableTerminationOnOutOfMemory();
84 content::RegisterInvalidParamHandler(); 62 content::RegisterInvalidParamHandler();
85 content::SetupCRT(command_line); 63 content::SetupCRT(command_line);
86 64
87 // Initialize the sandbox for this process. 65 // Initialize the sandbox for this process.
88 SandboxInitWrapper sandbox_wrapper; 66 bool sandbox_initialized_ok = content::InitializeSandbox(&sandbox_info);
89 sandbox_wrapper.SetServices(&sandbox_info);
90 bool sandbox_initialized_ok =
91 sandbox_wrapper.InitializeSandbox(command_line, process_type);
92 // Die if the sandbox can't be enabled. 67 // Die if the sandbox can't be enabled.
93 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " 68 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for "
94 << process_type; 69 << process_type;
95 MainFunctionParams main_params(command_line, sandbox_wrapper, NULL); 70 MainFunctionParams main_params(command_line);
71 main_params.sandbox_info = &sandbox_info;
96 72
97 if (process_type == switches::kNaClLoaderProcess) 73 if (process_type == switches::kNaClLoaderProcess)
98 return NaClMain(main_params); 74 return NaClMain(main_params);
99 75
100 if (process_type == switches::kNaClBrokerProcess) 76 if (process_type == switches::kNaClBrokerProcess)
101 return NaClBrokerMain(main_params); 77 return NaClBrokerMain(main_params);
102 78
103 CHECK(false) << "Unknown NaCl 64 process."; 79 CHECK(false) << "Unknown NaCl 64 process.";
104 return -1; 80 return -1;
105 } 81 }
OLDNEW
« base/message_pump_default.cc ('K') | « chrome/nacl/DEPS ('k') | chrome/nacl/nacl_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698