diff options
Diffstat (limited to 'dex2oat/sdk_checker.h')
-rw-r--r-- | dex2oat/sdk_checker.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/dex2oat/sdk_checker.h b/dex2oat/sdk_checker.h new file mode 100644 index 0000000000..a409d59981 --- /dev/null +++ b/dex2oat/sdk_checker.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_DEX2OAT_SDK_CHECKER_H_ +#define ART_DEX2OAT_SDK_CHECKER_H_ + +#include "art_field.h" +#include "art_method.h" +#include "base/locks.h" +#include "base/macros.h" +#include "dex/dex_file.h" + +namespace art HIDDEN { + +/** + * The SdkChecker verifies if a given symbol is present in a given classpath. + * + * For convenience and future extensibility the classpath is given as set of + * dex files, simillar to a regular classpath the APKs use. + * + * The symbol (method, field, class) is checked based on its descriptor and not + * according the any access check semantic. + * + * This class is intended to be used during off-device AOT verification when + * only some predefined symbols should be resolved (e.g. belonging to some public + * API classpath). + */ +class SdkChecker { + public: + // Constructs and SDK Checker from the given public sdk paths. The public_sdk + // format is the same as the classpath format (e.g. `dex1:dex2:dex3`). The + // method will attempt to open the dex files and if there are errors it will + // return a nullptr and set the error_msg appropriately. + EXPORT static SdkChecker* Create(const std::string& public_sdk, std::string* error_msg); + + // Verify if it should deny access to the given methods. + // The decision is based on whether or not any of the API dex files declares a method + // with the same signature. + // + // NOTE: This is an expensive check as it searches the dex files for the necessary type + // and string ids. This is OK because the functionality here is indended to be used + // only in AOT verification. + bool ShouldDenyAccess(ArtMethod* art_method) const REQUIRES_SHARED(Locks::mutator_lock_); + + // Similar to ShouldDenyAccess(ArtMethod* art_method). + bool ShouldDenyAccess(ArtField* art_field) const REQUIRES_SHARED(Locks::mutator_lock_); + + // Similar to ShouldDenyAccess(ArtMethod* art_method). + bool ShouldDenyAccess(std::string_view type_descriptor) const; + + // Enabled/Disable the checks. + void SetEnabled(bool enabled) { enabled_ = enabled; } + + private: + SdkChecker(); + + std::vector<std::unique_ptr<const DexFile>> sdk_dex_files_; + + bool enabled_; +}; + +} // namespace art + +#endif // ART_DEX2OAT_SDK_CHECKER_H_ |