blob: d4b5efd42623f36fb19e092f9bca1e2f1e3de4c6 [file] [log] [blame]
Dimitry Ivanovb943f302016-08-03 16:00:10 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
13 * distribution.
14 *
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
26 * SUCH DAMAGE.
27 */
28
29#ifndef __LINKER_NAMESPACES_H
30#define __LINKER_NAMESPACES_H
31
32#include "linker_common_types.h"
33
34#include <vector>
35
36struct android_namespace_t {
37 public:
38 android_namespace_t() : name_(nullptr), is_isolated_(false) {}
39
40 const char* get_name() const { return name_; }
41 void set_name(const char* name) { name_ = name; }
42
43 bool is_isolated() const { return is_isolated_; }
44 void set_isolated(bool isolated) { is_isolated_ = isolated; }
45
46 const std::vector<std::string>& get_ld_library_paths() const {
47 return ld_library_paths_;
48 }
49 void set_ld_library_paths(std::vector<std::string>&& library_paths) {
50 ld_library_paths_ = library_paths;
51 }
52
53 const std::vector<std::string>& get_default_library_paths() const {
54 return default_library_paths_;
55 }
56 void set_default_library_paths(std::vector<std::string>&& library_paths) {
57 default_library_paths_ = library_paths;
58 }
59
60 const std::vector<std::string>& get_permitted_paths() const {
61 return permitted_paths_;
62 }
63 void set_permitted_paths(std::vector<std::string>&& permitted_paths) {
64 permitted_paths_ = permitted_paths;
65 }
66
67 void add_soinfo(soinfo* si) {
68 soinfo_list_.push_back(si);
69 }
70
71 void add_soinfos(const soinfo_list_t& soinfos) {
72 for (auto si : soinfos) {
73 add_soinfo(si);
74 }
75 }
76
77 void remove_soinfo(soinfo* si) {
78 soinfo_list_.remove_if([&](soinfo* candidate) {
79 return si == candidate;
80 });
81 }
82
83 const soinfo_list_t& soinfo_list() const { return soinfo_list_; }
84
85 // For isolated namespaces - checks if the file is on the search path;
86 // always returns true for not isolated namespace.
87 bool is_accessible(const std::string& path);
88
89 private:
90 const char* name_;
91 bool is_isolated_;
92 std::vector<std::string> ld_library_paths_;
93 std::vector<std::string> default_library_paths_;
94 std::vector<std::string> permitted_paths_;
95 soinfo_list_t soinfo_list_;
96
97 DISALLOW_COPY_AND_ASSIGN(android_namespace_t);
98};
99
100#endif /* __LINKER_NAMESPACES_H */