Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a20a907 authored by Victor Chang's avatar Victor Chang
Browse files

Expose public libraries from runtime namepsace to classloader namespace

Bug: 121248172
Bug: 121372395
Test: DT_NEEDED libicuuc.so
Test: dlopen("libicuuc.so")
Test: dlopen("/system/lib64/libicuuc.so") for targetSdkVersion < Q
Test: dlopen("/apex/com.android.runtime/lib64/libicuuc.so")
Change-Id: Ib4a255696ed474b7993acc952a8d07e7d64604a5
parent 3e4b2ec2
Loading
Loading
Loading
Loading
+28 −0
Original line number Original line Diff line number Diff line
@@ -103,6 +103,11 @@ static constexpr const char kLlndkNativeLibrariesSystemConfigPathFromRoot[] =
static constexpr const char kVndkspNativeLibrariesSystemConfigPathFromRoot[] =
static constexpr const char kVndkspNativeLibrariesSystemConfigPathFromRoot[] =
    "/etc/vndksp.libraries.txt";
    "/etc/vndksp.libraries.txt";


static const std::vector<const std::string> kRuntimePublicLibraries = {
    "libicuuc.so",
    "libicui18n.so",
};

// The device may be configured to have the vendor libraries loaded to a separate namespace.
// 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
// 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
// to use to load vendor libraries to separate namespace with controlled interface between
@@ -111,6 +116,8 @@ static constexpr const char* kVendorNamespaceName = "sphal";


static constexpr const char* kVndkNamespaceName = "vndk";
static constexpr const char* kVndkNamespaceName = "vndk";


static constexpr const char* kRuntimeNamespaceName = "runtime";

static constexpr const char* kClassloaderNamespaceName = "classloader-namespace";
static constexpr const char* kClassloaderNamespaceName = "classloader-namespace";
static constexpr const char* kVendorClassloaderNamespaceName = "vendor-classloader-namespace";
static constexpr const char* kVendorClassloaderNamespaceName = "vendor-classloader-namespace";


@@ -245,6 +252,8 @@ class LibraryNamespaces {
      }
      }
    }
    }


    std::string runtime_exposed_libraries = base::Join(kRuntimePublicLibraries, ":");

    NativeLoaderNamespace native_loader_ns;
    NativeLoaderNamespace native_loader_ns;
    if (!is_native_bridge) {
    if (!is_native_bridge) {
      android_namespace_t* android_parent_ns =
      android_namespace_t* android_parent_ns =
@@ -265,11 +274,21 @@ class LibraryNamespaces {
      // which is expected behavior in this case.
      // which is expected behavior in this case.
      android_namespace_t* vendor_ns = android_get_exported_namespace(kVendorNamespaceName);
      android_namespace_t* vendor_ns = android_get_exported_namespace(kVendorNamespaceName);


      android_namespace_t* runtime_ns = android_get_exported_namespace(kRuntimeNamespaceName);

      if (!android_link_namespaces(ns, nullptr, system_exposed_libraries.c_str())) {
      if (!android_link_namespaces(ns, nullptr, system_exposed_libraries.c_str())) {
        *error_msg = dlerror();
        *error_msg = dlerror();
        return nullptr;
        return nullptr;
      }
      }


      // Runtime apex does not exist in host, and under certain build conditions.
      if (runtime_ns != nullptr) {
        if (!android_link_namespaces(ns, runtime_ns, runtime_exposed_libraries.c_str())) {
          *error_msg = dlerror();
          return nullptr;
        }
      }

      if (vndk_ns != nullptr && !system_vndksp_libraries_.empty()) {
      if (vndk_ns != nullptr && !system_vndksp_libraries_.empty()) {
        // vendor apks are allowed to use VNDK-SP libraries.
        // vendor apks are allowed to use VNDK-SP libraries.
        if (!android_link_namespaces(ns, vndk_ns, system_vndksp_libraries_.c_str())) {
        if (!android_link_namespaces(ns, vndk_ns, system_vndksp_libraries_.c_str())) {
@@ -301,12 +320,21 @@ class LibraryNamespaces {
      }
      }


      native_bridge_namespace_t* vendor_ns = NativeBridgeGetExportedNamespace(kVendorNamespaceName);
      native_bridge_namespace_t* vendor_ns = NativeBridgeGetExportedNamespace(kVendorNamespaceName);
      native_bridge_namespace_t* runtime_ns =
          NativeBridgeGetExportedNamespace(kRuntimeNamespaceName);


      if (!NativeBridgeLinkNamespaces(ns, nullptr, system_exposed_libraries.c_str())) {
      if (!NativeBridgeLinkNamespaces(ns, nullptr, system_exposed_libraries.c_str())) {
        *error_msg = NativeBridgeGetError();
        *error_msg = NativeBridgeGetError();
        return nullptr;
        return nullptr;
      }
      }


      // Runtime apex does not exist in host, and under certain build conditions.
      if (runtime_ns != nullptr) {
        if (!NativeBridgeLinkNamespaces(ns, runtime_ns, runtime_exposed_libraries.c_str())) {
          *error_msg = NativeBridgeGetError();
          return nullptr;
        }
      }
      if (!vendor_public_libraries_.empty()) {
      if (!vendor_public_libraries_.empty()) {
        if (!NativeBridgeLinkNamespaces(ns, vendor_ns, vendor_public_libraries_.c_str())) {
        if (!NativeBridgeLinkNamespaces(ns, vendor_ns, vendor_public_libraries_.c_str())) {
          *error_msg = NativeBridgeGetError();
          *error_msg = NativeBridgeGetError();