The Pedigree Project 0.1
DynamicLinker.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 DYNAMIC_LINKER_H
21#define DYNAMIC_LINKER_H
22#include "pedigree/kernel/compiler.h"
23#include "pedigree/kernel/processor/PageFaultHandler.h"
24#include "pedigree/kernel/processor/state_forward.h"
25#include "pedigree/kernel/processor/types.h"
27#include "pedigree/kernel/utilities/String.h"
28#include "pedigree/kernel/utilities/Tree.h"
29
30#include <config.h>
31
32class Elf;
33class File;
35class SymbolTable;
36
39class EXPORTED_PUBLIC DynamicLinker {
40 public:
43
45
47 DynamicLinker(const DynamicLinker& other);
48
51 bool checkInterpreter(File* pFile, String& actualFilename) {
52 return loadProgram(pFile, true, true, &actualFilename);
53 }
54
57 bool checkDependencies(File* pFile) {
58 return loadProgram(pFile, true);
59 }
60
65 bool loadProgram(File* pFile, bool bDryRun = false, bool bInterpreter = false,
66 String* sInterpreter = 0);
67
72 bool loadObject(File* pFile, bool bDryRun = false);
73
76 static uintptr_t resolvePlt(SyscallState& state);
77
81 bool trap(uintptr_t address);
82
85 return m_pProgramElf;
86 }
87
89 uintptr_t resolve(String name);
90
91#if defined(PEDIGREE_HOSTED_PAGE_CONTENT_REGRESSIONS)
92 static bool loadDemandPageForTest(Elf* pElf, uintptr_t buffer, size_t size, uintptr_t offset,
93 SymbolTable* pSymbols, uintptr_t address) {
94 return loadDemandPage(pElf, buffer, size, offset, pSymbols, address);
95 }
96
97 static void setDemandPageAllocationHookForTest(physical_uintptr_t (*hook)());
98 static void setDemandPageReadyHookForTest(void (*hook)(uintptr_t));
99 static void setDemandPageFreeHookForTest(void (*hook)(physical_uintptr_t));
100#endif
101
102 private:
105
108 SharedObject(Elf* e, MemoryMappedObject* f, uintptr_t b, uintptr_t a, size_t s)
109 : elf(e), file(f), buffer(b), address(a), size(s) {}
110 Elf* elf;
111 MemoryMappedObject* file;
112 uintptr_t buffer;
113 uintptr_t address;
114 size_t size;
115 };
116
117 uintptr_t resolvePltSymbol(uintptr_t libraryId, uintptr_t symIdx);
118
119 void initPlt(Elf* pElf, uintptr_t value);
120
121 static bool loadDemandPage(Elf* pElf, uintptr_t buffer, size_t size, uintptr_t offset,
122 SymbolTable* pSymbols, uintptr_t address);
123
124 Elf* m_pProgramElf;
125 uintptr_t m_ProgramStart;
126 size_t m_ProgramSize;
127 uintptr_t m_ProgramBuffer;
128 RadixTree<void*> m_LoadedObjects;
129
131};
132
137 public:
140 return m_Instance;
141 }
142
143 //
144 // MemoryTrapHandler interface.
145 //
146 virtual bool trap(InterruptState& state, uintptr_t address, bool bIsWrite, bool bWasPresent);
147
148 private:
153
154 static DLTrapHandler m_Instance;
155};
156
157#endif
Implements a Radix Tree, a kind of Trie with compressed keys.
static DLTrapHandler & instance()
virtual bool trap(InterruptState &state, uintptr_t address, bool bIsWrite, bool bWasPresent)
bool checkDependencies(File *pFile)
DynamicLinker & operator=(const DynamicLinker &)
Elf * getProgramElf()
bool checkInterpreter(File *pFile, String &actualFilename)
Definition Elf.h:201
Definition File.h:74
A key/value dictionary for string keys.
Definition RadixTree.h:46
A key/value dictionary.
Definition Tree.h:33