OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/dfe.h" | 5 #include "bin/dfe.h" |
6 #include "bin/dartutils.h" | 6 #include "bin/dartutils.h" |
7 #include "bin/error_exit.h" | 7 #include "bin/error_exit.h" |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include "vm/kernel.h" | 10 #include "vm/kernel.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const uint8_t** kernel_ir, | 136 const uint8_t** kernel_ir, |
137 intptr_t* kernel_ir_size) { | 137 intptr_t* kernel_ir_size) { |
138 *kernel_ir = NULL; | 138 *kernel_ir = NULL; |
139 *kernel_ir_size = -1; | 139 *kernel_ir_size = -1; |
140 void* script_file = DartUtils::OpenFile(script_uri, false); | 140 void* script_file = DartUtils::OpenFile(script_uri, false); |
141 if (script_file != NULL) { | 141 if (script_file != NULL) { |
142 const uint8_t* buffer = NULL; | 142 const uint8_t* buffer = NULL; |
143 DartUtils::ReadFile(&buffer, kernel_ir_size, script_file); | 143 DartUtils::ReadFile(&buffer, kernel_ir_size, script_file); |
144 DartUtils::CloseFile(script_file); | 144 DartUtils::CloseFile(script_file); |
145 if (*kernel_ir_size > 0 && buffer != NULL) { | 145 if (*kernel_ir_size > 0 && buffer != NULL) { |
146 // We need a temporary variable because SniffForMagicNumber modifies the | 146 if (DartUtils::SniffForMagicNumber(buffer, *kernel_ir_size) != |
147 // buffer pointer to skip snapshot magic number. | |
148 const uint8_t* temp = buffer; | |
149 if (DartUtils::SniffForMagicNumber(&temp, kernel_ir_size) != | |
150 DartUtils::kKernelMagicNumber) { | 147 DartUtils::kKernelMagicNumber) { |
151 free(const_cast<uint8_t*>(buffer)); | 148 free(const_cast<uint8_t*>(buffer)); |
152 *kernel_ir = NULL; | 149 *kernel_ir = NULL; |
153 *kernel_ir_size = -1; | 150 *kernel_ir_size = -1; |
154 return false; | 151 return false; |
155 } else { | 152 } else { |
156 // Do not free buffer if this is a kernel file - kernel_file will be | 153 // Do not free buffer if this is a kernel file - kernel_file will be |
157 // backed by the same memory as the buffer and caller will own it. | 154 // backed by the same memory as the buffer and caller will own it. |
158 // Caller is responsible for freeing the buffer when this function | 155 // Caller is responsible for freeing the buffer when this function |
159 // returns true. | 156 // returns true. |
160 *kernel_ir = buffer; | 157 *kernel_ir = buffer; |
161 return true; | 158 return true; |
162 } | 159 } |
163 } | 160 } |
164 } | 161 } |
165 return false; | 162 return false; |
166 } | 163 } |
167 | 164 |
168 } // namespace bin | 165 } // namespace bin |
169 } // namespace dart | 166 } // namespace dart |
OLD | NEW |