blob: c1cee8ec6a20d055e06f456fb689383bb433d2ee [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
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070034#include <string>
Dimitry Ivanovb943f302016-08-03 16:00:10 -070035#include <vector>
36
37struct android_namespace_t {
38 public:
39 android_namespace_t() : name_(nullptr), is_isolated_(false) {}
40
41 const char* get_name() const { return name_; }
42 void set_name(const char* name) { name_ = name; }
43
44 bool is_isolated() const { return is_isolated_; }
45 void set_isolated(bool isolated) { is_isolated_ = isolated; }
46
47 const std::vector<std::string>& get_ld_library_paths() const {
48 return ld_library_paths_;
49 }
50 void set_ld_library_paths(std::vector<std::string>&& library_paths) {
51 ld_library_paths_ = library_paths;
52 }
53
54 const std::vector<std::string>& get_default_library_paths() const {
55 return default_library_paths_;
56 }
57 void set_default_library_paths(std::vector<std::string>&& library_paths) {
58 default_library_paths_ = library_paths;
59 }
60
61 const std::vector<std::string>& get_permitted_paths() const {
62 return permitted_paths_;
63 }
64 void set_permitted_paths(std::vector<std::string>&& permitted_paths) {
65 permitted_paths_ = permitted_paths;
66 }
67
68 void add_soinfo(soinfo* si) {
69 soinfo_list_.push_back(si);
70 }
71
72 void add_soinfos(const soinfo_list_t& soinfos) {
73 for (auto si : soinfos) {
74 add_soinfo(si);
75 }
76 }
77
78 void remove_soinfo(soinfo* si) {
79 soinfo_list_.remove_if([&](soinfo* candidate) {
80 return si == candidate;
81 });
82 }
83
84 const soinfo_list_t& soinfo_list() const { return soinfo_list_; }
85
86 // For isolated namespaces - checks if the file is on the search path;
87 // always returns true for not isolated namespace.
88 bool is_accessible(const std::string& path);
89
90 private:
91 const char* name_;
92 bool is_isolated_;
93 std::vector<std::string> ld_library_paths_;
94 std::vector<std::string> default_library_paths_;
95 std::vector<std::string> permitted_paths_;
96 soinfo_list_t soinfo_list_;
97
98 DISALLOW_COPY_AND_ASSIGN(android_namespace_t);
99};
100
101#endif /* __LINKER_NAMESPACES_H */