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

Side by Side Diff: lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp

Issue 23753003: Report fatal translator errors to the browser (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Created 7 years, 3 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 //===- NaClBitcodeHeader.cpp ----------------------------------------------===// 1 //===- NaClBitcodeHeader.cpp ----------------------------------------------===//
2 // PNaCl bitcode header reader. 2 // PNaCl bitcode header reader.
3 // 3 //
4 // The LLVM Compiler Infrastructure 4 // The LLVM Compiler Infrastructure
5 // 5 //
6 // This file is distributed under the University of Illinois Open Source 6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details. 7 // License. See LICENSE.TXT for details.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 10
11 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" 11 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h"
12 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" 12 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
13 #include "llvm/Bitcode/ReaderWriter.h"
13 #include "llvm/Support/ErrorHandling.h" 14 #include "llvm/Support/ErrorHandling.h"
14 #include "llvm/Support/Format.h" 15 #include "llvm/Support/Format.h"
15 #include "llvm/Support/raw_ostream.h" 16 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Support/StreamableMemoryObject.h" 17 #include "llvm/Support/StreamableMemoryObject.h"
17 18
18 #include <limits> 19 #include <limits>
19 #include <cstring> 20 #include <cstring>
20 #include <iomanip> 21 #include <iomanip>
21 22
22 using namespace llvm; 23 using namespace llvm;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 case kBufferType: 112 case kBufferType:
112 ss << "["; 113 ss << "[";
113 for (size_t i = 0; i < Len; ++i) { 114 for (size_t i = 0; i < Len; ++i) {
114 if (i) 115 if (i)
115 ss << " "; 116 ss << " ";
116 ss << format("%02x", Data[i]); 117 ss << format("%02x", Data[i]);
117 } 118 }
118 ss << "]"; 119 ss << "]";
119 break; 120 break;
120 default: 121 default:
121 report_fatal_error("PNaCL bitcode file contains unknown field type"); 122 report_fatal_error("PNaCl bitcode file contains unknown field type");
122 } 123 }
123 return ss.str(); 124 return ss.str();
124 } 125 }
125 126
126 NaClBitcodeHeader::NaClBitcodeHeader() 127 NaClBitcodeHeader::NaClBitcodeHeader()
127 : HeaderSize(0), UnsupportedMessage(), IsSupportedFlag(false), 128 : HeaderSize(0), UnsupportedMessage(), IsSupportedFlag(false),
128 IsReadableFlag(false), PNaClVersion(0) {} 129 IsReadableFlag(false), PNaClVersion(0) {}
129 130
130 NaClBitcodeHeader::~NaClBitcodeHeader() { 131 NaClBitcodeHeader::~NaClBitcodeHeader() {
131 for (std::vector<NaClBitcodeHeaderField *>::const_iterator 132 for (std::vector<NaClBitcodeHeaderField *>::const_iterator
132 Iter = Fields.begin(), 133 Iter = Fields.begin(),
133 IterEnd = Fields.end(); 134 IterEnd = Fields.end();
134 Iter != IterEnd; ++Iter) { 135 Iter != IterEnd; ++Iter) {
135 delete *Iter; 136 delete *Iter;
136 } 137 }
137 } 138 }
138 139
139 bool NaClBitcodeHeader::ReadPrefix(const unsigned char *BufPtr, 140 bool NaClBitcodeHeader::ReadPrefix(const unsigned char *BufPtr,
140 const unsigned char *BufEnd, 141 const unsigned char *BufEnd,
141 unsigned &NumFields, unsigned &NumBytes) { 142 unsigned &NumFields, unsigned &NumBytes) {
142 // Must contain PEXE. 143 // Must contain PEXE.
143 if (!isNaClBitcode(BufPtr, BufEnd)) 144 if (!isNaClBitcode(BufPtr, BufEnd)) {
145 UnsupportedMessage = "Invalid PNaCl bitcode header";
146 if (isBitcode(BufPtr, BufEnd)) {
147 UnsupportedMessage += " (to run in Chrome, bitcode files must be "
148 "finalized using pnacl-finalize";
jvoung (off chromium) 2013/09/10 20:39:56 add an end parenthesis to match the beginning "(to
Derek Schuff 2013/09/13 19:53:36 Done.
149 }
144 return true; 150 return true;
151 }
145 BufPtr += WordSize; 152 BufPtr += WordSize;
146 153
147 // Read #Fields and number of bytes needed for the header. 154 // Read #Fields and number of bytes needed for the header.
148 if (BufPtr + WordSize > BufEnd) 155 if (BufPtr + WordSize > BufEnd)
149 return true; 156 return true;
150 NumFields = static_cast<unsigned>(BufPtr[0]) | 157 NumFields = static_cast<unsigned>(BufPtr[0]) |
151 (static_cast<unsigned>(BufPtr[1]) << 8); 158 (static_cast<unsigned>(BufPtr[1]) << 8);
152 NumBytes = static_cast<unsigned>(BufPtr[2]) | 159 NumBytes = static_cast<unsigned>(BufPtr[2]) |
153 (static_cast<unsigned>(BufPtr[3]) << 8); 160 (static_cast<unsigned>(BufPtr[3]) << 8);
154 BufPtr += WordSize; 161 BufPtr += WordSize;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 << PNaClVersion << "\n"; 263 << PNaClVersion << "\n";
257 UnsupportedStream.flush(); 264 UnsupportedStream.flush();
258 } 265 }
259 if (Fields.size() != 1) { 266 if (Fields.size() != 1) {
260 IsSupportedFlag = false; 267 IsSupportedFlag = false;
261 IsReadableFlag = false; 268 IsReadableFlag = false;
262 if (!UpdatedUnsupportedMessage) 269 if (!UpdatedUnsupportedMessage)
263 UnsupportedMessage = "Unknown header field(s) found"; 270 UnsupportedMessage = "Unknown header field(s) found";
264 } 271 }
265 } 272 }
OLDNEW
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp » ('j') | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698