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