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 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/PageFaultHandler.h"
25 #include "pedigree/kernel/processor/state_forward.h"
26 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/String.h"
29 #include "pedigree/kernel/utilities/Tree.h"
30 
31 class Elf;
32 class File;
33 class MemoryMappedObject;
34 
38 {
39  public:
41  DynamicLinker();
42 
43  ~DynamicLinker();
44 
47 
50  bool checkInterpreter(File *pFile, String &actualFilename)
51  {
52  return loadProgram(pFile, true, true, &actualFilename);
53  }
54 
57  bool checkDependencies(File *pFile)
58  {
59  return loadProgram(pFile, true);
60  }
61 
66  bool loadProgram(
67  File *pFile, bool bDryRun = false, bool bInterpreter = false,
68  String *sInterpreter = 0);
69 
74  bool loadObject(File *pFile, bool bDryRun = false);
75 
78  static uintptr_t resolvePlt(SyscallState &state);
79 
83  bool trap(uintptr_t address);
84 
87  {
88  return m_pProgramElf;
89  }
90 
92  uintptr_t resolve(String name);
93 
94  private:
96  DynamicLinker &operator=(const DynamicLinker &);
97 
99  struct SharedObject
100  {
101  SharedObject(
102  Elf *e, MemoryMappedObject *f, uintptr_t b, uintptr_t a, size_t s)
103  : elf(e), file(f), buffer(b), address(a), size(s)
104  {
105  }
106  Elf *elf;
107  MemoryMappedObject *file;
108  uintptr_t buffer;
109  uintptr_t address;
110  size_t size;
111  };
112 
113  uintptr_t resolvePltSymbol(uintptr_t libraryId, uintptr_t symIdx);
114 
115  void initPlt(Elf *pElf, uintptr_t value);
116 
117  Elf *m_pProgramElf;
118  uintptr_t m_ProgramStart;
119  size_t m_ProgramSize;
120  uintptr_t m_ProgramBuffer;
121  RadixTree<void *> m_LoadedObjects;
122 
124 };
125 
130 {
131  public:
134  {
135  return m_Instance;
136  }
137 
138  //
139  // MemoryTrapHandler interface.
140  //
141  virtual bool trap(InterruptState &state, uintptr_t address, bool bIsWrite);
142 
143  private:
145  DLTrapHandler();
147  ~DLTrapHandler();
148 
149  static DLTrapHandler m_Instance;
150 };
151 
152 #endif
Definition: String.h:49
static DLTrapHandler & instance()
bool checkDependencies(File *pFile)
Definition: DynamicLinker.h:57
Elf * getProgramElf()
Definition: DynamicLinker.h:86
A key/value dictionary.
Definition: Tree.h:33
Definition: Elf.h:201
bool checkInterpreter(File *pFile, String &actualFilename)
Definition: DynamicLinker.h:50
Definition: File.h:66
Implements a Radix Tree, a kind of Trie with compressed keys.