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

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

Issue 139993009: [WIP] Yet another demo for BMM NaCl ppapi connection. (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/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/synchronization/waitable_event.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"
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)
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_;
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 base::WaitableEvent event(true, false);
53 uintptr_t info[] = { 82 ppapi::proxy::SetPpapiStartEvent(&event);
54 0, // Do not use fini. 83 // TODO: memory management.
55 0, // envc. 84 (new PluginMainThread(entry_point))->Start();
56 0, // argc. 85 event.Wait();
Mark Seaborn 2014/02/07 22:53:43 This stuff with SetPpapiStartEvent() shouldn't be
57 0, // Null terminate for argv. 86 if (done_cls)
58 0, // Null terminate for envv. 87 (*done_cls->Run)(done_cls);
59 AT_SYSINFO,
60 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
61 AT_NULL,
62 0, // Null terminate for auxv.
63 };
64 reinterpret_cast<void (*)(uintptr_t*)>(entry_point)(info);
65 } 88 }
66 89
67 const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = { 90 const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = {
68 { NACL_SECURE_SERVICE_LOAD_MODULE, LoadModuleRpc, }, 91 { NACL_SECURE_SERVICE_LOAD_MODULE, LoadModuleRpc, },
69 { static_cast<const char*>(NULL), static_cast<NaClSrpcMethod>(NULL), }, 92 { static_cast<const char*>(NULL), static_cast<NaClSrpcMethod>(NULL), },
70 }; 93 };
71 94
72 // Creates two socketpairs to communicate with the host process. 95 // Creates two socketpairs to communicate with the host process.
73 void CreateSecureSocketPair(struct NaClDesc* secure_pair[2], 96 void CreateSecureSocketPair(struct NaClDesc* secure_pair[2],
74 struct NaClDesc* pair[2]) { 97 struct NaClDesc* pair[2]) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (status) { 158 if (status) {
136 LOG(ERROR) << "ServiceAccept: Failed to accept " << status; 159 LOG(ERROR) << "ServiceAccept: Failed to accept " << status;
137 return; 160 return;
138 } 161 }
139 162
140 NaClSrpcServerLoop(connected_desc, kNonSfiServiceHandlers, NULL); 163 NaClSrpcServerLoop(connected_desc, kNonSfiServiceHandlers, NULL);
141 } 164 }
142 165
143 } // namespace 166 } // namespace
144 167
168 void SetIPCFileDescriptors(int browser_ipc_fd, int renderer_ipc_fd) {
169 ppapi::proxy::SetIPCFileDescriptors(browser_ipc_fd, renderer_ipc_fd);
170 }
171
145 void MainStart(NaClHandle imc_bootstrap_handle) { 172 void MainStart(NaClHandle imc_bootstrap_handle) {
146 NaClSrpcModuleInit(); 173 NaClSrpcModuleInit();
147 174
148 struct NaClDesc* secure_pair[2] = { NULL, NULL }; 175 struct NaClDesc* secure_pair[2] = { NULL, NULL };
149 struct NaClDesc* pair[2] = { NULL, NULL }; 176 struct NaClDesc* pair[2] = { NULL, NULL };
150 CreateSecureSocketPair(secure_pair, pair); 177 CreateSecureSocketPair(secure_pair, pair);
151 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_port(secure_pair[0]); 178 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_port(secure_pair[0]);
152 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_address( 179 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> secure_address(
153 secure_pair[1]); 180 secure_pair[1]);
154 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_port(pair[0]); 181 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_port(pair[0]);
155 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_address(pair[1]); 182 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> service_address(pair[1]);
156 183
157 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> channel( 184 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> channel(
158 SetUpBootstrapChannel(imc_bootstrap_handle, 185 SetUpBootstrapChannel(imc_bootstrap_handle,
159 secure_address.get(), service_address.get())); 186 secure_address.get(), service_address.get()));
160 if (!channel) { 187 if (!channel) {
161 LOG(ERROR) << "MainStart: Failed to set up bootstrap channel."; 188 LOG(ERROR) << "MainStart: Failed to set up bootstrap channel.";
162 return; 189 return;
163 } 190 }
164 191
165 // Start the SRPC server loop. 192 // Start the SRPC server loop.
166 ServiceAccept(secure_port.get()); 193 ServiceAccept(secure_port.get());
167 } 194 }
168 195
169 } // namespace nonsfi 196 } // namespace nonsfi
170 } // namespace nacl 197 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698