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

Side by Side Diff: src/wasm/encoder.h

Issue 2355803002: [wasm] Fix EnsureSpace in the ZoneBuffer of the wasm encoder. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | test/unittests/wasm/encoder-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project 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 #ifndef V8_WASM_ENCODER_H_ 5 #ifndef V8_WASM_ENCODER_H_
6 #define V8_WASM_ENCODER_H_ 6 #define V8_WASM_ENCODER_H_
7 7
8 #include "src/signature.h" 8 #include "src/signature.h"
9 #include "src/zone-containers.h" 9 #include "src/zone-containers.h"
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 } 84 }
85 85
86 size_t offset() { return static_cast<size_t>(pos_ - buffer_); } 86 size_t offset() { return static_cast<size_t>(pos_ - buffer_); }
87 size_t size() { return static_cast<size_t>(pos_ - buffer_); } 87 size_t size() { return static_cast<size_t>(pos_ - buffer_); }
88 const byte* begin() { return buffer_; } 88 const byte* begin() { return buffer_; }
89 const byte* end() { return pos_; } 89 const byte* end() { return pos_; }
90 90
91 void EnsureSpace(size_t size) { 91 void EnsureSpace(size_t size) {
92 if ((pos_ + size) > end_) { 92 if ((pos_ + size) > end_) {
93 size_t new_size = 4096 + (end_ - buffer_) * 3; 93 size_t new_size = 4096 + size + (end_ - buffer_) * 3;
94 byte* new_buffer = reinterpret_cast<byte*>(zone_->New(new_size)); 94 byte* new_buffer = reinterpret_cast<byte*>(zone_->New(new_size));
95 memcpy(new_buffer, buffer_, (pos_ - buffer_)); 95 memcpy(new_buffer, buffer_, (pos_ - buffer_));
96 pos_ = new_buffer + (pos_ - buffer_); 96 pos_ = new_buffer + (pos_ - buffer_);
97 buffer_ = new_buffer; 97 buffer_ = new_buffer;
98 end_ = new_buffer + new_size; 98 end_ = new_buffer + new_size;
99 } 99 }
100 DCHECK(pos_ + size <= end_);
100 } 101 }
101 102
102 byte** pos_ptr() { return &pos_; } 103 byte** pos_ptr() { return &pos_; }
103 104
104 private: 105 private:
105 Zone* zone_; 106 Zone* zone_;
106 byte* buffer_; 107 byte* buffer_;
107 byte* pos_; 108 byte* pos_;
108 byte* end_; 109 byte* end_;
109 }; 110 };
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ZoneVector<std::pair<LocalType, bool>> globals_; 241 ZoneVector<std::pair<LocalType, bool>> globals_;
241 SignatureMap signature_map_; 242 SignatureMap signature_map_;
242 int start_function_index_; 243 int start_function_index_;
243 }; 244 };
244 245
245 } // namespace wasm 246 } // namespace wasm
246 } // namespace internal 247 } // namespace internal
247 } // namespace v8 248 } // namespace v8
248 249
249 #endif // V8_WASM_ENCODER_H_ 250 #endif // V8_WASM_ENCODER_H_
OLDNEW
« no previous file with comments | « no previous file | test/unittests/wasm/encoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698