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

Side by Side Diff: runtime/vm/isolate.cc

Issue 3003583002: [VM, Precompiler] PoC Obfuscator (Closed)
Patch Set: address comments and fix stuff 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/isolate.h" 5 #include "vm/isolate.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/text_buffer.h" 10 #include "platform/text_buffer.h"
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 684 }
685 } 685 }
686 #endif // !defined(PRODUCT) 686 #endif // !defined(PRODUCT)
687 return kError; 687 return kError;
688 } 688 }
689 } 689 }
690 return kOK; 690 return kOK;
691 } 691 }
692 692
693 void Isolate::FlagsInitialize(Dart_IsolateFlags* api_flags) { 693 void Isolate::FlagsInitialize(Dart_IsolateFlags* api_flags) {
694 const bool false_by_default = false;
695 const bool true_by_default = true;
696 USE(true_by_default);
697 USE(false_by_default);
698
694 api_flags->version = DART_FLAGS_CURRENT_VERSION; 699 api_flags->version = DART_FLAGS_CURRENT_VERSION;
695 #define INIT_FROM_FLAG(name, bitname, isolate_flag, flag) \ 700 #define INIT_FROM_FLAG(name, bitname, isolate_flag, flag) \
696 api_flags->isolate_flag = flag; 701 api_flags->isolate_flag = flag;
697 ISOLATE_FLAG_LIST(INIT_FROM_FLAG) 702 ISOLATE_FLAG_LIST(INIT_FROM_FLAG)
698 #undef INIT_FROM_FLAG 703 #undef INIT_FROM_FLAG
699 api_flags->use_dart_frontend = false; 704 api_flags->use_dart_frontend = false;
705 api_flags->entry_points = NULL;
700 } 706 }
701 707
702 void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { 708 void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const {
703 api_flags->version = DART_FLAGS_CURRENT_VERSION; 709 api_flags->version = DART_FLAGS_CURRENT_VERSION;
704 #define INIT_FROM_FIELD(name, bitname, isolate_flag, flag) \ 710 #define INIT_FROM_FIELD(name, bitname, isolate_flag, flag) \
705 api_flags->isolate_flag = name(); 711 api_flags->isolate_flag = name();
706 ISOLATE_FLAG_LIST(INIT_FROM_FIELD) 712 ISOLATE_FLAG_LIST(INIT_FROM_FIELD)
707 #undef INIT_FROM_FIELD 713 #undef INIT_FROM_FIELD
708 api_flags->use_dart_frontend = use_dart_frontend(); 714 api_flags->use_dart_frontend = use_dart_frontend();
715 api_flags->entry_points = NULL;
709 } 716 }
710 717
711 void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { 718 void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) {
712 #if !defined(PRODUCT) 719 #if !defined(PRODUCT)
713 #define SET_FROM_FLAG(name, bitname, isolate_flag, flag) \ 720 #define SET_FROM_FLAG(name, bitname, isolate_flag, flag) \
714 isolate_flags_ = bitname##Bit::update(api_flags.isolate_flag, isolate_flags_); 721 isolate_flags_ = bitname##Bit::update(api_flags.isolate_flag, isolate_flags_);
715 ISOLATE_FLAG_LIST(SET_FROM_FLAG) 722 ISOLATE_FLAG_LIST(SET_FROM_FLAG)
716 #undef SET_FROM_FLAG 723 #undef SET_FROM_FLAG
717 #endif // !defined(PRODUCT) 724 #endif // !defined(PRODUCT)
718 set_use_dart_frontend(api_flags.use_dart_frontend); 725 set_use_dart_frontend(api_flags.use_dart_frontend);
726
727 // Copy entry points list.
728 ASSERT(embedder_entry_points_ == NULL);
729 if (api_flags.entry_points != NULL) {
730 intptr_t count = 0;
731 while (api_flags.entry_points[count].function_name != NULL)
732 count++;
733 embedder_entry_points_ = new Dart_QualifiedFunctionName[count + 1];
734 for (intptr_t i = 0; i < count; i++) {
735 embedder_entry_points_[i].library_uri =
736 strdup(api_flags.entry_points[i].library_uri);
737 embedder_entry_points_[i].class_name =
738 strdup(api_flags.entry_points[i].class_name);
739 embedder_entry_points_[i].function_name =
740 strdup(api_flags.entry_points[i].function_name);
741 }
742 memset(&embedder_entry_points_[count], 0,
743 sizeof(Dart_QualifiedFunctionName));
744 }
745
719 // Leave others at defaults. 746 // Leave others at defaults.
720 } 747 }
721 748
722 #if defined(DEBUG) 749 #if defined(DEBUG)
723 // static 750 // static
724 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { 751 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) {
725 ASSERT(isolate == Isolate::Current()); 752 ASSERT(isolate == Isolate::Current());
726 } 753 }
727 754
728 void BaseIsolate::AssertCurrentThreadIsMutator() const { 755 void BaseIsolate::AssertCurrentThreadIsMutator() const {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 deoptimized_code_array_(GrowableObjectArray::null()), 835 deoptimized_code_array_(GrowableObjectArray::null()),
809 sticky_error_(Error::null()), 836 sticky_error_(Error::null()),
810 next_(NULL), 837 next_(NULL),
811 loading_invalidation_gen_(kInvalidGen), 838 loading_invalidation_gen_(kInvalidGen),
812 top_level_parsing_count_(0), 839 top_level_parsing_count_(0),
813 field_list_mutex_(new Mutex()), 840 field_list_mutex_(new Mutex()),
814 boxed_field_list_(GrowableObjectArray::null()), 841 boxed_field_list_(GrowableObjectArray::null()),
815 spawn_count_monitor_(new Monitor()), 842 spawn_count_monitor_(new Monitor()),
816 spawn_count_(0), 843 spawn_count_(0),
817 handler_info_cache_(), 844 handler_info_cache_(),
818 catch_entry_state_cache_() { 845 catch_entry_state_cache_(),
846 embedder_entry_points_(NULL),
847 obfuscation_map_(NULL) {
819 FlagsCopyFrom(api_flags); 848 FlagsCopyFrom(api_flags);
820 SetErrorsFatal(true); 849 SetErrorsFatal(true);
821 set_compilation_allowed(true); 850 set_compilation_allowed(true);
822 // TODO(asiva): A Thread is not available here, need to figure out 851 // TODO(asiva): A Thread is not available here, need to figure out
823 // how the vm_tag (kEmbedderTagId) can be set, these tags need to 852 // how the vm_tag (kEmbedderTagId) can be set, these tags need to
824 // move to the OSThread structure. 853 // move to the OSThread structure.
825 set_user_tag(UserTags::kDefaultUserTag); 854 set_user_tag(UserTags::kDefaultUserTag);
855
856 if (obfuscate()) {
857 OS::PrintErr(
858 "Warning: This VM has been configured to obfuscate symbol information "
859 "which violates the Dart standard.\n"
860 " See dartbug.com/30524 for more information.\n");
861 }
826 } 862 }
827 863
828 #undef REUSABLE_HANDLE_SCOPE_INIT 864 #undef REUSABLE_HANDLE_SCOPE_INIT
829 #undef REUSABLE_HANDLE_INITIALIZERS 865 #undef REUSABLE_HANDLE_INITIALIZERS
830 866
831 Isolate::~Isolate() { 867 Isolate::~Isolate() {
832 #if !defined(PRODUCT) 868 #if !defined(PRODUCT)
833 free(debugger_name_); 869 free(debugger_name_);
834 delete debugger_; 870 delete debugger_;
835 if (FLAG_support_service) { 871 if (FLAG_support_service) {
(...skipping 27 matching lines...) Expand all
863 delete message_handler_; 899 delete message_handler_;
864 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 900 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
865 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. 901 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted.
866 delete spawn_state_; 902 delete spawn_state_;
867 delete field_list_mutex_; 903 delete field_list_mutex_;
868 field_list_mutex_ = NULL; 904 field_list_mutex_ = NULL;
869 ASSERT(spawn_count_ == 0); 905 ASSERT(spawn_count_ == 0);
870 delete spawn_count_monitor_; 906 delete spawn_count_monitor_;
871 delete safepoint_handler_; 907 delete safepoint_handler_;
872 delete thread_registry_; 908 delete thread_registry_;
909
910 if (obfuscation_map_ != NULL) {
911 for (intptr_t i = 0; obfuscation_map_[i] != NULL; i++) {
912 delete[] obfuscation_map_[i];
913 }
914 delete[] obfuscation_map_;
915 }
916
917 if (embedder_entry_points_ != NULL) {
918 for (intptr_t i = 0; embedder_entry_points_[i].function_name != NULL; i++) {
919 free(const_cast<char*>(embedder_entry_points_[i].library_uri));
920 free(const_cast<char*>(embedder_entry_points_[i].class_name));
921 free(const_cast<char*>(embedder_entry_points_[i].function_name));
922 }
923 delete[] embedder_entry_points_;
924 }
873 } 925 }
874 926
875 void Isolate::InitOnce() { 927 void Isolate::InitOnce() {
876 create_callback_ = NULL; 928 create_callback_ = NULL;
877 isolates_list_monitor_ = new Monitor(); 929 isolates_list_monitor_ = new Monitor();
878 ASSERT(isolates_list_monitor_ != NULL); 930 ASSERT(isolates_list_monitor_ != NULL);
879 EnableIsolateCreation(); 931 EnableIsolateCreation();
880 } 932 }
881 933
882 Isolate* Isolate::Init(const char* name_prefix, 934 Isolate* Isolate::Init(const char* name_prefix,
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 void IsolateSpawnState::DecrementSpawnCount() { 2884 void IsolateSpawnState::DecrementSpawnCount() {
2833 ASSERT(spawn_count_monitor_ != NULL); 2885 ASSERT(spawn_count_monitor_ != NULL);
2834 ASSERT(spawn_count_ != NULL); 2886 ASSERT(spawn_count_ != NULL);
2835 MonitorLocker ml(spawn_count_monitor_); 2887 MonitorLocker ml(spawn_count_monitor_);
2836 ASSERT(*spawn_count_ > 0); 2888 ASSERT(*spawn_count_ > 0);
2837 *spawn_count_ = *spawn_count_ - 1; 2889 *spawn_count_ = *spawn_count_ - 1;
2838 ml.Notify(); 2890 ml.Notify();
2839 } 2891 }
2840 2892
2841 } // namespace dart 2893 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698