| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| 11 | 11 |
| 12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
| 13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
| 14 #include "bin/directory.h" | 14 #include "bin/directory.h" |
| 15 #include "bin/embedded_dart_io.h" | 15 #include "bin/embedded_dart_io.h" |
| 16 #include "bin/eventhandler.h" | 16 #include "bin/eventhandler.h" |
| 17 #include "bin/extensions.h" | 17 #include "bin/extensions.h" |
| 18 #include "bin/file.h" | 18 #include "bin/file.h" |
| 19 #include "bin/isolate_data.h" | 19 #include "bin/isolate_data.h" |
| 20 #include "bin/log.h" | 20 #include "bin/log.h" |
| 21 #include "bin/platform.h" | 21 #include "bin/platform.h" |
| 22 #include "bin/process.h" | 22 #include "bin/process.h" |
| 23 #include "bin/thread.h" | 23 #include "bin/thread.h" |
| 24 #include "bin/utils.h" | 24 #include "bin/utils.h" |
| 25 #include "bin/vmservice_impl.h" | 25 #include "bin/vmservice_impl.h" |
| 26 #include "platform/globals.h" | 26 #include "platform/globals.h" |
| 27 #include "platform/hashmap.h" | 27 #include "platform/hashmap.h" |
| 28 #include "platform/text_buffer.h" | 28 #include "platform/text_buffer.h" |
| 29 #include "zlib/zlib.h" |
| 29 | 30 |
| 30 namespace dart { | 31 namespace dart { |
| 31 namespace bin { | 32 namespace bin { |
| 32 | 33 |
| 33 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we | 34 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we |
| 34 // link in a snapshot otherwise it is initialized to NULL. | 35 // link in a snapshot otherwise it is initialized to NULL. |
| 35 extern const uint8_t* vm_isolate_snapshot_buffer; | 36 extern const uint8_t* vm_isolate_snapshot_buffer; |
| 36 | 37 |
| 37 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a | 38 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a |
| 38 // snapshot otherwise it is initialized to NULL. | 39 // snapshot otherwise it is initialized to NULL. |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 | 1276 |
| 1276 // No restart. | 1277 // No restart. |
| 1277 return false; | 1278 return false; |
| 1278 } | 1279 } |
| 1279 | 1280 |
| 1280 #undef CHECK_RESULT | 1281 #undef CHECK_RESULT |
| 1281 | 1282 |
| 1282 extern unsigned int observatory_assets_archive_len; | 1283 extern unsigned int observatory_assets_archive_len; |
| 1283 extern const uint8_t* observatory_assets_archive; | 1284 extern const uint8_t* observatory_assets_archive; |
| 1284 | 1285 |
| 1285 Dart_Handle GetVMServiceAssetsArchiveCallback() { | 1286 |
| 1286 return DartUtils::MakeUint8Array( | 1287 // |input| is assumed to be a gzipped stream. |
| 1287 observatory_assets_archive, | 1288 // This function allocates the output buffer in the C heap and the caller |
| 1288 observatory_assets_archive_len); | 1289 // is responsible for freeing it. |
| 1290 void Decompress(const uint8_t* input, unsigned int input_len, |
| 1291 uint8_t** output, unsigned int* output_length) { |
| 1292 ASSERT(input != NULL); |
| 1293 ASSERT(input_len > 0); |
| 1294 ASSERT(output != NULL); |
| 1295 ASSERT(output_length != NULL); |
| 1296 |
| 1297 // Initialize output. |
| 1298 *output = NULL; |
| 1299 *output_length = 0; |
| 1300 |
| 1301 const intptr_t kChunkSize = 256 * 1024; |
| 1302 uint8_t chunk_out[kChunkSize]; |
| 1303 z_stream strm; |
| 1304 strm.zalloc = Z_NULL; |
| 1305 strm.zfree = Z_NULL; |
| 1306 strm.opaque = Z_NULL; |
| 1307 strm.avail_in = 0; |
| 1308 strm.next_in = 0; |
| 1309 int ret = inflateInit2(&strm, 32 + MAX_WBITS); |
| 1310 ASSERT(ret == Z_OK); |
| 1311 |
| 1312 unsigned int input_cursor = 0; |
| 1313 unsigned int output_cursor = 0; |
| 1314 do { |
| 1315 // Setup input. |
| 1316 unsigned int size_in = input_len - input_cursor; |
| 1317 if (size_in > kChunkSize) { |
| 1318 size_in = kChunkSize; |
| 1319 } |
| 1320 strm.avail_in = size_in; |
| 1321 strm.next_in = const_cast<uint8_t*>(&input[input_cursor]); |
| 1322 |
| 1323 // Inflate until we've exhausted the current input chunk. |
| 1324 do { |
| 1325 // Setup output. |
| 1326 strm.avail_out = kChunkSize; |
| 1327 strm.next_out = &chunk_out[0]; |
| 1328 // Inflate. |
| 1329 ret = inflate(&strm, Z_SYNC_FLUSH); |
| 1330 // We either hit the end of the stream or made forward progress. |
| 1331 ASSERT((ret == Z_STREAM_END) || (ret == Z_OK)); |
| 1332 // Grow output buffer size. |
| 1333 unsigned int size_out = kChunkSize - strm.avail_out; |
| 1334 *output_length += size_out; |
| 1335 *output = reinterpret_cast<uint8_t*>(realloc(*output, *output_length)); |
| 1336 // Copy output. |
| 1337 memmove(&((*output)[output_cursor]), &chunk_out[0], size_out); |
| 1338 output_cursor += size_out; |
| 1339 } while (strm.avail_out == 0); |
| 1340 |
| 1341 // We've processed size_in bytes. |
| 1342 input_cursor += size_in; |
| 1343 |
| 1344 // We're finished decompressing when zlib tells us. |
| 1345 } while (ret != Z_STREAM_END); |
| 1346 |
| 1347 inflateEnd(&strm); |
| 1289 } | 1348 } |
| 1290 | 1349 |
| 1291 | 1350 |
| 1351 Dart_Handle GetVMServiceAssetsArchiveCallback() { |
| 1352 uint8_t* decompressed = NULL; |
| 1353 unsigned int decompressed_len = 0; |
| 1354 Decompress(observatory_assets_archive, |
| 1355 observatory_assets_archive_len, |
| 1356 &decompressed, |
| 1357 &decompressed_len); |
| 1358 Dart_Handle tar_file = DartUtils::MakeUint8Array(decompressed, |
| 1359 decompressed_len); |
| 1360 // Free decompressed memory as it has been copied into a Dart array. |
| 1361 free(decompressed); |
| 1362 return tar_file; |
| 1363 } |
| 1364 |
| 1365 |
| 1292 void main(int argc, char** argv) { | 1366 void main(int argc, char** argv) { |
| 1293 char* script_name; | 1367 char* script_name; |
| 1294 const int EXTRA_VM_ARGUMENTS = 2; | 1368 const int EXTRA_VM_ARGUMENTS = 2; |
| 1295 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1369 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 1296 CommandLineOptions dart_options(argc); | 1370 CommandLineOptions dart_options(argc); |
| 1297 bool print_flags_seen = false; | 1371 bool print_flags_seen = false; |
| 1298 bool verbose_debug_seen = false; | 1372 bool verbose_debug_seen = false; |
| 1299 | 1373 |
| 1300 vm_options.AddArgument("--no_write_protect_code"); | 1374 vm_options.AddArgument("--no_write_protect_code"); |
| 1301 // Perform platform specific initialization. | 1375 // Perform platform specific initialization. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 Platform::Exit(Process::GlobalExitCode()); | 1493 Platform::Exit(Process::GlobalExitCode()); |
| 1420 } | 1494 } |
| 1421 | 1495 |
| 1422 } // namespace bin | 1496 } // namespace bin |
| 1423 } // namespace dart | 1497 } // namespace dart |
| 1424 | 1498 |
| 1425 int main(int argc, char** argv) { | 1499 int main(int argc, char** argv) { |
| 1426 dart::bin::main(argc, argv); | 1500 dart::bin::main(argc, argv); |
| 1427 UNREACHABLE(); | 1501 UNREACHABLE(); |
| 1428 } | 1502 } |
| OLD | NEW |