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

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/platform_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"
20 22
21 namespace nacl { 23 namespace nacl {
22 namespace nonsfi { 24 namespace nonsfi {
23 namespace { 25 namespace {
24 26
27 typedef void (*EntryPointType)(uintptr_t *);
Mark Seaborn 2014/02/19 17:00:30 Nit: "uintptr_t*" (to follow Chrome spacing style)
hidehiko 2014/02/20 18:50:01 Done.
28
29 class PluginMainDelegate : public base::PlatformThread::Delegate {
30 public:
31 explicit PluginMainDelegate(EntryPointType entry_point)
32 : entry_point_(entry_point) {
33 }
34
35 virtual ~PluginMainDelegate() {
36 }
37
38 virtual void ThreadMain() OVERRIDE {
39 base::PlatformThread::SetName("NaClMainThread");
40
41 uintptr_t info[] = {
42 0, // Do not use fini.
43 0, // envc.
44 0, // argc.
45 0, // Null terminate for argv.
46 0, // Null terminate for envv.
47 AT_SYSINFO,
48 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
49 AT_NULL,
50 0, // Null terminate for auxv.
51 };
52 entry_point_(info);
53 }
54
55 private:
56 EntryPointType entry_point_;
57 };
58
59 // Default stack size of the plugin main thread. We heuristically chose 1M.
60 const size_t kStackSize = 1024 * 1024;
Mark Seaborn 2014/02/19 17:00:30 NaCl uses 16MB for the initial stack size (see NAC
hidehiko 2014/02/20 18:50:01 Good to know. Done.
61
25 struct NaClDescUnrefer { 62 struct NaClDescUnrefer {
26 void operator()(struct NaClDesc* desc) const { 63 void operator()(struct NaClDesc* desc) const {
27 NaClDescUnref(desc); 64 NaClDescUnref(desc);
28 } 65 }
29 }; 66 };
30 67
31 void LoadModuleRpc(struct NaClSrpcRpc* rpc, 68 void LoadModuleRpc(struct NaClSrpcRpc* rpc,
32 struct NaClSrpcArg** in_args, 69 struct NaClSrpcArg** in_args,
33 struct NaClSrpcArg** out_args, 70 struct NaClSrpcArg** out_args,
34 struct NaClSrpcClosure* done_cls) { 71 struct NaClSrpcClosure* done_cls) {
35 rpc->result = NACL_SRPC_RESULT_INTERNAL; 72 rpc->result = NACL_SRPC_RESULT_INTERNAL;
36 73
37 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(in_args[0]->u.hval); 74 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(in_args[0]->u.hval);
38 ElfImage image; 75 ElfImage image;
39 if (image.Read(desc.get()) != LOAD_OK) { 76 if (image.Read(desc.get()) != LOAD_OK) {
40 LOG(ERROR) << "LoadModuleRpc: Failed to read binary."; 77 LOG(ERROR) << "LoadModuleRpc: Failed to read binary.";
41 return; 78 return;
42 } 79 }
43 80
44 if (image.Load(desc.get()) != LOAD_OK) { 81 if (image.Load(desc.get()) != LOAD_OK) {
45 LOG(ERROR) << "LoadModuleRpc: Failed to load the image"; 82 LOG(ERROR) << "LoadModuleRpc: Failed to load the image";
46 return; 83 return;
47 } 84 }
48 85
49 uintptr_t entry_point = image.entry_point(); 86 EntryPointType entry_point =
87 reinterpret_cast<EntryPointType>(image.entry_point());
88 if (!base::PlatformThread::CreateNonJoinable(
89 kStackSize, new PluginMainDelegate(entry_point))) {
90 LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread.";
91 return;
92 }
93
50 rpc->result = NACL_SRPC_RESULT_OK; 94 rpc->result = NACL_SRPC_RESULT_OK;
51 95 (*done_cls->Run)(done_cls);
52 // Run for testing. TODO(hidehiko): Remove this.
53 uintptr_t info[] = {
54 0, // Do not use fini.
55 0, // envc.
56 0, // argc.
57 0, // Null terminate for argv.
58 0, // Null terminate for envv.
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 } 96 }
66 97
67 const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = { 98 const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = {
68 { NACL_SECURE_SERVICE_LOAD_MODULE, LoadModuleRpc, }, 99 { NACL_SECURE_SERVICE_LOAD_MODULE, LoadModuleRpc, },
69 { static_cast<const char*>(NULL), static_cast<NaClSrpcMethod>(NULL), }, 100 { static_cast<const char*>(NULL), static_cast<NaClSrpcMethod>(NULL), },
70 }; 101 };
71 102
72 // Creates two socketpairs to communicate with the host process. 103 // Creates two socketpairs to communicate with the host process.
73 void CreateSecureSocketPair(struct NaClDesc* secure_pair[2], 104 void CreateSecureSocketPair(struct NaClDesc* secure_pair[2],
74 struct NaClDesc* pair[2]) { 105 struct NaClDesc* pair[2]) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 LOG(ERROR) << "MainStart: Failed to set up bootstrap channel."; 192 LOG(ERROR) << "MainStart: Failed to set up bootstrap channel.";
162 return; 193 return;
163 } 194 }
164 195
165 // Start the SRPC server loop. 196 // Start the SRPC server loop.
166 ServiceAccept(secure_port.get()); 197 ServiceAccept(secure_port.get());
167 } 198 }
168 199
169 } // namespace nonsfi 200 } // namespace nonsfi
170 } // namespace nacl 201 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698