blob: dad77e730e1babcc83540c448993ba7c03e0f670 [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]4a0141b2012-03-27 01:15:3012#include "base/memory/mru_cache.h"
[email protected]4734d0b2011-12-03 07:10:4413#include "base/memory/singleton.h"
[email protected]0ae52b42012-03-27 02:53:5914#include "base/metrics/histogram.h"
[email protected]338466a82011-05-03 04:27:4315#include "base/path_service.h"
[email protected]8f42b4d2012-03-24 14:12:3316#include "base/string_util.h"
[email protected]1657e6d2012-03-30 20:28:0017#include "base/rand_util.h"
[email protected]a0a69bf2011-09-23 21:40:2818#include "base/stringprintf.h"
[email protected]be1ce6a72010-08-03 14:35:2219#include "base/utf_string_conversions.h"
[email protected]1e67c2b2011-03-04 01:17:3720#include "base/win/windows_version.h"
[email protected]a82af392012-02-24 04:40:2021#include "build/build_config.h"
[email protected]8f42b4d2012-03-24 14:12:3322#include "chrome/browser/extensions/extension_info_map.h"
23#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]31a665e72012-03-11 12:37:4624#include "chrome/common/chrome_constants.h"
[email protected]338466a82011-05-03 04:27:4325#include "chrome/common/chrome_paths.h"
[email protected]d032f492009-09-29 00:33:4626#include "chrome/common/chrome_switches.h"
[email protected]1657e6d2012-03-30 20:28:0027#include "chrome/common/chrome_version_info.h"
[email protected]d032f492009-09-29 00:33:4628#include "chrome/common/logging_chrome.h"
[email protected]103607e2010-02-01 18:57:0929#include "chrome/common/nacl_cmd_line.h"
[email protected]d032f492009-09-29 00:33:4630#include "chrome/common/nacl_messages.h"
[email protected]fb1277e82009-11-21 20:32:3031#include "chrome/common/render_messages.h"
[email protected]8f42b4d2012-03-24 14:12:3332#include "chrome/common/url_constants.h"
[email protected]4967f792012-01-20 22:14:4033#include "content/public/browser/browser_child_process_host.h"
34#include "content/public/browser/child_process_data.h"
[email protected]4734d0b2011-12-03 07:10:4435#include "content/public/common/child_process_host.h"
[email protected]8f42b4d2012-03-24 14:12:3336#include "googleurl/src/gurl.h"
[email protected]d032f492009-09-29 00:33:4637#include "ipc/ipc_switches.h"
[email protected]1d8a3d1f2011-02-19 07:11:5238#include "native_client/src/shared/imc/nacl_imc.h"
[email protected]d032f492009-09-29 00:33:4639
[email protected]d032f492009-09-29 00:33:4640#if defined(OS_POSIX)
[email protected]a82af392012-02-24 04:40:2041#include <fcntl.h>
42
[email protected]d032f492009-09-29 00:33:4643#include "ipc/ipc_channel_posix.h"
[email protected]4bdde602010-06-16 03:17:3544#elif defined(OS_WIN)
[email protected]a82af392012-02-24 04:40:2045#include <windows.h>
46
[email protected]b39c6d92012-01-31 16:38:4147#include "base/threading/thread.h"
48#include "base/process_util.h"
[email protected]4bdde602010-06-16 03:17:3549#include "chrome/browser/nacl_host/nacl_broker_service_win.h"
[email protected]b39c6d92012-01-31 16:38:4150#include "native_client/src/trusted/service_runtime/win/debug_exception_handler.h"
[email protected]d032f492009-09-29 00:33:4651#endif
52
[email protected]631bb742011-11-02 11:29:3953using content::BrowserThread;
[email protected]4967f792012-01-20 22:14:4054using content::ChildProcessData;
[email protected]4734d0b2011-12-03 07:10:4455using content::ChildProcessHost;
[email protected]631bb742011-11-02 11:29:3956
[email protected]b39c6d92012-01-31 16:38:4157#if defined(OS_WIN)
58class NaClProcessHost::DebugContext
59 : public base::RefCountedThreadSafe<NaClProcessHost::DebugContext> {
60 public:
61 DebugContext()
62 : can_send_start_msg_(false),
63 child_process_host_(NULL) {
64 }
65
66 ~DebugContext() {
67 }
68
69 void AttachDebugger(int pid, base::ProcessHandle process);
70
71 // 6 methods below must be called on Browser::IO thread.
72 void SetStartMessage(IPC::Message* start_msg);
73 void SetChildProcessHost(content::ChildProcessHost* child_process_host);
74 void SetDebugThread(base::Thread* thread_);
75
76 // Start message is sent from 2 flows of execution. The first flow is
77 // NaClProcessHost::SendStart. The second flow is
78 // NaClProcessHost::OnChannelConnected and
79 // NaClProcessHost::DebugContext::AttachThread. The message itself is created
80 // by first flow. But the moment it can be sent is determined by second flow.
81 // So first flow executes SetStartMessage and SendStartMessage while second
82 // flow uses AllowAndSendStartMessage to either send potentially pending
83 // start message or set the flag that allows the first flow to do this.
84
85 // Clears the flag that prevents sending start message.
86 void AllowToSendStartMsg();
87 // Send start message to the NaCl process or do nothing if message is not
88 // set or not allowed to be send. If message is sent, it is cleared and
89 // repeated calls do nothing.
90 void SendStartMessage();
91 // Clear the flag that prevents further sending start message and send start
92 // message if it is set.
93 void AllowAndSendStartMessage();
94 private:
95 void StopThread();
96 // These 4 fields are accessed only from Browser::IO thread.
97 scoped_ptr<base::Thread> thread_;
98 scoped_ptr<IPC::Message> start_msg_;
99 // Debugger is attached or exception handling is not switched on.
100 // This means that start message can be sent to the NaCl process.
101 bool can_send_start_msg_;
102 content::ChildProcessHost* child_process_host_;
103};
104
105void NaClProcessHost::DebugContext::AttachDebugger(
106 int pid, base::ProcessHandle process) {
107 BOOL attached;
108 DWORD exit_code;
109 attached = DebugActiveProcess(pid);
110 if (!attached) {
111 LOG(ERROR) << "Failed to connect to the process";
112 }
113 BrowserThread::PostTask(
114 BrowserThread::IO, FROM_HERE,
115 base::Bind(
116 &NaClProcessHost::DebugContext::AllowAndSendStartMessage, this));
117 if (attached) {
118 // debug the process
119 NaClDebugLoop(process, &exit_code);
120 base::CloseProcessHandle(process);
121 }
122 BrowserThread::PostTask(
123 BrowserThread::IO, FROM_HERE,
124 base::Bind(&NaClProcessHost::DebugContext::StopThread, this));
125}
126
127void NaClProcessHost::DebugContext::SetStartMessage(IPC::Message* start_msg) {
128 start_msg_.reset(start_msg);
129}
130
131void NaClProcessHost::DebugContext::SetChildProcessHost(
132 content::ChildProcessHost* child_process_host) {
133 child_process_host_ = child_process_host;
134}
135
136void NaClProcessHost::DebugContext::SetDebugThread(base::Thread* thread) {
137 thread_.reset(thread);
138}
139
140void NaClProcessHost::DebugContext::AllowToSendStartMsg() {
141 can_send_start_msg_ = true;
142}
143
144void NaClProcessHost::DebugContext::SendStartMessage() {
145 if (start_msg_.get() && can_send_start_msg_) {
146 if (child_process_host_) {
147 if (!child_process_host_->Send(start_msg_.release())) {
148 LOG(ERROR) << "Failed to send start message";
149 }
150 }
151 }
152}
153
154void NaClProcessHost::DebugContext::AllowAndSendStartMessage() {
155 AllowToSendStartMsg();
156 SendStartMessage();
157}
158
159void NaClProcessHost::DebugContext::StopThread() {
160 thread_->Stop();
161 thread_.reset();
162}
163#endif
164
[email protected]c47ec402010-07-29 10:20:49165namespace {
166
167void SetCloseOnExec(nacl::Handle fd) {
168#if defined(OS_POSIX)
169 int flags = fcntl(fd, F_GETFD);
[email protected]773ebb92011-11-15 19:06:52170 CHECK_NE(flags, -1);
[email protected]c47ec402010-07-29 10:20:49171 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
[email protected]773ebb92011-11-15 19:06:52172 CHECK_EQ(rc, 0);
[email protected]c47ec402010-07-29 10:20:49173#endif
174}
175
[email protected]773ebb92011-11-15 19:06:52176// Represents shared state for all NaClProcessHost objects in the browser.
177// Currently this just handles holding onto the file descriptor for the IRT.
178class NaClBrowser {
179 public:
180 static NaClBrowser* GetInstance() {
181 return Singleton<NaClBrowser>::get();
182 }
183
184 bool IrtAvailable() const {
185 return irt_platform_file_ != base::kInvalidPlatformFileValue;
186 }
187
188 base::PlatformFile IrtFile() const {
189 CHECK_NE(irt_platform_file_, base::kInvalidPlatformFileValue);
190 return irt_platform_file_;
191 }
192
193 // Asynchronously attempt to get the IRT open.
194 bool EnsureIrtAvailable();
195
196 // Make sure the IRT gets opened and follow up with the reply when it's ready.
197 bool MakeIrtAvailable(const base::Closure& reply);
198
[email protected]31a665e72012-03-11 12:37:46199 // Path to IRT. Available even before IRT is loaded.
200 const FilePath& GetIrtFilePath();
201
[email protected]1657e6d2012-03-30 20:28:00202 // Get the key used for HMACing validation signatures. This should be a
203 // string of cryptographically secure random bytes.
204 const std::string& GetValidatorCacheKey() const {
205 return validator_cache_key_;
206 }
207
[email protected]4a0141b2012-03-27 01:15:30208 // Is the validation signature in the database?
209 bool QueryKnownToValidate(const std::string& signature);
210
211 // Put the validation signature in the database.
212 void SetKnownToValidate(const std::string& signature);
213
[email protected]773ebb92011-11-15 19:06:52214 private:
215 base::PlatformFile irt_platform_file_;
216
[email protected]31a665e72012-03-11 12:37:46217 FilePath irt_filepath_;
218
[email protected]4a0141b2012-03-27 01:15:30219 typedef base::HashingMRUCache<std::string, bool> ValidationCacheType;
220 ValidationCacheType validation_cache_;
221
[email protected]1657e6d2012-03-30 20:28:00222 std::string validator_cache_key_;
223
[email protected]773ebb92011-11-15 19:06:52224 friend struct DefaultSingletonTraits<NaClBrowser>;
225
226 NaClBrowser()
[email protected]31a665e72012-03-11 12:37:46227 : irt_platform_file_(base::kInvalidPlatformFileValue),
[email protected]4a0141b2012-03-27 01:15:30228 irt_filepath_(),
229 // For the moment, choose an arbitrary cache size.
[email protected]1657e6d2012-03-30 20:28:00230 validation_cache_(200),
231 // TODO(ncbray) persist this key along with the cache.
232 // Key size is equal to the block size (not the digest size) of SHA256.
233 validator_cache_key_(base::RandBytesAsString(64)) {
[email protected]31a665e72012-03-11 12:37:46234 InitIrtFilePath();
235 }
[email protected]773ebb92011-11-15 19:06:52236
237 ~NaClBrowser() {
238 if (irt_platform_file_ != base::kInvalidPlatformFileValue)
239 base::ClosePlatformFile(irt_platform_file_);
240 }
241
[email protected]31a665e72012-03-11 12:37:46242 void InitIrtFilePath();
243
[email protected]773ebb92011-11-15 19:06:52244 void OpenIrtLibraryFile();
245
246 static void DoOpenIrtLibraryFile() {
247 GetInstance()->OpenIrtLibraryFile();
248 }
249
250 DISALLOW_COPY_AND_ASSIGN(NaClBrowser);
251};
252
[email protected]c47ec402010-07-29 10:20:49253} // namespace
254
[email protected]1d8a3d1f2011-02-19 07:11:52255struct NaClProcessHost::NaClInternal {
256 std::vector<nacl::Handle> sockets_for_renderer;
257 std::vector<nacl::Handle> sockets_for_sel_ldr;
258};
259
[email protected]773ebb92011-11-15 19:06:52260#if defined(OS_WIN)
[email protected]5804cb5d2011-12-19 21:55:35261static bool RunningOnWOW64() {
[email protected]773ebb92011-11-15 19:06:52262 return (base::win::OSInfo::GetInstance()->wow64_status() ==
263 base::win::OSInfo::WOW64_ENABLED);
[email protected]773ebb92011-11-15 19:06:52264}
[email protected]5804cb5d2011-12-19 21:55:35265#endif
[email protected]773ebb92011-11-15 19:06:52266
[email protected]1dbaaa702011-04-06 17:43:42267NaClProcessHost::NaClProcessHost(const std::wstring& url)
[email protected]a575da52012-03-22 13:08:36268 :
269#if defined(OS_WIN)
270 process_launched_by_broker_(false),
271#endif
272 reply_msg_(NULL),
[email protected]1d8a3d1f2011-02-19 07:11:52273 internal_(new NaClInternal()),
[email protected]5ca93be2012-03-21 20:04:06274 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
275 enable_exception_handling_(false) {
[email protected]4967f792012-01-20 22:14:40276 process_.reset(content::BrowserChildProcessHost::Create(
277 content::PROCESS_TYPE_NACL_LOADER, this));
278 process_->SetName(WideToUTF16Hack(url));
[email protected]5ca93be2012-03-21 20:04:06279
280 // We allow untrusted hardware exception handling to be enabled via
281 // an env var for consistency with the standalone build of NaCl.
282 if (CommandLine::ForCurrentProcess()->HasSwitch(
283 switches::kEnableNaClExceptionHandling) ||
284 getenv("NACL_UNTRUSTED_EXCEPTION_HANDLING") != NULL) {
285 enable_exception_handling_ = true;
[email protected]b39c6d92012-01-31 16:38:41286#if defined(OS_WIN)
[email protected]fb335fe2012-03-24 18:11:38287 debug_context_ = new DebugContext();
[email protected]b39c6d92012-01-31 16:38:41288#endif
[email protected]5ca93be2012-03-21 20:04:06289 }
[email protected]d032f492009-09-29 00:33:46290}
291
[email protected]fb1277e82009-11-21 20:32:30292NaClProcessHost::~NaClProcessHost() {
[email protected]4cb43102011-12-02 20:24:49293 int exit_code;
[email protected]4967f792012-01-20 22:14:40294 process_->GetTerminationStatus(&exit_code);
[email protected]4cb43102011-12-02 20:24:49295 std::string message =
296 base::StringPrintf("NaCl process exited with status %i (0x%x)",
297 exit_code, exit_code);
298 if (exit_code == 0) {
299 LOG(INFO) << message;
300 } else {
301 LOG(ERROR) << message;
302 }
303
[email protected]1d8a3d1f2011-02-19 07:11:52304 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
[email protected]909c2402011-05-09 11:39:04305 if (nacl::Close(internal_->sockets_for_renderer[i]) != 0) {
306 LOG(ERROR) << "nacl::Close() failed";
307 }
[email protected]c47ec402010-07-29 10:20:49308 }
[email protected]1d8a3d1f2011-02-19 07:11:52309 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
[email protected]909c2402011-05-09 11:39:04310 if (nacl::Close(internal_->sockets_for_sel_ldr[i]) != 0) {
311 LOG(ERROR) << "nacl::Close() failed";
312 }
[email protected]c47ec402010-07-29 10:20:49313 }
314
[email protected]909c2402011-05-09 11:39:04315 if (reply_msg_) {
316 // The process failed to launch for some reason.
317 // Don't keep the renderer hanging.
318 reply_msg_->set_reply_error();
319 chrome_render_message_filter_->Send(reply_msg_);
320 }
[email protected]b39c6d92012-01-31 16:38:41321#if defined(OS_WIN)
[email protected]a575da52012-03-22 13:08:36322 if (process_launched_by_broker_) {
323 NaClBrokerService::GetInstance()->OnLoaderDied();
[email protected]5ca93be2012-03-21 20:04:06324 }
325 if (debug_context_ != NULL) {
[email protected]b39c6d92012-01-31 16:38:41326 debug_context_->SetChildProcessHost(NULL);
327 }
328#endif
[email protected]fb1277e82009-11-21 20:32:30329}
330
[email protected]773ebb92011-11-15 19:06:52331// Attempt to ensure the IRT will be available when we need it, but don't wait.
332bool NaClBrowser::EnsureIrtAvailable() {
333 if (IrtAvailable())
334 return true;
335
336 return BrowserThread::PostTask(
337 BrowserThread::FILE, FROM_HERE,
338 base::Bind(&NaClBrowser::DoOpenIrtLibraryFile));
339}
340
341// We really need the IRT to be available now, so make sure that it is.
342// When it's ready, we'll run the reply closure.
343bool NaClBrowser::MakeIrtAvailable(const base::Closure& reply) {
344 return BrowserThread::PostTaskAndReply(
345 BrowserThread::FILE, FROM_HERE,
346 base::Bind(&NaClBrowser::DoOpenIrtLibraryFile), reply);
347}
348
349// This is called at browser startup.
350// static
351void NaClProcessHost::EarlyStartup() {
352#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
353 // Open the IRT file early to make sure that it isn't replaced out from
354 // under us by autoupdate.
355 NaClBrowser::GetInstance()->EnsureIrtAvailable();
356#endif
357}
358
[email protected]a575da52012-03-22 13:08:36359void NaClProcessHost::Launch(
[email protected]92d56412011-03-24 20:53:52360 ChromeRenderMessageFilter* chrome_render_message_filter,
361 int socket_count,
[email protected]8f42b4d2012-03-24 14:12:33362 IPC::Message* reply_msg,
363 scoped_refptr<ExtensionInfoMap> extension_info_map) {
[email protected]a575da52012-03-22 13:08:36364 chrome_render_message_filter_ = chrome_render_message_filter;
365 reply_msg_ = reply_msg;
[email protected]8f42b4d2012-03-24 14:12:33366 extension_info_map_ = extension_info_map;
[email protected]a575da52012-03-22 13:08:36367
[email protected]c47ec402010-07-29 10:20:49368 // Place an arbitrary limit on the number of sockets to limit
369 // exposure in case the renderer is compromised. We can increase
370 // this if necessary.
371 if (socket_count > 8) {
[email protected]a575da52012-03-22 13:08:36372 delete this;
373 return;
[email protected]c47ec402010-07-29 10:20:49374 }
375
[email protected]773ebb92011-11-15 19:06:52376 // Start getting the IRT open asynchronously while we launch the NaCl process.
377 // We'll make sure this actually finished in OnProcessLaunched, below.
378 if (!NaClBrowser::GetInstance()->EnsureIrtAvailable()) {
379 LOG(ERROR) << "Cannot launch NaCl process after IRT file open failed";
[email protected]a575da52012-03-22 13:08:36380 delete this;
381 return;
[email protected]773ebb92011-11-15 19:06:52382 }
383
[email protected]c47ec402010-07-29 10:20:49384 // Rather than creating a socket pair in the renderer, and passing
385 // one side through the browser to sel_ldr, socket pairs are created
386 // in the browser and then passed to the renderer and sel_ldr.
387 //
388 // This is mainly for the benefit of Windows, where sockets cannot
389 // be passed in messages, but are copied via DuplicateHandle().
390 // This means the sandboxed renderer cannot send handles to the
391 // browser process.
392
393 for (int i = 0; i < socket_count; i++) {
394 nacl::Handle pair[2];
395 // Create a connected socket
[email protected]a575da52012-03-22 13:08:36396 if (nacl::SocketPair(pair) == -1) {
397 delete this;
398 return;
399 }
[email protected]1d8a3d1f2011-02-19 07:11:52400 internal_->sockets_for_renderer.push_back(pair[0]);
401 internal_->sockets_for_sel_ldr.push_back(pair[1]);
[email protected]c47ec402010-07-29 10:20:49402 SetCloseOnExec(pair[0]);
403 SetCloseOnExec(pair[1]);
404 }
[email protected]d032f492009-09-29 00:33:46405
406 // Launch the process
[email protected]fb1277e82009-11-21 20:32:30407 if (!LaunchSelLdr()) {
[email protected]a575da52012-03-22 13:08:36408 delete this;
[email protected]d032f492009-09-29 00:33:46409 }
[email protected]d032f492009-09-29 00:33:46410}
411
[email protected]8ae7bd6f2012-03-14 03:23:02412scoped_ptr<CommandLine> NaClProcessHost::LaunchWithNaClGdb(
[email protected]8f42b4d2012-03-24 14:12:33413 const FilePath& nacl_gdb,
414 CommandLine* line,
415 const FilePath& manifest_path) {
[email protected]31a665e72012-03-11 12:37:46416 CommandLine* cmd_line = new CommandLine(nacl_gdb);
417 // We can't use PrependWrapper because our parameters contain spaces.
418 cmd_line->AppendArg("--eval-command");
419 const FilePath::StringType& irt_path =
420 NaClBrowser::GetInstance()->GetIrtFilePath().value();
421 cmd_line->AppendArgNative(FILE_PATH_LITERAL("nacl-irt ") + irt_path);
[email protected]8f42b4d2012-03-24 14:12:33422 if (!manifest_path.empty()) {
423 cmd_line->AppendArg("--eval-command");
424 cmd_line->AppendArgNative(FILE_PATH_LITERAL("nacl-manifest ") +
425 manifest_path.value());
426 }
[email protected]31a665e72012-03-11 12:37:46427 cmd_line->AppendArg("--args");
428 const CommandLine::StringVector& argv = line->argv();
429 for (size_t i = 0; i < argv.size(); i++) {
430 cmd_line->AppendArgNative(argv[i]);
431 }
432 return scoped_ptr<CommandLine>(cmd_line);
433}
434
[email protected]fb1277e82009-11-21 20:32:30435bool NaClProcessHost::LaunchSelLdr() {
[email protected]4967f792012-01-20 22:14:40436 std::string channel_id = process_->GetHost()->CreateChannel();
[email protected]4734d0b2011-12-03 07:10:44437 if (channel_id.empty())
[email protected]d032f492009-09-29 00:33:46438 return false;
439
[email protected]e3fc75a2011-05-05 08:20:42440 CommandLine::StringType nacl_loader_prefix;
441#if defined(OS_POSIX)
442 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative(
443 switches::kNaClLoaderCmdPrefix);
444#endif // defined(OS_POSIX)
445
[email protected]d032f492009-09-29 00:33:46446 // Build command line for nacl.
[email protected]8c40f322011-08-24 03:33:36447
448#if defined(OS_MACOSX)
449 // The Native Client process needs to be able to allocate a 1GB contiguous
450 // region to use as the client environment's virtual address space. ASLR
451 // (PIE) interferes with this by making it possible that no gap large enough
452 // to accomodate this request will exist in the child process' address
453 // space. Disable PIE for NaCl processes. See http://crbug.com/90221 and
454 // http://code.google.com/p/nativeclient/issues/detail?id=2043.
[email protected]4cb43102011-12-02 20:24:49455 int flags = ChildProcessHost::CHILD_NO_PIE;
[email protected]8c40f322011-08-24 03:33:36456#elif defined(OS_LINUX)
[email protected]4cb43102011-12-02 20:24:49457 int flags = nacl_loader_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF :
458 ChildProcessHost::CHILD_NORMAL;
[email protected]8c40f322011-08-24 03:33:36459#else
[email protected]4cb43102011-12-02 20:24:49460 int flags = ChildProcessHost::CHILD_NORMAL;
[email protected]8c40f322011-08-24 03:33:36461#endif
462
[email protected]4cb43102011-12-02 20:24:49463 FilePath exe_path = ChildProcessHost::GetChildPath(flags);
[email protected]fb1277e82009-11-21 20:32:30464 if (exe_path.empty())
[email protected]d032f492009-09-29 00:33:46465 return false;
466
[email protected]31a665e72012-03-11 12:37:46467#if defined(OS_WIN)
468 // On Windows 64-bit NaCl loader is called nacl64.exe instead of chrome.exe
469 if (RunningOnWOW64()) {
470 FilePath module_path;
471 if (!PathService::Get(base::FILE_MODULE, &module_path))
472 return false;
473 exe_path = module_path.DirName().Append(chrome::kNaClAppName);
474 }
475#endif
476
[email protected]33a05af2012-03-02 18:15:51477 scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path));
478 nacl::CopyNaClCommandLineArguments(cmd_line.get());
[email protected]599e6642010-01-27 18:52:13479
[email protected]05076ba22010-07-30 05:59:57480 cmd_line->AppendSwitchASCII(switches::kProcessType,
481 switches::kNaClLoaderProcess);
[email protected]4734d0b2011-12-03 07:10:44482 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id);
[email protected]93156cec2011-09-12 21:14:44483 if (logging::DialogsAreSuppressed())
484 cmd_line->AppendSwitch(switches::kNoErrorDialogs);
[email protected]d032f492009-09-29 00:33:46485
[email protected]e3fc75a2011-05-05 08:20:42486 if (!nacl_loader_prefix.empty())
487 cmd_line->PrependWrapper(nacl_loader_prefix);
488
[email protected]31a665e72012-03-11 12:37:46489 FilePath nacl_gdb = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
490 switches::kNaClGdb);
491 if (!nacl_gdb.empty()) {
[email protected]8f42b4d2012-03-24 14:12:33492 GURL manifest_url = GURL(process_->GetData().name);
493 FilePath manifest_path;
494 const Extension* extension = extension_info_map_->extensions().
495 GetExtensionOrAppByURL(ExtensionURLInfo(manifest_url));
496 if (extension != NULL && manifest_url.SchemeIs(chrome::kExtensionScheme)) {
497 std::string path = manifest_url.path();
498 TrimString(path, "/", &path); // Remove first slash
499 manifest_path = extension->path().AppendASCII(path);
500 }
[email protected]31a665e72012-03-11 12:37:46501 cmd_line->AppendSwitch(switches::kNoSandbox);
502 scoped_ptr<CommandLine> gdb_cmd_line(
[email protected]8f42b4d2012-03-24 14:12:33503 LaunchWithNaClGdb(nacl_gdb, cmd_line.get(), manifest_path));
[email protected]31a665e72012-03-11 12:37:46504 // We can't use process_->Launch() because OnProcessLaunched will be called
505 // with process_->GetData().handle filled by handle of gdb process. This
506 // handle will be used to duplicate handles for NaCl process and as
507 // a result NaCl process will not be able to use them.
508 //
509 // So we don't fill process_->GetData().handle and wait for
510 // OnChannelConnected to get handle of NaCl process from its pid. Then we
511 // call OnProcessLaunched.
512 return base::LaunchProcess(*gdb_cmd_line, base::LaunchOptions(), NULL);
513 }
514
[email protected]103607e2010-02-01 18:57:09515 // On Windows we might need to start the broker process to launch a new loader
[email protected]d032f492009-09-29 00:33:46516#if defined(OS_WIN)
[email protected]773ebb92011-11-15 19:06:52517 if (RunningOnWOW64()) {
[email protected]644b2e22012-03-25 01:41:07518 return NaClBrokerService::GetInstance()->LaunchLoader(this, channel_id);
[email protected]4bdde602010-06-16 03:17:35519 } else {
[email protected]33a05af2012-03-02 18:15:51520 process_->Launch(FilePath(), cmd_line.release());
[email protected]4bdde602010-06-16 03:17:35521 }
[email protected]103607e2010-02-01 18:57:09522#elif defined(OS_POSIX)
[email protected]4967f792012-01-20 22:14:40523 process_->Launch(nacl_loader_prefix.empty(), // use_zygote
[email protected]a82af392012-02-24 04:40:20524 base::EnvironmentVector(),
[email protected]33a05af2012-03-02 18:15:51525 cmd_line.release());
[email protected]103607e2010-02-01 18:57:09526#endif
[email protected]d032f492009-09-29 00:33:46527
[email protected]fb1277e82009-11-21 20:32:30528 return true;
[email protected]d032f492009-09-29 00:33:46529}
530
[email protected]a575da52012-03-22 13:08:36531#if defined(OS_WIN)
[email protected]fb335fe2012-03-24 18:11:38532void NaClProcessHost::OnProcessLaunchedByBroker(base::ProcessHandle handle) {
[email protected]a575da52012-03-22 13:08:36533 process_launched_by_broker_ = true;
[email protected]4967f792012-01-20 22:14:40534 process_->SetHandle(handle);
[email protected]103607e2010-02-01 18:57:09535 OnProcessLaunched();
536}
537
[email protected]fb335fe2012-03-24 18:11:38538void NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker() {
539 debug_context_->AllowAndSendStartMessage();
540}
541#endif
542
[email protected]463ea5f2011-12-03 06:57:47543void NaClProcessHost::OnProcessCrashed(int exit_code) {
544 std::string message = base::StringPrintf(
545 "NaCl process exited with status %i (0x%x)", exit_code, exit_code);
546 LOG(ERROR) << message;
[email protected]103607e2010-02-01 18:57:09547}
548
[email protected]75e0c502011-12-16 21:53:01549namespace {
550
551// Determine the name of the IRT file based on the architecture.
552
553#define NACL_IRT_FILE_NAME(arch_string) \
554 (FILE_PATH_LITERAL("nacl_irt_") \
555 FILE_PATH_LITERAL(arch_string) \
556 FILE_PATH_LITERAL(".nexe"))
557
558const FilePath::StringType NaClIrtName() {
559#if defined(ARCH_CPU_X86_FAMILY)
[email protected]75e0c502011-12-16 21:53:01560#if defined(ARCH_CPU_X86_64)
[email protected]5804cb5d2011-12-19 21:55:35561 bool is64 = true;
562#elif defined(OS_WIN)
563 bool is64 = RunningOnWOW64();
564#else
565 bool is64 = false;
[email protected]75e0c502011-12-16 21:53:01566#endif
567 return is64 ? NACL_IRT_FILE_NAME("x86_64") : NACL_IRT_FILE_NAME("x86_32");
568#elif defined(ARCH_CPU_ARMEL)
569 // TODO(mcgrathr): Eventually we'll need to distinguish arm32 vs thumb2.
570 // That may need to be based on the actual nexe rather than a static
571 // choice, which would require substantial refactoring.
572 return NACL_IRT_FILE_NAME("arm");
573#else
574#error Add support for your architecture to NaCl IRT file selection
575#endif
576}
577
578} // namespace
579
[email protected]31a665e72012-03-11 12:37:46580void NaClBrowser::InitIrtFilePath() {
[email protected]88e15832011-07-19 01:18:24581 // Allow the IRT library to be overridden via an environment
582 // variable. This allows the NaCl/Chromium integration bot to
583 // specify a newly-built IRT rather than using a prebuilt one
584 // downloaded via Chromium's DEPS file. We use the same environment
585 // variable that the standalone NaCl PPAPI plugin accepts.
586 const char* irt_path_var = getenv("NACL_IRT_LIBRARY");
587 if (irt_path_var != NULL) {
[email protected]773ebb92011-11-15 19:06:52588 FilePath::StringType path_string(
589 irt_path_var, const_cast<const char*>(strchr(irt_path_var, '\0')));
[email protected]31a665e72012-03-11 12:37:46590 irt_filepath_ = FilePath(path_string);
[email protected]88e15832011-07-19 01:18:24591 } else {
592 FilePath plugin_dir;
593 if (!PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &plugin_dir)) {
594 LOG(ERROR) << "Failed to locate the plugins directory";
[email protected]88e15832011-07-19 01:18:24595 return;
596 }
[email protected]773ebb92011-11-15 19:06:52597
[email protected]31a665e72012-03-11 12:37:46598 irt_filepath_ = plugin_dir.Append(NaClIrtName());
[email protected]338466a82011-05-03 04:27:43599 }
[email protected]31a665e72012-03-11 12:37:46600}
601
602const FilePath& NaClBrowser::GetIrtFilePath() {
603 return irt_filepath_;
604}
605
606// This only ever runs on the BrowserThread::FILE thread.
607// If multiple tasks are posted, the later ones are no-ops.
608void NaClBrowser::OpenIrtLibraryFile() {
609 if (irt_platform_file_ != base::kInvalidPlatformFileValue)
610 // We've already run.
611 return;
[email protected]88e15832011-07-19 01:18:24612
[email protected]773ebb92011-11-15 19:06:52613 base::PlatformFileError error_code;
[email protected]31a665e72012-03-11 12:37:46614 irt_platform_file_ = base::CreatePlatformFile(irt_filepath_,
[email protected]773ebb92011-11-15 19:06:52615 base::PLATFORM_FILE_OPEN |
616 base::PLATFORM_FILE_READ,
617 NULL,
618 &error_code);
619 if (error_code != base::PLATFORM_FILE_OK) {
620 LOG(ERROR) << "Failed to open NaCl IRT file \""
[email protected]31a665e72012-03-11 12:37:46621 << irt_filepath_.LossyDisplayName()
[email protected]773ebb92011-11-15 19:06:52622 << "\": " << error_code;
623 }
624}
625
626void NaClProcessHost::OnProcessLaunched() {
627 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
628
629 if (nacl_browser->IrtAvailable()) {
630 // The IRT is already open. Away we go.
[email protected]1657e6d2012-03-30 20:28:00631 SendStart();
[email protected]773ebb92011-11-15 19:06:52632 } else {
633 // We're waiting for the IRT to be open.
[email protected]98999e802011-12-21 21:54:43634 if (!nacl_browser->MakeIrtAvailable(
635 base::Bind(&NaClProcessHost::IrtReady,
636 weak_factory_.GetWeakPtr())))
637 delete this;
[email protected]773ebb92011-11-15 19:06:52638 }
639}
640
641// The asynchronous attempt to get the IRT file open has completed.
642void NaClProcessHost::IrtReady() {
643 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
644
645 if (nacl_browser->IrtAvailable()) {
[email protected]1657e6d2012-03-30 20:28:00646 SendStart();
[email protected]773ebb92011-11-15 19:06:52647 } else {
648 LOG(ERROR) << "Cannot launch NaCl process after IRT file open failed";
[email protected]338466a82011-05-03 04:27:43649 delete this;
650 }
651}
652
[email protected]b39c6d92012-01-31 16:38:41653#if defined(OS_WIN)
[email protected]b39c6d92012-01-31 16:38:41654void NaClProcessHost::OnChannelConnected(int32 peer_pid) {
[email protected]31a665e72012-03-11 12:37:46655 // Set process handle, if it was not set previously.
656 // This is needed when NaCl process is launched with nacl-gdb.
657 if (process_->GetData().handle == base::kNullProcessHandle) {
658 base::ProcessHandle process;
659 DCHECK(!CommandLine::ForCurrentProcess()->GetSwitchValuePath(
660 switches::kNaClGdb).empty());
661 if (base::OpenProcessHandleWithAccess(
662 peer_pid,
663 base::kProcessAccessDuplicateHandle |
[email protected]59261242012-03-19 13:08:59664 base::kProcessAccessQueryInformation |
[email protected]31a665e72012-03-11 12:37:46665 base::kProcessAccessWaitForTermination,
666 &process)) {
667 process_->SetHandle(process);
668 OnProcessLaunched();
669 } else {
670 LOG(ERROR) << "Failed to get process handle";
671 }
672 }
[email protected]5ca93be2012-03-21 20:04:06673 if (debug_context_ == NULL) {
[email protected]b39c6d92012-01-31 16:38:41674 return;
675 }
[email protected]b39c6d92012-01-31 16:38:41676 debug_context_->SetChildProcessHost(process_->GetHost());
[email protected]fb335fe2012-03-24 18:11:38677 if (RunningOnWOW64()) {
678 if (!NaClBrokerService::GetInstance()->LaunchDebugExceptionHandler(
679 this, peer_pid)) {
680 debug_context_->AllowAndSendStartMessage();
681 }
682 } else {
683 // Start new thread for debug loop
684 // We can't use process_->GetData().handle because it doesn't have necessary
685 // access rights.
686 base::ProcessHandle process;
687 if (!base::OpenProcessHandleWithAccess(
688 peer_pid,
689 base::kProcessAccessQueryInformation |
690 base::kProcessAccessSuspendResume |
691 base::kProcessAccessTerminate |
692 base::kProcessAccessVMOperation |
693 base::kProcessAccessVMRead |
694 base::kProcessAccessVMWrite |
695 base::kProcessAccessWaitForTermination,
696 &process)) {
697 LOG(ERROR) << "Failed to open the process";
698 debug_context_->AllowAndSendStartMessage();
699 return;
700 }
701 base::Thread* dbg_thread = new base::Thread("Debug thread");
702 if (!dbg_thread->Start()) {
703 LOG(ERROR) << "Debug thread not started";
704 debug_context_->AllowAndSendStartMessage();
705 base::CloseProcessHandle(process);
706 return;
707 }
708 debug_context_->SetDebugThread(dbg_thread);
709 // System can not reallocate pid until we close process handle. So using
710 // pid in different thread is fine.
711 dbg_thread->message_loop()->PostTask(FROM_HERE,
712 base::Bind(&NaClProcessHost::DebugContext::AttachDebugger,
713 debug_context_, peer_pid, process));
[email protected]b39c6d92012-01-31 16:38:41714 }
[email protected]b39c6d92012-01-31 16:38:41715}
716#else
717void NaClProcessHost::OnChannelConnected(int32 peer_pid) {
718}
719#endif
720
721
[email protected]773ebb92011-11-15 19:06:52722static bool SendHandleToSelLdr(
723 base::ProcessHandle processh,
724 nacl::Handle sourceh, bool close_source,
725 std::vector<nacl::FileDescriptor> *handles_for_sel_ldr) {
726#if defined(OS_WIN)
727 HANDLE channel;
728 int flags = DUPLICATE_SAME_ACCESS;
729 if (close_source)
730 flags |= DUPLICATE_CLOSE_SOURCE;
731 if (!DuplicateHandle(GetCurrentProcess(),
732 reinterpret_cast<HANDLE>(sourceh),
733 processh,
734 &channel,
735 0, // Unused given DUPLICATE_SAME_ACCESS.
736 FALSE,
737 flags)) {
738 LOG(ERROR) << "DuplicateHandle() failed";
739 return false;
740 }
741 handles_for_sel_ldr->push_back(
742 reinterpret_cast<nacl::FileDescriptor>(channel));
743#else
744 nacl::FileDescriptor channel;
745 channel.fd = sourceh;
746 channel.auto_close = close_source;
747 handles_for_sel_ldr->push_back(channel);
748#endif
749 return true;
750}
751
[email protected]1657e6d2012-03-30 20:28:00752void NaClProcessHost::SendStart() {
753 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
754 base::PlatformFile irt_file = nacl_browser->IrtFile();
[email protected]773ebb92011-11-15 19:06:52755 CHECK_NE(irt_file, base::kInvalidPlatformFileValue);
756
[email protected]c47ec402010-07-29 10:20:49757 std::vector<nacl::FileDescriptor> handles_for_renderer;
[email protected]fb1277e82009-11-21 20:32:30758 base::ProcessHandle nacl_process_handle;
[email protected]fb1277e82009-11-21 20:32:30759
[email protected]1d8a3d1f2011-02-19 07:11:52760 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
[email protected]c47ec402010-07-29 10:20:49761#if defined(OS_WIN)
762 // Copy the handle into the renderer process.
763 HANDLE handle_in_renderer;
[email protected]909c2402011-05-09 11:39:04764 if (!DuplicateHandle(base::GetCurrentProcessHandle(),
765 reinterpret_cast<HANDLE>(
766 internal_->sockets_for_renderer[i]),
767 chrome_render_message_filter_->peer_handle(),
768 &handle_in_renderer,
769 0, // Unused given DUPLICATE_SAME_ACCESS.
770 FALSE,
771 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
772 LOG(ERROR) << "DuplicateHandle() failed";
773 delete this;
774 return;
775 }
[email protected]c47ec402010-07-29 10:20:49776 handles_for_renderer.push_back(
777 reinterpret_cast<nacl::FileDescriptor>(handle_in_renderer));
778#else
779 // No need to dup the imc_handle - we don't pass it anywhere else so
780 // it cannot be closed.
781 nacl::FileDescriptor imc_handle;
[email protected]1d8a3d1f2011-02-19 07:11:52782 imc_handle.fd = internal_->sockets_for_renderer[i];
[email protected]c47ec402010-07-29 10:20:49783 imc_handle.auto_close = true;
784 handles_for_renderer.push_back(imc_handle);
785#endif
786 }
787
[email protected]4967f792012-01-20 22:14:40788 const ChildProcessData& data = process_->GetData();
[email protected]c47ec402010-07-29 10:20:49789#if defined(OS_WIN)
790 // Copy the process handle into the renderer process.
[email protected]909c2402011-05-09 11:39:04791 if (!DuplicateHandle(base::GetCurrentProcessHandle(),
[email protected]4967f792012-01-20 22:14:40792 data.handle,
[email protected]909c2402011-05-09 11:39:04793 chrome_render_message_filter_->peer_handle(),
794 &nacl_process_handle,
795 PROCESS_DUP_HANDLE,
796 FALSE,
797 0)) {
798 LOG(ERROR) << "DuplicateHandle() failed";
799 delete this;
800 return;
801 }
[email protected]fb1277e82009-11-21 20:32:30802#else
[email protected]fb1277e82009-11-21 20:32:30803 // We use pid as process handle on Posix
[email protected]4967f792012-01-20 22:14:40804 nacl_process_handle = data.handle;
[email protected]fb1277e82009-11-21 20:32:30805#endif
806
807 // Get the pid of the NaCl process
[email protected]4967f792012-01-20 22:14:40808 base::ProcessId nacl_process_id = base::GetProcId(data.handle);
[email protected]fb1277e82009-11-21 20:32:30809
[email protected]2ccf45c2011-08-19 23:35:50810 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams(
[email protected]c47ec402010-07-29 10:20:49811 reply_msg_, handles_for_renderer, nacl_process_handle, nacl_process_id);
[email protected]92d56412011-03-24 20:53:52812 chrome_render_message_filter_->Send(reply_msg_);
813 chrome_render_message_filter_ = NULL;
[email protected]fb1277e82009-11-21 20:32:30814 reply_msg_ = NULL;
[email protected]1d8a3d1f2011-02-19 07:11:52815 internal_->sockets_for_renderer.clear();
[email protected]fb1277e82009-11-21 20:32:30816
[email protected]c47ec402010-07-29 10:20:49817 std::vector<nacl::FileDescriptor> handles_for_sel_ldr;
[email protected]1d8a3d1f2011-02-19 07:11:52818 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
[email protected]4967f792012-01-20 22:14:40819 if (!SendHandleToSelLdr(data.handle,
[email protected]773ebb92011-11-15 19:06:52820 internal_->sockets_for_sel_ldr[i], true,
821 &handles_for_sel_ldr)) {
[email protected]909c2402011-05-09 11:39:04822 delete this;
[email protected]c47ec402010-07-29 10:20:49823 return;
824 }
[email protected]773ebb92011-11-15 19:06:52825 }
826
827 // Send over the IRT file handle. We don't close our own copy!
[email protected]4967f792012-01-20 22:14:40828 if (!SendHandleToSelLdr(data.handle, irt_file, false, &handles_for_sel_ldr)) {
[email protected]773ebb92011-11-15 19:06:52829 delete this;
830 return;
[email protected]c47ec402010-07-29 10:20:49831 }
832
[email protected]ab88d1542011-11-18 22:52:00833#if defined(OS_MACOSX)
834 // For dynamic loading support, NaCl requires a file descriptor that
835 // was created in /tmp, since those created with shm_open() are not
836 // mappable with PROT_EXEC. Rather than requiring an extra IPC
837 // round trip out of the sandbox, we create an FD here.
[email protected]cbbe7842011-11-17 22:01:25838 base::SharedMemory memory_buffer;
[email protected]b05df6b2011-12-01 23:19:31839 base::SharedMemoryCreateOptions options;
840 options.size = 1;
841 options.executable = true;
842 if (!memory_buffer.Create(options)) {
[email protected]2c68bf032010-11-11 23:16:30843 LOG(ERROR) << "Failed to allocate memory buffer";
[email protected]909c2402011-05-09 11:39:04844 delete this;
[email protected]2c68bf032010-11-11 23:16:30845 return;
846 }
[email protected]cbbe7842011-11-17 22:01:25847 nacl::FileDescriptor memory_fd;
848 memory_fd.fd = dup(memory_buffer.handle().fd);
849 if (memory_fd.fd < 0) {
850 LOG(ERROR) << "Failed to dup() a file descriptor";
851 delete this;
852 return;
853 }
854 memory_fd.auto_close = true;
[email protected]2c68bf032010-11-11 23:16:30855 handles_for_sel_ldr.push_back(memory_fd);
856#endif
857
[email protected]1657e6d2012-03-30 20:28:00858 // Sending the version string over IPC avoids linkage issues in cases where
859 // NaCl is not compiled into the main Chromium executable or DLL.
860 chrome::VersionInfo version_info;
[email protected]5ca93be2012-03-21 20:04:06861 IPC::Message* start_message =
[email protected]1657e6d2012-03-30 20:28:00862 new NaClProcessMsg_Start(handles_for_sel_ldr,
863 nacl_browser->GetValidatorCacheKey(),
864 version_info.CreateVersionString(),
865 enable_exception_handling_);
[email protected]b39c6d92012-01-31 16:38:41866#if defined(OS_WIN)
[email protected]5ca93be2012-03-21 20:04:06867 if (debug_context_ != NULL) {
868 debug_context_->SetStartMessage(start_message);
[email protected]b39c6d92012-01-31 16:38:41869 debug_context_->SendStartMessage();
870 } else {
[email protected]5ca93be2012-03-21 20:04:06871 process_->Send(start_message);
[email protected]b39c6d92012-01-31 16:38:41872 }
873#else
[email protected]5ca93be2012-03-21 20:04:06874 process_->Send(start_message);
[email protected]b39c6d92012-01-31 16:38:41875#endif
876
[email protected]1d8a3d1f2011-02-19 07:11:52877 internal_->sockets_for_sel_ldr.clear();
[email protected]d032f492009-09-29 00:33:46878}
879
[email protected]4a0141b2012-03-27 01:15:30880bool NaClBrowser::QueryKnownToValidate(const std::string& signature) {
[email protected]0ae52b42012-03-27 02:53:59881 bool result = false;
[email protected]4a0141b2012-03-27 01:15:30882 ValidationCacheType::iterator iter = validation_cache_.Get(signature);
[email protected]0ae52b42012-03-27 02:53:59883 if (iter != validation_cache_.end()) {
884 result = iter->second;
[email protected]4a0141b2012-03-27 01:15:30885 }
[email protected]0ae52b42012-03-27 02:53:59886 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Query",
887 result ? 1 : 0, 2);
888 return result;
[email protected]4a0141b2012-03-27 01:15:30889}
890
891void NaClBrowser::SetKnownToValidate(const std::string& signature) {
892 validation_cache_.Put(signature, true);
[email protected]0ae52b42012-03-27 02:53:59893 // The number of sets should be equal to the number of cache misses, minus
894 // validation failures and successful validations where stubout occurs.
895 // Bucket zero is reserved for future use.
896 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", 1, 2);
[email protected]4a0141b2012-03-27 01:15:30897}
898
899void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature,
900 bool* result) {
901 *result = NaClBrowser::GetInstance()->QueryKnownToValidate(signature);
902}
903
904void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) {
905 NaClBrowser::GetInstance()->SetKnownToValidate(signature);
906}
907
908// Needed to handle sync messages in OnMessageRecieved.
909bool NaClProcessHost::Send(IPC::Message* msg) {
910 return process_->Send(msg);
911}
912
[email protected]a95986a82010-12-24 06:19:28913bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) {
[email protected]4a0141b2012-03-27 01:15:30914 bool handled = true;
915 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
916 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate,
917 OnQueryKnownToValidate)
918 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate,
919 OnSetKnownToValidate)
920 IPC_MESSAGE_UNHANDLED(handled = false)
921 IPC_END_MESSAGE_MAP()
922 return handled;
[email protected]d032f492009-09-29 00:33:46923}