From 2061ae2d4558acd8b79256f16f7a8d79a5d396e1 Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Wed, 21 Dec 2022 12:43:56 +0000 Subject: Add a function to list all files managed by ART Service. This is going to be used in the "sweep" phase of the GC. Bug: 254013425 Test: m test-art-host-gtest-art_libarttools_tests Test: m test-art-host-gtest-art_artd_tests Test: atest art_standalone_libarttools_tests Test: atest atest art_standalone_artd_tests Ignore-AOSP-First: ART Services. Change-Id: Ie7a5bd6f805c370aa3c2e3a1ab1d5408e4552f83 --- libartbase/base/file_utils.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libartbase/base/file_utils.cc') diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc index 239628978e..d32a54e76b 100644 --- a/libartbase/base/file_utils.cc +++ b/libartbase/base/file_utils.cc @@ -73,6 +73,8 @@ static constexpr const char* kAndroidSystemExtRootEnvVar = "SYSTEM_EXT_ROOT"; static constexpr const char* kAndroidSystemExtRootDefaultPath = "/system_ext"; static constexpr const char* kAndroidDataEnvVar = "ANDROID_DATA"; static constexpr const char* kAndroidDataDefaultPath = "/data"; +static constexpr const char* kAndroidExpandEnvVar = "ANDROID_EXPAND"; +static constexpr const char* kAndroidExpandDefaultPath = "/mnt/expand"; static constexpr const char* kAndroidArtRootEnvVar = "ANDROID_ART_ROOT"; static constexpr const char* kAndroidConscryptRootEnvVar = "ANDROID_CONSCRYPT_ROOT"; static constexpr const char* kAndroidI18nRootEnvVar = "ANDROID_I18N_ROOT"; @@ -282,6 +284,18 @@ std::string GetAndroidDataSafe(std::string* error_msg) { std::string GetAndroidData() { return GetAndroidDir(kAndroidDataEnvVar, kAndroidDataDefaultPath); } +std::string GetAndroidExpandSafe(std::string* error_msg) { + const char* android_dir = GetAndroidDirSafe(kAndroidExpandEnvVar, + kAndroidExpandDefaultPath, + /*must_exist=*/true, + error_msg); + return (android_dir != nullptr) ? android_dir : ""; +} + +std::string GetAndroidExpand() { + return GetAndroidDir(kAndroidExpandEnvVar, kAndroidExpandDefaultPath); +} + std::string GetArtApexData() { return GetAndroidDir(kArtApexDataEnvVar, kArtApexDataDefaultPath, /*must_exist=*/false); } -- cgit v1.2.3-59-g8ed1b From c8842811a8c77e9f4fa1d7794a8830fc6774b1ec Mon Sep 17 00:00:00 2001 From: Jiakai Zhang Date: Thu, 20 Apr 2023 21:00:17 +0100 Subject: Pick up the boot image mainline extension generated by odrefresh. After this change, the runtime will pick up the boot image mainline extension in apex data dalvik-cache once odrefresh generates it. The odrefresh change will follow. Bug: 269230245 Test: Patch the odrefresh change and run odsign_e2e_tests_full. (cherry picked from https://android-review.googlesource.com/q/commit:ccba1e7e0beeca779b4889ab27c7b21930f85aa1) Merged-In: Ia9d3af1f59128a9e955ffb0fb9300cc96ece3f29 Change-Id: Ia9d3af1f59128a9e955ffb0fb9300cc96ece3f29 --- libartbase/base/file_utils.cc | 73 ++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 18 deletions(-) (limited to 'libartbase/base/file_utils.cc') diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc index bd66940ade..bd79eba723 100644 --- a/libartbase/base/file_utils.cc +++ b/libartbase/base/file_utils.cc @@ -362,6 +362,8 @@ static std::string GetFirstMainlineFrameworkLibraryName(std::string* error_msg) // Returns true when no error occurs, even if the extension doesn't exist. static bool MaybeAppendBootImageMainlineExtension(const std::string& android_root, + bool deny_system_files, + bool deny_art_apex_data_files, /*inout*/ std::string* location, /*out*/ std::string* error_msg) { if (!kIsTargetAndroid) { @@ -374,16 +376,34 @@ static bool MaybeAppendBootImageMainlineExtension(const std::string& android_roo if (library_name.empty()) { return false; } - std::string mainline_extension_location = StringPrintf( - "%s/framework/%s-%s.art", android_root.c_str(), kBootImageStem, library_name.c_str()); - std::string mainline_extension_path = - GetSystemImageFilename(mainline_extension_location.c_str(), kRuntimeISA); - if (!OS::FileExists(mainline_extension_path.c_str(), /*check_file_type=*/true)) { - // This is expected when the ART module is preloaded on an old source tree that doesn't - // dexpreopt mainline BCP jars, so it shouldn't be considered as an error. - return true; + + if (!deny_art_apex_data_files) { + std::string mainline_extension_location = + StringPrintf("%s/%s-%s.art", + GetApexDataDalvikCacheDirectory(InstructionSet::kNone).c_str(), + kBootImageStem, + library_name.c_str()); + std::string mainline_extension_path = + GetSystemImageFilename(mainline_extension_location.c_str(), kRuntimeISA); + if (OS::FileExists(mainline_extension_path.c_str(), /*check_file_type=*/true)) { + *location += ":" + mainline_extension_location; + return true; + } + } + + if (!deny_system_files) { + std::string mainline_extension_location = StringPrintf( + "%s/framework/%s-%s.art", android_root.c_str(), kBootImageStem, library_name.c_str()); + std::string mainline_extension_path = + GetSystemImageFilename(mainline_extension_location.c_str(), kRuntimeISA); + // It is expected that the file doesn't exist when the ART module is preloaded on an old source + // tree that doesn't dexpreopt mainline BCP jars, so it shouldn't be considered as an error. + if (OS::FileExists(mainline_extension_path.c_str(), /*check_file_type=*/true)) { + *location += ":" + mainline_extension_location; + return true; + } } - *location += ":" + mainline_extension_location; + return true; } @@ -400,14 +420,27 @@ std::string GetDefaultBootImageLocationSafe(const std::string& android_root, GetApexDataDalvikCacheDirectory(InstructionSet::kNone) + "/" + kBootImageStem + ".art"; const std::string boot_image_filename = GetSystemImageFilename(boot_image.c_str(), kRuntimeISA); if (OS::FileExists(boot_image_filename.c_str(), /*check_file_type=*/true)) { - // Typically "/data/misc/apexdata/com.android.art/dalvik-cache/boot.art!/apex/com.android.art - // /etc/boot-image.prof!/system/etc/boot-image.prof". - return StringPrintf("%s!%s/%s!%s/%s", - boot_image.c_str(), - kAndroidArtApexDefaultPath, - kEtcBootImageProf, - android_root.c_str(), - kEtcBootImageProf); + // Boot image consists of two parts: + // - the primary boot image (contains the Core Libraries and framework libraries) + // - the boot image mainline extension (contains mainline framework libraries) + // Typically + // "/data/misc/apexdata/com.android.art/dalvik-cache/boot.art!/apex/com.android.art + // /etc/boot-image.prof!/system/etc/boot-image.prof: + // /data/misc/apexdata/com.android.art/dalvik-cache/boot-framework-adservices.art". + std::string location = StringPrintf("%s!%s/%s!%s/%s", + boot_image.c_str(), + kAndroidArtApexDefaultPath, + kEtcBootImageProf, + android_root.c_str(), + kEtcBootImageProf); + if (!MaybeAppendBootImageMainlineExtension(android_root, + /*deny_system_files=*/true, + deny_art_apex_data_files, + &location, + error_msg)) { + return ""; + } + return location; } else if (errno == EACCES) { // Additional warning for potential SELinux misconfiguration. PLOG(ERROR) << "Default boot image check failed, could not stat: " << boot_image_filename; @@ -454,7 +487,11 @@ std::string GetDefaultBootImageLocationSafe(const std::string& android_root, kBootImageStem, android_root.c_str(), kEtcBootImageProf); - if (!MaybeAppendBootImageMainlineExtension(android_root, &location, error_msg)) { + if (!MaybeAppendBootImageMainlineExtension(android_root, + /*deny_system_files=*/false, + deny_art_apex_data_files, + &location, + error_msg)) { return ""; } return location; -- cgit v1.2.3-59-g8ed1b