paludis Version 3.0.2
The one true package mangler
elf_dynamic_section.hh
1/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3/*
4 * Copyright (c) 2007 Tiziano Müller
5 * Copyright (c) 2007 David Leverton
6 *
7 * This file is part of the Paludis package manager. Paludis is free software;
8 * you can redistribute it and/or modify it under the terms of the GNU General
9 * Public License version 2, as published by the Free Software Foundation.
10 *
11 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef PALUDIS_GUARD_PALUDIS_UTIL_ELF_DYNAMIC_SECTION_HH
22#define PALUDIS_GUARD_PALUDIS_UTIL_ELF_DYNAMIC_SECTION_HH 1
23
24#include <paludis/util/elf_sections.hh>
25#include <paludis/util/clone.hh>
26#include <paludis/util/iterator_range.hh>
28#include <paludis/util/pimp.hh>
29#include <paludis/util/wrapped_forward_iterator-fwd.hh>
30#include <paludis/util/visitor.hh>
31#include <paludis/util/type_list.hh>
32#include <memory>
33#include <string>
34#include <iosfwd>
35
36namespace paludis
37{
38 template <typename ElfType_> class DynamicEntry;
39 template <typename ElfType_> class DynamicEntryUnknown;
40 template <typename ElfType_> class DynamicEntryValue;
41 template <typename ElfType_> class DynamicEntryPointer;
42 template <typename ElfType_> class DynamicEntryString;
43 template <typename ElfType_> class DynamicEntryFlag;
44
45 template <typename ElfType_>
46 class DynamicEntry :
47 public virtual DeclareAbstractAcceptMethods<DynamicEntry<ElfType_>, typename MakeTypeList<
48 DynamicEntryUnknown<ElfType_>,
49 DynamicEntryValue<ElfType_>,
50 DynamicEntryPointer<ElfType_>,
51 DynamicEntryString<ElfType_>,
52 DynamicEntryFlag<ElfType_>
53 >::Type>,
54 public virtual Cloneable<DynamicEntry<ElfType_> >
55 {
56 private:
57 std::string _tag_name;
58 typename ElfType_::Word _index;
59
60 public:
61 DynamicEntry(const std::string &);
62 ~DynamicEntry() override;
63 virtual void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry & entry);
64
65 std::string tag_name() const
66 {
67 return _tag_name;
68 }
69
70 std::string description() const;
71 };
72
73 template <typename ElfType_>
74 class DynamicEntryUnknown :
75 public virtual DynamicEntry<ElfType_>,
76 public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryUnknown<ElfType_> >,
77 public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryUnknown<ElfType_> >
78 {
79 public:
80 DynamicEntryUnknown();
81 ~DynamicEntryUnknown() override;
82 };
83
84 template <typename ElfType_>
85 class DynamicEntryFlag :
86 public virtual DynamicEntry<ElfType_>,
87 public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryFlag<ElfType_> >,
88 public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryFlag<ElfType_> >
89 {
90 public:
91 DynamicEntryFlag(const std::string &);
92 ~DynamicEntryFlag() override;
93 };
94
95 template <typename ElfType_>
96 class DynamicEntryValue :
97 public virtual DynamicEntry<ElfType_>,
98 public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryValue<ElfType_> >,
99 public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryValue<ElfType_> >
100 {
101 private:
102 typename ElfType_::DynamicValue _value;
103
104 public:
105 DynamicEntryValue(const std::string &);
106 ~DynamicEntryValue() override;
107 void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry & entry) override;
108
109 typename ElfType_::DynamicValue operator() () const
110 {
111 return _value;
112 }
113 };
114
115 template <typename ElfType_>
116 class DynamicEntryPointer :
117 public virtual DynamicEntry<ElfType_>,
118 public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryPointer<ElfType_> >,
119 public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryPointer<ElfType_> >
120 {
121 private:
122 typename ElfType_::DynamicPointer _pointer;
123
124 public:
125 DynamicEntryPointer(const std::string &);
126 ~DynamicEntryPointer() override;
127 void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry &) override;
128
129 typename ElfType_::DynamicPointer operator() () const
130 {
131 return _pointer;
132 }
133 };
134
135 namespace littlelf_internals
136 {
137 template <typename ElfType_> class DynEntriesStringResolvingVisitor;
138 }
139
140 template <typename ElfType_>
141 class DynamicEntryString :
142 public virtual DynamicEntry<ElfType_>,
143 public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryString<ElfType_> >,
144 public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryString<ElfType_> >
145 {
147
148 private:
149 typename ElfType_::DynamicValue _value;
150 std::string _str;
151
152 public:
153 DynamicEntryString(const std::string &);
154 ~DynamicEntryString() override;
155 void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry &) override;
156
157 std::string operator() () const
158 {
159 return _str;
160 }
161
162 private:
163 void resolve_string(std::string str)
164 {
165 _str = str;
166 }
167
168 typename ElfType_::DynamicValue get_string_index() const
169 {
170 return _value;
171 }
172 };
173
174 template <typename ElfType_>
175 class DynamicEntries :
176 public Singleton<DynamicEntries<ElfType_> >
177 {
178 friend class Singleton<DynamicEntries>;
179
180 private:
182
183 public:
184 void register_type(typename ElfType_::DynamicTag, std::shared_ptr<DynamicEntry<ElfType_> >);
185
186 std::shared_ptr<DynamicEntry<ElfType_> > get_entry(typename ElfType_::DynamicTag) const;
187 bool has_entry(typename ElfType_::DynamicTag) const;
188
189 private:
190 DynamicEntries();
191 ~DynamicEntries();
192 };
193
194 template <typename ElfType_>
196
197 template <typename ElfType_>
198 class PALUDIS_VISIBLE DynamicSection :
199 public Section<ElfType_>,
200 public ImplementAcceptMethods<Section<ElfType_>, DynamicSection<ElfType_> >
201 {
202 private:
204
205 public:
206 DynamicSection(typename ElfType_::Word, const typename ElfType_::SectionHeader &, std::istream &, bool);
207 ~DynamicSection() override;
208
209 std::string get_type() const override;
210
211 void resolve_entry_names(Section<ElfType_> &);
212
213 typedef DynamicSectionEntryIteratorTag<ElfType_> EntryIteratorTag;
215 EntryIterator entry_begin() const;
216 EntryIterator entry_end() const;
217 IteratorRange<EntryIterator> entries() const noexcept
218 {
219 return {entry_begin(), entry_end()};
220 }
221 };
222}
223
224#endif
Definition clone.hh:77
Definition clone.hh:47
Definition visitor.hh:326
Definition elf_dynamic_section.hh:89
Definition elf_dynamic_section.hh:120
Definition elf_dynamic_section.hh:145
Definition elf_dynamic_section.hh:78
Definition elf_dynamic_section.hh:100
Definition elf_dynamic_section.hh:55
Definition visitor.hh:411
Definition iterator_range.hh:29
Definition pimp.hh:52
Definition wrapped_forward_iterator.hh:42
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24
Definition elf_dynamic_section.hh:195