2 * Copyright (C) 2017 The Android Open Source Project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef _LINKER_CONFIG_H_
30 #define _LINKER_CONFIG_H_
32 #include <android/api-level.h>
36 #include "private/bionic_macros.h"
41 #include <unordered_map>
43 class NamespaceLinkConfig {
45 NamespaceLinkConfig() = default;
46 NamespaceLinkConfig(const std::string& ns_name, const std::string& shared_libs)
47 : ns_name_(ns_name), shared_libs_(shared_libs) {}
49 const std::string& ns_name() const {
53 const std::string& shared_libs() const {
59 std::string shared_libs_;
62 class NamespaceConfig {
64 explicit NamespaceConfig(const std::string& name)
65 : name_(name), isolated_(false), visible_(false)
68 const char* name() const {
72 bool isolated() const {
76 bool visible() const {
80 const std::vector<std::string>& search_paths() const {
84 const std::vector<std::string>& permitted_paths() const {
85 return permitted_paths_;
88 const std::vector<NamespaceLinkConfig>& links() const {
89 return namespace_links_;
92 void add_namespace_link(const std::string& ns_name, const std::string& shared_libs) {
93 namespace_links_.push_back(NamespaceLinkConfig(ns_name, shared_libs));
96 void set_isolated(bool isolated) {
100 void set_visible(bool visible) {
104 void set_search_paths(std::vector<std::string>&& search_paths) {
105 search_paths_ = search_paths;
108 void set_permitted_paths(std::vector<std::string>&& permitted_paths) {
109 permitted_paths_ = permitted_paths;
112 const std::string name_;
115 std::vector<std::string> search_paths_;
116 std::vector<std::string> permitted_paths_;
117 std::vector<NamespaceLinkConfig> namespace_links_;
119 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceConfig);
124 Config() : target_sdk_version_(__ANDROID_API__) {}
126 const std::vector<std::unique_ptr<NamespaceConfig>>& namespace_configs() const {
127 return namespace_configs_;
130 const NamespaceConfig* default_namespace_config() const {
131 auto it = namespace_configs_map_.find("default");
132 return it == namespace_configs_map_.end() ? nullptr : it->second;
135 uint32_t target_sdk_version() const {
136 return target_sdk_version_;
139 // note that this is one time event and therefore there is no need to
140 // read every section of the config. Every linker instance needs at
141 // most one configuration.
142 // Returns false in case of an error. If binary config was not found
143 // sets *config = nullptr.
144 static bool read_binary_config(const char* ld_config_file_path,
145 const char* binary_realpath,
147 const Config** config,
148 std::string* error_msg);
152 void set_target_sdk_version(uint32_t target_sdk_version) {
153 target_sdk_version_ = target_sdk_version;
156 NamespaceConfig* create_namespace_config(const std::string& name);
158 std::vector<std::unique_ptr<NamespaceConfig>> namespace_configs_;
159 std::unordered_map<std::string, NamespaceConfig*> namespace_configs_map_;
160 uint32_t target_sdk_version_;
162 DISALLOW_COPY_AND_ASSIGN(Config);
165 #endif /* _LINKER_CONFIG_H_ */