Keep pointer to original DexFile during JVMTI redefine for hiddenapi
JVMTI redefine overwrites the pointer to the class' DexFile which
prevents access checks from reading the hiddenapi flags store. Store
the pointer in ClassExt together with the original ClassDef index
to preserve the access to flags store. Because method/field indices
are still lost, the corresponding dex member is found using string
comparison of member's name and type.
Bug: 119688837
Test: 999-redefine-hiddenapi
Change-Id: Ifdf35668e838869a971233bbaae61851014658b1
diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h
index eea58e9..614154c 100644
--- a/runtime/hidden_api.h
+++ b/runtime/hidden_api.h
@@ -137,9 +137,14 @@
public:
explicit MemberSignature(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_);
explicit MemberSignature(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
+ explicit MemberSignature(const ClassAccessor::Field& field);
+ explicit MemberSignature(const ClassAccessor::Method& method);
void Dump(std::ostream& os) const;
+ bool Equals(const MemberSignature& other);
+ bool MemberNameAndTypeMatch(const MemberSignature& other);
+
// Performs prefix match on this member. Since the full member signature is
// composed of several parts, we match each part in turn (rather than
// building the entire thing in memory and performing a simple prefix match)
@@ -160,11 +165,8 @@
// Locates hiddenapi flags for `field` in the corresponding dex file.
// NB: This is an O(N) operation, linear with the number of members in the class def.
-uint32_t GetDexFlags(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_);
-
-// Locates hiddenapi flags for `method` in the corresponding dex file.
-// NB: This is an O(N) operation, linear with the number of members in the class def.
-uint32_t GetDexFlags(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
+template<typename T>
+uint32_t GetDexFlags(T* member) REQUIRES_SHARED(Locks::mutator_lock_);
template<typename T>
bool ShouldDenyAccessToMemberImpl(T* member, ApiList api_list, AccessMethod access_method)