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 Renderscript internal libraries. This
18 // namespace has slightly looser restriction than the vndk namespace because of
19 // the genuine characteristics of Renderscript; /data is in the permitted path
20 // to load the compiled *.so file and libmediandk.so can be used here.
21 
22 #include "linkerconfig/namespacebuilder.h"
23 
24 using android::linkerconfig::modules::AsanPath;
25 using android::linkerconfig::modules::Namespace;
26 
27 namespace android {
28 namespace linkerconfig {
29 namespace contents {
30 Namespace BuildRsNamespace([[maybe_unused]] const Context& ctx) {
31   Namespace ns(
32       "rs", /*is_isolated=*/!ctx.IsUnrestrictedSection(), /*is_visible=*/true);
33 
34   ns.AddSearchPath("/odm/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
35   ns.AddSearchPath("/vendor/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
36   ns.AddSearchPath(
37       "/apex/com.android.vndk.v" + Var("VENDOR_VNDK_VERSION") + "/${LIB}",
38       AsanPath::SAME_PATH);
39   ns.AddSearchPath("/odm/${LIB}", AsanPath::WITH_DATA_ASAN);
40   ns.AddSearchPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
41 
42   ns.AddPermittedPath("/odm/${LIB}", AsanPath::WITH_DATA_ASAN);
43   ns.AddPermittedPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
44   ns.AddPermittedPath("/system/vendor/${LIB}", AsanPath::NONE);
45   ns.AddPermittedPath("/data", AsanPath::SAME_PATH);
46 
47   // Private LLNDK libs (e.g. libft2.so) are exceptionally allowed to this
48   // namespace because RS framework libs are using them.
49   ns.GetLink(ctx.GetSystemNamespaceName())
50       .AddSharedLib({Var("LLNDK_LIBRARIES_VENDOR"),
51                      Var("PRIVATE_LLNDK_LIBRARIES_VENDOR", "")});
52 
53   ns.AddRequires(std::vector{"libneuralnetworks.so"});
54 
55   return ns;
56 }
57 }  // namespace contents
58 }  // namespace linkerconfig
59 }  // namespace android
60