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 // [email protected], 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 #include "linkerconfig/environment.h"
30
31 #include <android-base/strings.h>
32
33 using android::linkerconfig::modules::Namespace;
34
35 namespace android {
36 namespace linkerconfig {
37 namespace contents {
BuildSphalNamespace(const Context & ctx)38 Namespace BuildSphalNamespace([[maybe_unused]] const Context& ctx) {
39 // Visible to allow use with android_dlopen_ext, and with
40 // android_link_namespaces in libnativeloader.
41 Namespace ns("sphal",
42 /*is_isolated=*/!ctx.IsUnrestrictedSection(),
43 /*is_visible=*/true);
44 ns.AddSearchPath("/odm/${LIB}");
45 ns.AddSearchPath("/vendor/${LIB}");
46 ns.AddSearchPath("/vendor/${LIB}/egl");
47 ns.AddSearchPath("/vendor/${LIB}/hw");
48
49 ns.AddPermittedPath("/odm/${LIB}");
50 ns.AddPermittedPath("/vendor/${LIB}");
51 ns.AddPermittedPath("/vendor/odm/${LIB}");
52 ns.AddPermittedPath("/system/vendor/${LIB}");
53
54 // TODO(b/326839235) Remove access to data once renderscript is deprecated.
55 if (!android::linkerconfig::modules::IsVendorVndkVersionDefined()) {
56 ns.AddPermittedPath("/data");
57 ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("libft2.so");
58 }
59
60 if (ctx.IsApexBinaryConfig() &&
61 !android::linkerconfig::modules::IsTreblelizedDevice()) {
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 AddLlndkLibraries(ctx, &ns, VndkUserPartition::Vendor);
69
70 if (ctx.IsApexBinaryConfig()) {
71 if (android::linkerconfig::modules::IsVendorVndkVersionDefined()) {
72 ns.AddRequires(std::vector{":vndksp"});
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 if (android::linkerconfig::modules::IsVendorVndkVersionDefined()) {
83 ns.GetLink("vndk").AddSharedLib(
84 Var("VNDK_SAMEPROCESS_LIBRARIES_VENDOR", ""));
85 }
86 }
87
88 return ns;
89 }
90 } // namespace contents
91 } // namespace linkerconfig
92 } // namespace android
93