Verify the class loader context when loading oat files
Previously, the oat_file_manager would expect and perform validation on a
simple classpath: a list of dex files separated by ':'.
This is no longer enough since the oat file may encode a chain of class
loaders now. The CL moves the validation logic in ClassLoaderContext and
extends it to verify the complete chain of class loaders.
Test: m test-art-host
Bug: 38138251
Change-Id: I8ac9c65db1a14909aaecb04fa7a7115ddedc673f
diff --git a/runtime/class_loader_context.h b/runtime/class_loader_context.h
index 81c8903..8c65e2e 100644
--- a/runtime/class_loader_context.h
+++ b/runtime/class_loader_context.h
@@ -78,6 +78,13 @@
// Should only be called if OpenDexFiles() returned true.
std::vector<const DexFile*> FlattenOpenedDexFiles() const;
+ // Verifies that the current context is identical to the context encoded as `context_spec`.
+ // Identical means:
+ // - the number and type of the class loaders from the chain matches
+ // - the class loader from the same position have the same classpath
+ // (the order and checksum of the dex files matches)
+ bool VerifyClassLoaderContextMatch(const std::string& context_spec);
+
// Creates the class loader context from the given string.
// The format: ClassLoaderType1[ClasspathElem1:ClasspathElem2...];ClassLoaderType2[...]...
// ClassLoaderType is either "PCL" (PathClassLoader) or "DLC" (DelegateLastClassLoader).
@@ -86,17 +93,6 @@
// class loader for the source dex files.
static std::unique_ptr<ClassLoaderContext> Create(const std::string& spec);
- // Decodes the class loader context stored in the oat file with EncodeContextForOatFile.
- // Returns true if the format matches, or false otherwise. If the return is true, the out
- // arguments will contain the classpath dex files, their checksums and whether or not the
- // context is a special shared library.
- // The method asserts that the context is made out of only one PathClassLoader.
- static bool DecodePathClassLoaderContextFromOatFileKey(
- const std::string& context_spec,
- std::vector<std::string>* out_classpath,
- std::vector<uint32_t>* out_checksums,
- bool* out_is_special_shared_library);
-
// Creates a context for the given class_loader and dex_elements.
// The method will walk the parent chain starting from `class_loader` and add their dex files
// to the current class loaders chain. The `dex_elements` will be added at the end of the