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

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: Use IPC::Channel directly instead of ChildProcess 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"
6
7 #include <vector> 5 #include <vector>
8 6
9 #include "base/atomicops.h" 7 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
11 #include "chrome/common/nacl_messages.h" 9 #include "chrome/common/nacl_types.h"
10 #include "chrome/nacl/nacl_listener.h"
11 #include "ipc/ipc_channel.h"
12 #include "native_client/src/shared/imc/nacl_imc.h" 12 #include "native_client/src/shared/imc/nacl_imc.h"
13 13
14 #if defined(OS_LINUX) 14 #if defined(OS_LINUX)
15 #include "content/common/child_process_sandbox_support_linux.h" 15 #include "content/common/child_process_sandbox_support_linux.h"
16 #endif 16 #endif
17 17
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #include <fcntl.h> 19 #include <fcntl.h>
20 #include <io.h> 20 #include <io.h>
21 #endif 21 #endif
22 22
23 // This is ugly. We need an interface header file for the exported
24 // sel_ldr interfaces.
25 // TODO(gregoryd,sehr): Add an interface header.
26 #if defined(OS_WIN)
27 typedef HANDLE NaClHandle;
28 #else
29 typedef int NaClHandle;
30 #endif // NaClHandle
31
23 #if defined(OS_MACOSX) 32 #if defined(OS_MACOSX)
24 namespace { 33 namespace {
25 34
26 // On Mac OS X, shm_open() works in the sandbox but does not give us 35 // 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 36 // 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, 37 // get an executable SHM region when CreateMemoryObject() is called,
29 // we preallocate one on startup, since NaCl's sel_ldr only needs one 38 // we preallocate one on startup, since NaCl's sel_ldr only needs one
30 // of them. This saves a round trip. 39 // of them. This saves a round trip.
31 40
32 base::subtle::Atomic32 g_shm_fd = -1; 41 base::subtle::Atomic32 g_shm_fd = -1;
(...skipping 16 matching lines...) Expand all
49 return result_fd; 58 return result_fd;
50 } 59 }
51 } 60 }
52 // Fall back to NaCl's default implementation. 61 // Fall back to NaCl's default implementation.
53 return -1; 62 return -1;
54 } 63 }
55 64
56 } // namespace 65 } // namespace
57 #endif // defined(OS_MACOSX) 66 #endif // defined(OS_MACOSX)
58 67
59 // This is ugly. We need an interface header file for the exported 68 extern "C" int NaClMainForChromium(int handle_count,
60 // sel_ldr interfaces. 69 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); 70 int debug);
73 extern "C" void NaClSetIrtFileDesc(int fd); 71 extern "C" void NaClSetIrtFileDesc(int fd);
74 72
75 NaClLauncherThread::NaClLauncherThread(bool debug) { 73 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
76 debug_enabled_ = debug ? 1 : 0;
77 }
78
79 NaClLauncherThread::~NaClLauncherThread() {
80 }
81
82 NaClLauncherThread* NaClLauncherThread::current() {
83 return static_cast<NaClLauncherThread*>(ChildThread::current());
84 }
85
86 bool NaClLauncherThread::OnControlMessageReceived(const IPC::Message& msg) {
87 bool handled = true; 74 bool handled = true;
88 IPC_BEGIN_MESSAGE_MAP(NaClLauncherThread, msg) 75 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
89 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStartSelLdr) 76 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStartSelLdr)
90 IPC_MESSAGE_UNHANDLED(handled = false) 77 IPC_MESSAGE_UNHANDLED(handled = false)
91 IPC_END_MESSAGE_MAP() 78 IPC_END_MESSAGE_MAP()
92 return handled; 79 return handled;
93 } 80 }
94 81
95 void NaClLauncherThread::OnStartSelLdr( 82 void NaClListener::OnStartSelLdr(
96 std::vector<nacl::FileDescriptor> handles, 83 std::vector<nacl::FileDescriptor> handles,
97 bool have_irt_file) { 84 bool have_irt_file) {
98 #if defined(OS_LINUX) 85 #if defined(OS_LINUX)
99 nacl::SetCreateMemoryObjectFunc( 86 nacl::SetCreateMemoryObjectFunc(
100 child_process_sandbox_support::MakeSharedMemorySegmentViaIPC); 87 child_process_sandbox_support::MakeSharedMemorySegmentViaIPC);
101 #elif defined(OS_MACOSX) 88 #elif defined(OS_MACOSX)
102 nacl::SetCreateMemoryObjectFunc(CreateMemoryObject); 89 nacl::SetCreateMemoryObjectFunc(CreateMemoryObject);
103 CHECK(handles.size() >= 1); 90 CHECK(handles.size() >= 1);
104 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); 91 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]);
105 handles.pop_back(); 92 handles.pop_back();
(...skipping 14 matching lines...) Expand all
120 int irt_desc = irt_handle; 107 int irt_desc = irt_handle;
121 #endif 108 #endif
122 NaClSetIrtFileDesc(irt_desc); 109 NaClSetIrtFileDesc(irt_desc);
123 } 110 }
124 111
125 scoped_array<NaClHandle> array(new NaClHandle[handles.size()]); 112 scoped_array<NaClHandle> array(new NaClHandle[handles.size()]);
126 for (size_t i = 0; i < handles.size(); i++) { 113 for (size_t i = 0; i < handles.size(); i++) {
127 array[i] = nacl::ToNativeHandle(handles[i]); 114 array[i] = nacl::ToNativeHandle(handles[i]);
128 } 115 }
129 NaClMainForChromium(static_cast<int>(handles.size()), array.get(), 116 NaClMainForChromium(static_cast<int>(handles.size()), array.get(),
130 debug_enabled_); 117 false /* debug */);
131 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698