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

Side by Side Diff: components/nacl/loader/nacl_listener.cc

Issue 1125043002: NaCl: Stop sending resource FDs with NaClProcessMsg_Start (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nonsfi/nonsfi_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" 5 #include "components/nacl/loader/nacl_listener.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 200
201 NaClListener::NaClListener() : shutdown_event_(true, false), 201 NaClListener::NaClListener() : shutdown_event_(true, false),
202 io_thread_("NaCl_IOThread"), 202 io_thread_("NaCl_IOThread"),
203 #if defined(OS_LINUX) 203 #if defined(OS_LINUX)
204 prereserved_sandbox_size_(0), 204 prereserved_sandbox_size_(0),
205 #endif 205 #endif
206 #if defined(OS_POSIX) 206 #if defined(OS_POSIX)
207 number_of_cores_(-1), // unknown/error 207 number_of_cores_(-1), // unknown/error
208 #endif 208 #endif
209 main_loop_(NULL) { 209 main_loop_(NULL),
210 is_started_(false) {
210 io_thread_.StartWithOptions( 211 io_thread_.StartWithOptions(
211 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 212 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
212 DCHECK(g_listener == NULL); 213 DCHECK(g_listener == NULL);
213 g_listener = this; 214 g_listener = this;
214 } 215 }
215 216
216 NaClListener::~NaClListener() { 217 NaClListener::~NaClListener() {
217 NOTREACHED(); 218 NOTREACHED();
218 shutdown_event_.Signal(); 219 shutdown_event_.Signal();
219 g_listener = NULL; 220 g_listener = NULL;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 channel_->AddFilter(filter_.get()); 269 channel_->AddFilter(filter_.get());
269 channel_->AddFilter(new FileTokenMessageFilter()); 270 channel_->AddFilter(new FileTokenMessageFilter());
270 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); 271 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true);
271 main_loop_ = base::MessageLoop::current(); 272 main_loop_ = base::MessageLoop::current();
272 main_loop_->Run(); 273 main_loop_->Run();
273 } 274 }
274 275
275 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 276 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
276 bool handled = true; 277 bool handled = true;
277 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 278 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
279 IPC_MESSAGE_HANDLER(NaClProcessMsg_AddPrefetchedResource,
280 OnAddPrefetchedResource)
278 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 281 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
279 IPC_MESSAGE_UNHANDLED(handled = false) 282 IPC_MESSAGE_UNHANDLED(handled = false)
280 IPC_END_MESSAGE_MAP() 283 IPC_END_MESSAGE_MAP()
281 return handled; 284 return handled;
282 } 285 }
283 286
284 bool NaClListener::OnOpenResource( 287 bool NaClListener::OnOpenResource(
285 const IPC::Message& msg, 288 const IPC::Message& msg,
286 const std::string& key, 289 const std::string& key,
287 NaClIPCAdapter::OpenResourceReplyCallback cb) { 290 NaClIPCAdapter::OpenResourceReplyCallback cb) {
(...skipping 12 matching lines...) Expand all
300 // and return true. 303 // and return true.
301 cb.Run(msg, file, path); 304 cb.Run(msg, file, path);
302 return true; 305 return true;
303 } 306 }
304 307
305 // Return false to fall back to the slow path. Let NaClIPCAdapter issue an 308 // Return false to fall back to the slow path. Let NaClIPCAdapter issue an
306 // IPC to the renderer. 309 // IPC to the renderer.
307 return false; 310 return false;
308 } 311 }
309 312
313 void NaClListener::OnAddPrefetchedResource(
314 const nacl::NaClResourcePrefetchResult& prefetched_resource_file) {
315 DCHECK(!is_started_);
316 if (is_started_)
317 return;
318 bool result = prefetched_resource_files_.insert(std::make_pair(
319 prefetched_resource_file.file_key,
320 std::make_pair(
321 prefetched_resource_file.file,
322 prefetched_resource_file.file_path_metadata))).second;
323 if (!result) {
324 LOG(FATAL) << "Duplicated open_resource key: "
325 << prefetched_resource_file.file_key;
326 }
327 }
328
310 void NaClListener::OnStart(const nacl::NaClStartParams& params) { 329 void NaClListener::OnStart(const nacl::NaClStartParams& params) {
330 is_started_ = true;
311 #if defined(OS_LINUX) || defined(OS_MACOSX) 331 #if defined(OS_LINUX) || defined(OS_MACOSX)
312 int urandom_fd = dup(base::GetUrandomFD()); 332 int urandom_fd = dup(base::GetUrandomFD());
313 if (urandom_fd < 0) { 333 if (urandom_fd < 0) {
314 LOG(ERROR) << "Failed to dup() the urandom FD"; 334 LOG(ERROR) << "Failed to dup() the urandom FD";
315 return; 335 return;
316 } 336 }
317 NaClChromeMainSetUrandomFd(urandom_fd); 337 NaClChromeMainSetUrandomFd(urandom_fd);
318 #endif 338 #endif
319 struct NaClApp* nap = NULL; 339 struct NaClApp* nap = NULL;
320 NaClChromeMainInit(); 340 NaClChromeMainInit();
321 341
322 CHECK(base::SharedMemory::IsHandleValid(params.crash_info_shmem_handle)); 342 CHECK(base::SharedMemory::IsHandleValid(params.crash_info_shmem_handle));
323 crash_info_shmem_.reset(new base::SharedMemory( 343 crash_info_shmem_.reset(new base::SharedMemory(
324 params.crash_info_shmem_handle, false /* not readonly */)); 344 params.crash_info_shmem_handle, false /* not readonly */));
325 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 345 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
326 NaClSetFatalErrorCallback(&FatalLogHandler); 346 NaClSetFatalErrorCallback(&FatalLogHandler);
327 347
328 nap = NaClAppCreate(); 348 nap = NaClAppCreate();
329 if (nap == NULL) { 349 if (nap == NULL) {
330 LOG(ERROR) << "NaClAppCreate() failed"; 350 LOG(ERROR) << "NaClAppCreate() failed";
331 return; 351 return;
332 } 352 }
333 353
334 IPC::ChannelHandle browser_handle; 354 IPC::ChannelHandle browser_handle;
335 IPC::ChannelHandle ppapi_renderer_handle; 355 IPC::ChannelHandle ppapi_renderer_handle;
336 IPC::ChannelHandle manifest_service_handle; 356 IPC::ChannelHandle manifest_service_handle;
337 357
338 for (size_t i = 0; i < params.prefetched_resource_files.size(); ++i) {
339 bool result = prefetched_resource_files_.insert(std::make_pair(
340 params.prefetched_resource_files[i].file_key,
341 std::make_pair(
342 params.prefetched_resource_files[i].file,
343 params.prefetched_resource_files[i].file_path_metadata))).second;
344 if (!result) {
345 LOG(FATAL) << "Duplicated open_resource key: "
346 << params.prefetched_resource_files[i].file_key;
347 }
348 }
349
350 if (params.enable_ipc_proxy) { 358 if (params.enable_ipc_proxy) {
351 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 359 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
352 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 360 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
353 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 361 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
354 362
355 // Create the PPAPI IPC channels between the NaCl IRT and the host 363 // Create the PPAPI IPC channels between the NaCl IRT and the host
356 // (browser/renderer) processes. The IRT uses these channels to 364 // (browser/renderer) processes. The IRT uses these channels to
357 // communicate with the host and to initialize the IPC dispatchers. 365 // communicate with the host and to initialize the IPC dispatchers.
358 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), 366 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
359 nap, NACL_CHROME_DESC_BASE, 367 nap, NACL_CHROME_DESC_BASE,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 507 }
500 508
501 void NaClListener::OnFileTokenResolved( 509 void NaClListener::OnFileTokenResolved(
502 uint64_t token_lo, 510 uint64_t token_lo,
503 uint64_t token_hi, 511 uint64_t token_hi,
504 IPC::PlatformFileForTransit ipc_fd, 512 IPC::PlatformFileForTransit ipc_fd,
505 base::FilePath file_path) { 513 base::FilePath file_path) {
506 resolved_cb_.Run(ipc_fd, file_path); 514 resolved_cb_.Run(ipc_fd, file_path);
507 resolved_cb_.Reset(); 515 resolved_cb_.Reset();
508 } 516 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/loader/nonsfi/nonsfi_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698