From 8a9b51e34f3769a5e3ea3a4383e3f00489088738 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Tue, 30 Jan 2024 21:33:09 +0000 Subject: Refactorings to make more logic available at the top level in native_loader.cpp. - Make the code that determines the partition from the dex path available to code in native_loader.cpp, and rename it since it'll be applied to arbitrary paths, not just APK's. - Move the linker namespace constants to a header file. - Various other minor code cleanups. To prepare for a later CL that needs to access these things from OpenNativeLibrary. No functional changes. Test: atest libnativeloader_e2e_tests libnativeloader_test Bug: 237577392 Change-Id: Ifc762bf6d4664b2d477c4ed3af58f149fb4c1189 --- libnativeloader/library_namespaces.h | 45 ++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'libnativeloader/library_namespaces.h') diff --git a/libnativeloader/library_namespaces.h b/libnativeloader/library_namespaces.h index 4871528f47..25edf4faf7 100644 --- a/libnativeloader/library_namespaces.h +++ b/libnativeloader/library_namespaces.h @@ -21,20 +21,40 @@ #error "Not available for host or linux target" #endif -#define LOG_TAG "nativeloader" - -#include "native_loader_namespace.h" - #include #include -#include -#include +#include "android-base/result.h" +#include "jni.h" +#include "native_loader_namespace.h" namespace android::nativeloader { using android::base::Result; +// The device may be configured to have the vendor libraries loaded to a separate namespace. +// For historical reasons this namespace was named sphal but effectively it is intended +// to use to load vendor libraries to separate namespace with controlled interface between +// vendor and system namespaces. +constexpr const char* kVendorNamespaceName = "sphal"; +// Similar to sphal namespace, product namespace provides some product libraries. +constexpr const char* kProductNamespaceName = "product"; + +// vndk namespace for unbundled vendor apps +constexpr const char* kVndkNamespaceName = "vndk"; +// vndk_product namespace for unbundled product apps +constexpr const char* kVndkProductNamespaceName = "vndk_product"; + +// API domains, roughly corresponding to partitions. Interdependencies between +// these must follow API restrictions, while intradependencies do not. +using ApiDomain = enum { + API_DOMAIN_DEFAULT = 0, // Locations other than those below, in particular for ordinary apps + API_DOMAIN_VENDOR = 1, // Vendor partition + API_DOMAIN_PRODUCT = 2, // Product partition +}; + +nativeloader::ApiDomain GetApiDomainFromPath(const std::string& path); + // LibraryNamespaces is a singleton object that manages NativeLoaderNamespace // objects for an app process. Its main job is to create (and configure) a new // NativeLoaderNamespace object for a Java ClassLoader, and to find an existing @@ -53,10 +73,15 @@ class LibraryNamespaces { initialized_ = false; app_main_namespace_ = nullptr; } - Result Create(JNIEnv* env, uint32_t target_sdk_version, - jobject class_loader, bool is_shared, jstring dex_path, - jstring java_library_path, jstring java_permitted_path, - jstring uses_library_list); + Result Create(JNIEnv* env, + uint32_t target_sdk_version, + jobject class_loader, + ApiDomain api_domain, + bool is_shared, + const std::string& dex_path, + jstring library_path_j, + jstring permitted_path_j, + jstring uses_library_list_j); NativeLoaderNamespace* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader); private: -- cgit v1.2.3-59-g8ed1b