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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 2991393002: [standalone] Automatically decompress gzip'd resources, including sources and script snapshots. (Closed)
Patch Set: Fix case in decompression where the snapshot it smaller than the chunk size. Created 3 years, 4 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 | « runtime/bin/dartutils.h ('k') | runtime/bin/dfe.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 (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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "bin/crypto.h" 7 #include "bin/crypto.h"
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 #include "bin/extensions.h" 9 #include "bin/extensions.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
(...skipping 30 matching lines...) Expand all
41 const char* const DartUtils::kCoreLibURL = "dart:core"; 41 const char* const DartUtils::kCoreLibURL = "dart:core";
42 const char* const DartUtils::kInternalLibURL = "dart:_internal"; 42 const char* const DartUtils::kInternalLibURL = "dart:_internal";
43 const char* const DartUtils::kIsolateLibURL = "dart:isolate"; 43 const char* const DartUtils::kIsolateLibURL = "dart:isolate";
44 const char* const DartUtils::kIOLibURL = "dart:io"; 44 const char* const DartUtils::kIOLibURL = "dart:io";
45 const char* const DartUtils::kIOLibPatchURL = "dart:io-patch"; 45 const char* const DartUtils::kIOLibPatchURL = "dart:io-patch";
46 const char* const DartUtils::kUriLibURL = "dart:uri"; 46 const char* const DartUtils::kUriLibURL = "dart:uri";
47 const char* const DartUtils::kHttpScheme = "http:"; 47 const char* const DartUtils::kHttpScheme = "http:";
48 const char* const DartUtils::kVMServiceLibURL = "dart:vmservice"; 48 const char* const DartUtils::kVMServiceLibURL = "dart:vmservice";
49 49
50 struct MagicNumberData { 50 struct MagicNumberData {
51 static const intptr_t kLength = 4; 51 static const intptr_t kMaxLength = 4;
52 52
53 const uint8_t bytes[kLength]; 53 intptr_t length;
54 bool should_skip; 54 const uint8_t bytes[kMaxLength];
55 }; 55 };
56 56
57 MagicNumberData snapshot_magic_number = {{0xf5, 0xf5, 0xdc, 0xdc}, true}; 57 MagicNumberData snapshot_magic_number = {4, {0xf5, 0xf5, 0xdc, 0xdc}};
58 MagicNumberData kernel_magic_number = {{0x90, 0xab, 0xcd, 0xef}, false}; 58 MagicNumberData kernel_magic_number = {4, {0x90, 0xab, 0xcd, 0xef}};
59 MagicNumberData gzip_magic_number = {2, {0x1f, 0x8b, 0, 0}};
59 60
60 static bool IsWindowsHost() { 61 static bool IsWindowsHost() {
61 #if defined(HOST_OS_WINDOWS) 62 #if defined(HOST_OS_WINDOWS)
62 return true; 63 return true;
63 #else // defined(HOST_OS_WINDOWS) 64 #else // defined(HOST_OS_WINDOWS)
64 return false; 65 return false;
65 #endif // defined(HOST_OS_WINDOWS) 66 #endif // defined(HOST_OS_WINDOWS)
66 } 67 }
67 68
68 const char* DartUtils::MapLibraryUrl(const char* url_string) { 69 const char* DartUtils::MapLibraryUrl(const char* url_string) {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 333 }
333 334
334 Dart_Handle DartUtils::ResolveScript(Dart_Handle url) { 335 Dart_Handle DartUtils::ResolveScript(Dart_Handle url) {
335 const int kNumArgs = 1; 336 const int kNumArgs = 1;
336 Dart_Handle dart_args[kNumArgs]; 337 Dart_Handle dart_args[kNumArgs];
337 dart_args[0] = url; 338 dart_args[0] = url;
338 return Dart_Invoke(DartUtils::BuiltinLib(), NewString("_resolveScriptUri"), 339 return Dart_Invoke(DartUtils::BuiltinLib(), NewString("_resolveScriptUri"),
339 kNumArgs, dart_args); 340 kNumArgs, dart_args);
340 } 341 }
341 342
342 static bool CheckMagicNumber(const uint8_t** buf, 343 static bool CheckMagicNumber(const uint8_t* buffer,
343 intptr_t* len, 344 intptr_t buffer_length,
344 const MagicNumberData& magic_number) { 345 const MagicNumberData& magic_number) {
345 if ((*len >= MagicNumberData::kLength) && 346 if ((buffer_length >= magic_number.length)) {
346 (memcmp(*buf, magic_number.bytes, MagicNumberData::kLength) == 0)) { 347 return memcmp(buffer, magic_number.bytes, magic_number.length) == 0;
347 if (magic_number.should_skip) {
348 *buf += MagicNumberData::kLength;
349 *len -= MagicNumberData::kLength;
350 }
351 return true;
352 } 348 }
353 return false; 349 return false;
354 } 350 }
355 351
356 DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t** buf, 352 DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t* buffer,
357 intptr_t* len) { 353 intptr_t buffer_length) {
358 if (CheckMagicNumber(buf, len, snapshot_magic_number)) { 354 if (CheckMagicNumber(buffer, buffer_length, snapshot_magic_number)) {
359 return kSnapshotMagicNumber; 355 return kSnapshotMagicNumber;
360 } 356 }
361 357
362 if (CheckMagicNumber(buf, len, kernel_magic_number)) { 358 if (CheckMagicNumber(buffer, buffer_length, kernel_magic_number)) {
363 return kKernelMagicNumber; 359 return kKernelMagicNumber;
364 } 360 }
365 361
362 if (CheckMagicNumber(buffer, buffer_length, gzip_magic_number)) {
363 return kGzipMagicNumber;
364 }
365
366 return kUnknownMagicNumber; 366 return kUnknownMagicNumber;
367 } 367 }
368 368
369 void DartUtils::WriteMagicNumber(File* file) { 369 void DartUtils::WriteSnapshotMagicNumber(File* file) {
370 // Write a magic number and version information into the snapshot file. 370 // Write a magic number and version information into the snapshot file.
371 bool bytes_written = 371 bool bytes_written = file->WriteFully(snapshot_magic_number.bytes,
372 file->WriteFully(snapshot_magic_number.bytes, MagicNumberData::kLength); 372 snapshot_magic_number.length);
373 ASSERT(bytes_written); 373 ASSERT(bytes_written);
374 } 374 }
375 375
376 void DartUtils::SkipSnapshotMagicNumber(const uint8_t** buffer,
377 intptr_t* buffer_length) {
378 *buffer += snapshot_magic_number.length;
379 *buffer_length -= snapshot_magic_number.length;
380 }
381
376 void FUNCTION_NAME(Builtin_GetCurrentDirectory)(Dart_NativeArguments args) { 382 void FUNCTION_NAME(Builtin_GetCurrentDirectory)(Dart_NativeArguments args) {
377 const char* current = Directory::Current(); 383 const char* current = Directory::Current();
378 if (current != NULL) { 384 if (current != NULL) {
379 Dart_SetReturnValue(args, DartUtils::NewString(current)); 385 Dart_SetReturnValue(args, DartUtils::NewString(current));
380 } else { 386 } else {
381 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); 387 Dart_Handle err = DartUtils::NewError("Failed to get current directory.");
382 Dart_PropagateError(err); 388 Dart_PropagateError(err);
383 } 389 }
384 } 390 }
385 391
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 new CObjectString(CObject::NewString(os_error->message())); 960 new CObjectString(CObject::NewString(os_error->message()));
955 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 961 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
956 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 962 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
957 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 963 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
958 result->SetAt(2, error_message); 964 result->SetAt(2, error_message);
959 return result; 965 return result;
960 } 966 }
961 967
962 } // namespace bin 968 } // namespace bin
963 } // namespace dart 969 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/dfe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698