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 "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/hi_res_timer_manager.h" | 7 #include "base/hi_res_timer_manager.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/system_monitor/system_monitor.h" | 12 #include "base/system_monitor/system_monitor.h" |
13 #include "chrome/app/breakpad_win.h" | 13 #include "chrome/app/breakpad_win.h" |
14 #include "chrome/common/chrome_result_codes.h" | 14 #include "chrome/common/chrome_result_codes.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/logging_chrome.h" | 16 #include "chrome/common/logging_chrome.h" |
17 #include "chrome/nacl/nacl_broker_listener.h" | 17 #include "chrome/nacl/nacl_broker_listener.h" |
18 #include "chrome/nacl/nacl_listener.h" | 18 #include "chrome/nacl/nacl_listener.h" |
19 #include "chrome/nacl/nacl_main_platform_delegate.h" | 19 #include "chrome/nacl/nacl_main_platform_delegate.h" |
20 #include "content/public/app/startup_helper_win.h" | 20 #include "content/public/app/startup_helper_win.h" |
21 #include "content/public/common/main_function_params.h" | 21 #include "content/public/common/main_function_params.h" |
22 #include "content/public/common/sandbox_init.h" | 22 #include "content/public/common/sandbox_init.h" |
| 23 #include "sandbox/win/src/sandbox_policy.h" |
23 #include "sandbox/win/src/sandbox_types.h" | 24 #include "sandbox/win/src/sandbox_types.h" |
24 | 25 |
25 extern int NaClMain(const content::MainFunctionParams&); | 26 extern int NaClMain(const content::MainFunctionParams&); |
26 | 27 |
| 28 namespace { |
| 29 // This code is duplicated in chrome_browser_main_win.cc. |
| 30 void AddPolicyCallback(CommandLine* cmd_line, |
| 31 sandbox::TargetPolicy* policy) { |
| 32 // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 33 // namespace so that it cannot impersonate other system or other chrome |
| 34 // service pipes. |
| 35 sandbox::ResultCode result = policy->AddRule( |
| 36 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, |
| 37 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
| 38 L"\\\\.\\pipe\\chrome.nacl.*"); |
| 39 CHECK(result == sandbox::SBOX_ALL_OK); |
| 40 } |
| 41 } |
| 42 |
27 // main() routine for the NaCl broker process. | 43 // main() routine for the NaCl broker process. |
28 // This is necessary for supporting NaCl in Chrome on Win64. | 44 // This is necessary for supporting NaCl in Chrome on Win64. |
29 int NaClBrokerMain(const content::MainFunctionParams& parameters) { | 45 int NaClBrokerMain(const content::MainFunctionParams& parameters) { |
30 const CommandLine& parsed_command_line = parameters.command_line; | 46 const CommandLine& parsed_command_line = parameters.command_line; |
31 | 47 |
32 MessageLoopForIO main_message_loop; | 48 MessageLoopForIO main_message_loop; |
33 base::PlatformThread::SetName("CrNaClBrokerMain"); | 49 base::PlatformThread::SetName("CrNaClBrokerMain"); |
34 | 50 |
35 base::SystemMonitor system_monitor; | 51 base::SystemMonitor system_monitor; |
36 HighResolutionTimerManager hi_res_timer_manager; | 52 HighResolutionTimerManager hi_res_timer_manager; |
(...skipping 19 matching lines...) Expand all Loading... |
56 | 72 |
57 // Copy what ContentMain() does. | 73 // Copy what ContentMain() does. |
58 base::EnableTerminationOnHeapCorruption(); | 74 base::EnableTerminationOnHeapCorruption(); |
59 base::EnableTerminationOnOutOfMemory(); | 75 base::EnableTerminationOnOutOfMemory(); |
60 content::RegisterInvalidParamHandler(); | 76 content::RegisterInvalidParamHandler(); |
61 content::SetupCRT(command_line); | 77 content::SetupCRT(command_line); |
62 // Route stdio to parent console (if any) or create one. | 78 // Route stdio to parent console (if any) or create one. |
63 if (command_line.HasSwitch(switches::kEnableLogging)) | 79 if (command_line.HasSwitch(switches::kEnableLogging)) |
64 base::RouteStdioToConsole(); | 80 base::RouteStdioToConsole(); |
65 | 81 |
| 82 content::SetSandboxedProcessStartingCallback(base::Bind(AddPolicyCallback)); |
| 83 |
66 // Initialize the sandbox for this process. | 84 // Initialize the sandbox for this process. |
67 bool sandbox_initialized_ok = content::InitializeSandbox(&sandbox_info); | 85 bool sandbox_initialized_ok = content::InitializeSandbox(&sandbox_info); |
68 // Die if the sandbox can't be enabled. | 86 // Die if the sandbox can't be enabled. |
69 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " | 87 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " |
70 << process_type; | 88 << process_type; |
71 content::MainFunctionParams main_params(command_line); | 89 content::MainFunctionParams main_params(command_line); |
72 main_params.sandbox_info = &sandbox_info; | 90 main_params.sandbox_info = &sandbox_info; |
73 | 91 |
74 if (process_type == switches::kNaClLoaderProcess) | 92 if (process_type == switches::kNaClLoaderProcess) |
75 return NaClMain(main_params); | 93 return NaClMain(main_params); |
76 | 94 |
77 if (process_type == switches::kNaClBrokerProcess) | 95 if (process_type == switches::kNaClBrokerProcess) |
78 return NaClBrokerMain(main_params); | 96 return NaClBrokerMain(main_params); |
79 | 97 |
80 CHECK(false) << "Unknown NaCl 64 process."; | 98 CHECK(false) << "Unknown NaCl 64 process."; |
81 return -1; | 99 return -1; |
82 } | 100 } |
OLD | NEW |