• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // SP-HAL(Sameprocess-HAL)s are the only vendor libraries that are allowed to be
18 // loaded inside system processes. libEGL_<chipset>.so, libGLESv2_<chipset>.so,
19 // android.hardware.graphics.mapper@2.0-impl.so, etc are SP-HALs.
20 //
21 // This namespace is exclusivly for SP-HALs. When the framework tries to
22 // dynamically load SP-HALs, android_dlopen_ext() is used to explicitly specify
23 // that they should be searched and loaded from this namespace.
24 //
25 // Note that there is no link from the default namespace to this namespace.
26 
27 #include "linkerconfig/namespacebuilder.h"
28 
29 using android::linkerconfig::modules::Namespace;
30 
31 namespace android {
32 namespace linkerconfig {
33 namespace contents {
BuildSphalNamespace(const Context & ctx)34 Namespace BuildSphalNamespace([[maybe_unused]] const Context& ctx) {
35   // Visible to allow use with android_dlopen_ext, and with
36   // android_link_namespaces in libnativeloader.
37   Namespace ns("sphal",
38                /*is_isolated=*/!ctx.IsUnrestrictedSection(),
39                /*is_visible=*/true);
40   ns.AddSearchPath("/odm/${LIB}");
41   ns.AddSearchPath("/vendor/${LIB}");
42   ns.AddSearchPath("/vendor/${LIB}/egl");
43   ns.AddSearchPath("/vendor/${LIB}/hw");
44 
45   ns.AddPermittedPath("/odm/${LIB}");
46   ns.AddPermittedPath("/vendor/${LIB}");
47   ns.AddPermittedPath("/system/vendor/${LIB}");
48 
49   for (const auto& apex : ctx.GetApexModules()) {
50     for (const auto& contribution : apex.contributions) {
51       if (contribution.namespace_name == "sphal") {
52         for (const auto& rel_path : contribution.paths) {
53           std::string path = "/apex/" + apex.name + "/" + rel_path;
54           ns.AddSearchPath(path);
55           ns.AddPermittedPath(std::move(path));
56         }
57       }
58     }
59   }
60 
61   if (ctx.IsApexBinaryConfig() && !ctx.IsVndkAvailable()) {
62     // If device is legacy, let Sphal libraries access to system lib path for
63     // VNDK-SP libraries
64     ns.AddSearchPath("/system/${LIB}");
65     ns.AddPermittedPath("/system/${LIB}");
66   }
67 
68   if (ctx.IsApexBinaryConfig()) {
69     if (ctx.IsVndkAvailable()) {
70       ns.AddRequires(std::vector{":vndksp"});
71       ns.GetLink(ctx.GetSystemNamespaceName())
72           .AddSharedLib(Var("LLNDK_LIBRARIES_VENDOR", ""));
73     }
74   } else {
75     // Once in this namespace, access to libraries in /system/lib is restricted.
76     // Only libs listed here can be used. Order is important here as the
77     // namespaces are tried in this order. rs should be before vndk because both
78     // are capable of loading libRS_internal.so
79     if (ctx.IsSystemSection() || ctx.IsUnrestrictedSection()) {
80       ns.GetLink("rs").AddSharedLib("libRS_internal.so");
81     }
82     ns.GetLink(ctx.GetSystemNamespaceName())
83         .AddSharedLib(Var("LLNDK_LIBRARIES_VENDOR", ""));
84     ns.GetLink("vndk").AddSharedLib(
85         Var("VNDK_SAMEPROCESS_LIBRARIES_VENDOR", ""));
86     ns.AddRequires(std::vector{"libneuralnetworks.so"});
87   }
88 
89   return ns;
90 }
91 }  // namespace contents
92 }  // namespace linkerconfig
93 }  // namespace android
94