1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // This namespace is exclusively for vndk-sp libs. 18 19 #include "linkerconfig/environment.h" 20 #include "linkerconfig/namespacebuilder.h" 21 22 using android::linkerconfig::modules::Namespace; 23 24 namespace android { 25 namespace linkerconfig { 26 namespace contents { 27 Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx, 28 VndkUserPartition vndk_user) { 29 bool is_system_or_unrestricted_section = ctx.IsSystemSection() || 30 ctx.IsUnrestrictedSection(); 31 if (ctx.IsApexBinaryConfig()) { 32 is_system_or_unrestricted_section = ctx.GetCurrentApex().InSystem(); 33 } 34 // In the system section, we need to have an additional vndk namespace for 35 // product apps. We must have a different name "vndk_product" for this 36 // namespace. "vndk_product" namespace is used only from the native_loader for 37 // product apps. 38 const char* name; 39 if (is_system_or_unrestricted_section && 40 vndk_user == VndkUserPartition::Product) { 41 name = "vndk_product"; 42 } else { 43 name = "vndk"; 44 } 45 46 // Isolated and visible when used in the [system] or [unrestricted] section to 47 // allow links to be created at runtime, e.g. through android_link_namespaces 48 // in libnativeloader. Otherwise namespace should be isolated but not visible 49 // so namespace itself keep strict and links would not be modified at runtime. 50 Namespace ns(name, 51 /*is_isolated=*/true, 52 /*is_visible=*/is_system_or_unrestricted_section); 53 54 std::vector<std::string> lib_paths; 55 std::string vndk_version; 56 if (vndk_user == VndkUserPartition::Product) { 57 lib_paths = {Var("PRODUCT") + "/${LIB}"}; 58 vndk_version = Var("PRODUCT_VNDK_VERSION"); 59 } else { 60 // default for vendor 61 lib_paths = {"/odm/${LIB}", "/vendor/${LIB}"}; 62 vndk_version = Var("VENDOR_VNDK_VERSION"); 63 } 64 65 // Search order: 66 // 1. VNDK Extensions 67 // 2. VNDK APEX 68 // 3. vendor/lib or product/lib to allow extensions to use them 69 70 // 1. VNDK Extensions 71 for (const auto& lib_path : lib_paths) { 72 ns.AddSearchPath(lib_path + "/vndk-sp"); 73 if (!is_system_or_unrestricted_section) { 74 ns.AddSearchPath(lib_path + "/vndk"); 75 } 76 } 77 78 // 2. VNDK APEX 79 ns.AddSearchPath("/apex/com.android.vndk.v" + vndk_version + "/${LIB}"); 80 81 if (vndk_user == VndkUserPartition::Vendor) { 82 // It is for vendor sp-hal 83 ns.AddPermittedPath("/odm/${LIB}/hw"); 84 ns.AddPermittedPath("/odm/${LIB}/egl"); 85 ns.AddPermittedPath("/vendor/${LIB}/hw"); 86 ns.AddPermittedPath("/vendor/${LIB}/egl"); 87 ns.AddPermittedPath("/system/vendor/${LIB}/hw"); 88 ns.AddPermittedPath("/system/vendor/${LIB}/egl"); 89 90 // This is exceptionally required since android.hidl.memory@1.0-impl.so is here 91 ns.AddPermittedPath("/apex/com.android.vndk.v" + 92 Var("VENDOR_VNDK_VERSION") + "/${LIB}/hw"); 93 } 94 95 // 3. vendor/lib or product/lib 96 for (const auto& lib_path : lib_paths) { 97 ns.AddSearchPath(lib_path); 98 } 99 100 // For the non-system section, the links should be identical to that of the 101 // 'vndk_in_system' namespace, except the links to 'default' and 'vndk_in_system'. 102 if (vndk_user == VndkUserPartition::Product) { 103 ns.GetLink(ctx.GetSystemNamespaceName()) 104 .AddSharedLib({Var("LLNDK_LIBRARIES_PRODUCT")}); 105 } else { 106 ns.GetLink(ctx.GetSystemNamespaceName()) 107 .AddSharedLib({Var("LLNDK_LIBRARIES_VENDOR")}); 108 } 109 110 if (ctx.IsProductSection() || ctx.IsVendorSection()) { 111 if (android::linkerconfig::modules::IsVndkInSystemNamespace()) { 112 ns.GetLink("vndk_in_system") 113 .AddSharedLib(Var("VNDK_USING_CORE_VARIANT_LIBRARIES")); 114 } 115 } 116 117 ns.AddRequires(std::vector{"libneuralnetworks.so"}); 118 119 return ns; 120 } 121 } // namespace contents 122 } // namespace linkerconfig 123 } // namespace android 124