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

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/native_client/src/shared/ppapi_proxy/ppruntime.h"
dmichael (off chromium) 2014/02/13 19:00:34 I don't really want us to add stuff to ppapi/nativ
hidehiko 2014/02/14 10:49:05 Moved to ppapi/proxy with renaming it to plugin_ma
20 23
21 namespace nacl { 24 namespace nacl {
22 namespace nonsfi { 25 namespace nonsfi {
23 namespace { 26 namespace {
24 27
28 class PluginMainThread : public base::SimpleThread {
29 public:
30 PluginMainThread(uintptr_t entry_point)
dmichael (off chromium) 2014/02/13 19:00:34 nit: explicit
hidehiko 2014/02/14 10:49:05 Done.
31 : base::SimpleThread("NaClMainThread"),
32 entry_point_(entry_point) {
33 }
34
35 virtual void Run() OVERRIDE {
36 uintptr_t info[] = {
37 0, // Do not use fini.
38 0, // envc.
39 0, // argc.
40 0, // Null terminate for argv.
41 0, // Null terminate for envv.
42 AT_SYSINFO,
43 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
44 AT_NULL,
45 0, // Null terminate for auxv.
46 };
47 reinterpret_cast<void (*)(uintptr_t*)>(entry_point_)(info);
48 }
49
50 private:
51 uintptr_t entry_point_;
dmichael (off chromium) 2014/02/13 19:00:34 It seems like it would make more sense to store th
hidehiko 2014/02/14 10:49:05 Done.
52 };
53
25 struct NaClDescUnrefer { 54 struct NaClDescUnrefer {
26 void operator()(struct NaClDesc* desc) const { 55 void operator()(struct NaClDesc* desc) const {
27 NaClDescUnref(desc); 56 NaClDescUnref(desc);
28 } 57 }
29 }; 58 };
30 59
31 void LoadModuleRpc(struct NaClSrpcRpc* rpc, 60 void LoadModuleRpc(struct NaClSrpcRpc* rpc,
32 struct NaClSrpcArg** in_args, 61 struct NaClSrpcArg** in_args,
33 struct NaClSrpcArg** out_args, 62 struct NaClSrpcArg** out_args,
34 struct NaClSrpcClosure* done_cls) { 63 struct NaClSrpcClosure* done_cls) {
35 rpc->result = NACL_SRPC_RESULT_INTERNAL; 64 rpc->result = NACL_SRPC_RESULT_INTERNAL;
36 65
37 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(in_args[0]->u.hval); 66 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(in_args[0]->u.hval);
38 ElfImage image; 67 ElfImage image;
39 if (image.Read(desc.get()) != LOAD_OK) { 68 if (image.Read(desc.get()) != LOAD_OK) {
40 LOG(ERROR) << "LoadModuleRpc: Failed to read binary."; 69 LOG(ERROR) << "LoadModuleRpc: Failed to read binary.";
41 return; 70 return;
42 } 71 }
43 72
44 if (image.Load(desc.get()) != LOAD_OK) { 73 if (image.Load(desc.get()) != LOAD_OK) {
45 LOG(ERROR) << "LoadModuleRpc: Failed to load the image"; 74 LOG(ERROR) << "LoadModuleRpc: Failed to load the image";
46 return; 75 return;
47 } 76 }
48 77
49 uintptr_t entry_point = image.entry_point(); 78 uintptr_t entry_point = image.entry_point();
50 rpc->result = NACL_SRPC_RESULT_OK; 79 rpc->result = NACL_SRPC_RESULT_OK;
51 80
52 // Run for testing. TODO(hidehiko): Remove this. 81 // We intentionally leak the thread. The plugin runs on the thread, and once
53 uintptr_t info[] = { 82 // it is completed, this process should be killed so that the memory for
54 0, // Do not use fini. 83 // the thread is also collected correctly.
55 0, // envc. 84 // We may want to manage the thread pointer after we switch the
56 0, // argc. 85 // initialization message passing between the renderer from SRPC to IPC.
57 0, // Null terminate for argv. 86 base::SimpleThread* thread = new PluginMainThread(entry_point);
58 0, // Null terminate for envv. 87 ANNOTATE_LEAKING_OBJECT_PTR(thread);
59 AT_SYSINFO, 88 thread->Start();
60 reinterpret_cast<uintptr_t>(&NaClIrtInterface), 89
61 AT_NULL, 90 // Wait until the PPAPI set up is completed on the main thread.
62 0, // Null terminate for auxv. 91 ppapi::proxy::WaitForPpapiStartEvent();
63 }; 92
64 reinterpret_cast<void (*)(uintptr_t*)>(entry_point)(info); 93 if (done_cls)
94 (*done_cls->Run)(done_cls);
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 ppapi::proxy::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