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

Side by Side Diff: components/nacl/loader/nonsfi/nonsfi_main.cc

Issue 140573003: Connect PPAPI IPC channels for non-SFI mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/nonsfi/nonsfi_main.h" 5 #include "components/nacl/loader/nonsfi/nonsfi_main.h"
6 6
7 #include "base/debug/leak_annotations.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/simple_thread.h"
9 #include "components/nacl/loader/nonsfi/elf_loader.h" 11 #include "components/nacl/loader/nonsfi/elf_loader.h"
10 #include "components/nacl/loader/nonsfi/irt_interfaces.h" 12 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
11 #include "native_client/src/include/elf_auxv.h" 13 #include "native_client/src/include/elf_auxv.h"
12 #include "native_client/src/include/nacl_macros.h" 14 #include "native_client/src/include/nacl_macros.h"
13 #include "native_client/src/public/secure_service.h" 15 #include "native_client/src/public/secure_service.h"
14 #include "native_client/src/shared/srpc/nacl_srpc.h" 16 #include "native_client/src/shared/srpc/nacl_srpc.h"
15 #include "native_client/src/trusted/desc/nacl_desc_base.h" 17 #include "native_client/src/trusted/desc/nacl_desc_base.h"
16 #include "native_client/src/trusted/desc/nacl_desc_imc.h" 18 #include "native_client/src/trusted/desc/nacl_desc_imc.h"
17 #include "native_client/src/trusted/desc/nrd_all_modules.h" 19 #include "native_client/src/trusted/desc/nrd_all_modules.h"
18 #include "native_client/src/trusted/desc/nrd_xfer.h" 20 #include "native_client/src/trusted/desc/nrd_xfer.h"
19 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" 21 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
22 #include "ppapi/proxy/plugin_main_irt.h"
20 23
21 namespace nacl { 24 namespace nacl {
22 namespace nonsfi { 25 namespace nonsfi {
23 namespace { 26 namespace {
24 27
28 typedef void (*EntryPointType)(uintptr_t *);
29
30 class PluginMainThread : public base::SimpleThread {
31 public:
32 explicit PluginMainThread(EntryPointType entry_point)
33 : base::SimpleThread("NaClMainThread"),
34 entry_point_(entry_point) {
35 }
36
37 virtual void Run() OVERRIDE {
38 uintptr_t info[] = {
39 0, // Do not use fini.
40 0, // envc.
41 0, // argc.
42 0, // Null terminate for argv.
43 0, // Null terminate for envv.
44 AT_SYSINFO,
45 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
46 AT_NULL,
47 0, // Null terminate for auxv.
48 };
49 entry_point_(info);
50 }
51
52 private:
53 EntryPointType entry_point_;
54 };
55
25 struct NaClDescUnrefer { 56 struct NaClDescUnrefer {
26 void operator()(struct NaClDesc* desc) const { 57 void operator()(struct NaClDesc* desc) const {
27 NaClDescUnref(desc); 58 NaClDescUnref(desc);
28 } 59 }
29 }; 60 };
30 61
31 void LoadModuleRpc(struct NaClSrpcRpc* rpc, 62 void LoadModuleRpc(struct NaClSrpcRpc* rpc,
32 struct NaClSrpcArg** in_args, 63 struct NaClSrpcArg** in_args,
33 struct NaClSrpcArg** out_args, 64 struct NaClSrpcArg** out_args,
34 struct NaClSrpcClosure* done_cls) { 65 struct NaClSrpcClosure* done_cls) {
35 rpc->result = NACL_SRPC_RESULT_INTERNAL; 66 rpc->result = NACL_SRPC_RESULT_INTERNAL;
36 67
37 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(in_args[0]->u.hval); 68 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(in_args[0]->u.hval);
38 ElfImage image; 69 ElfImage image;
39 if (image.Read(desc.get()) != LOAD_OK) { 70 if (image.Read(desc.get()) != LOAD_OK) {
40 LOG(ERROR) << "LoadModuleRpc: Failed to read binary."; 71 LOG(ERROR) << "LoadModuleRpc: Failed to read binary.";
41 return; 72 return;
42 } 73 }
43 74
44 if (image.Load(desc.get()) != LOAD_OK) { 75 if (image.Load(desc.get()) != LOAD_OK) {
45 LOG(ERROR) << "LoadModuleRpc: Failed to load the image"; 76 LOG(ERROR) << "LoadModuleRpc: Failed to load the image";
46 return; 77 return;
47 } 78 }
48 79
49 uintptr_t entry_point = image.entry_point(); 80 uintptr_t entry_point = image.entry_point();
50 rpc->result = NACL_SRPC_RESULT_OK; 81 rpc->result = NACL_SRPC_RESULT_OK;
51 82
52 // Run for testing. TODO(hidehiko): Remove this. 83 // We intentionally leak the thread. The plugin runs on the thread, and once
53 uintptr_t info[] = { 84 // it is completed, this process should be killed so that the memory for
54 0, // Do not use fini. 85 // the thread is also collected correctly.
55 0, // envc. 86 // We may want to manage the thread pointer after we switch the
Mark Seaborn 2014/02/15 03:00:52 Do you mean the SimpleThread pointer?
hidehiko 2014/02/19 13:05:02 Acknowledged.
56 0, // argc. 87 // initialization message passing between the renderer from SRPC to IPC.
57 0, // Null terminate for argv. 88 base::SimpleThread* thread =
58 0, // Null terminate for envv. 89 new PluginMainThread(reinterpret_cast<EntryPointType>(entry_point));
59 AT_SYSINFO, 90 ANNOTATE_LEAKING_OBJECT_PTR(thread);
Mark Seaborn 2014/02/15 03:00:52 Maybe use base::PlatformThread::CreateNonJoinable(
hidehiko 2014/02/19 13:05:02 Great to know. Done.
60 reinterpret_cast<uintptr_t>(&NaClIrtInterface), 91 thread->Start();
61 AT_NULL, 92
62 0, // Null terminate for auxv. 93 if (done_cls)
Mark Seaborn 2014/02/15 03:00:52 I don't think you need a NULL check here
hidehiko 2014/02/19 13:05:02 Done.
63 }; 94 (*done_cls->Run)(done_cls);
64 reinterpret_cast<void (*)(uintptr_t*)>(entry_point)(info);
65 } 95 }
66 96
67 const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = { 97 const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = {
68 { NACL_SECURE_SERVICE_LOAD_MODULE, LoadModuleRpc, }, 98 { NACL_SECURE_SERVICE_LOAD_MODULE, LoadModuleRpc, },
69 { static_cast<const char*>(NULL), static_cast<NaClSrpcMethod>(NULL), }, 99 { static_cast<const char*>(NULL), static_cast<NaClSrpcMethod>(NULL), },
70 }; 100 };
71 101
72 // Creates two socketpairs to communicate with the host process. 102 // Creates two socketpairs to communicate with the host process.
73 void CreateSecureSocketPair(struct NaClDesc* secure_pair[2], 103 void CreateSecureSocketPair(struct NaClDesc* secure_pair[2],
74 struct NaClDesc* pair[2]) { 104 struct NaClDesc* pair[2]) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (status) { 165 if (status) {
136 LOG(ERROR) << "ServiceAccept: Failed to accept " << status; 166 LOG(ERROR) << "ServiceAccept: Failed to accept " << status;
137 return; 167 return;
138 } 168 }
139 169
140 NaClSrpcServerLoop(connected_desc, kNonSfiServiceHandlers, NULL); 170 NaClSrpcServerLoop(connected_desc, kNonSfiServiceHandlers, NULL);
141 } 171 }
142 172
143 } // namespace 173 } // namespace
144 174
175 void SetIPCFileDescriptors(int browser_ipc_fd, int renderer_ipc_fd) {
176 ::SetIPCFileDescriptors(browser_ipc_fd, renderer_ipc_fd);
177 }
178
145 void MainStart(NaClHandle imc_bootstrap_handle) { 179 void MainStart(NaClHandle imc_bootstrap_handle) {
146 NaClSrpcModuleInit(); 180 NaClSrpcModuleInit();
147 181
148 struct NaClDesc* secure_pair[2] = { NULL, NULL }; 182 struct NaClDesc* secure_pair[2] = { NULL, NULL };
149 struct NaClDesc* pair[2] = { NULL, NULL }; 183 struct NaClDesc* pair[2] = { NULL, NULL };
150 CreateSecureSocketPair(secure_pair, pair); 184 CreateSecureSocketPair(secure_pair, pair);
151 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_port(secure_pair[0]); 185 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_port(secure_pair[0]);
152 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_address( 186 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_address(
153 secure_pair[1]); 187 secure_pair[1]);
154 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_port(pair[0]); 188 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_port(pair[0]);
155 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_address(pair[1]); 189 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_address(pair[1]);
156 190
157 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> channel( 191 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> channel(
158 SetUpBootstrapChannel(imc_bootstrap_handle, 192 SetUpBootstrapChannel(imc_bootstrap_handle,
159 secure_address.get(), service_address.get())); 193 secure_address.get(), service_address.get()));
160 if (!channel) { 194 if (!channel) {
161 LOG(ERROR) << "MainStart: Failed to set up bootstrap channel."; 195 LOG(ERROR) << "MainStart: Failed to set up bootstrap channel.";
162 return; 196 return;
163 } 197 }
164 198
165 // Start the SRPC server loop. 199 // Start the SRPC server loop.
166 ServiceAccept(secure_port.get()); 200 ServiceAccept(secure_port.get());
167 } 201 }
168 202
169 } // namespace nonsfi 203 } // namespace nonsfi
170 } // namespace nacl 204 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698