Replace shared_ptr with plain object
Currently most of objects are managed with shared_ptr. However, as these
objects are not being shared, it can be managed with plain object. To
make it simple, it would be better to remove all shared_ptr in use.
Bug: 123722631
Test: m -j & atest passed
Change-Id: I16fbf8bc63f016dc0603e1081164fbaabcb32d8e
diff --git a/contents/configuration/baseconfig.cc b/contents/configuration/baseconfig.cc
index fea9baf..63b3713 100644
--- a/contents/configuration/baseconfig.cc
+++ b/contents/configuration/baseconfig.cc
@@ -24,17 +24,15 @@
namespace linkerconfig {
namespace contents {
android::linkerconfig::modules::Configuration CreateBaseConfiguration() {
- std::vector<std::shared_ptr<Section>> sections;
+ std::vector<Section> sections;
Context current_context;
- sections.push_back(BuildSystemSection(current_context));
- sections.push_back(BuildVendorSection(current_context));
- sections.push_back(BuildUnrestrictedSection(current_context));
- sections.push_back(BuildPostInstallSection(current_context));
+ sections.emplace_back(BuildSystemSection(current_context));
+ sections.emplace_back(BuildVendorSection(current_context));
+ sections.emplace_back(BuildUnrestrictedSection(current_context));
+ sections.emplace_back(BuildPostInstallSection(current_context));
- android::linkerconfig::modules::Configuration config(sections);
-
- return config;
+ return android::linkerconfig::modules::Configuration(std::move(sections));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/configuration/legacy.cc b/contents/configuration/legacy.cc
index 25a04e4..b15be16 100644
--- a/contents/configuration/legacy.cc
+++ b/contents/configuration/legacy.cc
@@ -24,14 +24,13 @@
namespace linkerconfig {
namespace contents {
android::linkerconfig::modules::Configuration CreateLegacyConfiguration() {
- std::vector<std::shared_ptr<Section>> sections;
+ std::vector<Section> sections;
Context current_context;
- sections.push_back(BuildLegacySection(current_context));
- sections.push_back(BuildPostInstallSection(current_context));
+ sections.emplace_back(BuildLegacySection(current_context));
+ sections.emplace_back(BuildPostInstallSection(current_context));
- android::linkerconfig::modules::Configuration config(sections);
- return config;
+ return android::linkerconfig::modules::Configuration(std::move(sections));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/include/linkerconfig/baseconfig.h b/contents/include/linkerconfig/baseconfig.h
index eb12949..5aa43fe 100644
--- a/contents/include/linkerconfig/baseconfig.h
+++ b/contents/include/linkerconfig/baseconfig.h
@@ -15,8 +15,6 @@
*/
#pragma once
-#include <memory>
-
#include "linkerconfig/configuration.h"
namespace android {
diff --git a/contents/include/linkerconfig/legacy.h b/contents/include/linkerconfig/legacy.h
index 241b201..3a6e9bf 100644
--- a/contents/include/linkerconfig/legacy.h
+++ b/contents/include/linkerconfig/legacy.h
@@ -15,8 +15,6 @@
*/
#pragma once
-#include <memory>
-
#include "linkerconfig/configuration.h"
namespace android {
diff --git a/contents/include/linkerconfig/namespacebuilder.h b/contents/include/linkerconfig/namespacebuilder.h
index 45cd65a..d1e0ecf 100644
--- a/contents/include/linkerconfig/namespacebuilder.h
+++ b/contents/include/linkerconfig/namespacebuilder.h
@@ -15,14 +15,11 @@
*/
#pragma once
-#include <memory>
-#include <string>
-
#include "linkerconfig/context.h"
#include "linkerconfig/namespace.h"
-typedef std::shared_ptr<android::linkerconfig::modules::Namespace>
-NamespaceBuilder(const android::linkerconfig::contents::Context& ctx);
+typedef android::linkerconfig::modules::Namespace NamespaceBuilder(
+ const android::linkerconfig::contents::Context& ctx);
namespace android {
namespace linkerconfig {
diff --git a/contents/include/linkerconfig/sectionbuilder.h b/contents/include/linkerconfig/sectionbuilder.h
index a2e348e..0c08358 100644
--- a/contents/include/linkerconfig/sectionbuilder.h
+++ b/contents/include/linkerconfig/sectionbuilder.h
@@ -15,13 +15,10 @@
*/
#pragma once
-#include <memory>
-#include <string>
-
#include "linkerconfig/context.h"
#include "linkerconfig/section.h"
-typedef std::shared_ptr<android::linkerconfig::modules::Section> SectionBuilder(
+typedef android::linkerconfig::modules::Section SectionBuilder(
android::linkerconfig::contents::Context& ctx);
namespace android {
diff --git a/contents/namespace/conscrypt.cc b/contents/namespace/conscrypt.cc
index 459f9d6..dbf7071 100644
--- a/contents/namespace/conscrypt.cc
+++ b/contents/namespace/conscrypt.cc
@@ -19,7 +19,6 @@
#include <string>
#include <vector>
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
const std::vector<std::string> kLibsFromDefault = {"libc.so", "libm.so",
@@ -28,13 +27,13 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildConscryptNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("conscrypt", true, true);
+Namespace BuildConscryptNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("conscrypt", /*is_isolated=*/true, /*is_visible=*/true);
- ns->AddSearchPath("/apex/com.android.conscrypt/${LIB}", true, false);
- ns->CreateLink("runtime")->AddSharedLib("libandroidio.so");
- ns->CreateLink("default")->AddSharedLib(kLibsFromDefault);
+ ns.AddSearchPath("/apex/com.android.conscrypt/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/false);
+ ns.CreateLink("runtime").AddSharedLib("libandroidio.so");
+ ns.CreateLink("default").AddSharedLib(kLibsFromDefault);
return ns;
}
diff --git a/contents/namespace/media.cc b/contents/namespace/media.cc
index 335d62c..8b594a6 100644
--- a/contents/namespace/media.cc
+++ b/contents/namespace/media.cc
@@ -21,7 +21,6 @@
#include "linkerconfig/environment.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
const std::vector<std::string> kLibsFromDefaultLegacy = {
@@ -48,15 +47,15 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildMediaNamespace([
- [maybe_unused]] const Context& ctx) {
+Namespace BuildMediaNamespace([[maybe_unused]] const Context& ctx) {
bool is_legacy = android::linkerconfig::modules::IsLegacyDevice();
- auto ns = CreateNamespace("media", true, true);
- ns->AddSearchPath("/apex/com.android.media/${LIB}", true, false);
- ns->AddPermittedPath("/apex/com.android.media/${LIB}/extractors", false,
- false);
- ns->CreateLink("default")->AddSharedLib(is_legacy ? kLibsFromDefaultLegacy
- : kLibsFromDefault);
+ Namespace ns("media", /*is_isolated=*/true, /*is_visible=*/true);
+ ns.AddSearchPath("/apex/com.android.media/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/false);
+ ns.AddPermittedPath("/apex/com.android.media/${LIB}/extractors",
+ /*also_in_asan=*/false, /*with_data_asan=*/false);
+ ns.CreateLink("default").AddSharedLib(is_legacy ? kLibsFromDefaultLegacy
+ : kLibsFromDefault);
return ns;
}
diff --git a/contents/namespace/postinstall.cc b/contents/namespace/postinstall.cc
index daf9645..f7ef8e6 100644
--- a/contents/namespace/postinstall.cc
+++ b/contents/namespace/postinstall.cc
@@ -16,17 +16,15 @@
#include "linkerconfig/namespacebuilder.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildPostInstallNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("default", false, false);
- ns->AddSearchPath("/system/${LIB}");
- ns->AddSearchPath("/@{PRODUCT:product}/${LIB}");
+Namespace BuildPostInstallNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("default", /*is_isolated=*/false, /*is_visible=*/false);
+ ns.AddSearchPath("/system/${LIB}");
+ ns.AddSearchPath("/@{PRODUCT:product}/${LIB}");
return ns;
}
diff --git a/contents/namespace/resolv.cc b/contents/namespace/resolv.cc
index ef61058..d68d060 100644
--- a/contents/namespace/resolv.cc
+++ b/contents/namespace/resolv.cc
@@ -19,7 +19,6 @@
#include <string>
#include <vector>
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
const std::vector<std::string> kLibsFromDefault = {
@@ -32,12 +31,11 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildResolvNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("resolv", true, true);
- ns->AddSearchPath("/apex/com.android.resolv/${LIB}", true, false);
- auto link_to_default = ns->CreateLink("default");
- link_to_default->AddSharedLib(
+Namespace BuildResolvNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("resolv", /*is_isolated=*/true, /*is_visible=*/true);
+ ns.AddSearchPath("/apex/com.android.resolv/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/false);
+ ns.CreateLink("default").AddSharedLib(
ctx.IsSystemSection() ? kLibsFromDefault : kLibsFromUnrestrictedDefault);
return ns;
diff --git a/contents/namespace/rs.cc b/contents/namespace/rs.cc
index 784152d..dcfd5b6 100644
--- a/contents/namespace/rs.cc
+++ b/contents/namespace/rs.cc
@@ -16,30 +16,37 @@
#include "linkerconfig/namespacebuilder.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildRsNamespace([[maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("rs", true, true);
+Namespace BuildRsNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("rs", /*is_isolated=*/true, /*is_visible=*/true);
- ns->AddSearchPath("/odm/${LIB}/vndk-sp", true, true);
- ns->AddSearchPath("/vendor/${LIB}/vndk-sp", true, true);
- ns->AddSearchPath("/system/${LIB}/vndk-sp@{VNDK_VER}", true, true);
- ns->AddSearchPath("/odm/${LIB}", true, true);
- ns->AddSearchPath("/vendor/${LIB}", true, true);
+ ns.AddSearchPath("/odm/${LIB}/vndk-sp", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}/vndk-sp", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/system/${LIB}/vndk-sp@{VNDK_VER}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
- ns->AddPermittedPath("/odm/${LIB}", true, true);
- ns->AddPermittedPath("/vendor/${LIB}", true, true);
- ns->AddPermittedPath("/system/vendor/${LIB}", false, false);
- ns->AddPermittedPath("/data", true, false);
+ ns.AddPermittedPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/system/vendor/${LIB}", /*also_in_asan=*/false,
+ /*with_data_asan=*/false);
+ ns.AddPermittedPath("/data", /*also_in_asan=*/true, /*with_data_asan=*/false);
- ns->CreateLink("default")->AddSharedLib({"@{LLNDK_LIBRARIES}",
- "@{SANITIZER_RUNTIME_LIBRARIES}",
- "@{PRIVATE_LLNDK_LIBRARIES}"});
- ns->CreateLink("vndk")->AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES}");
+ ns.CreateLink("default").AddSharedLib({"@{LLNDK_LIBRARIES}",
+ "@{SANITIZER_RUNTIME_LIBRARIES}",
+ "@{PRIVATE_LLNDK_LIBRARIES}"});
+ ns.CreateLink("vndk").AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES}");
return ns;
}
diff --git a/contents/namespace/runtime.cc b/contents/namespace/runtime.cc
index 593c347..095bc01 100644
--- a/contents/namespace/runtime.cc
+++ b/contents/namespace/runtime.cc
@@ -16,19 +16,19 @@
#include "linkerconfig/namespacebuilder.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildRuntimeNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("runtime", true, !ctx.IsVendorSection());
- ns->AddSearchPath("/apex/com.android.runtime/${LIB}", true, false);
+Namespace BuildRuntimeNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("runtime", /*is_isolated=*/true,
+ /*is_visible=*/!ctx.IsVendorSection());
+ ns.AddSearchPath("/apex/com.android.runtime/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/false);
// TODO(b/119867084): Restrict to Bionic dlopen dependencies and PALette
// library when it exists.
- ns->CreateLink(ctx.IsVendorSection() ? "system" : "default", true);
+ ns.CreateLink(ctx.IsVendorSection() ? "system" : "default", true);
return ns;
}
diff --git a/contents/namespace/sphal.cc b/contents/namespace/sphal.cc
index 2fd0831..7e69f66 100644
--- a/contents/namespace/sphal.cc
+++ b/contents/namespace/sphal.cc
@@ -16,27 +16,31 @@
#include "linkerconfig/namespacebuilder.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildSphalNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("sphal", true, true);
- ns->AddSearchPath("/odm/${LIB}", true, true);
- ns->AddSearchPath("/vendor/${LIB}", true, true);
- ns->AddSearchPath("/vendor/${LIB}/hw", false, false);
+Namespace BuildSphalNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("sphal", /*is_isolated=*/true, /*is_visible=*/true);
+ ns.AddSearchPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}/hw", /*also_in_asan=*/false,
+ /*with_data_asan=*/false);
- ns->AddPermittedPath("/odm/${LIB}", true, true);
- ns->AddPermittedPath("/vendor/${LIB}", true, true);
- ns->AddPermittedPath("/system/vendor/${LIB}", false, false);
+ ns.AddPermittedPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/system/vendor/${LIB}", /*also_in_asan=*/false,
+ /*with_data_asan=*/false);
- ns->CreateLink("rs")->AddSharedLib("libRS_internal.so");
- ns->CreateLink("default")->AddSharedLib(
+ ns.CreateLink("rs").AddSharedLib("libRS_internal.so");
+ ns.CreateLink("default").AddSharedLib(
{"@{LLNDK_LIBRARIES:}", "@{SANITIZER_RUNTIME_LIBRARIES:}"});
- ns->CreateLink("vndk")->AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES:}");
+ ns.CreateLink("vndk").AddSharedLib("@{VNDK_SAMEPROCESS_LIBRARIES:}");
return ns;
}
diff --git a/contents/namespace/system.cc b/contents/namespace/system.cc
index fe9aaf4..c571054 100644
--- a/contents/namespace/system.cc
+++ b/contents/namespace/system.cc
@@ -16,20 +16,21 @@
#include "linkerconfig/namespacebuilder.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildSystemNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("system", false, false);
- ns->AddSearchPath("/system/${LIB}", true, true);
- ns->AddSearchPath("/@{PRODUCT:product}/${LIB}", true, true);
- ns->AddSearchPath("/@{PRODUCT_SERVICES}/${LIB}", true, true);
+Namespace BuildSystemNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("system", /*is_isolated=*/false, /*is_visible=*/false);
+ ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/@{PRODUCT_SERVICES}/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
- ns->CreateLink("runtime")->AddSharedLib(
+ ns.CreateLink("runtime").AddSharedLib(
{"libdexfile_external.so", "libnativebridge.so", "libnativehelper.so",
"libnativeloader.so", "libandroidicu.so"});
diff --git a/contents/namespace/systemdefault.cc b/contents/namespace/systemdefault.cc
index 9e9f8f2..ada0343 100644
--- a/contents/namespace/systemdefault.cc
+++ b/contents/namespace/systemdefault.cc
@@ -19,7 +19,6 @@
#include "linkerconfig/environment.h"
#include "linkerconfig/namespace.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
const std::vector<std::string> kLibsFromRuntimeLegacy = {
@@ -49,9 +48,9 @@
namespace {
using android::linkerconfig::modules::Namespace;
-void BuildPermittedPath(std::shared_ptr<Namespace> ns) {
+void BuildPermittedPath(Namespace& ns) {
for (const auto& path : kPermittedPaths) {
- ns->AddPermittedPath(path, true, false);
+ ns.AddPermittedPath(path, true, false);
}
}
} // namespace
@@ -59,28 +58,31 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildSystemDefaultNamespace([
- [maybe_unused]] const Context& ctx) {
+Namespace BuildSystemDefaultNamespace([[maybe_unused]] const Context& ctx) {
bool is_legacy = android::linkerconfig::modules::IsLegacyDevice();
- auto ns = CreateNamespace("default", !is_legacy, true);
+ Namespace ns("default", /*is_isolated=*/!is_legacy, /*is_visible=*/true);
- ns->AddSearchPath("/system/${LIB}", true, true);
- ns->AddSearchPath("/@{PRODUCT:product}/${LIB}", true, true);
+ ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
if (is_legacy) {
- ns->AddSearchPath("/vendor/${LIB}", true, true);
- ns->AddSearchPath("/odm/${LIB}", true, true);
+ ns.AddSearchPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
} else {
- ns->AddSearchPath("/@{PRODUCT_SERVICES:product_services}/${LIB}", true,
- true);
+ ns.AddSearchPath("/@{PRODUCT_SERVICES:product_services}/${LIB}",
+ /*also_in_asan=*/true, /*with_data_asan=*/true);
}
if (!is_legacy) {
BuildPermittedPath(ns);
}
- ns->CreateLink("runtime")->AddSharedLib(is_legacy ? kLibsFromRuntimeLegacy
- : kLibsFromRuntime);
- ns->CreateLink("resolv")->AddSharedLib("libnetd_resolv.so");
+ ns.CreateLink("runtime").AddSharedLib(is_legacy ? kLibsFromRuntimeLegacy
+ : kLibsFromRuntime);
+ ns.CreateLink("resolv").AddSharedLib("libnetd_resolv.so");
return ns;
}
diff --git a/contents/namespace/unrestricteddefault.cc b/contents/namespace/unrestricteddefault.cc
index 20bdaa6..9c8bf56 100644
--- a/contents/namespace/unrestricteddefault.cc
+++ b/contents/namespace/unrestricteddefault.cc
@@ -19,7 +19,6 @@
#include "linkerconfig/environment.h"
#include "linkerconfig/namespace.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
const std::vector<std::string> kLibsFromRuntime = {
@@ -29,16 +28,18 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildUnrestrictedDefaultNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("default", false, true);
+Namespace BuildUnrestrictedDefaultNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("default", /*is_isolated=*/false, /*is_visible=*/true);
- ns->AddSearchPath("/system/${LIB}", true, true);
- ns->AddSearchPath("/odm/${LIB}", true, true);
- ns->AddSearchPath("/vendor/${LIB}", true, true);
+ ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
- ns->CreateLink("runtime")->AddSharedLib(kLibsFromRuntime);
- ns->CreateLink("resolv")->AddSharedLib("libnetd_resolv.so");
+ ns.CreateLink("runtime").AddSharedLib(kLibsFromRuntime);
+ ns.CreateLink("resolv").AddSharedLib("libnetd_resolv.so");
return ns;
}
diff --git a/contents/namespace/vendordefault.cc b/contents/namespace/vendordefault.cc
index 5ada033..2d4a19b 100644
--- a/contents/namespace/vendordefault.cc
+++ b/contents/namespace/vendordefault.cc
@@ -18,35 +18,38 @@
#include "linkerconfig/environment.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::GetVendorVndkVersion;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildVendorDefaultNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("default", true, true);
+Namespace BuildVendorDefaultNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("default", /*is_isolated=*/true, /*is_visible=*/true);
- ns->AddSearchPath("/odm/${LIB}", true, true);
- ns->AddSearchPath("/vendor/${LIB}", true, true);
+ ns.AddSearchPath("/odm/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
if (GetVendorVndkVersion() == "27") {
- ns->AddSearchPath("/vendor/${LIB}/hw", true, true);
- ns->AddSearchPath("/vendor/${LIB}/egl", true, true);
+ ns.AddSearchPath("/vendor/${LIB}/hw", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}/egl", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
}
- ns->AddPermittedPath("/odm", true, true);
- ns->AddPermittedPath("/vendor", true, true);
- ns->AddPermittedPath("/system/vendor", false, false);
+ ns.AddPermittedPath("/odm", /*also_in_asan=*/true, /*with_data_asan=*/true);
+ ns.AddPermittedPath("/vendor", /*also_in_asan=*/true, /*with_data_asan=*/true);
+ ns.AddPermittedPath("/system/vendor", /*also_in_asan=*/false,
+ /*with_data_asan=*/false);
- ns->CreateLink("system")->AddSharedLib("@{LLNDK_LIBRARIES}");
- ns->CreateLink("vndk")->AddSharedLib(
+ ns.CreateLink("system").AddSharedLib("@{LLNDK_LIBRARIES}");
+ ns.CreateLink("vndk").AddSharedLib(
{"@{VNDK_SAMEPROCESS_LIBRARIES", "@{VNDK_CORE_LIBRARIES}"});
if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
- ns->CreateLink("vndk_in_system")
- ->AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+ ns.CreateLink("vndk_in_system")
+ .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
}
return ns;
diff --git a/contents/namespace/vndk.cc b/contents/namespace/vndk.cc
index b3e0a71..40c3fff 100644
--- a/contents/namespace/vndk.cc
+++ b/contents/namespace/vndk.cc
@@ -18,47 +18,58 @@
#include "linkerconfig/environment.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildVndkNamespace([
- [maybe_unused]] const Context& ctx) {
+Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx) {
bool is_system_section = ctx.IsSystemSection();
- auto ns = CreateNamespace("vndk", true, true);
+ Namespace ns("vndk", /*is_isolated=*/true, /*is_visible=*/true);
- ns->AddSearchPath("/odm/${LIB}/vndk-sp", true, true);
- ns->AddSearchPath("/vendor/${LIB}/vndk-sp", true, true);
- ns->AddSearchPath("/system/${LIB}/vndk-sp@{VNDK_VER}", true, true);
+ ns.AddSearchPath("/odm/${LIB}/vndk-sp", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}/vndk-sp", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/system/${LIB}/vndk-sp@{VNDK_VER}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
if (!is_system_section) {
- ns->AddSearchPath("/odm/${LIB}/vndk", true, true);
- ns->AddSearchPath("/vendor/${LIB}/vndk", true, true);
- ns->AddSearchPath("/system/${LIB}/vndk@{VNDK_VER}", true, true);
+ ns.AddSearchPath("/odm/${LIB}/vndk", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/vendor/${LIB}/vndk", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/system/${LIB}/vndk@{VNDK_VER}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
}
if (is_system_section) {
- ns->AddPermittedPath("/odm/${LIB}/hw", true, true);
- ns->AddPermittedPath("/odm/${LIB}/egl", true, true);
- ns->AddPermittedPath("/vendor/${LIB}/hw", true, true);
- ns->AddPermittedPath("/vendor/${LIB}/egl", true, true);
- ns->AddPermittedPath("/system/vendor/${LIB}/hw", false, false);
- ns->AddPermittedPath("/system/vendor/${LIB}/egl", false, false);
- ns->AddPermittedPath("/system/${LIB}/vndk-sp@{VNDK_VER}/hw", true, true);
+ ns.AddPermittedPath("/odm/${LIB}/hw", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/odm/${LIB}/egl", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/vendor/${LIB}/hw", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/vendor/${LIB}/egl", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddPermittedPath("/system/vendor/${LIB}/hw", /*also_in_asan=*/false,
+ /*with_data_asan=*/false);
+ ns.AddPermittedPath("/system/vendor/${LIB}/egl", /*also_in_asan=*/false,
+ /*with_data_asan=*/false);
+ ns.AddPermittedPath("/system/${LIB}/vndk-sp@{VNDK_VER}/hw",
+ /*also_in_asan=*/true, /*with_data_asan=*/true);
}
- ns->CreateLink(is_system_section ? "default" : "system")
- ->AddSharedLib({"@{LLNDK_LIBRARIES}", "@{SANITIZER_RUNTIME_LIBRARIES}"});
+ ns.CreateLink(is_system_section ? "default" : "system")
+ .AddSharedLib({"@{LLNDK_LIBRARIES}", "@{SANITIZER_RUNTIME_LIBRARIES}"});
if (is_system_section) {
- ns->CreateLink("sphal", true);
+ ns.CreateLink("sphal", true);
} else {
- ns->CreateLink("default", true);
+ ns.CreateLink("default", true);
if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
- ns->CreateLink("vndk_in_system")
- ->AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES");
+ ns.CreateLink("vndk_in_system")
+ .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES");
}
}
diff --git a/contents/namespace/vndkinsystem.cc b/contents/namespace/vndkinsystem.cc
index c5d2b4c..0745fcd 100644
--- a/contents/namespace/vndkinsystem.cc
+++ b/contents/namespace/vndkinsystem.cc
@@ -16,25 +16,26 @@
#include "linkerconfig/namespacebuilder.h"
-using android::linkerconfig::modules::CreateNamespace;
using android::linkerconfig::modules::Namespace;
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Namespace> BuildVndkInSystemNamespace([
- [maybe_unused]] const Context& ctx) {
- auto ns = CreateNamespace("vndk_in_system", true, true);
+Namespace BuildVndkInSystemNamespace([[maybe_unused]] const Context& ctx) {
+ Namespace ns("vndk_in_system", /*is_isolated=*/true, /*is_visible=*/true);
- ns->AddSearchPath("/system/${LIB}", true, true);
- ns->AddSearchPath("/@{PRODUCT:product}/${LIB}", true, true);
- ns->AddSearchPath("/@{PRODUCT_SERVICES:product_services}/${LIB}", true, true);
+ ns.AddSearchPath("/system/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", /*also_in_asan=*/true,
+ /*with_data_asan=*/true);
+ ns.AddSearchPath("/@{PRODUCT_SERVICES:product_services}/${LIB}",
+ /*also_in_asan=*/true, /*with_data_asan=*/true);
- ns->AddWhitelisted("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+ ns.AddWhitelisted("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
- ns->CreateLink("system")->AddSharedLib(
+ ns.CreateLink("system").AddSharedLib(
{"@{LLNDK_LIBRARIES}", "@{SANITIZER_RUNTIME_LIBRARIES}"});
- ns->CreateLink("vndk", true);
+ ns.CreateLink("vndk", true);
return ns;
}
diff --git a/contents/section/legacy.cc b/contents/section/legacy.cc
index 1eeac69..89e7c04 100644
--- a/contents/section/legacy.cc
+++ b/contents/section/legacy.cc
@@ -34,17 +34,17 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Section> BuildLegacySection(Context& ctx) {
+Section BuildLegacySection(Context& ctx) {
ctx.SetCurrentSection(SectionType::System);
- std::vector<std::shared_ptr<Namespace>> namespaces;
+ std::vector<Namespace> namespaces;
- namespaces.push_back(BuildSystemDefaultNamespace(ctx));
- namespaces.push_back(BuildRuntimeNamespace(ctx));
- namespaces.push_back(BuildMediaNamespace(ctx));
- namespaces.push_back(BuildConscryptNamespace(ctx));
- namespaces.push_back(BuildResolvNamespace(ctx));
+ namespaces.emplace_back(BuildSystemDefaultNamespace(ctx));
+ namespaces.emplace_back(BuildRuntimeNamespace(ctx));
+ namespaces.emplace_back(BuildMediaNamespace(ctx));
+ namespaces.emplace_back(BuildConscryptNamespace(ctx));
+ namespaces.emplace_back(BuildResolvNamespace(ctx));
- return std::make_shared<Section>("legacy", kLegacyBinaryPath, namespaces);
+ return Section("legacy", kLegacyBinaryPath, std::move(namespaces));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/section/postinstall.cc b/contents/section/postinstall.cc
index f780fcf..8aa8f16 100644
--- a/contents/section/postinstall.cc
+++ b/contents/section/postinstall.cc
@@ -29,13 +29,13 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Section> BuildPostInstallSection(Context& ctx) {
+Section BuildPostInstallSection(Context& ctx) {
ctx.SetCurrentSection(SectionType::Other);
- std::vector<std::shared_ptr<Namespace>> namespaces;
+ std::vector<Namespace> namespaces;
- namespaces.push_back(BuildPostInstallNamespace(ctx));
+ namespaces.emplace_back(BuildPostInstallNamespace(ctx));
- return std::make_shared<Section>("postinstall", kBinaryPath, namespaces);
+ return Section("postinstall", kBinaryPath, std::move(namespaces));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/section/system.cc b/contents/section/system.cc
index 8465172..9b2f9e2 100644
--- a/contents/section/system.cc
+++ b/contents/section/system.cc
@@ -35,20 +35,20 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Section> BuildSystemSection(Context& ctx) {
+Section BuildSystemSection(Context& ctx) {
ctx.SetCurrentSection(SectionType::System);
- std::vector<std::shared_ptr<Namespace>> namespaces;
+ std::vector<Namespace> namespaces;
- namespaces.push_back(BuildSystemDefaultNamespace(ctx));
- namespaces.push_back(BuildRuntimeNamespace(ctx));
- namespaces.push_back(BuildMediaNamespace(ctx));
- namespaces.push_back(BuildConscryptNamespace(ctx));
- namespaces.push_back(BuildResolvNamespace(ctx));
- namespaces.push_back(BuildSphalNamespace(ctx));
- namespaces.push_back(BuildRsNamespace(ctx));
- namespaces.push_back(BuildVndkNamespace(ctx));
+ namespaces.emplace_back(BuildSystemDefaultNamespace(ctx));
+ namespaces.emplace_back(BuildRuntimeNamespace(ctx));
+ namespaces.emplace_back(BuildMediaNamespace(ctx));
+ namespaces.emplace_back(BuildConscryptNamespace(ctx));
+ namespaces.emplace_back(BuildResolvNamespace(ctx));
+ namespaces.emplace_back(BuildSphalNamespace(ctx));
+ namespaces.emplace_back(BuildRsNamespace(ctx));
+ namespaces.emplace_back(BuildVndkNamespace(ctx));
- return std::make_shared<Section>("system", kBinaryPath, namespaces);
+ return Section("system", kBinaryPath, std::move(namespaces));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/section/unrestricted.cc b/contents/section/unrestricted.cc
index 8003c34..8057f5a 100644
--- a/contents/section/unrestricted.cc
+++ b/contents/section/unrestricted.cc
@@ -33,17 +33,17 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Section> BuildUnrestrictedSection(Context& ctx) {
+Section BuildUnrestrictedSection(Context& ctx) {
ctx.SetCurrentSection(SectionType::Other);
- std::vector<std::shared_ptr<Namespace>> namespaces;
+ std::vector<Namespace> namespaces;
- namespaces.push_back(BuildUnrestrictedDefaultNamespace(ctx));
- namespaces.push_back(BuildRuntimeNamespace(ctx));
- namespaces.push_back(BuildMediaNamespace(ctx));
- namespaces.push_back(BuildConscryptNamespace(ctx));
- namespaces.push_back(BuildResolvNamespace(ctx));
+ namespaces.emplace_back(BuildUnrestrictedDefaultNamespace(ctx));
+ namespaces.emplace_back(BuildRuntimeNamespace(ctx));
+ namespaces.emplace_back(BuildMediaNamespace(ctx));
+ namespaces.emplace_back(BuildConscryptNamespace(ctx));
+ namespaces.emplace_back(BuildResolvNamespace(ctx));
- return std::make_shared<Section>("unrestricted", kBinaryPath, namespaces);
+ return Section("unrestricted", kBinaryPath, std::move(namespaces));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/section/vendor.cc b/contents/section/vendor.cc
index 952cc42..3079c6b 100644
--- a/contents/section/vendor.cc
+++ b/contents/section/vendor.cc
@@ -40,19 +40,19 @@
namespace android {
namespace linkerconfig {
namespace contents {
-std::shared_ptr<Section> BuildVendorSection(Context& ctx) {
+Section BuildVendorSection(Context& ctx) {
ctx.SetCurrentSection(SectionType::Vendor);
- std::vector<std::shared_ptr<Namespace>> namespaces;
+ std::vector<Namespace> namespaces;
- namespaces.push_back(BuildVendorDefaultNamespace(ctx));
- namespaces.push_back(BuildRuntimeNamespace(ctx));
- namespaces.push_back(BuildVndkNamespace(ctx));
- namespaces.push_back(BuildSystemNamespace(ctx));
+ namespaces.emplace_back(BuildVendorDefaultNamespace(ctx));
+ namespaces.emplace_back(BuildRuntimeNamespace(ctx));
+ namespaces.emplace_back(BuildVndkNamespace(ctx));
+ namespaces.emplace_back(BuildSystemNamespace(ctx));
if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
- namespaces.push_back(BuildVndkInSystemNamespace(ctx));
+ namespaces.emplace_back(BuildVndkInSystemNamespace(ctx));
}
- return std::make_shared<Section>("vendor", kBinaryPath, namespaces);
+ return Section("vendor", kBinaryPath, std::move(namespaces));
}
} // namespace contents
} // namespace linkerconfig
diff --git a/contents/tests/backward_compatibility/testbase.h b/contents/tests/backward_compatibility/testbase.h
index 06a21b4..c21c01b 100644
--- a/contents/tests/backward_compatibility/testbase.h
+++ b/contents/tests/backward_compatibility/testbase.h
@@ -15,8 +15,6 @@
*/
#pragma once
-#include <memory>
-
#include "linkerconfig/variables.h"
inline void MockVariables(std::string vndk_ver = "Q") {
diff --git a/modules/configuration.cc b/modules/configuration.cc
index 6a5dcc8..5cf7cd2 100644
--- a/modules/configuration.cc
+++ b/modules/configuration.cc
@@ -23,7 +23,7 @@
BinaryPathMap binary_paths_with_priority;
for (auto& section : sections_) {
- section->CollectBinaryPaths(binary_paths_with_priority);
+ section.CollectBinaryPaths(binary_paths_with_priority);
}
for (auto& binary_path : binary_paths_with_priority) {
@@ -31,14 +31,14 @@
}
for (auto& section : sections_) {
- section->WriteConfig(writer);
+ section.WriteConfig(writer);
}
}
-std::shared_ptr<Section> Configuration::GetSection(const std::string& name) {
+Section* Configuration::GetSection(const std::string& name) {
for (auto& section : sections_) {
- if (section->GetName() == name) {
- return section;
+ if (section.GetName() == name) {
+ return §ion;
}
}
diff --git a/modules/configwriter.cc b/modules/configwriter.cc
index aed8abf..878d0fb 100644
--- a/modules/configwriter.cc
+++ b/modules/configwriter.cc
@@ -19,7 +19,6 @@
#include <cstdarg>
#include <cstdio>
#include <iostream>
-#include <memory>
#include <regex>
#include "linkerconfig/log.h"
diff --git a/modules/include/linkerconfig/configuration.h b/modules/include/linkerconfig/configuration.h
index f2cbe4e..8cff279 100644
--- a/modules/include/linkerconfig/configuration.h
+++ b/modules/include/linkerconfig/configuration.h
@@ -15,7 +15,6 @@
*/
#pragma once
-#include <memory>
#include <string>
#include <vector>
@@ -27,16 +26,19 @@
namespace modules {
class Configuration {
public:
- Configuration(std::vector<std::shared_ptr<Section>> sections)
- : sections_(sections) {
+ explicit Configuration(std::vector<Section> sections)
+ : sections_(std::move(sections)) {
}
+ Configuration(const Configuration&) = delete;
+ Configuration(Configuration&&) = default;
+
void WriteConfig(ConfigWriter& writer);
// For test usage
- std::shared_ptr<Section> GetSection(const std::string& name);
+ Section* GetSection(const std::string& name);
private:
- std::vector<std::shared_ptr<Section>> sections_;
+ std::vector<Section> sections_;
};
} // namespace modules
} // namespace linkerconfig
diff --git a/modules/include/linkerconfig/link.h b/modules/include/linkerconfig/link.h
index ce0d3b9..53a7b66 100644
--- a/modules/include/linkerconfig/link.h
+++ b/modules/include/linkerconfig/link.h
@@ -33,6 +33,9 @@
target_namespace_(target_namespace),
allow_all_shared_libs_(allow_all_shared_libs) {
}
+ Link(const Link&) = delete;
+ Link(Link&&) = default;
+
template <typename T, typename... Args>
void AddSharedLib(T&& lib_name, Args&&... lib_names);
void AddSharedLib(std::vector<std::string> lib_names);
diff --git a/modules/include/linkerconfig/namespace.h b/modules/include/linkerconfig/namespace.h
index 88ed85b..3289454 100644
--- a/modules/include/linkerconfig/namespace.h
+++ b/modules/include/linkerconfig/namespace.h
@@ -22,6 +22,8 @@
#include "linkerconfig/configwriter.h"
#include "linkerconfig/link.h"
+#include "linkerconfig/log.h"
+
namespace android {
namespace linkerconfig {
namespace modules {
@@ -32,6 +34,9 @@
: is_isolated_(is_isolated), is_visible_(is_visible), name_(name) {
}
+ Namespace(const Namespace& ns) = delete;
+ Namespace(Namespace&& ns) = default;
+
// Add path to search path
// This function will add path to namespace.<<namespace>>.search.paths
// If also_in_asan is true, this will add path also to
@@ -69,8 +74,8 @@
// namespace.xxx.asan.permitted.paths += /data/asan/system/${LIB}
void AddPermittedPath(const std::string& path, bool also_in_asan = true,
bool with_data_asan = true);
- std::shared_ptr<Link> CreateLink(const std::string& target_namespace,
- bool allow_all_shared_libs = false);
+ Link& CreateLink(const std::string& target_namespace,
+ bool allow_all_shared_libs = false);
void WriteConfig(ConfigWriter& writer);
void AddWhitelisted(const std::string& path);
@@ -91,14 +96,10 @@
std::vector<std::string> asan_search_paths_;
std::vector<std::string> asan_permitted_paths_;
std::vector<std::string> whitelisted_;
- std::map<std::string, std::shared_ptr<Link>> links_;
+ std::map<std::string, Link> links_;
void WritePathString(ConfigWriter& writer, const std::string& path_type,
const std::vector<std::string>& path_list);
};
-
-std::shared_ptr<Namespace> CreateNamespace(const std::string& name,
- bool is_isolated = false,
- bool is_visible = false);
} // namespace modules
} // namespace linkerconfig
} // namespace android
\ No newline at end of file
diff --git a/modules/include/linkerconfig/section.h b/modules/include/linkerconfig/section.h
index 530b922..2a40564 100644
--- a/modules/include/linkerconfig/section.h
+++ b/modules/include/linkerconfig/section.h
@@ -16,7 +16,6 @@
#pragma once
#include <map>
-#include <memory>
#include <string>
#include <utility>
#include <vector>
@@ -39,20 +38,26 @@
class Section {
public:
Section(const std::string& name, BinaryPathList binary_paths,
- std::vector<std::shared_ptr<Namespace>> namespaces)
- : name_(name), binary_paths_(binary_paths), namespaces_(namespaces) {
+ std::vector<Namespace> namespaces)
+ : name_(name),
+ binary_paths_(binary_paths),
+ namespaces_(std::move(namespaces)) {
}
+
+ Section(const Section&) = delete;
+ Section(Section&&) = default;
+
void WriteConfig(ConfigWriter& writer);
void CollectBinaryPaths(BinaryPathMap& binary_paths);
// For test usage
- std::shared_ptr<Namespace> GetNamespace(const std::string& namespace_name);
+ Namespace* GetNamespace(const std::string& namespace_name);
std::string GetName();
private:
const std::string name_;
BinaryPathList binary_paths_;
- std::vector<std::shared_ptr<Namespace>> namespaces_;
+ std::vector<Namespace> namespaces_;
};
} // namespace modules
} // namespace linkerconfig
diff --git a/modules/namespace.cc b/modules/namespace.cc
index ff50202..9257228 100644
--- a/modules/namespace.cc
+++ b/modules/namespace.cc
@@ -50,18 +50,17 @@
}
}
-std::shared_ptr<Link> Namespace::CreateLink(const std::string& target_namespace,
- bool allow_all_shared_libs) {
- auto new_link =
- std::make_shared<Link>(name_, target_namespace, allow_all_shared_libs);
+Link& Namespace::CreateLink(const std::string& target_namespace,
+ bool allow_all_shared_libs) {
+ Link new_link(name_, target_namespace, allow_all_shared_libs);
if (links_.find(target_namespace) != links_.end()) {
LOG(INFO) << "Link to " << target_namespace
<< " already exists. Overwriting link.";
}
- links_[target_namespace] = new_link;
- return new_link;
+ links_.emplace(target_namespace, std::move(new_link));
+ return links_.find(target_namespace)->second;
}
void Namespace::WriteConfig(ConfigWriter& writer) {
@@ -100,7 +99,7 @@
writer.WriteLine("links = " + link_list);
for (auto& link : links_) {
- link.second->WriteConfig(writer);
+ link.second.WriteConfig(writer);
}
}
@@ -153,11 +152,6 @@
(!also_in_asan || !with_data_asan ||
FindFromPathList(asan_permitted_paths_, kDataAsanPath + path));
}
-
-std::shared_ptr<Namespace> CreateNamespace(const std::string& name,
- bool is_isolated, bool is_visible) {
- return std::make_shared<Namespace>(name, is_isolated, is_visible);
-}
} // namespace modules
} // namespace linkerconfig
} // namespace android
\ No newline at end of file
diff --git a/modules/section.cc b/modules/section.cc
index e3b0243..765c4fc 100644
--- a/modules/section.cc
+++ b/modules/section.cc
@@ -28,12 +28,12 @@
bool is_first = true;
for (auto& ns : namespaces_) {
- if (ns->GetName() != "default") {
+ if (ns.GetName() != "default") {
if (!is_first) {
additional_namespaces += ",";
}
- additional_namespaces += ns->GetName();
+ additional_namespaces += ns.GetName();
is_first = false;
}
}
@@ -43,7 +43,7 @@
}
for (auto& ns : namespaces_) {
- ns->WriteConfig(writer);
+ ns.WriteConfig(writer);
}
}
@@ -55,11 +55,10 @@
}
}
-std::shared_ptr<Namespace> Section::GetNamespace(
- const std::string& namespace_name) {
+Namespace* Section::GetNamespace(const std::string& namespace_name) {
for (auto& ns : namespaces_) {
- if (ns->GetName() == namespace_name) {
- return ns;
+ if (ns.GetName() == namespace_name) {
+ return &ns;
}
}
diff --git a/modules/tests/configuration_test.cc b/modules/tests/configuration_test.cc
index b8f39b8..0ad2107 100644
--- a/modules/tests/configuration_test.cc
+++ b/modules/tests/configuration_test.cc
@@ -91,34 +91,37 @@
)";
TEST(linkerconfig_configuration, generate_configuration) {
- std::vector<std::shared_ptr<Section>> sections;
+ std::vector<Section> sections;
- std::vector<std::shared_ptr<Namespace>> system_namespaces;
+ std::vector<Namespace> system_namespaces;
BinaryPathList system_binary_path = {{"/system/bin", kDefaultPriority},
{"/system/xbin", kDefaultPriority},
{"/product/bin", kLowPriority + 10}};
- system_namespaces.push_back(CreateNamespaceWithLinks(
+ system_namespaces.emplace_back(CreateNamespaceWithLinks(
"default", false, false, "namespace1", "namespace2"));
- system_namespaces.push_back(
+ system_namespaces.emplace_back(
CreateNamespaceWithPaths("namespace1", false, false));
- system_namespaces.push_back(
+ system_namespaces.emplace_back(
CreateNamespaceWithPaths("namespace2", false, false));
- sections.push_back(std::make_shared<Section>("system", system_binary_path,
- system_namespaces));
+ Section system_section("system", system_binary_path,
+ std::move(system_namespaces));
+ sections.emplace_back(std::move(system_section));
- std::vector<std::shared_ptr<Namespace>> vendor_namespaces;
+ std::vector<Namespace> vendor_namespaces;
BinaryPathList vendor_binary_path = {{"/odm/bin", kLowPriority},
{"/vendor/bin", kLowPriority},
{"/data/nativetest/odm", kLowPriority}};
- vendor_namespaces.push_back(CreateNamespaceWithPaths("default", false, false));
+ vendor_namespaces.emplace_back(
+ CreateNamespaceWithPaths("default", false, false));
- sections.push_back(std::make_shared<Section>("vendor", vendor_binary_path,
- vendor_namespaces));
+ Section vendor_section("vendor", vendor_binary_path,
+ std::move(vendor_namespaces));
+ sections.emplace_back(std::move(vendor_section));
- Configuration conf(sections);
+ Configuration conf(std::move(sections));
android::linkerconfig::modules::ConfigWriter writer;
conf.WriteConfig(writer);
diff --git a/modules/tests/modules_testbase.h b/modules/tests/modules_testbase.h
index 5988859..10298d3 100644
--- a/modules/tests/modules_testbase.h
+++ b/modules/tests/modules_testbase.h
@@ -15,33 +15,30 @@
*/
#pragma once
-#include <memory>
-
#include "linkerconfig/namespace.h"
using namespace android::linkerconfig::modules;
-inline std::shared_ptr<Namespace> CreateNamespaceWithPaths(std::string name,
- bool is_isolated,
- bool is_visible) {
- auto ns = CreateNamespace(name, is_isolated, is_visible);
- ns->AddSearchPath("/search_path1");
- ns->AddSearchPath("/search_path2", true, false);
- ns->AddSearchPath("/search_path3", false, false);
- ns->AddPermittedPath("/permitted_path1");
- ns->AddPermittedPath("/permitted_path2", true, false);
- ns->AddPermittedPath("/permitted_path3", false, false);
+inline Namespace CreateNamespaceWithPaths(std::string name, bool is_isolated,
+ bool is_visible) {
+ Namespace ns(name, is_isolated, is_visible);
+ ns.AddSearchPath("/search_path1");
+ ns.AddSearchPath("/search_path2", true, false);
+ ns.AddSearchPath("/search_path3", false, false);
+ ns.AddPermittedPath("/permitted_path1");
+ ns.AddPermittedPath("/permitted_path2", true, false);
+ ns.AddPermittedPath("/permitted_path3", false, false);
return ns;
}
-inline std::shared_ptr<Namespace> CreateNamespaceWithLinks(
- std::string name, bool is_isolated, bool is_visible, std::string target_1,
- std::string target_2) {
- auto ns = CreateNamespaceWithPaths(name, is_isolated, is_visible);
- auto link = ns->CreateLink(target_1, false);
- link->AddSharedLib("lib1.so", "lib2.so", "lib3.so");
+inline Namespace CreateNamespaceWithLinks(std::string name, bool is_isolated,
+ bool is_visible, std::string target_1,
+ std::string target_2) {
+ Namespace ns = CreateNamespaceWithPaths(name, is_isolated, is_visible);
+ auto& link = ns.CreateLink(target_1, false);
+ link.AddSharedLib("lib1.so", "lib2.so", "lib3.so");
- ns->CreateLink(target_2, true);
+ ns.CreateLink(target_2, true);
return ns;
}
\ No newline at end of file
diff --git a/modules/tests/namespace_test.cc b/modules/tests/namespace_test.cc
index 4fe58f7..9ec99c1 100644
--- a/modules/tests/namespace_test.cc
+++ b/modules/tests/namespace_test.cc
@@ -78,7 +78,7 @@
TEST(linkerconfig_namespace, simple_namespace) {
android::linkerconfig::modules::ConfigWriter writer;
auto ns = CreateNamespaceWithPaths("test_namespace", false, false);
- ns->WriteConfig(writer);
+ ns.WriteConfig(writer);
auto config = writer.ToString();
ASSERT_EQ(config, kExpectedSimpleNamespaceConfig);
@@ -89,7 +89,7 @@
auto ns = CreateNamespaceWithLinks("test_namespace", true, true,
"target_namespace1", "target_namespace2");
- ns->WriteConfig(writer);
+ ns.WriteConfig(writer);
auto config = writer.ToString();
ASSERT_EQ(config, kExpectedNamespaceWithLinkConfig);
@@ -98,9 +98,9 @@
TEST(linkerconfig_namespace, namespace_with_whitelisted) {
android::linkerconfig::modules::ConfigWriter writer;
auto ns = CreateNamespaceWithPaths("test_namespace", false, false);
- ns->AddWhitelisted("whitelisted_path1");
- ns->AddWhitelisted("whitelisted_path2");
- ns->WriteConfig(writer);
+ ns.AddWhitelisted("whitelisted_path1");
+ ns.AddWhitelisted("whitelisted_path2");
+ ns.WriteConfig(writer);
auto config = writer.ToString();
diff --git a/modules/tests/section_test.cc b/modules/tests/section_test.cc
index 36df728..6c3d181 100644
--- a/modules/tests/section_test.cc
+++ b/modules/tests/section_test.cc
@@ -103,17 +103,17 @@
TEST(linkerconfig_section, section_with_namespaces) {
ConfigWriter writer;
- std::vector<std::shared_ptr<Namespace>> namespaces;
+ std::vector<Namespace> namespaces;
- namespaces.push_back(CreateNamespaceWithLinks("default", true, true,
- "namespace1", "namespace2"));
- namespaces.push_back(CreateNamespaceWithLinks("namespace1", false, false,
- "default", "namespace2"));
- namespaces.push_back(CreateNamespaceWithPaths("namespace2", false, false));
+ namespaces.emplace_back(CreateNamespaceWithLinks("default", true, true,
+ "namespace1", "namespace2"));
+ namespaces.emplace_back(CreateNamespaceWithLinks("namespace1", false, false,
+ "default", "namespace2"));
+ namespaces.emplace_back(CreateNamespaceWithPaths("namespace2", false, false));
BinaryPathList empty_list;
- Section section("test_section", empty_list, namespaces);
+ Section section("test_section", empty_list, std::move(namespaces));
section.WriteConfig(writer);
auto config = writer.ToString();
@@ -123,12 +123,12 @@
TEST(linkerconfig_section, section_with_one_namespace) {
android::linkerconfig::modules::ConfigWriter writer;
- std::vector<std::shared_ptr<Namespace>> namespaces;
- namespaces.push_back(CreateNamespaceWithPaths("default", false, false));
+ std::vector<Namespace> namespaces;
+ namespaces.emplace_back(CreateNamespaceWithPaths("default", false, false));
BinaryPathList empty_list;
- Section section("test_section", empty_list, namespaces);
+ Section section("test_section", empty_list, std::move(namespaces));
section.WriteConfig(writer);
auto config = writer.ToString();
ASSERT_EQ(config, kSectionWithOneNamespaceExpectedResult);
@@ -138,8 +138,8 @@
BinaryPathList binary_paths = {{"binary_path2", kLowPriority},
{"binary_path3", kLowPriority + 10},
{"binary_path1", kDefaultPriority}};
- std::vector<std::shared_ptr<Namespace>> empty_namespace;
- Section section("test_section", binary_paths, empty_namespace);
+ std::vector<Namespace> empty_namespace;
+ Section section("test_section", binary_paths, std::move(empty_namespace));
android::linkerconfig::modules::BinaryPathMap paths;
section.CollectBinaryPaths(paths);