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

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

Issue 6995121: New NaCl zygote implementation 2 (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Enable with command-line flag, pass channel ID from zygote Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/nacl/nacl_launcher_thread.h" 5 #include <errno.h>
6
7 #include <vector> 6 #include <vector>
8 7
9 #include "base/atomicops.h" 8 #include "chrome/nacl/nacl_listener.h"
9
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "base/message_loop.h"
jam 2011/06/24 00:10:34 nit: this should go after the next line
Brad Chen 2011/06/24 00:40:11 Done.
10 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
11 #include "chrome/common/nacl_messages.h" 14 #include "chrome/common/nacl_messages.h"
15 #include "ipc/ipc_channel.h"
16 #include "ipc/ipc_switches.h"
12 #include "native_client/src/shared/imc/nacl_imc.h" 17 #include "native_client/src/shared/imc/nacl_imc.h"
13 18
14 #if defined(OS_LINUX) 19 #if defined(OS_LINUX)
15 #include "content/common/child_process_sandbox_support_linux.h" 20 #include "content/common/child_process_sandbox_support_linux.h"
16 #endif 21 #endif
17 22
18 #if defined(OS_WIN) 23 #if defined(OS_WIN)
19 #include <fcntl.h> 24 #include <fcntl.h>
20 #include <io.h> 25 #include <io.h>
21 #endif 26 #endif
22 27
28 // This is ugly. We need an interface header file for the exported
29 // sel_ldr interfaces.
30 // TODO(gregoryd,sehr): Add an interface header.
31 #if defined(OS_WIN)
32 typedef HANDLE NaClHandle;
33 #else
34 typedef int NaClHandle;
35 #endif // NaClHandle
36
23 #if defined(OS_MACOSX) 37 #if defined(OS_MACOSX)
24 namespace { 38 namespace {
25 39
26 // On Mac OS X, shm_open() works in the sandbox but does not give us 40 // On Mac OS X, shm_open() works in the sandbox but does not give us
27 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to 41 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to
28 // get an executable SHM region when CreateMemoryObject() is called, 42 // get an executable SHM region when CreateMemoryObject() is called,
29 // we preallocate one on startup, since NaCl's sel_ldr only needs one 43 // we preallocate one on startup, since NaCl's sel_ldr only needs one
30 // of them. This saves a round trip. 44 // of them. This saves a round trip.
31 45
32 base::subtle::Atomic32 g_shm_fd = -1; 46 base::subtle::Atomic32 g_shm_fd = -1;
(...skipping 16 matching lines...) Expand all
49 return result_fd; 63 return result_fd;
50 } 64 }
51 } 65 }
52 // Fall back to NaCl's default implementation. 66 // Fall back to NaCl's default implementation.
53 return -1; 67 return -1;
54 } 68 }
55 69
56 } // namespace 70 } // namespace
57 #endif // defined(OS_MACOSX) 71 #endif // defined(OS_MACOSX)
58 72
59 // This is ugly. We need an interface header file for the exported 73 extern "C" int NaClMainForChromium(int handle_count,
60 // sel_ldr interfaces. 74 const NaClHandle* handles,
61 // TODO(gregoryd,sehr): Add an interface header.
62 #if defined(OS_WIN)
63 typedef HANDLE NaClHandle;
64 #else
65 typedef int NaClHandle;
66 #endif // NaClHandle
67
68 // This is currently necessary because we have a conflict between
69 // NaCl's LOG_FATAL (from platform/nacl_log.h) and Chromium's
70 // LOG_FATAL (from base/logging.h).
71 extern "C" int NaClMainForChromium(int handle_count, const NaClHandle* handles,
72 int debug); 75 int debug);
73 extern "C" void NaClSetIrtFileDesc(int fd); 76 extern "C" void NaClSetIrtFileDesc(int fd);
74 77
75 NaClLauncherThread::NaClLauncherThread(bool debug) { 78 NaClListener::NaClListener() {
76 debug_enabled_ = debug ? 1 : 0; 79 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
jam 2011/06/24 00:10:34 nit: why store this as a member variable instead o
Brad Chen 2011/06/24 00:40:11 Done.
80 switches::kProcessChannelID);
77 } 81 }
78 82
79 NaClLauncherThread::~NaClLauncherThread() { 83 NaClListener::~NaClListener() {
84 delete channel_;
80 } 85 }
81 86
82 NaClLauncherThread* NaClLauncherThread::current() { 87 void NaClListener::Listen() {
83 return static_cast<NaClLauncherThread*>(ChildThread::current()); 88 channel_ = new IPC::Channel(channel_name_, IPC::Channel::MODE_CLIENT, this);
89 CHECK(channel_->Connect());
90 MessageLoop::current()->Run();
84 } 91 }
85 92
86 bool NaClLauncherThread::OnControlMessageReceived(const IPC::Message& msg) { 93 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
87 bool handled = true; 94 bool handled = true;
88 IPC_BEGIN_MESSAGE_MAP(NaClLauncherThread, msg) 95 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
89 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStartSelLdr) 96 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStartSelLdr)
90 IPC_MESSAGE_UNHANDLED(handled = false) 97 IPC_MESSAGE_UNHANDLED(handled = false)
91 IPC_END_MESSAGE_MAP() 98 IPC_END_MESSAGE_MAP()
92 return handled; 99 return handled;
93 } 100 }
94 101
95 void NaClLauncherThread::OnStartSelLdr( 102 void NaClListener::OnStartSelLdr(
96 std::vector<nacl::FileDescriptor> handles, 103 std::vector<nacl::FileDescriptor> handles,
97 bool have_irt_file) { 104 bool have_irt_file) {
98 #if defined(OS_LINUX) 105 #if defined(OS_LINUX)
99 nacl::SetCreateMemoryObjectFunc( 106 nacl::SetCreateMemoryObjectFunc(
100 child_process_sandbox_support::MakeSharedMemorySegmentViaIPC); 107 child_process_sandbox_support::MakeSharedMemorySegmentViaIPC);
101 #elif defined(OS_MACOSX) 108 #elif defined(OS_MACOSX)
102 nacl::SetCreateMemoryObjectFunc(CreateMemoryObject); 109 nacl::SetCreateMemoryObjectFunc(CreateMemoryObject);
103 CHECK(handles.size() >= 1); 110 CHECK(handles.size() >= 1);
104 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); 111 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]);
105 handles.pop_back(); 112 handles.pop_back();
(...skipping 14 matching lines...) Expand all
120 int irt_desc = irt_handle; 127 int irt_desc = irt_handle;
121 #endif 128 #endif
122 NaClSetIrtFileDesc(irt_desc); 129 NaClSetIrtFileDesc(irt_desc);
123 } 130 }
124 131
125 scoped_array<NaClHandle> array(new NaClHandle[handles.size()]); 132 scoped_array<NaClHandle> array(new NaClHandle[handles.size()]);
126 for (size_t i = 0; i < handles.size(); i++) { 133 for (size_t i = 0; i < handles.size(); i++) {
127 array[i] = nacl::ToNativeHandle(handles[i]); 134 array[i] = nacl::ToNativeHandle(handles[i]);
128 } 135 }
129 NaClMainForChromium(static_cast<int>(handles.size()), array.get(), 136 NaClMainForChromium(static_cast<int>(handles.size()), array.get(),
130 debug_enabled_); 137 false /* debug */);
131 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698