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
33class Elf;
34
44 public:
46 enum Binding { Local, Global, Weak };
47
58
60 SymbolTable(Elf* pElf);
63
65 SymbolTable(const SymbolTable& symtab);
66
68 void copyTable(Elf* pNewElf, const SymbolTable& newSymtab);
69
71 void insert(const String& name, Binding binding, Elf* pParent, uintptr_t value);
72
74 void insertMultiple(SymbolTable* pOther, const String& name, Binding binding, Elf* pParent,
75 uintptr_t value);
76
78 void preallocate(size_t numGlobal, size_t numWeak, Elf* localElf, size_t numLocal);
82 void preallocateAdditional(size_t numGlobal, size_t numWeak, Elf* localElf, size_t numLocal);
83
85 bool hasPreallocated() const;
86
87 void eraseByElf(Elf* pParent);
88
101 uintptr_t EXPORTED_PUBLIC lookup(const HashedStringView& name, Elf* pElf,
102 Policy policy = LocalFirst, Binding* pBinding = 0);
103
105 uintptr_t lookupOwned(const HashedStringView& name, Elf* owner);
106
107 private:
111
112 class Symbol {
113 public:
114 Symbol() : m_pParent(0), m_Binding(Global), m_Value(0) {}
115 Symbol(Elf* pP, Binding b, uintptr_t v) : m_pParent(pP), m_Binding(b), m_Value(v) {}
116
117 Elf* getParent() const {
118 return m_pParent;
119 }
120 Binding getBinding() const {
121 return m_Binding;
122 }
123 uintptr_t getValue() const {
124 return m_Value;
125 }
126
127 private:
128 Elf* m_pParent;
129 Binding m_Binding;
130 uintptr_t m_Value;
131 };
132
134 SharedPointer<Symbol> doInsert(const String& name, Binding binding, Elf* pParent,
135 uintptr_t value);
138
141
143 symbolTree_t* getOrInsertTree(Elf*, Binding table = Local);
144
145 parentedSymbolTree_t m_LocalSymbols;
146 parentedSymbolTree_t m_GlobalSymbols;
147 parentedSymbolTree_t m_WeakSymbols;
148
149 Elf* m_pOriginatingElf;
150
151 mutable Mutex m_Lock;
152
153 bool m_bPreallocated;
154};
155
156#endif
Definition Elf.h:201
Definition Mutex.h:56
void insert(const String &name, Binding binding, Elf *pParent, uintptr_t value)
void preallocate(size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal)
void insertMultiple(SymbolTable *pOther, const String &name, Binding binding, Elf *pParent, uintptr_t value)
uintptr_t lookupOwned(const HashedStringView &name, Elf *owner)
void copyTable(Elf *pNewElf, const SymbolTable &newSymtab)
SharedPointer< Symbol > doInsert(const String &name, Binding binding, Elf *pParent, uintptr_t value)
SymbolTable & operator=(const SymbolTable &)
symbolTree_t * getOrInsertTree(Elf *, Binding table=Local)
SymbolTable(const SymbolTable &symtab)
void insertShared(const String &name, SharedPointer< Symbol > &symbol)
uintptr_t EXPORTED_PUBLIC lookup(const HashedStringView &name, Elf *pElf, Policy policy=LocalFirst, Binding *pBinding=0)
bool hasPreallocated() const
void preallocateAdditional(size_t numGlobal, size_t numWeak, Elf *localElf, size_t numLocal)
A key/value dictionary.
Definition Tree.h:33