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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/plugin.cc

Issue 15697019: Parametrize names of llc and ld nexes by reading them from the resource info JSON file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win build Created 7 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifdef _MSC_VER 5 #ifdef _MSC_VER
6 // Do not warn about use of std::copy with raw pointers. 6 // Do not warn about use of std::copy with raw pointers.
7 #pragma warning(disable : 4996) 7 #pragma warning(disable : 4996)
8 #endif 8 #endif
9 9
10 #include "native_client/src/trusted/plugin/plugin.h" 10 #include "native_client/src/trusted/plugin/plugin.h"
11 11
12 #include <fcntl.h> 12 #include <fcntl.h>
jvoung (off chromium) 2013/05/23 20:33:19 does fcntl.h still need to be included? There's s
eliben 2013/05/23 20:54:25 Removed
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16
17 #include <sys/stat.h> 13 #include <sys/stat.h>
18 #include <sys/types.h> 14 #include <sys/types.h>
19 15
20 #include <algorithm> 16 #include <algorithm>
21 #include <deque> 17 #include <deque>
22 #include <string> 18 #include <string>
23 #include <vector> 19 #include <vector>
24 20
25 #include "native_client/src/include/nacl_base.h" 21 #include "native_client/src/include/nacl_base.h"
26 #include "native_client/src/include/nacl_macros.h" 22 #include "native_client/src/include/nacl_macros.h"
27 #include "native_client/src/include/nacl_scoped_ptr.h" 23 #include "native_client/src/include/nacl_scoped_ptr.h"
28 #include "native_client/src/include/nacl_string.h" 24 #include "native_client/src/include/nacl_string.h"
29 #include "native_client/src/include/portability.h" 25 #include "native_client/src/include/portability.h"
30 #include "native_client/src/include/portability_io.h" 26 #include "native_client/src/include/portability_io.h"
31 #include "native_client/src/include/portability_string.h" 27 #include "native_client/src/include/portability_string.h"
32 #include "native_client/src/shared/platform/nacl_check.h" 28 #include "native_client/src/shared/platform/nacl_check.h"
33 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 29 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
34 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" 30 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h"
31 #include "native_client/src/trusted/plugin/file_utils.h"
35 #include "native_client/src/trusted/plugin/json_manifest.h" 32 #include "native_client/src/trusted/plugin/json_manifest.h"
36 #include "native_client/src/trusted/plugin/nacl_entry_points.h" 33 #include "native_client/src/trusted/plugin/nacl_entry_points.h"
37 #include "native_client/src/trusted/plugin/nacl_subprocess.h" 34 #include "native_client/src/trusted/plugin/nacl_subprocess.h"
38 #include "native_client/src/trusted/plugin/nexe_arch.h" 35 #include "native_client/src/trusted/plugin/nexe_arch.h"
39 #include "native_client/src/trusted/plugin/plugin_error.h" 36 #include "native_client/src/trusted/plugin/plugin_error.h"
40 #include "native_client/src/trusted/plugin/scriptable_plugin.h" 37 #include "native_client/src/trusted/plugin/scriptable_plugin.h"
41 #include "native_client/src/trusted/plugin/service_runtime.h" 38 #include "native_client/src/trusted/plugin/service_runtime.h"
42 #include "native_client/src/trusted/plugin/utility.h" 39 #include "native_client/src/trusted/plugin/utility.h"
43 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" 40 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
44 41
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, 1094 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL,
1098 "access to manifest url was denied."); 1095 "access to manifest url was denied.");
1099 ReportLoadError(error_info); 1096 ReportLoadError(error_info);
1100 } else { 1097 } else {
1101 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, 1098 error_info.SetReport(ERROR_MANIFEST_LOAD_URL,
1102 "could not load manifest url."); 1099 "could not load manifest url.");
1103 ReportLoadError(error_info); 1100 ReportLoadError(error_info);
1104 } 1101 }
1105 return; 1102 return;
1106 } 1103 }
1107 // Duplicate the file descriptor in order to create a FILE stream with it 1104 // SlurpFile closes the file descriptor after reading (or on error).
1108 // that can later be closed without closing the original descriptor. The 1105 // Duplicate our file descriptor since it will be handled by the browser.
1109 // browser will take care of the original descriptor.
1110 int dup_file_desc = DUP(file_desc); 1106 int dup_file_desc = DUP(file_desc);
1111 struct stat stat_buf; 1107 nacl::string json_buffer;
1112 if (0 != fstat(dup_file_desc, &stat_buf)) { 1108 file_utils::StatusCode status = file_utils::SlurpFile(
1113 CLOSE(dup_file_desc); 1109 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes);
1114 error_info.SetReport(ERROR_MANIFEST_STAT, 1110
1115 "could not stat manifest file."); 1111 if (status != file_utils::SUCCESS) {
1112 switch (status) {
1113 case file_utils::SUCCESS:
1114 CHECK(0);
1115 break;
1116 case file_utils::ERROR_MEM_ALLOC:
1117 error_info.SetReport(ERROR_MANIFEST_MEMORY_ALLOC,
1118 "could not allocate manifest memory.");
1119 break;
1120 case file_utils::ERROR_OPEN:
1121 error_info.SetReport(ERROR_MANIFEST_OPEN,
1122 "could not open manifest file.");
1123 break;
1124 case file_utils::ERROR_FILE_TOO_LARGE:
1125 error_info.SetReport(ERROR_MANIFEST_TOO_LARGE,
1126 "manifest file too large.");
1127 break;
1128 case file_utils::ERROR_STAT:
1129 error_info.SetReport(ERROR_MANIFEST_STAT,
1130 "could not stat manifest file.");
1131 break;
1132 case file_utils::ERROR_READ:
1133 error_info.SetReport(ERROR_MANIFEST_READ,
1134 "could not read manifest file.");
1135 break;
1136 }
1116 ReportLoadError(error_info); 1137 ReportLoadError(error_info);
1117 return; 1138 return;
1118 } 1139 }
1119 size_t bytes_to_read = static_cast<size_t>(stat_buf.st_size);
1120 if (bytes_to_read > kNaClManifestMaxFileBytes) {
1121 CLOSE(dup_file_desc);
1122 error_info.SetReport(ERROR_MANIFEST_TOO_LARGE,
1123 "manifest file too large.");
1124 ReportLoadError(error_info);
1125 return;
1126 }
1127 FILE* json_file = fdopen(dup_file_desc, "rb");
1128 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen "
1129 "(dup_file_desc=%"NACL_PRId32", json_file=%p)\n",
1130 dup_file_desc, static_cast<void*>(json_file)));
1131 if (json_file == NULL) {
1132 CLOSE(dup_file_desc);
1133 error_info.SetReport(ERROR_MANIFEST_OPEN,
1134 "could not open manifest file.");
1135 ReportLoadError(error_info);
1136 return;
1137 }
1138 nacl::scoped_array<char> json_buffer(new char[bytes_to_read + 1]);
1139 if (json_buffer == NULL) {
1140 fclose(json_file);
1141 error_info.SetReport(ERROR_MANIFEST_MEMORY_ALLOC,
1142 "could not allocate manifest memory.");
1143 ReportLoadError(error_info);
1144 return;
1145 }
1146 // json_buffer could hold a large enough buffer that the system might need
1147 // multiple reads to fill it, so iterate through reads.
1148 size_t total_bytes_read = 0;
1149 while (0 < bytes_to_read) {
1150 size_t bytes_this_read = fread(&json_buffer[total_bytes_read],
1151 sizeof(char),
1152 bytes_to_read,
1153 json_file);
1154 if (bytes_this_read < bytes_to_read &&
1155 (feof(json_file) || ferror(json_file))) {
1156 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen failed: "
1157 "total_bytes_read=%"NACL_PRIuS" "
1158 "bytes_to_read=%"NACL_PRIuS"\n",
1159 total_bytes_read, bytes_to_read));
1160 fclose(json_file);
1161 error_info.SetReport(ERROR_MANIFEST_READ,
1162 "could not read manifest file.");
1163 ReportLoadError(error_info);
1164 return;
1165 }
1166 total_bytes_read += bytes_this_read;
1167 bytes_to_read -= bytes_this_read;
1168 }
1169 // Once the bytes are read, the FILE is no longer needed, so close it. This
1170 // allows for early returns without leaking the |json_file| FILE object.
1171 fclose(json_file);
1172 // No need to close |file_desc|, that is handled by |nexe_downloader_|.
1173 json_buffer[total_bytes_read] = '\0'; // Force null termination.
1174 1140
1175 ProcessNaClManifest(json_buffer.get()); 1141 ProcessNaClManifest(json_buffer);
1176 } 1142 }
1177 1143
1178 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { 1144 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
1179 HistogramSizeKB("NaCl.Perf.Size.Manifest", 1145 HistogramSizeKB("NaCl.Perf.Size.Manifest",
1180 static_cast<int32_t>(manifest_json.length() / 1024)); 1146 static_cast<int32_t>(manifest_json.length() / 1024));
1181 nacl::string program_url; 1147 nacl::string program_url;
1182 PnaclOptions pnacl_options; 1148 PnaclOptions pnacl_options;
1183 ErrorInfo error_info; 1149 ErrorInfo error_info;
1184 if (!SetManifestObject(manifest_json, &error_info)) { 1150 if (!SetManifestObject(manifest_json, &error_info)) {
1185 ReportLoadError(error_info); 1151 ReportLoadError(error_info);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 static_cast<uint32_t>(text.size())); 1641 static_cast<uint32_t>(text.size()));
1676 const PPB_Console* console_interface = 1642 const PPB_Console* console_interface =
1677 static_cast<const PPB_Console*>( 1643 static_cast<const PPB_Console*>(
1678 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); 1644 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE));
1679 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); 1645 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str);
1680 var_interface->Release(prefix); 1646 var_interface->Release(prefix);
1681 var_interface->Release(str); 1647 var_interface->Release(str);
1682 } 1648 }
1683 1649
1684 } // namespace plugin 1650 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698