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 <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "bin/process.h" | 25 #include "bin/process.h" |
26 #include "bin/snapshot_utils.h" | 26 #include "bin/snapshot_utils.h" |
27 #include "bin/thread.h" | 27 #include "bin/thread.h" |
28 #include "bin/utils.h" | 28 #include "bin/utils.h" |
29 #include "bin/vmservice_impl.h" | 29 #include "bin/vmservice_impl.h" |
30 #include "platform/globals.h" | 30 #include "platform/globals.h" |
31 #include "platform/growable_array.h" | 31 #include "platform/growable_array.h" |
32 #include "platform/hashmap.h" | 32 #include "platform/hashmap.h" |
33 #include "platform/text_buffer.h" | 33 #include "platform/text_buffer.h" |
34 #if !defined(DART_PRECOMPILER) | 34 #if !defined(DART_PRECOMPILER) |
35 #include "zlib/zlib.h" | 35 #include "bin/gzip.h" |
36 #endif | 36 #endif |
37 | 37 |
38 #include "vm/kernel.h" | 38 #include "vm/kernel.h" |
39 | 39 |
40 extern "C" { | 40 extern "C" { |
41 extern const uint8_t kDartVmSnapshotData[]; | 41 extern const uint8_t kDartVmSnapshotData[]; |
42 extern const uint8_t kDartVmSnapshotInstructions[]; | 42 extern const uint8_t kDartVmSnapshotInstructions[]; |
43 extern const uint8_t kDartCoreIsolateSnapshotData[]; | 43 extern const uint8_t kDartCoreIsolateSnapshotData[]; |
44 extern const uint8_t kDartCoreIsolateSnapshotInstructions[]; | 44 extern const uint8_t kDartCoreIsolateSnapshotInstructions[]; |
45 } | 45 } |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 return false; | 1650 return false; |
1651 } | 1651 } |
1652 | 1652 |
1653 #undef CHECK_RESULT | 1653 #undef CHECK_RESULT |
1654 | 1654 |
1655 // Observatory assets are only needed in the regular dart binary. | 1655 // Observatory assets are only needed in the regular dart binary. |
1656 #if !defined(DART_PRECOMPILER) && !defined(NO_OBSERVATORY) | 1656 #if !defined(DART_PRECOMPILER) && !defined(NO_OBSERVATORY) |
1657 extern unsigned int observatory_assets_archive_len; | 1657 extern unsigned int observatory_assets_archive_len; |
1658 extern const uint8_t* observatory_assets_archive; | 1658 extern const uint8_t* observatory_assets_archive; |
1659 | 1659 |
1660 // |input| is assumed to be a gzipped stream. | |
1661 // This function allocates the output buffer in the C heap and the caller | |
1662 // is responsible for freeing it. | |
1663 void Decompress(const uint8_t* input, | |
1664 unsigned int input_len, | |
1665 uint8_t** output, | |
1666 unsigned int* output_length) { | |
1667 ASSERT(input != NULL); | |
1668 ASSERT(input_len > 0); | |
1669 ASSERT(output != NULL); | |
1670 ASSERT(output_length != NULL); | |
1671 | |
1672 // Initialize output. | |
1673 *output = NULL; | |
1674 *output_length = 0; | |
1675 | |
1676 const unsigned int kChunkSize = 256 * 1024; | |
1677 uint8_t chunk_out[kChunkSize]; | |
1678 z_stream strm; | |
1679 strm.zalloc = Z_NULL; | |
1680 strm.zfree = Z_NULL; | |
1681 strm.opaque = Z_NULL; | |
1682 strm.avail_in = 0; | |
1683 strm.next_in = 0; | |
1684 int ret = inflateInit2(&strm, 32 + MAX_WBITS); | |
1685 ASSERT(ret == Z_OK); | |
1686 | |
1687 unsigned int input_cursor = 0; | |
1688 unsigned int output_cursor = 0; | |
1689 do { | |
1690 // Setup input. | |
1691 unsigned int size_in = input_len - input_cursor; | |
1692 if (size_in > kChunkSize) { | |
1693 size_in = kChunkSize; | |
1694 } | |
1695 strm.avail_in = size_in; | |
1696 strm.next_in = const_cast<uint8_t*>(&input[input_cursor]); | |
1697 | |
1698 // Inflate until we've exhausted the current input chunk. | |
1699 do { | |
1700 // Setup output. | |
1701 strm.avail_out = kChunkSize; | |
1702 strm.next_out = &chunk_out[0]; | |
1703 // Inflate. | |
1704 ret = inflate(&strm, Z_SYNC_FLUSH); | |
1705 // We either hit the end of the stream or made forward progress. | |
1706 ASSERT((ret == Z_STREAM_END) || (ret == Z_OK)); | |
1707 // Grow output buffer size. | |
1708 unsigned int size_out = kChunkSize - strm.avail_out; | |
1709 *output_length += size_out; | |
1710 *output = reinterpret_cast<uint8_t*>(realloc(*output, *output_length)); | |
1711 // Copy output. | |
1712 memmove(&((*output)[output_cursor]), &chunk_out[0], size_out); | |
1713 output_cursor += size_out; | |
1714 } while (strm.avail_out == 0); | |
1715 | |
1716 // We've processed size_in bytes. | |
1717 input_cursor += size_in; | |
1718 | |
1719 // We're finished decompressing when zlib tells us. | |
1720 } while (ret != Z_STREAM_END); | |
1721 | |
1722 inflateEnd(&strm); | |
1723 } | |
1724 | 1660 |
1725 Dart_Handle GetVMServiceAssetsArchiveCallback() { | 1661 Dart_Handle GetVMServiceAssetsArchiveCallback() { |
1726 uint8_t* decompressed = NULL; | 1662 uint8_t* decompressed = NULL; |
1727 unsigned int decompressed_len = 0; | 1663 intptr_t decompressed_len = 0; |
1728 Decompress(observatory_assets_archive, observatory_assets_archive_len, | 1664 Decompress(observatory_assets_archive, observatory_assets_archive_len, |
1729 &decompressed, &decompressed_len); | 1665 &decompressed, &decompressed_len); |
1730 Dart_Handle tar_file = | 1666 Dart_Handle tar_file = |
1731 DartUtils::MakeUint8Array(decompressed, decompressed_len); | 1667 DartUtils::MakeUint8Array(decompressed, decompressed_len); |
1732 // Free decompressed memory as it has been copied into a Dart array. | 1668 // Free decompressed memory as it has been copied into a Dart array. |
1733 free(decompressed); | 1669 free(decompressed); |
1734 return tar_file; | 1670 return tar_file; |
1735 } | 1671 } |
1736 #else // !defined(DART_PRECOMPILER) | 1672 #else // !defined(DART_PRECOMPILER) |
1737 static Dart_GetVMServiceAssetsArchive GetVMServiceAssetsArchiveCallback = NULL; | 1673 static Dart_GetVMServiceAssetsArchive GetVMServiceAssetsArchiveCallback = NULL; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 Platform::Exit(Process::GlobalExitCode()); | 1840 Platform::Exit(Process::GlobalExitCode()); |
1905 } | 1841 } |
1906 | 1842 |
1907 } // namespace bin | 1843 } // namespace bin |
1908 } // namespace dart | 1844 } // namespace dart |
1909 | 1845 |
1910 int main(int argc, char** argv) { | 1846 int main(int argc, char** argv) { |
1911 dart::bin::main(argc, argv); | 1847 dart::bin::main(argc, argv); |
1912 UNREACHABLE(); | 1848 UNREACHABLE(); |
1913 } | 1849 } |
OLD | NEW |