OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <stdio.h> |
| 7 |
| 8 #include <memory> |
6 | 9 |
7 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 11 #include "base/logging.h" |
9 #include "build/build_config.h" | 12 #include "build/build_config.h" |
10 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" | 13 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" |
11 #include "mojo/public/cpp/bindings/array.h" | 14 #include "mojo/public/cpp/bindings/array.h" |
12 #include "mojo/public/cpp/bindings/string.h" | 15 #include "mojo/public/cpp/bindings/string.h" |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
14 #include "mojo/public/cpp/utility/run_loop.h" | 17 #include "mojo/public/cpp/utility/run_loop.h" |
15 #include "native_client/src/untrusted/irt/irt_dev.h" | 18 #include "native_client/src/untrusted/irt/irt_dev.h" |
(...skipping 18 matching lines...) Expand all Loading... |
34 const size_t obj_file_count = num_threads; | 37 const size_t obj_file_count = num_threads; |
35 #else | 38 #else |
36 // subzero does need split modules. | 39 // subzero does need split modules. |
37 const size_t obj_file_count = 1; | 40 const size_t obj_file_count = 1; |
38 #endif | 41 #endif |
39 auto obj_file_names = mojo::Array<mojo::String>::New(obj_file_count); | 42 auto obj_file_names = mojo::Array<mojo::String>::New(obj_file_count); |
40 int obj_file_fds[obj_file_count]; | 43 int obj_file_fds[obj_file_count]; |
41 | 44 |
42 for (size_t i = 0; i < obj_file_count; i++) { | 45 for (size_t i = 0; i < obj_file_count; i++) { |
43 base::FilePath obj_file_name; | 46 base::FilePath obj_file_name; |
44 CHECK(CreateTemporaryFile(&obj_file_name)) | 47 CHECK(base::CreateTemporaryFile(&obj_file_name)) |
45 << "Could not make temporary object file"; | 48 << "Could not make temporary object file"; |
46 obj_file_fds[i] = open(obj_file_name.value().c_str(), O_RDWR, O_TRUNC); | 49 obj_file_fds[i] = open(obj_file_name.value().c_str(), O_RDWR, O_TRUNC); |
47 CHECK_GE(obj_file_fds[i], 0) | 50 CHECK_GE(obj_file_fds[i], 0) |
48 << "Could not create temporary file for compiled pexe"; | 51 << "Could not create temporary file for compiled pexe"; |
49 obj_file_names[i] = mojo::String(obj_file_name.value()); | 52 obj_file_names[i] = mojo::String(obj_file_name.value()); |
50 } | 53 } |
51 | 54 |
52 #if defined(__arm__) // No subzero on arm: Uses pnacl-llc.nexe. | 55 #if defined(__arm__) // No subzero on arm: Uses pnacl-llc.nexe. |
53 // Number of modules should be equal to the number of object files for | 56 // Number of modules should be equal to the number of object files for |
54 // stability. Use a char buffer more than large enough to hold any expected | 57 // stability. Use a char buffer more than large enough to hold any expected |
(...skipping 14 matching lines...) Expand all Loading... |
69 "-filetype=obj", "-target=x8632", | 72 "-filetype=obj", "-target=x8632", |
70 "-nonsfi", threads, | 73 "-nonsfi", threads, |
71 nullptr}; | 74 nullptr}; |
72 #endif | 75 #endif |
73 constexpr const size_t argc = sizeof(args) / sizeof(*args) - 1; | 76 constexpr const size_t argc = sizeof(args) / sizeof(*args) - 1; |
74 funcs_->init_callback(num_threads, obj_file_fds, obj_file_count, | 77 funcs_->init_callback(num_threads, obj_file_fds, obj_file_count, |
75 const_cast<char**>(args), argc); | 78 const_cast<char**>(args), argc); |
76 | 79 |
77 // Read the pexe using fread, and write the pexe into the callback function. | 80 // Read the pexe using fread, and write the pexe into the callback function. |
78 static const size_t kBufferSize = 0x100000; | 81 static const size_t kBufferSize = 0x100000; |
79 scoped_ptr<char[]> buf(new char[kBufferSize]); | 82 std::unique_ptr<char[]> buf(new char[kBufferSize]); |
80 FILE* pexe_file_stream = fopen(pexe_file_name.get().c_str(), "r"); | 83 FILE* pexe_file_stream = fopen(pexe_file_name.get().c_str(), "r"); |
81 // Once the pexe has been opened, it is no longer needed, so we unlink it. | 84 // Once the pexe has been opened, it is no longer needed, so we unlink it. |
82 CHECK(!unlink(pexe_file_name.get().c_str())) | 85 CHECK(!unlink(pexe_file_name.get().c_str())) |
83 << "Could not unlink temporary pexe file"; | 86 << "Could not unlink temporary pexe file"; |
84 CHECK(pexe_file_stream) << "Could not open pexe for reading"; | 87 CHECK(pexe_file_stream) << "Could not open pexe for reading"; |
85 // TODO(smklein): Remove these LOG statements once translation speed | 88 // TODO(smklein): Remove these LOG statements once translation speed |
86 // is improved. | 89 // is improved. |
87 LOG(INFO) << "Starting compilation of pexe into nexe"; | 90 LOG(INFO) << "Starting compilation of pexe into nexe"; |
88 for (;;) { | 91 for (;;) { |
89 size_t num_bytes_from_pexe = fread(buf.get(), 1, kBufferSize, | 92 size_t num_bytes_from_pexe = fread(buf.get(), 1, kBufferSize, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } // namespace anonymous | 130 } // namespace anonymous |
128 | 131 |
129 namespace nacl { | 132 namespace nacl { |
130 | 133 |
131 const struct nacl_irt_private_pnacl_translator_compile | 134 const struct nacl_irt_private_pnacl_translator_compile |
132 nacl_irt_private_pnacl_translator_compile = { | 135 nacl_irt_private_pnacl_translator_compile = { |
133 ServeTranslateRequest | 136 ServeTranslateRequest |
134 }; | 137 }; |
135 | 138 |
136 } // namespace nacl | 139 } // namespace nacl |
OLD | NEW |