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 #pragma once 17 18 #include <map> 19 #include <string> 20 #include <vector> 21 22 #include "linkerconfig/configwriter.h" 23 #include "linkerconfig/link.h" 24 25 namespace android { 26 namespace linkerconfig { 27 namespace modules { 28 29 class Namespace { 30 public: 31 Namespace(const std::string& name, bool is_isolated = false, 32 bool is_visible = false) is_isolated_(is_isolated)33 : is_isolated_(is_isolated), is_visible_(is_visible), name_(name) { 34 } 35 36 // Add path to search path 37 // This function will add path to namespace.<<namespace>>.search.paths 38 // If also_in_asan is true, this will add path also to 39 // namespace.<<namespace>>.asan.search.paths 40 // If with_data_asan is true when also_in_asan is true, 41 // this will also add asan path starts with /data/asan 42 // 43 // AddSearchPath("/system/${LIB}", false, false) : 44 // namespace.xxx.search.paths += /system/${LIB} 45 // AddSearchPath("/system/${LIB}", true, false) : 46 // namespace.xxx.search.paths += /system/${LIB} 47 // namespace.xxx.asan.search.paths += /system/${LIB} 48 // AddSearchPath("/system/${LIB}", true, true) : 49 // namespace.xxx.search.paths += /system/${LIB} 50 // namespace.xxx.asan.search.paths += /system/${LIB} 51 // namespace.xxx.asan.search.paths += /data/asan/system/${LIB} 52 void AddSearchPath(const std::string& path, bool also_in_asan = true, 53 bool with_data_asan = true); 54 55 // Add path to permitted path 56 // This function will add path to namespace.<<namespace>>.permitted.paths 57 // If also_in_asan is true, this will add path also to 58 // namespace.<<namespace>>.asan.permitted.paths 59 // If with_data_asan is true when also_in_asan is true, 60 // this will also add asan path starts with /data/asan 61 // 62 // AddSearchPath("/system/${LIB}", false, false) : 63 // namespace.xxx.permitted.paths += /system/${LIB} 64 // AddSearchPath("/system/${LIB}", true, false) : 65 // namespace.xxx.permitted.paths += /system/${LIB} 66 // namespace.xxx.asan.permitted.paths += /system/${LIB} 67 // AddSearchPath("/system/${LIB}", true, true) : 68 // namespace.xxx.permitted.paths += /system/${LIB} 69 // namespace.xxx.asan.permitted.paths += /system/${LIB} 70 // namespace.xxx.asan.permitted.paths += /data/asan/system/${LIB} 71 void AddPermittedPath(const std::string& path, bool also_in_asan = true, 72 bool with_data_asan = true); 73 std::shared_ptr<Link> CreateLink(const std::string& target_namespace, 74 bool allow_all_shared_libs = false); 75 void WriteConfig(ConfigWriter& writer); 76 77 private: 78 const bool is_isolated_; 79 const bool is_visible_; 80 const std::string name_; 81 std::vector<std::string> search_paths_; 82 std::vector<std::string> permitted_paths_; 83 std::vector<std::string> asan_search_paths_; 84 std::vector<std::string> asan_permitted_paths_; 85 std::map<std::string, std::shared_ptr<Link>> links_; 86 void WritePathString(ConfigWriter& writer, const std::string& path_type, 87 const std::vector<std::string>& path_list); 88 }; 89 } // namespace modules 90 } // namespace linkerconfig 91 } // namespace android