2017-03-07 20:19:05 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2018-02-13 23:26:29 +01:00
|
|
|
#pragma once
|
2017-03-07 20:19:05 +01:00
|
|
|
|
|
|
|
#include <android/api-level.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2018-10-25 20:00:00 +02:00
|
|
|
#include <android-base/macros.h>
|
|
|
|
|
2019-12-03 01:55:48 +01:00
|
|
|
#if defined(__LP64__)
|
|
|
|
static constexpr const char* kLibPath = "lib64";
|
|
|
|
#else
|
|
|
|
static constexpr const char* kLibPath = "lib";
|
|
|
|
#endif
|
|
|
|
|
2017-03-07 20:19:05 +01:00
|
|
|
class NamespaceLinkConfig {
|
|
|
|
public:
|
|
|
|
NamespaceLinkConfig() = default;
|
2018-01-18 05:05:09 +01:00
|
|
|
NamespaceLinkConfig(const std::string& ns_name, const std::string& shared_libs,
|
|
|
|
bool allow_all_shared_libs)
|
|
|
|
: ns_name_(ns_name), shared_libs_(shared_libs),
|
|
|
|
allow_all_shared_libs_(allow_all_shared_libs) {}
|
2017-03-07 20:19:05 +01:00
|
|
|
|
|
|
|
const std::string& ns_name() const {
|
|
|
|
return ns_name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& shared_libs() const {
|
|
|
|
return shared_libs_;
|
|
|
|
}
|
|
|
|
|
2018-01-18 05:05:09 +01:00
|
|
|
bool allow_all_shared_libs() const {
|
|
|
|
return allow_all_shared_libs_;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:19:05 +01:00
|
|
|
private:
|
|
|
|
std::string ns_name_;
|
|
|
|
std::string shared_libs_;
|
2018-01-18 05:05:09 +01:00
|
|
|
bool allow_all_shared_libs_;
|
2017-03-07 20:19:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NamespaceConfig {
|
|
|
|
public:
|
|
|
|
explicit NamespaceConfig(const std::string& name)
|
2017-04-03 16:10:37 +02:00
|
|
|
: name_(name), isolated_(false), visible_(false)
|
2017-03-07 20:19:05 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
const char* name() const {
|
|
|
|
return name_.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isolated() const {
|
|
|
|
return isolated_;
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:10:37 +02:00
|
|
|
bool visible() const {
|
|
|
|
return visible_;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:19:05 +01:00
|
|
|
const std::vector<std::string>& search_paths() const {
|
|
|
|
return search_paths_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::string>& permitted_paths() const {
|
|
|
|
return permitted_paths_;
|
|
|
|
}
|
|
|
|
|
2020-07-30 09:09:18 +02:00
|
|
|
const std::vector<std::string>& allowed_libs() const { return allowed_libs_; }
|
2019-01-13 06:03:25 +01:00
|
|
|
|
2017-03-07 20:19:05 +01:00
|
|
|
const std::vector<NamespaceLinkConfig>& links() const {
|
|
|
|
return namespace_links_;
|
|
|
|
}
|
|
|
|
|
2018-01-18 05:05:09 +01:00
|
|
|
void add_namespace_link(const std::string& ns_name, const std::string& shared_libs,
|
|
|
|
bool allow_all_shared_libs) {
|
|
|
|
namespace_links_.push_back(NamespaceLinkConfig(ns_name, shared_libs, allow_all_shared_libs));
|
2017-03-07 20:19:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_isolated(bool isolated) {
|
|
|
|
isolated_ = isolated;
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:10:37 +02:00
|
|
|
void set_visible(bool visible) {
|
|
|
|
visible_ = visible;
|
|
|
|
}
|
|
|
|
|
2017-03-07 20:19:05 +01:00
|
|
|
void set_search_paths(std::vector<std::string>&& search_paths) {
|
2019-03-12 21:38:30 +01:00
|
|
|
search_paths_ = std::move(search_paths);
|
2017-03-07 20:19:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_permitted_paths(std::vector<std::string>&& permitted_paths) {
|
2019-03-12 21:38:30 +01:00
|
|
|
permitted_paths_ = std::move(permitted_paths);
|
2017-03-07 20:19:05 +01:00
|
|
|
}
|
2019-01-13 06:03:25 +01:00
|
|
|
|
2020-07-30 09:09:18 +02:00
|
|
|
void set_allowed_libs(std::vector<std::string>&& allowed_libs) {
|
|
|
|
allowed_libs_ = std::move(allowed_libs);
|
2019-01-13 06:03:25 +01:00
|
|
|
}
|
2020-07-30 09:09:18 +02:00
|
|
|
|
2017-03-07 20:19:05 +01:00
|
|
|
private:
|
|
|
|
const std::string name_;
|
|
|
|
bool isolated_;
|
2017-04-03 16:10:37 +02:00
|
|
|
bool visible_;
|
2017-03-07 20:19:05 +01:00
|
|
|
std::vector<std::string> search_paths_;
|
|
|
|
std::vector<std::string> permitted_paths_;
|
2020-07-30 09:09:18 +02:00
|
|
|
std::vector<std::string> allowed_libs_;
|
2017-03-07 20:19:05 +01:00
|
|
|
std::vector<NamespaceLinkConfig> namespace_links_;
|
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceConfig);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Config {
|
|
|
|
public:
|
|
|
|
Config() : target_sdk_version_(__ANDROID_API__) {}
|
|
|
|
|
|
|
|
const std::vector<std::unique_ptr<NamespaceConfig>>& namespace_configs() const {
|
|
|
|
return namespace_configs_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NamespaceConfig* default_namespace_config() const {
|
|
|
|
auto it = namespace_configs_map_.find("default");
|
|
|
|
return it == namespace_configs_map_.end() ? nullptr : it->second;
|
|
|
|
}
|
|
|
|
|
2018-11-13 01:01:37 +01:00
|
|
|
int target_sdk_version() const {
|
2017-03-07 20:19:05 +01:00
|
|
|
return target_sdk_version_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// note that this is one time event and therefore there is no need to
|
|
|
|
// read every section of the config. Every linker instance needs at
|
|
|
|
// most one configuration.
|
|
|
|
// Returns false in case of an error. If binary config was not found
|
|
|
|
// sets *config = nullptr.
|
|
|
|
static bool read_binary_config(const char* ld_config_file_path,
|
|
|
|
const char* binary_realpath,
|
|
|
|
bool is_asan,
|
2023-03-23 00:12:49 +01:00
|
|
|
bool is_hwasan,
|
2017-03-07 20:19:05 +01:00
|
|
|
const Config** config,
|
|
|
|
std::string* error_msg);
|
2017-11-27 08:28:07 +01:00
|
|
|
|
2019-10-17 00:37:10 +02:00
|
|
|
static std::string get_vndk_version_string(const char delimiter);
|
2017-03-07 20:19:05 +01:00
|
|
|
private:
|
|
|
|
void clear();
|
|
|
|
|
2018-11-13 01:01:37 +01:00
|
|
|
void set_target_sdk_version(int target_sdk_version) {
|
2017-03-07 20:19:05 +01:00
|
|
|
target_sdk_version_ = target_sdk_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
NamespaceConfig* create_namespace_config(const std::string& name);
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<NamespaceConfig>> namespace_configs_;
|
|
|
|
std::unordered_map<std::string, NamespaceConfig*> namespace_configs_map_;
|
2018-11-13 01:01:37 +01:00
|
|
|
int target_sdk_version_;
|
2017-03-07 20:19:05 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Config);
|
|
|
|
};
|