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

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

Issue 1409633002: Non-SFI mode: Remove old Non-SFI code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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/threading/platform_thread.h" 8 #include "base/threading/platform_thread.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "native_client/src/include/elf_auxv.h" 10 #include "native_client/src/include/elf_auxv.h"
11
12 #if defined(OS_NACL_NONSFI)
13 #include "native_client/src/public/nonsfi/elf_loader.h" 11 #include "native_client/src/public/nonsfi/elf_loader.h"
14 #include "ppapi/nacl_irt/irt_interfaces.h" 12 #include "ppapi/nacl_irt/irt_interfaces.h"
15 #else 13
16 #include "base/memory/scoped_ptr.h" 14 #if !defined(OS_NACL_NONSFI)
17 #include "components/nacl/loader/nonsfi/elf_loader.h" 15 #error "nonsfi_main.cc must be built for nacl_helper_nonsfi."
18 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
19 #include "native_client/src/include/nacl_macros.h"
20 #include "native_client/src/public/nacl_desc.h"
21 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
22 #endif 16 #endif
23 17
18
Mark Seaborn 2015/10/15 18:10:10 Nit: don't add extra empty line
hidehiko 2015/10/19 04:39:17 Done.
24 namespace nacl { 19 namespace nacl {
25 namespace nonsfi { 20 namespace nonsfi {
26 namespace { 21 namespace {
27 22
28 typedef void (*EntryPointType)(uintptr_t*); 23 typedef void (*EntryPointType)(uintptr_t*);
29 24
30 class PluginMainDelegate : public base::PlatformThread::Delegate { 25 class PluginMainDelegate : public base::PlatformThread::Delegate {
31 public: 26 public:
32 explicit PluginMainDelegate(EntryPointType entry_point) 27 explicit PluginMainDelegate(EntryPointType entry_point)
33 : entry_point_(entry_point) { 28 : entry_point_(entry_point) {
34 } 29 }
35 30
36 ~PluginMainDelegate() override {} 31 ~PluginMainDelegate() override {}
37 32
38 void ThreadMain() override { 33 void ThreadMain() override {
39 base::PlatformThread::SetName("NaClMainThread"); 34 base::PlatformThread::SetName("NaClMainThread");
40 35
41 // This will only happen once per process, so we give the permission to 36 // This will only happen once per process, so we give the permission to
42 // create Singletons. 37 // create Singletons.
43 base::ThreadRestrictions::SetSingletonAllowed(true); 38 base::ThreadRestrictions::SetSingletonAllowed(true);
44 uintptr_t info[] = { 39 uintptr_t info[] = {
45 0, // Do not use fini. 40 0, // Do not use fini.
46 0, // envc. 41 0, // envc.
47 0, // argc. 42 0, // argc.
48 0, // Null terminate for argv. 43 0, // Null terminate for argv.
49 0, // Null terminate for envv. 44 0, // Null terminate for envv.
50 AT_SYSINFO, 45 AT_SYSINFO,
51 #if defined(OS_NACL_NONSFI)
52 reinterpret_cast<uintptr_t>(&chrome_irt_query), 46 reinterpret_cast<uintptr_t>(&chrome_irt_query),
53 #else
54 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
55 #endif
56 AT_NULL, 47 AT_NULL,
57 0, // Null terminate for auxv. 48 0, // Null terminate for auxv.
58 }; 49 };
59 entry_point_(info); 50 entry_point_(info);
60 } 51 }
61 52
62 private: 53 private:
63 EntryPointType entry_point_; 54 EntryPointType entry_point_;
64 }; 55 };
65 56
66 // Default stack size of the plugin main thread. We heuristically chose 16M. 57 // Default stack size of the plugin main thread. We heuristically chose 16M.
67 const size_t kStackSize = (16 << 20); 58 const size_t kStackSize = (16 << 20);
68 59
69 #if !defined(OS_NACL_NONSFI)
70 struct NaClDescUnrefer {
71 void operator()(struct NaClDesc* desc) const {
72 NaClDescUnref(desc);
73 }
74 };
75 #endif
76
77 } // namespace 60 } // namespace
78 61
79 void MainStart(int nexe_file) { 62 void MainStart(int nexe_file) {
80 #if defined(OS_NACL_NONSFI)
81 EntryPointType entry_point = 63 EntryPointType entry_point =
82 reinterpret_cast<EntryPointType>(NaClLoadElfFile(nexe_file)); 64 reinterpret_cast<EntryPointType>(NaClLoadElfFile(nexe_file));
83 #else
84 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(
85 NaClDescIoMakeFromHandle(nexe_file, NACL_ABI_O_RDONLY));
86 ElfImage image;
87 if (image.Read(desc.get()) != LOAD_OK) {
88 LOG(ERROR) << "LoadModuleRpc: Failed to read binary.";
89 return;
90 }
91
92 if (image.Load(desc.get()) != LOAD_OK) {
93 LOG(ERROR) << "LoadModuleRpc: Failed to load the image";
94 return;
95 }
96
97 EntryPointType entry_point =
98 reinterpret_cast<EntryPointType>(image.entry_point());
99 #endif
100 if (!base::PlatformThread::CreateNonJoinable( 65 if (!base::PlatformThread::CreateNonJoinable(
101 kStackSize, new PluginMainDelegate(entry_point))) { 66 kStackSize, new PluginMainDelegate(entry_point))) {
102 LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread."; 67 LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread.";
103 return; 68 return;
104 } 69 }
105 } 70 }
106 71
107 } // namespace nonsfi 72 } // namespace nonsfi
108 } // namespace nacl 73 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698