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

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
24 namespace nacl { 18 namespace nacl {
25 namespace nonsfi { 19 namespace nonsfi {
26 namespace { 20 namespace {
27 21
28 typedef void (*EntryPointType)(uintptr_t*); 22 typedef void (*EntryPointType)(uintptr_t*);
29 23
30 class PluginMainDelegate : public base::PlatformThread::Delegate { 24 class PluginMainDelegate : public base::PlatformThread::Delegate {
31 public: 25 public:
32 explicit PluginMainDelegate(EntryPointType entry_point) 26 explicit PluginMainDelegate(EntryPointType entry_point)
33 : entry_point_(entry_point) { 27 : entry_point_(entry_point) {
34 } 28 }
35 29
36 ~PluginMainDelegate() override {} 30 ~PluginMainDelegate() override {}
37 31
38 void ThreadMain() override { 32 void ThreadMain() override {
39 base::PlatformThread::SetName("NaClMainThread"); 33 base::PlatformThread::SetName("NaClMainThread");
40 34
41 // This will only happen once per process, so we give the permission to 35 // This will only happen once per process, so we give the permission to
42 // create Singletons. 36 // create Singletons.
43 base::ThreadRestrictions::SetSingletonAllowed(true); 37 base::ThreadRestrictions::SetSingletonAllowed(true);
44 uintptr_t info[] = { 38 uintptr_t info[] = {
45 0, // Do not use fini. 39 0, // Do not use fini.
46 0, // envc. 40 0, // envc.
47 0, // argc. 41 0, // argc.
48 0, // Null terminate for argv. 42 0, // Null terminate for argv.
49 0, // Null terminate for envv. 43 0, // Null terminate for envv.
50 AT_SYSINFO, 44 AT_SYSINFO,
51 #if defined(OS_NACL_NONSFI)
52 reinterpret_cast<uintptr_t>(&chrome_irt_query), 45 reinterpret_cast<uintptr_t>(&chrome_irt_query),
53 #else
54 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
55 #endif
56 AT_NULL, 46 AT_NULL,
57 0, // Null terminate for auxv. 47 0, // Null terminate for auxv.
58 }; 48 };
59 entry_point_(info); 49 entry_point_(info);
60 } 50 }
61 51
62 private: 52 private:
63 EntryPointType entry_point_; 53 EntryPointType entry_point_;
64 }; 54 };
65 55
66 // Default stack size of the plugin main thread. We heuristically chose 16M. 56 // Default stack size of the plugin main thread. We heuristically chose 16M.
67 const size_t kStackSize = (16 << 20); 57 const size_t kStackSize = (16 << 20);
68 58
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 59 } // namespace
78 60
79 void MainStart(int nexe_file) { 61 void MainStart(int nexe_file) {
80 #if defined(OS_NACL_NONSFI)
81 EntryPointType entry_point = 62 EntryPointType entry_point =
82 reinterpret_cast<EntryPointType>(NaClLoadElfFile(nexe_file)); 63 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( 64 if (!base::PlatformThread::CreateNonJoinable(
101 kStackSize, new PluginMainDelegate(entry_point))) { 65 kStackSize, new PluginMainDelegate(entry_point))) {
102 LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread."; 66 LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread.";
103 return; 67 return;
104 } 68 }
105 } 69 }
106 70
107 } // namespace nonsfi 71 } // namespace nonsfi
108 } // namespace nacl 72 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_listener.cc ('k') | components/nacl/loader/nonsfi/nonsfi_sandbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698