blob: a21d16365a047471ae0bd996988560e7a6cb5cf0 [file] [log] [blame]
[email protected]b39c6d92012-01-31 16:38:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d032f492009-09-29 00:33:462// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e15a4fa2010-02-11 23:09:295#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]d032f492009-09-29 00:33:466
[email protected]a82af392012-02-24 04:40:207#include <string>
8#include <vector>
[email protected]d032f492009-09-29 00:33:469
[email protected]30c1eea2011-10-17 18:40:3010#include "base/bind.h"
[email protected]103607e2010-02-01 18:57:0911#include "base/command_line.h"
[email protected]5b974952012-04-05 18:18:2312#include "base/message_loop.h"
[email protected]338466a82011-05-03 04:27:4313#include "base/path_service.h"
[email protected]5b974952012-04-05 18:18:2314#include "base/string_number_conversions.h"
15#include "base/string_split.h"
[email protected]8f42b4d2012-03-24 14:12:3316#include "base/string_util.h"
[email protected]a0a69bf2011-09-23 21:40:2817#include "base/stringprintf.h"
[email protected]be1ce6a72010-08-03 14:35:2218#include "base/utf_string_conversions.h"
[email protected]1e67c2b2011-03-04 01:17:3719#include "base/win/windows_version.h"
[email protected]a82af392012-02-24 04:40:2020#include "build/build_config.h"
[email protected]8510d282012-08-30 19:47:3821#include "chrome/browser/browser_process.h"
[email protected]8f42b4d2012-03-24 14:12:3322#include "chrome/browser/extensions/extension_info_map.h"
[email protected]8510d282012-08-30 19:47:3823#include "chrome/browser/io_thread.h"
[email protected]2e5f2ea42012-05-09 21:39:2124#include "chrome/browser/nacl_host/nacl_browser.h"
[email protected]8f42b4d2012-03-24 14:12:3325#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]31a665e72012-03-11 12:37:4626#include "chrome/common/chrome_constants.h"
[email protected]338466a82011-05-03 04:27:4327#include "chrome/common/chrome_paths.h"
[email protected]d032f492009-09-29 00:33:4628#include "chrome/common/chrome_switches.h"
[email protected]1657e6d2012-03-30 20:28:0029#include "chrome/common/chrome_version_info.h"
[email protected]d032f492009-09-29 00:33:4630#include "chrome/common/logging_chrome.h"
[email protected]103607e2010-02-01 18:57:0931#include "chrome/common/nacl_cmd_line.h"
[email protected]d032f492009-09-29 00:33:4632#include "chrome/common/nacl_messages.h"
[email protected]fb1277e82009-11-21 20:32:3033#include "chrome/common/render_messages.h"
[email protected]8f42b4d2012-03-24 14:12:3334#include "chrome/common/url_constants.h"
[email protected]4967f792012-01-20 22:14:4035#include "content/public/browser/browser_child_process_host.h"
36#include "content/public/browser/child_process_data.h"
[email protected]4734d0b2011-12-03 07:10:4437#include "content/public/common/child_process_host.h"
[email protected]8510d282012-08-30 19:47:3838#include "ipc/ipc_channel.h"
[email protected]d032f492009-09-29 00:33:4639#include "ipc/ipc_switches.h"
[email protected]1d8a3d1f2011-02-19 07:11:5240#include "native_client/src/shared/imc/nacl_imc.h"
[email protected]87f35592012-04-08 00:49:1641#include "net/base/net_util.h"
[email protected]8510d282012-08-30 19:47:3842#include "ppapi/proxy/ppapi_messages.h"
[email protected]d032f492009-09-29 00:33:4643
[email protected]d032f492009-09-29 00:33:4644#if defined(OS_POSIX)
[email protected]a82af392012-02-24 04:40:2045#include <fcntl.h>
46
[email protected]d032f492009-09-29 00:33:4647#include "ipc/ipc_channel_posix.h"
[email protected]4bdde602010-06-16 03:17:3548#elif defined(OS_WIN)
[email protected]a82af392012-02-24 04:40:2049#include <windows.h>
50
[email protected]b39c6d92012-01-31 16:38:4151#include "base/threading/thread.h"
52#include "base/process_util.h"
[email protected]4c65fb632012-04-27 00:42:2553#include "base/win/scoped_handle.h"
[email protected]4bdde602010-06-16 03:17:3554#include "chrome/browser/nacl_host/nacl_broker_service_win.h"
[email protected]ea6588842012-05-03 05:39:3855#include "chrome/common/nacl_debug_exception_handler_win.h"
[email protected]e4f6eb0232012-04-17 00:47:5056#include "content/public/common/sandbox_init.h"
[email protected]d032f492009-09-29 00:33:4657#endif
58
[email protected]631bb742011-11-02 11:29:3959using content::BrowserThread;
[email protected]4967f792012-01-20 22:14:4060using content::ChildProcessData;
[email protected]4734d0b2011-12-03 07:10:4461using content::ChildProcessHost;
[email protected]8510d282012-08-30 19:47:3862using ppapi::proxy::SerializedHandle;
[email protected]631bb742011-11-02 11:29:3963
[email protected]646e15552012-04-06 22:01:0464namespace {
65
66#if defined(OS_WIN)
67bool RunningOnWOW64() {
68 return (base::win::OSInfo::GetInstance()->wow64_status() ==
69 base::win::OSInfo::WOW64_ENABLED);
70}
71#endif
72
[email protected]646e15552012-04-06 22:01:0473void SetCloseOnExec(nacl::Handle fd) {
74#if defined(OS_POSIX)
75 int flags = fcntl(fd, F_GETFD);
76 CHECK_NE(flags, -1);
77 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
78 CHECK_EQ(rc, 0);
79#endif
80}
81
[email protected]00d99542012-04-17 22:48:0282bool ShareHandleToSelLdr(
[email protected]646e15552012-04-06 22:01:0483 base::ProcessHandle processh,
84 nacl::Handle sourceh,
85 bool close_source,
86 std::vector<nacl::FileDescriptor> *handles_for_sel_ldr) {
87#if defined(OS_WIN)
88 HANDLE channel;
89 int flags = DUPLICATE_SAME_ACCESS;
90 if (close_source)
91 flags |= DUPLICATE_CLOSE_SOURCE;
92 if (!DuplicateHandle(GetCurrentProcess(),
93 reinterpret_cast<HANDLE>(sourceh),
94 processh,
95 &channel,
96 0, // Unused given DUPLICATE_SAME_ACCESS.
97 FALSE,
98 flags)) {
[email protected]09afc2e2012-04-10 17:29:0399 DLOG(ERROR) << "DuplicateHandle() failed";
[email protected]646e15552012-04-06 22:01:04100 return false;
101 }
102 handles_for_sel_ldr->push_back(
103 reinterpret_cast<nacl::FileDescriptor>(channel));
104#else
105 nacl::FileDescriptor channel;
106 channel.fd = sourceh;
107 channel.auto_close = close_source;
108 handles_for_sel_ldr->push_back(channel);
109#endif
110 return true;
111}
112
[email protected]646e15552012-04-06 22:01:04113} // namespace
114
[email protected]1d8a3d1f2011-02-19 07:11:52115struct NaClProcessHost::NaClInternal {
116 std::vector<nacl::Handle> sockets_for_renderer;
117 std::vector<nacl::Handle> sockets_for_sel_ldr;
118};
119
[email protected]646e15552012-04-06 22:01:04120// -----------------------------------------------------------------------------
[email protected]773ebb92011-11-15 19:06:52121
[email protected]8510d282012-08-30 19:47:38122NaClProcessHost::PluginListener::PluginListener(NaClProcessHost* host)
123 : host_(host) {
124}
125
126bool NaClProcessHost::PluginListener::OnMessageReceived(
127 const IPC::Message& msg) {
128 return host_->OnUntrustedMessageForwarded(msg);
129}
130
[email protected]57473ebc2012-05-30 07:44:52131NaClProcessHost::NaClProcessHost(const GURL& manifest_url, bool off_the_record)
[email protected]87f35592012-04-08 00:49:16132 : manifest_url_(manifest_url),
[email protected]a575da52012-03-22 13:08:36133#if defined(OS_WIN)
134 process_launched_by_broker_(false),
[email protected]5b974952012-04-05 18:18:23135#elif defined(OS_LINUX)
136 wait_for_nacl_gdb_(false),
[email protected]a575da52012-03-22 13:08:36137#endif
138 reply_msg_(NULL),
[email protected]ea6588842012-05-03 05:39:38139#if defined(OS_WIN)
140 debug_exception_handler_requested_(false),
141#endif
[email protected]1d8a3d1f2011-02-19 07:11:52142 internal_(new NaClInternal()),
[email protected]5ca93be2012-03-21 20:04:06143 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
[email protected]57473ebc2012-05-30 07:44:52144 enable_exception_handling_(false),
[email protected]2c227ff2012-08-11 00:51:32145 enable_debug_stub_(false),
[email protected]8510d282012-08-30 19:47:38146 off_the_record_(off_the_record),
147 enable_ipc_proxy_(false),
148 ALLOW_THIS_IN_INITIALIZER_LIST(ipc_plugin_listener_(this)) {
[email protected]4967f792012-01-20 22:14:40149 process_.reset(content::BrowserChildProcessHost::Create(
150 content::PROCESS_TYPE_NACL_LOADER, this));
[email protected]87f35592012-04-08 00:49:16151
152 // Set the display name so the user knows what plugin the process is running.
153 // We aren't on the UI thread so getting the pref locale for language
154 // formatting isn't possible, so IDN will be lost, but this is probably OK
155 // for this use case.
156 process_->SetName(net::FormatUrl(manifest_url_, std::string()));
[email protected]5ca93be2012-03-21 20:04:06157
158 // We allow untrusted hardware exception handling to be enabled via
159 // an env var for consistency with the standalone build of NaCl.
160 if (CommandLine::ForCurrentProcess()->HasSwitch(
161 switches::kEnableNaClExceptionHandling) ||
162 getenv("NACL_UNTRUSTED_EXCEPTION_HANDLING") != NULL) {
163 enable_exception_handling_ = true;
[email protected]5ca93be2012-03-21 20:04:06164 }
[email protected]2c227ff2012-08-11 00:51:32165 enable_debug_stub_ = CommandLine::ForCurrentProcess()->HasSwitch(
166 switches::kEnableNaClDebug);
[email protected]17b5a8172012-06-22 21:09:09167
168 enable_ipc_proxy_ = CommandLine::ForCurrentProcess()->HasSwitch(
169 switches::kEnableNaClIPCProxy);
[email protected]d032f492009-09-29 00:33:46170}
171
[email protected]fb1277e82009-11-21 20:32:30172NaClProcessHost::~NaClProcessHost() {
[email protected]4cb43102011-12-02 20:24:49173 int exit_code;
[email protected]4967f792012-01-20 22:14:40174 process_->GetTerminationStatus(&exit_code);
[email protected]4cb43102011-12-02 20:24:49175 std::string message =
176 base::StringPrintf("NaCl process exited with status %i (0x%x)",
177 exit_code, exit_code);
178 if (exit_code == 0) {
179 LOG(INFO) << message;
180 } else {
181 LOG(ERROR) << message;
182 }
183
[email protected]1d8a3d1f2011-02-19 07:11:52184 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
[email protected]909c2402011-05-09 11:39:04185 if (nacl::Close(internal_->sockets_for_renderer[i]) != 0) {
[email protected]09afc2e2012-04-10 17:29:03186 NOTREACHED() << "nacl::Close() failed";
[email protected]909c2402011-05-09 11:39:04187 }
[email protected]c47ec402010-07-29 10:20:49188 }
[email protected]1d8a3d1f2011-02-19 07:11:52189 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
[email protected]909c2402011-05-09 11:39:04190 if (nacl::Close(internal_->sockets_for_sel_ldr[i]) != 0) {
[email protected]09afc2e2012-04-10 17:29:03191 NOTREACHED() << "nacl::Close() failed";
[email protected]909c2402011-05-09 11:39:04192 }
[email protected]c47ec402010-07-29 10:20:49193 }
194
[email protected]909c2402011-05-09 11:39:04195 if (reply_msg_) {
196 // The process failed to launch for some reason.
197 // Don't keep the renderer hanging.
198 reply_msg_->set_reply_error();
199 chrome_render_message_filter_->Send(reply_msg_);
200 }
[email protected]b39c6d92012-01-31 16:38:41201#if defined(OS_WIN)
[email protected]a575da52012-03-22 13:08:36202 if (process_launched_by_broker_) {
203 NaClBrokerService::GetInstance()->OnLoaderDied();
[email protected]5ca93be2012-03-21 20:04:06204 }
[email protected]b39c6d92012-01-31 16:38:41205#endif
[email protected]fb1277e82009-11-21 20:32:30206}
207
[email protected]773ebb92011-11-15 19:06:52208// This is called at browser startup.
209// static
210void NaClProcessHost::EarlyStartup() {
211#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
212 // Open the IRT file early to make sure that it isn't replaced out from
213 // under us by autoupdate.
214 NaClBrowser::GetInstance()->EnsureIrtAvailable();
215#endif
216}
217
[email protected]a575da52012-03-22 13:08:36218void NaClProcessHost::Launch(
[email protected]92d56412011-03-24 20:53:52219 ChromeRenderMessageFilter* chrome_render_message_filter,
220 int socket_count,
[email protected]8f42b4d2012-03-24 14:12:33221 IPC::Message* reply_msg,
222 scoped_refptr<ExtensionInfoMap> extension_info_map) {
[email protected]a575da52012-03-22 13:08:36223 chrome_render_message_filter_ = chrome_render_message_filter;
224 reply_msg_ = reply_msg;
[email protected]8f42b4d2012-03-24 14:12:33225 extension_info_map_ = extension_info_map;
[email protected]a575da52012-03-22 13:08:36226
[email protected]c47ec402010-07-29 10:20:49227 // Place an arbitrary limit on the number of sockets to limit
228 // exposure in case the renderer is compromised. We can increase
229 // this if necessary.
230 if (socket_count > 8) {
[email protected]a575da52012-03-22 13:08:36231 delete this;
232 return;
[email protected]c47ec402010-07-29 10:20:49233 }
234
[email protected]773ebb92011-11-15 19:06:52235 // Start getting the IRT open asynchronously while we launch the NaCl process.
[email protected]09afc2e2012-04-10 17:29:03236 // We'll make sure this actually finished in StartWithLaunchedProcess, below.
[email protected]e97990f2012-05-15 22:06:06237 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
238 nacl_browser->EnsureAllResourcesAvailable();
239 if (!nacl_browser->IsOk()) {
240 DLOG(ERROR) << "Cannot launch NaCl process";
[email protected]a575da52012-03-22 13:08:36241 delete this;
242 return;
[email protected]773ebb92011-11-15 19:06:52243 }
244
[email protected]c47ec402010-07-29 10:20:49245 // Rather than creating a socket pair in the renderer, and passing
246 // one side through the browser to sel_ldr, socket pairs are created
247 // in the browser and then passed to the renderer and sel_ldr.
248 //
249 // This is mainly for the benefit of Windows, where sockets cannot
250 // be passed in messages, but are copied via DuplicateHandle().
251 // This means the sandboxed renderer cannot send handles to the
252 // browser process.
253
254 for (int i = 0; i < socket_count; i++) {
255 nacl::Handle pair[2];
256 // Create a connected socket
[email protected]a575da52012-03-22 13:08:36257 if (nacl::SocketPair(pair) == -1) {
258 delete this;
259 return;
260 }
[email protected]1d8a3d1f2011-02-19 07:11:52261 internal_->sockets_for_renderer.push_back(pair[0]);
262 internal_->sockets_for_sel_ldr.push_back(pair[1]);
[email protected]c47ec402010-07-29 10:20:49263 SetCloseOnExec(pair[0]);
264 SetCloseOnExec(pair[1]);
265 }
[email protected]d032f492009-09-29 00:33:46266
267 // Launch the process
[email protected]fb1277e82009-11-21 20:32:30268 if (!LaunchSelLdr()) {
[email protected]a575da52012-03-22 13:08:36269 delete this;
[email protected]d032f492009-09-29 00:33:46270 }
[email protected]d032f492009-09-29 00:33:46271}
[email protected]646e15552012-04-06 22:01:04272
[email protected]5b974952012-04-05 18:18:23273#if defined(OS_WIN)
[email protected]646e15552012-04-06 22:01:04274void NaClProcessHost::OnChannelConnected(int32 peer_pid) {
275 // Set process handle, if it was not set previously.
276 // This is needed when NaCl process is launched with nacl-gdb.
[email protected]82d17502012-05-23 19:12:40277 if (!CommandLine::ForCurrentProcess()->GetSwitchValuePath(
278 switches::kNaClGdb).empty()) {
[email protected]646e15552012-04-06 22:01:04279 base::ProcessHandle process;
[email protected]82d17502012-05-23 19:12:40280 DCHECK(process_->GetData().handle == base::kNullProcessHandle);
[email protected]646e15552012-04-06 22:01:04281 if (base::OpenProcessHandleWithAccess(
282 peer_pid,
283 base::kProcessAccessDuplicateHandle |
284 base::kProcessAccessQueryInformation |
285 base::kProcessAccessWaitForTermination,
286 &process)) {
287 process_->SetHandle(process);
[email protected]09afc2e2012-04-10 17:29:03288 if (!StartWithLaunchedProcess()) {
289 delete this;
290 return;
291 }
[email protected]646e15552012-04-06 22:01:04292 } else {
[email protected]09afc2e2012-04-10 17:29:03293 DLOG(ERROR) << "Failed to get process handle";
[email protected]646e15552012-04-06 22:01:04294 }
295 }
[email protected]646e15552012-04-06 22:01:04296}
297#else
298void NaClProcessHost::OnChannelConnected(int32 peer_pid) {
299}
300#endif
301
302#if defined(OS_WIN)
303void NaClProcessHost::OnProcessLaunchedByBroker(base::ProcessHandle handle) {
304 process_launched_by_broker_ = true;
305 process_->SetHandle(handle);
[email protected]09afc2e2012-04-10 17:29:03306 if (!StartWithLaunchedProcess())
307 delete this;
[email protected]646e15552012-04-06 22:01:04308}
309
[email protected]ea6588842012-05-03 05:39:38310void NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker(bool success) {
311 IPC::Message* reply = attach_debug_exception_handler_reply_msg_.release();
312 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply, success);
313 Send(reply);
[email protected]646e15552012-04-06 22:01:04314}
315#endif
316
317// Needed to handle sync messages in OnMessageRecieved.
318bool NaClProcessHost::Send(IPC::Message* msg) {
319 return process_->Send(msg);
320}
321
322#if defined(OS_WIN)
323scoped_ptr<CommandLine> NaClProcessHost::GetCommandForLaunchWithGdb(
[email protected]8f42b4d2012-03-24 14:12:33324 const FilePath& nacl_gdb,
[email protected]5b974952012-04-05 18:18:23325 CommandLine* line) {
[email protected]31a665e72012-03-11 12:37:46326 CommandLine* cmd_line = new CommandLine(nacl_gdb);
327 // We can't use PrependWrapper because our parameters contain spaces.
328 cmd_line->AppendArg("--eval-command");
329 const FilePath::StringType& irt_path =
330 NaClBrowser::GetInstance()->GetIrtFilePath().value();
331 cmd_line->AppendArgNative(FILE_PATH_LITERAL("nacl-irt ") + irt_path);
[email protected]5b974952012-04-05 18:18:23332 FilePath manifest_path = GetManifestPath();
[email protected]8f42b4d2012-03-24 14:12:33333 if (!manifest_path.empty()) {
334 cmd_line->AppendArg("--eval-command");
335 cmd_line->AppendArgNative(FILE_PATH_LITERAL("nacl-manifest ") +
336 manifest_path.value());
337 }
[email protected]401b90792012-05-30 11:41:13338 FilePath script = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
339 switches::kNaClGdbScript);
340 if (!script.empty()) {
341 cmd_line->AppendArg("--command");
342 cmd_line->AppendArgNative(script.value());
343 }
[email protected]31a665e72012-03-11 12:37:46344 cmd_line->AppendArg("--args");
345 const CommandLine::StringVector& argv = line->argv();
346 for (size_t i = 0; i < argv.size(); i++) {
347 cmd_line->AppendArgNative(argv[i]);
348 }
349 return scoped_ptr<CommandLine>(cmd_line);
350}
[email protected]5b974952012-04-05 18:18:23351#elif defined(OS_LINUX)
[email protected]512d03f2012-06-26 01:06:06352class NaClProcessHost::NaClGdbWatchDelegate
353 : public MessageLoopForIO::Watcher {
[email protected]5b974952012-04-05 18:18:23354 public:
355 // fd_write_ is used by nacl-gdb via /proc/browser_PID/fd/fd_write_
356 NaClGdbWatchDelegate(int fd_read, int fd_write,
357 const base::Closure& reply)
358 : fd_read_(fd_read),
359 fd_write_(fd_write),
360 reply_(reply) {}
361
362 ~NaClGdbWatchDelegate() {
363 if (HANDLE_EINTR(close(fd_read_)) != 0)
364 DLOG(ERROR) << "close(fd_read_) failed";
365 if (HANDLE_EINTR(close(fd_write_)) != 0)
366 DLOG(ERROR) << "close(fd_write_) failed";
367 }
368
369 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
370 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {}
371
372 private:
373 int fd_read_;
374 int fd_write_;
375 base::Closure reply_;
376};
377
[email protected]512d03f2012-06-26 01:06:06378void NaClProcessHost::NaClGdbWatchDelegate::OnFileCanReadWithoutBlocking(
379 int fd) {
[email protected]5b974952012-04-05 18:18:23380 char buf;
381 if (HANDLE_EINTR(read(fd_read_, &buf, 1)) != 1 || buf != '\0')
382 LOG(ERROR) << "Failed to sync with nacl-gdb";
383 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, reply_);
384}
[email protected]5b974952012-04-05 18:18:23385
386bool NaClProcessHost::LaunchNaClGdb(base::ProcessId pid) {
387 CommandLine::StringType nacl_gdb =
388 CommandLine::ForCurrentProcess()->GetSwitchValueNative(
389 switches::kNaClGdb);
390 CommandLine::StringVector argv;
391 // We don't support spaces inside arguments in --nacl-gdb switch.
392 base::SplitString(nacl_gdb, static_cast<CommandLine::CharType>(' '), &argv);
393 CommandLine cmd_line(argv);
394 cmd_line.AppendArg("--eval-command");
395 const FilePath::StringType& irt_path =
396 NaClBrowser::GetInstance()->GetIrtFilePath().value();
397 cmd_line.AppendArgNative(FILE_PATH_LITERAL("nacl-irt ") + irt_path);
398 FilePath manifest_path = GetManifestPath();
399 if (!manifest_path.empty()) {
400 cmd_line.AppendArg("--eval-command");
401 cmd_line.AppendArgNative(FILE_PATH_LITERAL("nacl-manifest ") +
402 manifest_path.value());
403 }
404 cmd_line.AppendArg("--eval-command");
405 cmd_line.AppendArg("attach " + base::IntToString(pid));
406 int fds[2];
407 if (pipe(fds) != 0)
408 return false;
409 // Tell the debugger to send a byte to the writable end of the pipe.
410 // We use a file descriptor in our process because the debugger will be
411 // typically launched in a separate terminal, and a lot of terminals close all
412 // file descriptors before launching external programs.
413 cmd_line.AppendArg("--eval-command");
414 cmd_line.AppendArg("dump binary value /proc/" +
415 base::IntToString(base::GetCurrentProcId()) +
416 "/fd/" + base::IntToString(fds[1]) + " (char)0");
[email protected]401b90792012-05-30 11:41:13417 FilePath script = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
418 switches::kNaClGdbScript);
419 if (!script.empty()) {
420 cmd_line.AppendArg("--command");
421 cmd_line.AppendArgNative(script.value());
422 }
[email protected]5b974952012-04-05 18:18:23423 // wait on fds[0]
424 // If the debugger crashes before attaching to the NaCl process, the user can
425 // release resources by terminating the NaCl loader in Chrome Task Manager.
426 nacl_gdb_watcher_delegate_.reset(
427 new NaClGdbWatchDelegate(
428 fds[0], fds[1],
429 base::Bind(&NaClProcessHost::OnNaClGdbAttached,
430 weak_factory_.GetWeakPtr())));
431 MessageLoopForIO::current()->WatchFileDescriptor(
432 fds[0],
433 true,
434 MessageLoopForIO::WATCH_READ,
435 &nacl_gdb_watcher_,
436 nacl_gdb_watcher_delegate_.get());
437 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL);
438}
439
440void NaClProcessHost::OnNaClGdbAttached() {
441 wait_for_nacl_gdb_ = false;
442 nacl_gdb_watcher_.StopWatchingFileDescriptor();
443 nacl_gdb_watcher_delegate_.reset();
444 OnProcessLaunched();
445}
446#endif
447
448FilePath NaClProcessHost::GetManifestPath() {
[email protected]1c321ee2012-05-21 03:02:34449 const extensions::Extension* extension = extension_info_map_->extensions()
[email protected]87f35592012-04-08 00:49:16450 .GetExtensionOrAppByURL(ExtensionURLInfo(manifest_url_));
451 if (extension != NULL && manifest_url_.SchemeIs(chrome::kExtensionScheme)) {
452 std::string path = manifest_url_.path();
[email protected]5b974952012-04-05 18:18:23453 TrimString(path, "/", &path); // Remove first slash
454 return extension->path().AppendASCII(path);
455 }
456 return FilePath();
457}
[email protected]31a665e72012-03-11 12:37:46458
[email protected]fb1277e82009-11-21 20:32:30459bool NaClProcessHost::LaunchSelLdr() {
[email protected]4967f792012-01-20 22:14:40460 std::string channel_id = process_->GetHost()->CreateChannel();
[email protected]4734d0b2011-12-03 07:10:44461 if (channel_id.empty())
[email protected]d032f492009-09-29 00:33:46462 return false;
463
[email protected]e3fc75a2011-05-05 08:20:42464 CommandLine::StringType nacl_loader_prefix;
465#if defined(OS_POSIX)
466 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative(
467 switches::kNaClLoaderCmdPrefix);
468#endif // defined(OS_POSIX)
469
[email protected]d032f492009-09-29 00:33:46470 // Build command line for nacl.
[email protected]8c40f322011-08-24 03:33:36471
472#if defined(OS_MACOSX)
473 // The Native Client process needs to be able to allocate a 1GB contiguous
474 // region to use as the client environment's virtual address space. ASLR
475 // (PIE) interferes with this by making it possible that no gap large enough
476 // to accomodate this request will exist in the child process' address
477 // space. Disable PIE for NaCl processes. See http://crbug.com/90221 and
478 // http://code.google.com/p/nativeclient/issues/detail?id=2043.
[email protected]4cb43102011-12-02 20:24:49479 int flags = ChildProcessHost::CHILD_NO_PIE;
[email protected]8c40f322011-08-24 03:33:36480#elif defined(OS_LINUX)
[email protected]4cb43102011-12-02 20:24:49481 int flags = nacl_loader_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF :
482 ChildProcessHost::CHILD_NORMAL;
[email protected]8c40f322011-08-24 03:33:36483#else
[email protected]4cb43102011-12-02 20:24:49484 int flags = ChildProcessHost::CHILD_NORMAL;
[email protected]8c40f322011-08-24 03:33:36485#endif
486
[email protected]4cb43102011-12-02 20:24:49487 FilePath exe_path = ChildProcessHost::GetChildPath(flags);
[email protected]fb1277e82009-11-21 20:32:30488 if (exe_path.empty())
[email protected]d032f492009-09-29 00:33:46489 return false;
490
[email protected]31a665e72012-03-11 12:37:46491#if defined(OS_WIN)
492 // On Windows 64-bit NaCl loader is called nacl64.exe instead of chrome.exe
493 if (RunningOnWOW64()) {
494 FilePath module_path;
495 if (!PathService::Get(base::FILE_MODULE, &module_path))
496 return false;
497 exe_path = module_path.DirName().Append(chrome::kNaClAppName);
498 }
499#endif
500
[email protected]33a05af2012-03-02 18:15:51501 scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path));
502 nacl::CopyNaClCommandLineArguments(cmd_line.get());
[email protected]599e6642010-01-27 18:52:13503
[email protected]05076ba22010-07-30 05:59:57504 cmd_line->AppendSwitchASCII(switches::kProcessType,
505 switches::kNaClLoaderProcess);
[email protected]4734d0b2011-12-03 07:10:44506 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id);
[email protected]93156cec2011-09-12 21:14:44507 if (logging::DialogsAreSuppressed())
508 cmd_line->AppendSwitch(switches::kNoErrorDialogs);
[email protected]d032f492009-09-29 00:33:46509
[email protected]e3fc75a2011-05-05 08:20:42510 if (!nacl_loader_prefix.empty())
511 cmd_line->PrependWrapper(nacl_loader_prefix);
512
[email protected]31a665e72012-03-11 12:37:46513 FilePath nacl_gdb = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
514 switches::kNaClGdb);
515 if (!nacl_gdb.empty()) {
[email protected]5b974952012-04-05 18:18:23516#if defined(OS_WIN)
[email protected]31a665e72012-03-11 12:37:46517 cmd_line->AppendSwitch(switches::kNoSandbox);
518 scoped_ptr<CommandLine> gdb_cmd_line(
[email protected]646e15552012-04-06 22:01:04519 GetCommandForLaunchWithGdb(nacl_gdb, cmd_line.get()));
[email protected]31a665e72012-03-11 12:37:46520 // We can't use process_->Launch() because OnProcessLaunched will be called
521 // with process_->GetData().handle filled by handle of gdb process. This
522 // handle will be used to duplicate handles for NaCl process and as
523 // a result NaCl process will not be able to use them.
524 //
525 // So we don't fill process_->GetData().handle and wait for
526 // OnChannelConnected to get handle of NaCl process from its pid. Then we
527 // call OnProcessLaunched.
528 return base::LaunchProcess(*gdb_cmd_line, base::LaunchOptions(), NULL);
[email protected]5b974952012-04-05 18:18:23529#elif defined(OS_LINUX)
530 wait_for_nacl_gdb_ = true;
531#endif
[email protected]31a665e72012-03-11 12:37:46532 }
533
[email protected]103607e2010-02-01 18:57:09534 // On Windows we might need to start the broker process to launch a new loader
[email protected]d032f492009-09-29 00:33:46535#if defined(OS_WIN)
[email protected]773ebb92011-11-15 19:06:52536 if (RunningOnWOW64()) {
[email protected]26b3c002012-04-26 19:38:34537 return NaClBrokerService::GetInstance()->LaunchLoader(
538 weak_factory_.GetWeakPtr(), channel_id);
[email protected]4bdde602010-06-16 03:17:35539 } else {
[email protected]33a05af2012-03-02 18:15:51540 process_->Launch(FilePath(), cmd_line.release());
[email protected]4bdde602010-06-16 03:17:35541 }
[email protected]103607e2010-02-01 18:57:09542#elif defined(OS_POSIX)
[email protected]4967f792012-01-20 22:14:40543 process_->Launch(nacl_loader_prefix.empty(), // use_zygote
[email protected]a82af392012-02-24 04:40:20544 base::EnvironmentVector(),
[email protected]33a05af2012-03-02 18:15:51545 cmd_line.release());
[email protected]103607e2010-02-01 18:57:09546#endif
[email protected]d032f492009-09-29 00:33:46547
[email protected]fb1277e82009-11-21 20:32:30548 return true;
[email protected]d032f492009-09-29 00:33:46549}
550
[email protected]646e15552012-04-06 22:01:04551bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) {
552 bool handled = true;
553 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
554 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate,
555 OnQueryKnownToValidate)
556 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate,
557 OnSetKnownToValidate)
[email protected]ea6588842012-05-03 05:39:38558#if defined(OS_WIN)
559 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler,
560 OnAttachDebugExceptionHandler)
561#endif
[email protected]17b5a8172012-06-22 21:09:09562 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated,
563 OnPpapiChannelCreated)
[email protected]646e15552012-04-06 22:01:04564 IPC_MESSAGE_UNHANDLED(handled = false)
565 IPC_END_MESSAGE_MAP()
566 return handled;
[email protected]103607e2010-02-01 18:57:09567}
568
[email protected]773ebb92011-11-15 19:06:52569void NaClProcessHost::OnProcessLaunched() {
[email protected]09afc2e2012-04-10 17:29:03570 if (!StartWithLaunchedProcess())
571 delete this;
[email protected]773ebb92011-11-15 19:06:52572}
573
[email protected]e97990f2012-05-15 22:06:06574// Called when the NaClBrowser singleton has been fully initialized.
575void NaClProcessHost::OnResourcesReady() {
[email protected]773ebb92011-11-15 19:06:52576 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
[email protected]e97990f2012-05-15 22:06:06577 if (!nacl_browser->IsReady() || !SendStart()) {
[email protected]09afc2e2012-04-10 17:29:03578 DLOG(ERROR) << "Cannot launch NaCl process";
[email protected]338466a82011-05-03 04:27:43579 delete this;
580 }
581}
582
[email protected]17b5a8172012-06-22 21:09:09583bool NaClProcessHost::ReplyToRenderer(
584 const IPC::ChannelHandle& channel_handle) {
[email protected]c47ec402010-07-29 10:20:49585 std::vector<nacl::FileDescriptor> handles_for_renderer;
[email protected]1d8a3d1f2011-02-19 07:11:52586 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
[email protected]c47ec402010-07-29 10:20:49587#if defined(OS_WIN)
588 // Copy the handle into the renderer process.
589 HANDLE handle_in_renderer;
[email protected]909c2402011-05-09 11:39:04590 if (!DuplicateHandle(base::GetCurrentProcessHandle(),
591 reinterpret_cast<HANDLE>(
592 internal_->sockets_for_renderer[i]),
593 chrome_render_message_filter_->peer_handle(),
594 &handle_in_renderer,
595 0, // Unused given DUPLICATE_SAME_ACCESS.
596 FALSE,
597 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
[email protected]09afc2e2012-04-10 17:29:03598 DLOG(ERROR) << "DuplicateHandle() failed";
599 return false;
[email protected]909c2402011-05-09 11:39:04600 }
[email protected]c47ec402010-07-29 10:20:49601 handles_for_renderer.push_back(
602 reinterpret_cast<nacl::FileDescriptor>(handle_in_renderer));
603#else
604 // No need to dup the imc_handle - we don't pass it anywhere else so
605 // it cannot be closed.
606 nacl::FileDescriptor imc_handle;
[email protected]1d8a3d1f2011-02-19 07:11:52607 imc_handle.fd = internal_->sockets_for_renderer[i];
[email protected]c47ec402010-07-29 10:20:49608 imc_handle.auto_close = true;
609 handles_for_renderer.push_back(imc_handle);
610#endif
611 }
612
613#if defined(OS_WIN)
[email protected]e4f6eb0232012-04-17 00:47:50614 // If we are on 64-bit Windows, the NaCl process's sandbox is
615 // managed by a different process from the renderer's sandbox. We
616 // need to inform the renderer's sandbox about the NaCl process so
617 // that the renderer can send handles to the NaCl process using
618 // BrokerDuplicateHandle().
619 if (RunningOnWOW64()) {
[email protected]171fa98d2012-04-23 21:34:01620 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) {
[email protected]e4f6eb0232012-04-17 00:47:50621 DLOG(ERROR) << "Failed to add NaCl process PID";
622 return false;
623 }
624 }
[email protected]fb1277e82009-11-21 20:32:30625#endif
626
[email protected]2ccf45c2011-08-19 23:35:50627 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams(
[email protected]17b5a8172012-06-22 21:09:09628 reply_msg_, handles_for_renderer, channel_handle);
[email protected]92d56412011-03-24 20:53:52629 chrome_render_message_filter_->Send(reply_msg_);
630 chrome_render_message_filter_ = NULL;
[email protected]fb1277e82009-11-21 20:32:30631 reply_msg_ = NULL;
[email protected]1d8a3d1f2011-02-19 07:11:52632 internal_->sockets_for_renderer.clear();
[email protected]00d99542012-04-17 22:48:02633 return true;
634}
[email protected]fb1277e82009-11-21 20:32:30635
[email protected]00d99542012-04-17 22:48:02636bool NaClProcessHost::StartNaClExecution() {
637 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
638
639 nacl::NaClStartParams params;
[email protected]8c670832012-05-26 04:30:12640 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled();
641 params.validation_cache_key = nacl_browser->GetValidationCacheKey();
[email protected]00d99542012-04-17 22:48:02642 params.version = chrome::VersionInfo().CreateVersionString();
643 params.enable_exception_handling = enable_exception_handling_;
[email protected]2c227ff2012-08-11 00:51:32644 params.enable_debug_stub = enable_debug_stub_;
[email protected]17b5a8172012-06-22 21:09:09645 params.enable_ipc_proxy = enable_ipc_proxy_;
[email protected]00d99542012-04-17 22:48:02646
647 base::PlatformFile irt_file = nacl_browser->IrtFile();
648 CHECK_NE(irt_file, base::kInvalidPlatformFileValue);
649
650 const ChildProcessData& data = process_->GetData();
[email protected]1d8a3d1f2011-02-19 07:11:52651 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
[email protected]00d99542012-04-17 22:48:02652 if (!ShareHandleToSelLdr(data.handle,
653 internal_->sockets_for_sel_ldr[i], true,
654 &params.handles)) {
[email protected]09afc2e2012-04-10 17:29:03655 return false;
[email protected]c47ec402010-07-29 10:20:49656 }
[email protected]773ebb92011-11-15 19:06:52657 }
658
659 // Send over the IRT file handle. We don't close our own copy!
[email protected]00d99542012-04-17 22:48:02660 if (!ShareHandleToSelLdr(data.handle, irt_file, false, &params.handles))
[email protected]09afc2e2012-04-10 17:29:03661 return false;
[email protected]c47ec402010-07-29 10:20:49662
[email protected]ab88d1542011-11-18 22:52:00663#if defined(OS_MACOSX)
664 // For dynamic loading support, NaCl requires a file descriptor that
665 // was created in /tmp, since those created with shm_open() are not
666 // mappable with PROT_EXEC. Rather than requiring an extra IPC
667 // round trip out of the sandbox, we create an FD here.
[email protected]cbbe7842011-11-17 22:01:25668 base::SharedMemory memory_buffer;
[email protected]b05df6b2011-12-01 23:19:31669 base::SharedMemoryCreateOptions options;
670 options.size = 1;
671 options.executable = true;
672 if (!memory_buffer.Create(options)) {
[email protected]09afc2e2012-04-10 17:29:03673 DLOG(ERROR) << "Failed to allocate memory buffer";
674 return false;
[email protected]2c68bf032010-11-11 23:16:30675 }
[email protected]cbbe7842011-11-17 22:01:25676 nacl::FileDescriptor memory_fd;
677 memory_fd.fd = dup(memory_buffer.handle().fd);
678 if (memory_fd.fd < 0) {
[email protected]09afc2e2012-04-10 17:29:03679 DLOG(ERROR) << "Failed to dup() a file descriptor";
680 return false;
[email protected]cbbe7842011-11-17 22:01:25681 }
682 memory_fd.auto_close = true;
[email protected]00d99542012-04-17 22:48:02683 params.handles.push_back(memory_fd);
[email protected]2c68bf032010-11-11 23:16:30684#endif
685
[email protected]ea6588842012-05-03 05:39:38686 process_->Send(new NaClProcessMsg_Start(params));
[email protected]b39c6d92012-01-31 16:38:41687
[email protected]1d8a3d1f2011-02-19 07:11:52688 internal_->sockets_for_sel_ldr.clear();
[email protected]09afc2e2012-04-10 17:29:03689 return true;
690}
691
[email protected]00d99542012-04-17 22:48:02692bool NaClProcessHost::SendStart() {
[email protected]17b5a8172012-06-22 21:09:09693 if (!enable_ipc_proxy_) {
694 if (!ReplyToRenderer(IPC::ChannelHandle()))
695 return false;
696 }
697 return StartNaClExecution();
698}
699
[email protected]8510d282012-08-30 19:47:38700// This method is called when NaClProcessHostMsg_PpapiChannelCreated is
701// received or PpapiHostMsg_ChannelCreated is forwarded by our plugin
702// listener.
[email protected]17b5a8172012-06-22 21:09:09703void NaClProcessHost::OnPpapiChannelCreated(
704 const IPC::ChannelHandle& channel_handle) {
705 DCHECK(enable_ipc_proxy_);
[email protected]8510d282012-08-30 19:47:38706 // If the proxy channel is null, this must be the initial NaCl-Browser IPC
707 // channel.
708 if (!ipc_proxy_channel_.get()) {
709 ipc_proxy_channel_.reset(
710 new IPC::ChannelProxy(channel_handle,
711 IPC::Channel::MODE_CLIENT,
712 &ipc_plugin_listener_,
713 base::MessageLoopProxy::current()));
714 // Send a message to create the NaCl-Renderer channel. The handle is just
715 // a place holder.
716 ipc_proxy_channel_->Send(
717 new PpapiMsg_CreateNaClChannel(
718 chrome_render_message_filter_->render_process_id(),
719 chrome_render_message_filter_->off_the_record(),
720 SerializedHandle(SerializedHandle::CHANNEL_HANDLE,
721 IPC::InvalidPlatformFileForTransit())));
722 } else if (reply_msg_) {
723 // Otherwise, this must be a renderer channel.
724 ReplyToRenderer(channel_handle);
725 } else {
726 // Attempt to open more than 1 renderer channel is not supported.
727 // Shut down the NaCl process.
728 process_->GetHost()->ForceShutdown();
729 }
730}
731
732bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) {
733 // Handle messages that have been forwarded from our PluginListener.
734 // These messages come from untrusted code so should be handled with care.
735 bool handled = true;
736 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
737 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated,
738 OnPpapiChannelCreated)
739 IPC_MESSAGE_UNHANDLED(handled = false)
740 IPC_END_MESSAGE_MAP()
741 return handled;
[email protected]00d99542012-04-17 22:48:02742}
743
[email protected]09afc2e2012-04-10 17:29:03744bool NaClProcessHost::StartWithLaunchedProcess() {
745#if defined(OS_LINUX)
746 if (wait_for_nacl_gdb_) {
747 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) {
748 // We will be called with wait_for_nacl_gdb_ = false once debugger is
749 // attached to the program.
750 return true;
751 }
752 DLOG(ERROR) << "Failed to launch debugger";
753 // Continue execution without debugger.
754 }
755#endif
756
757 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
[email protected]09afc2e2012-04-10 17:29:03758
[email protected]e97990f2012-05-15 22:06:06759 if (nacl_browser->IsReady()) {
760 return SendStart();
761 } else if (nacl_browser->IsOk()) {
762 nacl_browser->WaitForResources(
763 base::Bind(&NaClProcessHost::OnResourcesReady,
764 weak_factory_.GetWeakPtr()));
765 return true;
766 } else {
767 return false;
768 }
[email protected]d032f492009-09-29 00:33:46769}
770
[email protected]4a0141b2012-03-27 01:15:30771void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature,
772 bool* result) {
[email protected]7cfaf982012-05-09 18:37:47773 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
[email protected]57473ebc2012-05-30 07:44:52774 *result = nacl_browser->QueryKnownToValidate(signature, off_the_record_);
[email protected]4a0141b2012-03-27 01:15:30775}
776
777void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) {
[email protected]57473ebc2012-05-30 07:44:52778 NaClBrowser::GetInstance()->SetKnownToValidate(signature, off_the_record_);
[email protected]4a0141b2012-03-27 01:15:30779}
[email protected]ea6588842012-05-03 05:39:38780
781#if defined(OS_WIN)
782void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info,
783 IPC::Message* reply_msg) {
784 if (!AttachDebugExceptionHandler(info, reply_msg)) {
785 // Send failure message.
786 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg,
787 false);
788 Send(reply_msg);
789 }
790}
791
792bool NaClProcessHost::AttachDebugExceptionHandler(const std::string& info,
793 IPC::Message* reply_msg) {
[email protected]2c227ff2012-08-11 00:51:32794 if (!enable_exception_handling_ && !enable_debug_stub_) {
[email protected]ea6588842012-05-03 05:39:38795 DLOG(ERROR) <<
[email protected]2c227ff2012-08-11 00:51:32796 "Debug exception handler requested by NaCl process when not enabled";
[email protected]ea6588842012-05-03 05:39:38797 return false;
798 }
799 if (debug_exception_handler_requested_) {
800 // The NaCl process should not request this multiple times.
801 DLOG(ERROR) << "Multiple AttachDebugExceptionHandler requests received";
802 return false;
803 }
804 debug_exception_handler_requested_ = true;
805
806 base::ProcessId nacl_pid = base::GetProcId(process_->GetData().handle);
807 base::win::ScopedHandle process_handle;
808 // We cannot use process_->GetData().handle because it does not have
809 // the necessary access rights. We open the new handle here rather
810 // than in the NaCl broker process in case the NaCl loader process
811 // dies before the NaCl broker process receives the message we send.
812 // The debug exception handler uses DebugActiveProcess() to attach,
813 // but this takes a PID. We need to prevent the NaCl loader's PID
814 // from being reused before DebugActiveProcess() is called, and
815 // holding a process handle open achieves this.
816 if (!base::OpenProcessHandleWithAccess(
817 nacl_pid,
818 base::kProcessAccessQueryInformation |
819 base::kProcessAccessSuspendResume |
820 base::kProcessAccessTerminate |
821 base::kProcessAccessVMOperation |
822 base::kProcessAccessVMRead |
823 base::kProcessAccessVMWrite |
824 base::kProcessAccessWaitForTermination,
825 process_handle.Receive())) {
826 LOG(ERROR) << "Failed to get process handle";
827 return false;
828 }
829
830 attach_debug_exception_handler_reply_msg_.reset(reply_msg);
831 // If the NaCl loader is 64-bit, the process running its debug
832 // exception handler must be 64-bit too, so we use the 64-bit NaCl
833 // broker process for this. Otherwise, on a 32-bit system, we use
834 // the 32-bit browser process to run the debug exception handler.
835 if (RunningOnWOW64()) {
836 return NaClBrokerService::GetInstance()->LaunchDebugExceptionHandler(
[email protected]fd37bf62012-05-04 16:46:48837 weak_factory_.GetWeakPtr(), nacl_pid, process_handle, info);
[email protected]ea6588842012-05-03 05:39:38838 } else {
839 NaClStartDebugExceptionHandlerThread(
[email protected]fd37bf62012-05-04 16:46:48840 process_handle.Take(), info,
[email protected]ea6588842012-05-03 05:39:38841 base::MessageLoopProxy::current(),
842 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
843 weak_factory_.GetWeakPtr()));
844 return true;
845 }
846}
847#endif