OSDN Git Service

Add product section for product interface enforcement
authorJustin Yun <justinyun@google.com>
Mon, 16 Dec 2019 08:47:02 +0000 (17:47 +0900)
committerJustin Yun <justinyun@google.com>
Fri, 3 Jan 2020 01:34:07 +0000 (10:34 +0900)
If ro.product.vndk.version is defined, product partition will have
seprate section from system section.
Modules in /product allowed to use VNDKs only from /system partition.
Modules in /system or /system_ext are not allowed to link to the
libraries in /product.

Bug: 124024578
Bug: 120954888
Test: build with "PRODUCT_PRODUCT_VNDK_VERSION := current"
      check device boot and basic functions

Change-Id: I0f9cd8b27c56c6a786b10aa23ffc4b197cea714d

20 files changed:
contents/configuration/baseconfig.cc
contents/context/context.cc
contents/include/linkerconfig/context.h
contents/include/linkerconfig/namespacebuilder.h
contents/include/linkerconfig/sectionbuilder.h
contents/namespace/media.cc
contents/namespace/productdefault.cc [new file with mode: 0644]
contents/namespace/rs.cc
contents/namespace/sphal.cc
contents/namespace/system.cc
contents/namespace/systemdefault.cc
contents/namespace/vendordefault.cc
contents/namespace/vndk.cc
contents/namespace/vndkinsystem.cc
contents/section/product.cc [new file with mode: 0644]
contents/tests/configuration/include/mockenv.h
contents/tests/configuration/vndk_test.cc
generator/variableloader.cc
modules/environment.cc
modules/include/linkerconfig/environment.h

index 838a40c..b5cf23f 100644 (file)
@@ -22,39 +22,14 @@ using android::linkerconfig::modules::DirToSection;
 using android::linkerconfig::modules::Section;
 
 namespace {
-
-// Don't change the order here. The first pattern that matches with the
-// absolute path of an executable is selected.
-const std::vector<DirToSection> kDirToSection = {
-    {"/system/bin/", "system"},
-    {"/system/xbin/", "system"},
-    {"/@{SYSTEM_EXT:system_ext}/bin/", "system"},
-    {"/@{PRODUCT:product}/bin/", "system"},
-
-    {"/odm/bin/", "vendor"},
-    {"/vendor/bin/", "vendor"},
-    {"/data/nativetest/odm", "vendor"},
-    {"/data/nativetest64/odm", "vendor"},
-    {"/data/benchmarktest/odm", "vendor"},
-    {"/data/benchmarktest64/odm", "vendor"},
-    {"/data/nativetest/vendor", "vendor"},
-    {"/data/nativetest64/vendor", "vendor"},
-    {"/data/benchmarktest/vendor", "vendor"},
-    {"/data/benchmarktest64/vendor", "vendor"},
-
-    {"/data/nativetest/unrestricted", "unrestricted"},
-    {"/data/nativetest64/unrestricted", "unrestricted"},
-
-    // TODO(b/123864775): Ensure tests are run from /data/nativetest{,64} or (if
-    // necessary) the unrestricted subdirs above. Then clean this up.
-    {"/data/local/tmp", "unrestricted"},
-
-    {"/postinstall", "postinstall"},
-    // Fallback entry to provide APEX namespace lookups for binaries anywhere
-    // else. This must be last.
-    {"/data", "system"},
-};
-
+void redirect_section(std::vector<DirToSection>& dirToSection,
+                      const std::string& from, const std::string& to) {
+  for (auto& [key, val] : dirToSection) {
+    if (val == from) {
+      val = to;
+    }
+  }
+}
 }  // namespace
 
 namespace android {
@@ -68,13 +43,56 @@ android::linkerconfig::modules::Configuration CreateBaseConfiguration() {
     current_context.SetCurrentLinkerConfigType(LinkerConfigType::Vndklite);
   }
 
+  // Don't change the order here. The first pattern that matches with the
+  // absolute path of an executable is selected.
+  std::vector<DirToSection> dirToSection = {
+      {"/system/bin/", "system"},
+      {"/system/xbin/", "system"},
+      {"/@{SYSTEM_EXT:system_ext}/bin/", "system"},
+
+      // Processes from the product partition will have a separate section if
+      // PRODUCT_PRODUCT_VNDK_VERSION is defined. Otherwise, they are run from
+      // the "system" section.
+      {"/@{PRODUCT:product}/bin/", "product"},
+
+      {"/odm/bin/", "vendor"},
+      {"/vendor/bin/", "vendor"},
+      {"/data/nativetest/odm", "vendor"},
+      {"/data/nativetest64/odm", "vendor"},
+      {"/data/benchmarktest/odm", "vendor"},
+      {"/data/benchmarktest64/odm", "vendor"},
+      {"/data/nativetest/vendor", "vendor"},
+      {"/data/nativetest64/vendor", "vendor"},
+      {"/data/benchmarktest/vendor", "vendor"},
+      {"/data/benchmarktest64/vendor", "vendor"},
+
+      {"/data/nativetest/unrestricted", "unrestricted"},
+      {"/data/nativetest64/unrestricted", "unrestricted"},
+
+      // TODO(b/123864775): Ensure tests are run from /data/nativetest{,64} or
+      // (if necessary) the unrestricted subdirs above. Then clean this up.
+      {"/data/local/tmp", "unrestricted"},
+
+      {"/postinstall", "postinstall"},
+      // Fallback entry to provide APEX namespace lookups for binaries anywhere
+      // else. This must be last.
+      {"/data", "system"},
+  };
+
   sections.emplace_back(BuildSystemSection(current_context));
   sections.emplace_back(BuildVendorSection(current_context));
+  if (android::linkerconfig::modules::IsProductVndkVersionDefined() &&
+      !android::linkerconfig::modules::IsVndkLiteDevice()) {
+    sections.emplace_back(BuildProductSection(current_context));
+  } else {
+    redirect_section(dirToSection, "product", "system");
+  }
+
   sections.emplace_back(BuildUnrestrictedSection(current_context));
   sections.emplace_back(BuildPostInstallSection(current_context));
 
   return android::linkerconfig::modules::Configuration(std::move(sections),
-                                                       kDirToSection);
+                                                       dirToSection);
 }
 }  // namespace contents
 }  // namespace linkerconfig
index d1535ff..c08ad53 100644 (file)
@@ -27,6 +27,10 @@ bool Context::IsVendorSection() const {
   return current_section == SectionType::Vendor;
 }
 
+bool Context::IsProductSection() const {
+  return current_section == SectionType::Product;
+}
+
 bool Context::IsDefaultConfig() const {
   return current_linkerconfig_type == LinkerConfigType::Default;
 }
@@ -48,7 +52,9 @@ void Context::SetCurrentSection(SectionType section_type) {
 }
 
 std::string Context::GetSystemNamespaceName() const {
-  return IsVendorSection() && !IsVndkliteConfig() ? "system" : "default";
+  return (IsVendorSection() || IsProductSection()) && !IsVndkliteConfig()
+             ? "system"
+             : "default";
 }
 
 void Context::SetCurrentLinkerConfigType(LinkerConfigType config_type) {
index a2c0a7e..91bfd02 100644 (file)
@@ -24,6 +24,7 @@ namespace contents {
 enum class SectionType {
   System,
   Vendor,
+  Product,
   Other,
 };
 
@@ -42,6 +43,7 @@ class Context {
   }
   bool IsSystemSection() const;
   bool IsVendorSection() const;
+  bool IsProductSection() const;
 
   bool IsDefaultConfig() const;
   bool IsLegacyConfig() const;
index c5be269..c1ecb7a 100644 (file)
@@ -36,6 +36,7 @@ NamespaceBuilder BuildVndkNamespace;
 NamespaceBuilder BuildVendorDefaultNamespace;
 NamespaceBuilder BuildSystemNamespace;
 NamespaceBuilder BuildVndkInSystemNamespace;
+NamespaceBuilder BuildProductDefaultNamespace;
 NamespaceBuilder BuildUnrestrictedDefaultNamespace;
 NamespaceBuilder BuildPostInstallNamespace;
 NamespaceBuilder BuildNeuralNetworksNamespace;
index e410186..8ae35d7 100644 (file)
@@ -26,10 +26,11 @@ namespace linkerconfig {
 namespace contents {
 SectionBuilder BuildSystemSection;
 SectionBuilder BuildVendorSection;
+SectionBuilder BuildProductSection;
 SectionBuilder BuildUnrestrictedSection;
 SectionBuilder BuildLegacySection;
 SectionBuilder BuildPostInstallSection;
 SectionBuilder BuildRecoverySection;
 }  // namespace contents
 }  // namespace linkerconfig
-}  // namespace android
\ No newline at end of file
+}  // namespace android
index 2879927..63b3029 100644 (file)
@@ -36,7 +36,7 @@ const std::vector<std::string> kLibsFromDefaultLegacy = {"libandroid.so",
                                                          "libmediandk.so",
                                                          "libvndksupport.so"};
 
-const std::vector<std::string> kLibsFromDefault = {"@{LLNDK_LIBRARIES}",
+const std::vector<std::string> kLibsFromDefault = {"@{LLNDK_LIBRARIES_VENDOR}",
                                                    "libbinder_ndk.so",
                                                    "libmediametrics.so"};
 
diff --git a/contents/namespace/productdefault.cc b/contents/namespace/productdefault.cc
new file mode 100644 (file)
index 0000000..4618aaf
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This is the default linker namespace for a vendor process (a process started
+// from /vendor/bin/*).
+
+#include "linkerconfig/environment.h"
+#include "linkerconfig/namespacebuilder.h"
+
+using android::linkerconfig::modules::AsanPath;
+using android::linkerconfig::modules::Namespace;
+
+namespace android {
+namespace linkerconfig {
+namespace contents {
+Namespace BuildProductDefaultNamespace([[maybe_unused]] const Context& ctx) {
+  Namespace ns("default", /*is_isolated=*/true, /*is_visible=*/true);
+
+  ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  ns.AddPermittedPath("/@{PRODUCT:product}", AsanPath::WITH_DATA_ASAN);
+
+  ns.GetLink(ctx.GetSystemNamespaceName())
+      .AddSharedLib("@{LLNDK_LIBRARIES_PRODUCT}");
+  ns.GetLink("vndk").AddSharedLib({"@{VNDK_SAMEPROCESS_LIBRARIES_PRODUCT}",
+                                   "@{VNDK_CORE_LIBRARIES_PRODUCT}"});
+  if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
+    ns.GetLink("vndk_in_system")
+        .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+  }
+  ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
+
+  return ns;
+}
+}  // namespace contents
+}  // namespace linkerconfig
+}  // namespace android
index c0e3d89..b0de77b 100644 (file)
@@ -32,7 +32,7 @@ Namespace BuildRsNamespace([[maybe_unused]] const Context& ctx) {
 
   ns.AddSearchPath("/odm/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/vendor/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
-  ns.AddSearchPath("/apex/com.android.vndk.v@{VNDK_VER}/${LIB}",
+  ns.AddSearchPath("/apex/com.android.vndk.v@{VENDOR_VNDK_VERSION}/${LIB}",
                    AsanPath::SAME_PATH);
   ns.AddSearchPath("/odm/${LIB}", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
@@ -45,7 +45,8 @@ Namespace BuildRsNamespace([[maybe_unused]] const Context& ctx) {
   // Private LLNDK libs (e.g. libft2.so) are exceptionally allowed to this
   // namespace because RS framework libs are using them.
   ns.GetLink(ctx.GetSystemNamespaceName())
-      .AddSharedLib({"@{LLNDK_LIBRARIES}", "@{PRIVATE_LLNDK_LIBRARIES:}"});
+      .AddSharedLib(
+          {"@{LLNDK_LIBRARIES_VENDOR}", "@{PRIVATE_LLNDK_LIBRARIES_VENDOR:}"});
 
   ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
 
index afc2a1d..b7631f4 100644 (file)
@@ -49,8 +49,9 @@ Namespace BuildSphalNamespace([[maybe_unused]] const Context& ctx) {
   // namespaces are tried in this order. rs should be before vndk because both
   // are capable of loading libRS_internal.so
   ns.GetLink("rs").AddSharedLib("libRS_internal.so");
-  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("@{LLNDK_LIBRARIES:}");
-  ns.GetLink("vndk").AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES:}");
+  ns.GetLink(ctx.GetSystemNamespaceName())
+      .AddSharedLib("@{LLNDK_LIBRARIES_VENDOR:}");
+  ns.GetLink("vndk").AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES_VENDOR:}");
   ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
 
   return ns;
index 262a162..9561d2a 100644 (file)
 // This namespace is where system libs (VNDK and LLNDK libs) are loaded for a
 // vendor process.
 
+#include "linkerconfig/environment.h"
 #include "linkerconfig/namespacebuilder.h"
 
 using android::linkerconfig::modules::AsanPath;
+using android::linkerconfig::modules::IsProductVndkVersionDefined;
 using android::linkerconfig::modules::Namespace;
 
 namespace android {
@@ -29,7 +31,9 @@ Namespace BuildSystemNamespace([[maybe_unused]] const Context& ctx) {
   Namespace ns("system", /*is_isolated=*/false, /*is_visible=*/false);
   ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}", AsanPath::WITH_DATA_ASAN);
-  ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  if (!IsProductVndkVersionDefined()) {
+    ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  }
 
   ns.GetLink("art").AddSharedLib(
       {"libdexfile_external.so",
index 1d7563b..8f76ede 100644 (file)
@@ -22,6 +22,7 @@
 #include "linkerconfig/namespacebuilder.h"
 
 using android::linkerconfig::modules::AsanPath;
+using android::linkerconfig::modules::IsProductVndkVersionDefined;
 using android::linkerconfig::modules::Namespace;
 
 namespace {
@@ -54,7 +55,6 @@ const std::vector<std::string> kPermittedPaths = {
     "/system/${LIB}/extractors",
     "/system/${LIB}/hw",
     "/@{SYSTEM_EXT:system_ext}/${LIB}",
-    "/@{PRODUCT:product}/${LIB}",
 
     // These are where odex files are located. libart has to be able to
     // dlopen the files
@@ -87,6 +87,10 @@ void BuildPermittedPath(Namespace& ns) {
   for (const auto& path : kPermittedPaths) {
     ns.AddPermittedPath(path, AsanPath::SAME_PATH);
   }
+  if (!IsProductVndkVersionDefined()) {
+    // System processes can use product libs only if product VNDK is not enforced.
+    ns.AddPermittedPath("/@{PRODUCT:product}/${LIB}", AsanPath::SAME_PATH);
+  }
 }
 }  // namespace
 
@@ -103,7 +107,11 @@ Namespace BuildSystemDefaultNamespace([[maybe_unused]] const Context& ctx) {
 
   ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}", AsanPath::WITH_DATA_ASAN);
-  ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  if (!IsProductVndkVersionDefined() || !is_fully_treblelized) {
+    // System processes can search product libs only if product VNDK is not
+    // enforced.
+    ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  }
   if (!is_fully_treblelized) {
     ns.AddSearchPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/odm/${LIB}", AsanPath::WITH_DATA_ASAN);
index 3361a15..3c2c824 100644 (file)
@@ -71,7 +71,7 @@ Namespace BuildVendorDefaultNamespace([[maybe_unused]] const Context& ctx) {
                      AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
     // Put system vndk at the last search order in vndk_lite for GSI
-    ns.AddSearchPath("/apex/com.android.vndk.v@{VNDK_VER}/${LIB}",
+    ns.AddSearchPath("/apex/com.android.vndk.v@{VENDOR_VNDK_VERSION}/${LIB}",
                      AsanPath::SAME_PATH);
   }
 
@@ -87,9 +87,10 @@ Namespace BuildVendorDefaultNamespace([[maybe_unused]] const Context& ctx) {
   if (is_vndklite) {
     ns.GetLink("art").AddSharedLib(kVndkLiteArtLibs);
   } else {
-    ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("@{LLNDK_LIBRARIES}");
-    ns.GetLink("vndk").AddSharedLib(
-        {"@{VNDK_SAMEPROCESS_LIBRARIES}", "@{VNDK_CORE_LIBRARIES}"});
+    ns.GetLink(ctx.GetSystemNamespaceName())
+        .AddSharedLib("@{LLNDK_LIBRARIES_VENDOR}");
+    ns.GetLink("vndk").AddSharedLib({"@{VNDK_SAMEPROCESS_LIBRARIES_VENDOR}",
+                                     "@{VNDK_CORE_LIBRARIES_VENDOR}"});
     if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
       ns.GetLink("vndk_in_system")
           .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
index 180de8b..a9adac8 100644 (file)
@@ -28,6 +28,7 @@ namespace linkerconfig {
 namespace contents {
 Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx) {
   bool is_system_section = ctx.IsSystemSection();
+  bool is_product_section = ctx.IsProductSection();
   bool is_vndklite = ctx.IsVndkliteConfig();
   // Isolated but visible when used in the [system] section to allow links to be
   // created at runtime, e.g. through android_link_namespaces in
@@ -37,16 +38,22 @@ Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx) {
                /*is_visible=*/is_system_section);
 
   if (is_system_section) {
+    // It is linked from vendor HAL. It must use vendor vndk libs.
     ns.AddSearchPath("/odm/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/vendor/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
-    ns.AddSearchPath("/apex/com.android.vndk.v@{VNDK_VER}/${LIB}",
+    ns.AddSearchPath("/apex/com.android.vndk.v@{VENDOR_VNDK_VERSION}/${LIB}",
+                     AsanPath::SAME_PATH);
+  } else if (is_product_section) {
+    ns.AddSearchPath("/product/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/product/${LIB}/vndk", AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/apex/com.android.vndk.v@{PRODUCT_VNDK_VERSION}/${LIB}",
                      AsanPath::SAME_PATH);
   } else {
     ns.AddSearchPath("/odm/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/odm/${LIB}/vndk", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/vendor/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/vendor/${LIB}/vndk", AsanPath::WITH_DATA_ASAN);
-    ns.AddSearchPath("/apex/com.android.vndk.v@{VNDK_VER}/${LIB}",
+    ns.AddSearchPath("/apex/com.android.vndk.v@{VENDOR_VNDK_VERSION}/${LIB}",
                      AsanPath::SAME_PATH);
   }
 
@@ -61,14 +68,21 @@ Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx) {
     ns.AddPermittedPath("/system/vendor/${LIB}/egl", AsanPath::NONE);
 
     // This is exceptionally required since android.hidl.memory@1.0-impl.so is here
-    ns.AddPermittedPath("/apex/com.android.vndk.v@{VNDK_VER}/${LIB}/hw",
-                        AsanPath::SAME_PATH);
+    ns.AddPermittedPath(
+        "/apex/com.android.vndk.v@{VENDOR_VNDK_VERSION}/${LIB}/hw",
+        AsanPath::SAME_PATH);
   }
 
   // For the [vendor] section, the links should be identical to that of the
   // 'vndk_in_system' namespace, except the links to 'default' and 'vndk_in_system'.
 
-  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib({"@{LLNDK_LIBRARIES}"});
+  if (is_product_section) {
+    ns.GetLink(ctx.GetSystemNamespaceName())
+        .AddSharedLib({"@{LLNDK_LIBRARIES_PRODUCT}"});
+  } else {
+    ns.GetLink(ctx.GetSystemNamespaceName())
+        .AddSharedLib({"@{LLNDK_LIBRARIES_VENDOR}"});
+  }
 
   if (!is_vndklite) {
     if (is_system_section) {
@@ -77,7 +91,7 @@ Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx) {
       // the system namespace has higher priority than the "sphal" namespace.
       ns.GetLink("sphal").AllowAllSharedLibs();
     } else {
-      // [vendor] section
+      // [vendor] or [product] section
       ns.GetLink("default").AllowAllSharedLibs();
 
       if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
index 0bee29b..c85ac57 100644 (file)
@@ -30,6 +30,7 @@
 #include "linkerconfig/environment.h"
 
 using android::linkerconfig::modules::AsanPath;
+using android::linkerconfig::modules::IsProductVndkVersionDefined;
 using android::linkerconfig::modules::Namespace;
 
 namespace android {
@@ -42,7 +43,9 @@ Namespace BuildVndkInSystemNamespace([[maybe_unused]] const Context& ctx) {
   // The search paths here should be kept the same as that of the 'system' namespace.
   ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}", AsanPath::WITH_DATA_ASAN);
-  ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  if (!IsProductVndkVersionDefined()) {
+    ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+  }
 
   if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
     ns.AddWhitelisted("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
@@ -53,7 +56,13 @@ Namespace BuildVndkInSystemNamespace([[maybe_unused]] const Context& ctx) {
   //   1. 'vndk_in_system' needs to be freely linked back to 'vndk'.
   //   2. 'vndk_in_system' does not need to link to 'default', as any library that
   //      requires anything vendor would not be a vndk_in_system library.
-  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("@{LLNDK_LIBRARIES}");
+  if (ctx.IsProductSection()) {
+    ns.GetLink(ctx.GetSystemNamespaceName())
+        .AddSharedLib("@{LLNDK_LIBRARIES_PRODUCT}");
+  } else {
+    ns.GetLink(ctx.GetSystemNamespaceName())
+        .AddSharedLib("@{LLNDK_LIBRARIES_VENDOR}");
+  }
   ns.GetLink("vndk").AllowAllSharedLibs();
   ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
 
diff --git a/contents/section/product.cc b/contents/section/product.cc
new file mode 100644 (file)
index 0000000..b4e2b61
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Namespace config for product processes.
+
+#include "linkerconfig/sectionbuilder.h"
+
+#include "linkerconfig/common.h"
+#include "linkerconfig/environment.h"
+#include "linkerconfig/namespacebuilder.h"
+#include "linkerconfig/section.h"
+
+using android::linkerconfig::contents::SectionType;
+using android::linkerconfig::modules::Namespace;
+using android::linkerconfig::modules::Section;
+
+namespace android {
+namespace linkerconfig {
+namespace contents {
+Section BuildProductSection(Context& ctx) {
+  ctx.SetCurrentSection(SectionType::Product);
+  std::vector<Namespace> namespaces;
+
+  namespaces.emplace_back(BuildProductDefaultNamespace(ctx));
+  namespaces.emplace_back(BuildArtNamespace(ctx));
+  namespaces.emplace_back(BuildVndkNamespace(ctx));
+  namespaces.emplace_back(BuildSystemNamespace(ctx));
+  namespaces.emplace_back(BuildNeuralNetworksNamespace(ctx));
+
+  if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
+    namespaces.emplace_back(BuildVndkInSystemNamespace(ctx));
+  }
+
+  namespaces.emplace_back(BuildRuntimeNamespace(ctx));
+
+  Section section("product", std::move(namespaces));
+  AddStandardSystemLinks(ctx, &section);
+  return section;
+}
+}  // namespace contents
+}  // namespace linkerconfig
+}  // namespace android
index 2815b4a..8fce4b5 100644 (file)
 #include "linkerconfig/variables.h"
 
 inline void MockGenericVariables() {
-  android::linkerconfig::modules::Variables::AddValue("VNDK_VER", "99");
+  android::linkerconfig::modules::Variables::AddValue("VENDOR_VNDK_VERSION",
+                                                      "99");
+  android::linkerconfig::modules::Variables::AddValue("PRODUCT_VNDK_VERSION",
+                                                      "99");
   android::linkerconfig::modules::Variables::AddValue("PRODUCT", "product");
   android::linkerconfig::modules::Variables::AddValue("SYSTEM_EXT",
                                                       "system_ext");
-  android::linkerconfig::modules::Variables::AddValue("LLNDK_LIBRARIES",
+  android::linkerconfig::modules::Variables::AddValue("LLNDK_LIBRARIES_VENDOR",
+                                                      "llndk_libraries");
+  android::linkerconfig::modules::Variables::AddValue("LLNDK_LIBRARIES_PRODUCT",
                                                       "llndk_libraries");
   android::linkerconfig::modules::Variables::AddValue(
       "SANITIZER_RUNTIME_LIBRARIES", "sanitizer_runtime_libraries");
   android::linkerconfig::modules::Variables::AddValue(
-      "PRIVATE_LLNDK_LIBRARIES", "private_llndk_libraries");
+      "PRIVATE_LLNDK_LIBRARIES_VENDOR", "private_llndk_libraries");
+  android::linkerconfig::modules::Variables::AddValue(
+      "PRIVATE_LLNDK_LIBRARIES_PRODUCT", "private_llndk_libraries");
+  android::linkerconfig::modules::Variables::AddValue(
+      "VNDK_SAMEPROCESS_LIBRARIES_VENDOR", "vndk_sameprocess_libraries");
   android::linkerconfig::modules::Variables::AddValue(
-      "VNDK_SAMEPROCESS_LIBRARIES", "vndk_sameprocess_libraries");
-  android::linkerconfig::modules::Variables::AddValue("VNDK_CORE_LIBRARIES",
-                                                      "vndk_core_libraries");
+      "VNDK_SAMEPROCESS_LIBRARIES_PRODUCT", "vndk_sameprocess_libraries");
+  android::linkerconfig::modules::Variables::AddValue(
+      "VNDK_CORE_LIBRARIES_VENDOR", "vndk_core_libraries");
+  android::linkerconfig::modules::Variables::AddValue(
+      "VNDK_CORE_LIBRARIES_PRODUCT", "vndk_core_libraries");
   android::linkerconfig::modules::Variables::AddValue(
       "VNDK_USING_CORE_VARIANT_LIBRARIES", "");
 }
 
 inline void MockVndkVersion(std::string vndk_version) {
-  android::linkerconfig::modules::Variables::AddValue("VNDK_VER", vndk_version);
+  android::linkerconfig::modules::Variables::AddValue("VENDOR_VNDK_VERSION",
+                                                      vndk_version);
+  android::linkerconfig::modules::Variables::AddValue("PRODUCT_VNDK_VERSION",
+                                                      vndk_version);
 }
 
 inline void MockVndkUsingCoreVariant() {
@@ -47,4 +61,4 @@ inline void MockVndkUsingCoreVariant() {
 
 inline void MockVnkdLite() {
   android::linkerconfig::modules::Variables::AddValue("ro.vndk.lite", "true");
-}
\ No newline at end of file
+}
index 81d4b98..c793e98 100644 (file)
@@ -59,7 +59,8 @@ TEST(vndk_namespace, vndk_ext) {
   auto vendor_lib_path = "/vendor/${LIB}";
   auto vendor_vndk_lib_path = "/vendor/${LIB}/vndk";
   auto vendor_vndksp_lib_path = "/vendor/${LIB}/vndk-sp";
-  auto apex_vndk_lib_path = "/apex/com.android.vndk.v@{VNDK_VER}/${LIB}";
+  auto apex_vndk_lib_path =
+      "/apex/com.android.vndk.v@{VENDOR_VNDK_VERSION}/${LIB}";
 
   auto fs = fsmap{
       {system_lib_path, {libvndk, libvndksp}},
index 09ea358..6c61c77 100644 (file)
@@ -28,6 +28,7 @@
 
 using android::base::ErrnoErrorf;
 using android::base::Result;
+using android::linkerconfig::modules::GetProductVndkVersion;
 using android::linkerconfig::modules::GetVendorVndkVersion;
 using android::linkerconfig::modules::Variables;
 
@@ -35,7 +36,8 @@ namespace {
 using namespace android::linkerconfig::generator;
 
 void LoadVndkVersionVariable() {
-  Variables::AddValue("VNDK_VER", GetVendorVndkVersion());
+  Variables::AddValue("VENDOR_VNDK_VERSION", GetVendorVndkVersion());
+  Variables::AddValue("PRODUCT_VNDK_VERSION", GetProductVndkVersion());
 }
 
 Result<std::string> GetRealPath(std::string target_path) {
@@ -68,37 +70,65 @@ void LoadPartitionPathVariables(const std::string& root) {
 }
 
 void LoadLibraryListVariables(const std::string& root) {
-  auto private_library_path = root + "/system/etc/vndkprivate.libraries." +
-                              GetVendorVndkVersion() + ".txt";
-  auto llndk_library_path =
+  auto private_library_path_vendor = root +
+                                     "/system/etc/vndkprivate.libraries." +
+                                     GetVendorVndkVersion() + ".txt";
+  auto llndk_library_path_vendor =
       root + "/system/etc/llndk.libraries." + GetVendorVndkVersion() + ".txt";
-  auto vndksp_library_path =
+  auto vndksp_library_path_vendor =
       root + "/system/etc/vndksp.libraries." + GetVendorVndkVersion() + ".txt";
-  auto vndkcore_library_path = root + "/system/etc/vndkcore.libraries." +
-                               GetVendorVndkVersion() + ".txt";
+  auto vndkcore_library_path_vendor = root + "/system/etc/vndkcore.libraries." +
+                                      GetVendorVndkVersion() + ".txt";
+
+  auto private_library_path_product = root +
+                                      "/system/etc/vndkprivate.libraries." +
+                                      GetProductVndkVersion() + ".txt";
+  auto llndk_library_path_product =
+      root + "/system/etc/llndk.libraries." + GetProductVndkVersion() + ".txt";
+  auto vndksp_library_path_product =
+      root + "/system/etc/vndksp.libraries." + GetProductVndkVersion() + ".txt";
+  auto vndkcore_library_path_product = root + "/system/etc/vndkcore.libraries." +
+                                       GetProductVndkVersion() + ".txt";
+
   auto vndkcorevariant_library_path =
       root + "/system/etc/vndkcorevariant.libraries.txt";
   auto sanitizer_library_path = root + "/system/etc/sanitizer.libraries.txt";
 
-  Variables::AddValue(
-      "LLNDK_LIBRARIES",
-      GetPublicLibrariesString(llndk_library_path, private_library_path));
+  Variables::AddValue("LLNDK_LIBRARIES_VENDOR",
+                      GetPublicLibrariesString(llndk_library_path_vendor,
+                                               private_library_path_vendor));
+
+  Variables::AddValue("PRIVATE_LLNDK_LIBRARIES_VENDOR",
+                      GetPrivateLibrariesString(llndk_library_path_vendor,
+                                                private_library_path_vendor));
+
+  Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_VENDOR",
+                      GetPublicLibrariesString(vndksp_library_path_vendor,
+                                               private_library_path_vendor));
+
+  Variables::AddValue("VNDK_CORE_LIBRARIES_VENDOR",
+                      GetPublicLibrariesString(vndkcore_library_path_vendor,
+                                               private_library_path_vendor));
+
+  Variables::AddValue("LLNDK_LIBRARIES_PRODUCT",
+                      GetPublicLibrariesString(llndk_library_path_product,
+                                               private_library_path_product));
 
-  Variables::AddValue(
-      "PRIVATE_LLNDK_LIBRARIES",
-      GetPrivateLibrariesString(llndk_library_path, private_library_path));
+  Variables::AddValue("PRIVATE_LLNDK_LIBRARIES_PRODUCT",
+                      GetPrivateLibrariesString(llndk_library_path_product,
+                                                private_library_path_product));
 
-  Variables::AddValue(
-      "VNDK_SAMEPROCESS_LIBRARIES",
-      GetPublicLibrariesString(vndksp_library_path, private_library_path));
+  Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_PRODUCT",
+                      GetPublicLibrariesString(vndksp_library_path_product,
+                                               private_library_path_product));
 
-  Variables::AddValue(
-      "VNDK_CORE_LIBRARIES",
-      GetPublicLibrariesString(vndkcore_library_path, private_library_path));
+  Variables::AddValue("VNDK_CORE_LIBRARIES_PRODUCT",
+                      GetPublicLibrariesString(vndkcore_library_path_product,
+                                               private_library_path_product));
 
   Variables::AddValue("VNDK_USING_CORE_VARIANT_LIBRARIES",
                       GetPublicLibrariesString(vndkcorevariant_library_path,
-                                               private_library_path));
+                                               private_library_path_vendor));
 
   Variables::AddValue("SANITIZER_RUNTIME_LIBRARIES",
                       GetLibrariesString(sanitizer_library_path));
index 54e2ff3..e63be71 100644 (file)
@@ -41,9 +41,17 @@ std::string GetVendorVndkVersion() {
   return Variables::GetValue("ro.vndk.version").value_or("");
 }
 
+std::string GetProductVndkVersion() {
+  return Variables::GetValue("ro.product.vndk.version").value_or("");
+}
+
+bool IsProductVndkVersionDefined() {
+  return Variables::GetValue("ro.product.vndk.version").has_value();
+}
+
 bool IsRecoveryMode() {
   return access("/system/bin/recovery", F_OK) == 0;
 }
 }  // namespace modules
 }  // namespace linkerconfig
-}  // namespace android
\ No newline at end of file
+}  // namespace android
index fb6e9f9..3aa0d32 100644 (file)
@@ -23,7 +23,9 @@ bool IsLegacyDevice();
 bool IsVndkLiteDevice();
 bool IsVndkInSystemNamespace();
 std::string GetVendorVndkVersion();
+std::string GetProductVndkVersion();
+bool IsProductVndkVersionDefined();
 bool IsRecoveryMode();
 }  // namespace modules
 }  // namespace linkerconfig
-}  // namespace android
\ No newline at end of file
+}  // namespace android