The Pedigree Project  0.1
SymbolTable.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_LINKER_SYMBOLTABLE_H
21 #define KERNEL_LINKER_SYMBOLTABLE_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/process/Mutex.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/HashTable.h"
27 #include "pedigree/kernel/utilities/SharedPointer.h"
28 #include "pedigree/kernel/utilities/String.h"
29 #include "pedigree/kernel/utilities/StringView.h"
30 #include "pedigree/kernel/utilities/Tree.h"
31 #include "pedigree/kernel/utilities/utility.h"
32 
33 class Elf;
34 
44 {
45  public:
47  enum Binding
48  {
49  Local,
50  Global,
51  Weak
52  };
53 
56  enum Policy
57  {
61  };
65 
67  SymbolTable(Elf *pElf);
69  ~SymbolTable();
70 
72  SymbolTable(const SymbolTable &symtab);
73 
75  void copyTable(Elf *pNewElf, const SymbolTable &newSymtab);
76 
78  void
79  insert(const String &name, Binding binding, Elf *pParent, uintptr_t value);
80 
82  void insertMultiple(
83  SymbolTable *pOther, const String &name, Binding binding, Elf *pParent,
84  uintptr_t value);
85 
87  void preallocate(
88  size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal);
93  size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal);
94 
95  void eraseByElf(Elf *pParent);
96 
109  uintptr_t EXPORTED_PUBLIC lookup(
110  const HashedStringView &name, Elf *pElf, Policy policy = LocalFirst,
111  Binding *pBinding = 0);
112 
113  private:
117 
118  class Symbol
119  {
120  public:
121  Symbol() : m_pParent(0), m_Binding(Global), m_Value(0)
122  {
123  }
124  Symbol(Elf *pP, Binding b, uintptr_t v)
125  : m_pParent(pP), m_Binding(b), m_Value(v)
126  {
127  }
128 
129  Elf *getParent() const
130  {
131  return m_pParent;
132  }
133  Binding getBinding() const
134  {
135  return m_Binding;
136  }
137  uintptr_t getValue() const
138  {
139  return m_Value;
140  }
141 
142  private:
143  Elf *m_pParent;
144  Binding m_Binding;
145  uintptr_t m_Value;
146  };
147 
150  const String &name, Binding binding, Elf *pParent, uintptr_t value);
152  void insertShared(const String &name, SharedPointer<Symbol> &symbol);
153 
156 
158  symbolTree_t *getOrInsertTree(Elf *, Binding table = Local);
159 
160  parentedSymbolTree_t m_LocalSymbols;
161  parentedSymbolTree_t m_GlobalSymbols;
162  parentedSymbolTree_t m_WeakSymbols;
163 
164  Elf *m_pOriginatingElf;
165 
166 #ifdef THREADS
167  Mutex m_Lock;
168 #endif
169 };
170 
171 #endif
uintptr_t EXPORTED_PUBLIC lookup(const HashedStringView &name, Elf *pElf, Policy policy=LocalFirst, Binding *pBinding=0)
Definition: SymbolTable.cc:126
void preallocateAdditional(size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal)
Definition: SymbolTable.cc:86
Definition: Mutex.h:58
Definition: String.h:49
symbolTree_t * getOrInsertTree(Elf *, Binding table=Local)
Definition: SymbolTable.cc:188
void insert(const String &name, Binding binding, Elf *pParent, uintptr_t value)
Definition: SymbolTable.cc:51
A key/value dictionary.
Definition: Tree.h:33
void insertShared(const String &name, SharedPointer< Symbol > &symbol)
Definition: SymbolTable.cc:109
Definition: Elf.h:201
void copyTable(Elf *pNewElf, const SymbolTable &newSymtab)
Definition: SymbolTable.cc:40
SymbolTable(Elf *pElf)
Definition: SymbolTable.cc:30
void insertMultiple(SymbolTable *pOther, const String &name, Binding binding, Elf *pParent, uintptr_t value)
Definition: SymbolTable.cc:59
SharedPointer< Symbol > doInsert(const String &name, Binding binding, Elf *pParent, uintptr_t value)
Definition: SymbolTable.cc:99
void preallocate(size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal)
Definition: SymbolTable.cc:73
SymbolTable & operator=(const SymbolTable &)