Correctly track texture cleared state for sharing
[chromium-blink-merge.git] / components / nacl / loader / nonsfi / nonsfi_main.cc
blob1b05d84db421a9ee167126e9d8ce3d0080188aff
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
3 // found in the LICENSE file.
5 #include "components/nacl/loader/nonsfi/nonsfi_main.h"
7 #include "base/logging.h"
8 #include "base/threading/platform_thread.h"
9 #include "base/threading/thread_restrictions.h"
10 #include "native_client/src/include/elf_auxv.h"
12 #if defined(OS_NACL_NONSFI)
13 #include "native_client/src/public/nonsfi/elf_loader.h"
14 #include "ppapi/nacl_irt/irt_ppapi.h"
15 #else
16 #include "base/memory/scoped_ptr.h"
17 #include "components/nacl/loader/nonsfi/elf_loader.h"
18 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
19 #include "native_client/src/include/nacl_macros.h"
20 #include "native_client/src/trusted/desc/nacl_desc_base.h"
21 #include "native_client/src/trusted/desc/nacl_desc_io.h"
22 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
23 #endif
25 namespace nacl {
26 namespace nonsfi {
27 namespace {
29 typedef void (*EntryPointType)(uintptr_t*);
31 class PluginMainDelegate : public base::PlatformThread::Delegate {
32 public:
33 explicit PluginMainDelegate(EntryPointType entry_point)
34 : entry_point_(entry_point) {
37 ~PluginMainDelegate() override {}
39 void ThreadMain() override {
40 base::PlatformThread::SetName("NaClMainThread");
42 // This will only happen once per process, so we give the permission to
43 // create Singletons.
44 base::ThreadRestrictions::SetSingletonAllowed(true);
45 uintptr_t info[] = {
46 0, // Do not use fini.
47 0, // envc.
48 0, // argc.
49 0, // Null terminate for argv.
50 0, // Null terminate for envv.
51 AT_SYSINFO,
52 #if defined(OS_NACL_NONSFI)
53 reinterpret_cast<uintptr_t>(&chrome_irt_query),
54 #else
55 reinterpret_cast<uintptr_t>(&NaClIrtInterface),
56 #endif
57 AT_NULL,
58 0, // Null terminate for auxv.
60 entry_point_(info);
63 private:
64 EntryPointType entry_point_;
67 // Default stack size of the plugin main thread. We heuristically chose 16M.
68 const size_t kStackSize = (16 << 20);
70 #if !defined(OS_NACL_NONSFI)
71 struct NaClDescUnrefer {
72 void operator()(struct NaClDesc* desc) const {
73 NaClDescUnref(desc);
76 #endif
78 } // namespace
80 void MainStart(int nexe_file) {
81 #if defined(OS_NACL_NONSFI)
82 EntryPointType entry_point =
83 reinterpret_cast<EntryPointType>(NaClLoadElfFile(nexe_file));
84 #else
85 ::scoped_ptr<struct NaClDesc, NaClDescUnrefer> desc(
86 NaClDescIoDescFromDescAllocCtor(nexe_file, NACL_ABI_O_RDONLY));
87 ElfImage image;
88 if (image.Read(desc.get()) != LOAD_OK) {
89 LOG(ERROR) << "LoadModuleRpc: Failed to read binary.";
90 return;
93 if (image.Load(desc.get()) != LOAD_OK) {
94 LOG(ERROR) << "LoadModuleRpc: Failed to load the image";
95 return;
98 EntryPointType entry_point =
99 reinterpret_cast<EntryPointType>(image.entry_point());
100 #endif
101 if (!base::PlatformThread::CreateNonJoinable(
102 kStackSize, new PluginMainDelegate(entry_point))) {
103 LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread.";
104 return;
108 } // namespace nonsfi
109 } // namespace nacl