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 exposes externally accessible libraries from the ART APEX.
18 // Keep in sync with the "art" namespace in art/build/apex/ld.config.txt.
19
20 #include "linkerconfig/namespacebuilder.h"
21
22 using android::linkerconfig::modules::ApexInfo;
23 using android::linkerconfig::modules::Namespace;
24
25 namespace android {
26 namespace linkerconfig {
27 namespace contents {
28
BuildArtNamespace(const Context & ctx,const ApexInfo & apex)29 Namespace BuildArtNamespace([[maybe_unused]] const Context& ctx,
30 [[maybe_unused]] const ApexInfo& apex) {
31 // Make the namespace visible to allow links to be created at runtime, e.g.
32 // through android_link_namespaces in libnativeloader. That is not applicable
33 // to the vendor section.
34 Namespace ns(apex.namespace_name,
35 /*is_isolated=*/true,
36 /*is_visible=*/!ctx.IsVendorSection());
37 InitializeWithApex(ns, apex);
38
39 if (ctx.IsApexBinaryConfig()) {
40 // JVMTI libraries used in ART testing are located under /data; dalvikvm has
41 // to be able to dlopen them.
42 // TODO(b/129534335): Move this to the linker configuration of the Test ART
43 // APEX when it is available.
44 ns.AddPermittedPath("/data");
45
46 // odex files are in /system/framework and /apex/com.android.art/javalib.
47 // dalvikvm has to be able to dlopen the files for CTS.
48 ns.AddPermittedPath("/system/framework");
49 }
50
51 // Primary boot image is loaded through dlopen, so pass the primary boot image
52 // to the list of paths.
53 ns.AddPermittedPath("/apex/com.android.art/javalib");
54
55 // Need allow_all_shared_libs to let libart.so dlopen oat files in
56 // /system/framework and /data.
57 // TODO(b/130340935): Use a dynamically created linker namespace similar to
58 // classloader-namespace for oat files, and tighten this up.
59 ns.GetLink(ctx.GetSystemNamespaceName()).AllowAllSharedLibs();
60
61 return ns;
62 }
63
64 } // namespace contents
65 } // namespace linkerconfig
66 } // namespace android
67