ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
elf-loader.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_PLUGINS_ELF_LOADER_H
23 #define BACKENDS_PLUGINS_ELF_LOADER_H
24 
25 #include "common/scummsys.h"
26 
27 #if defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER)
28 
29 #include <stddef.h>
30 
31 #include "backends/plugins/elf/elf32.h"
32 #include "backends/plugins/dynamic-plugin.h"
33 
34 #include "common/stream.h"
35 
43 class DLObject {
44 protected:
46 
47  byte *_segment;
48  Elf32_Sym *_symtab;
49  char *_strtab;
50 
51  uint32 _segmentSize;
52  ptrdiff_t _segmentOffset;
53  uint32 _segmentVMA;
54 
55  uint32 _symbol_cnt;
56  int32 _symtab_sect;
57  void *_dtors_start, *_dtors_end;
58 
59  virtual void unload();
60  bool load();
61 
62  bool readElfHeader(Elf32_Ehdr *ehdr);
63  bool readProgramHeaders(Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, Elf32_Half num);
64  virtual bool loadSegment(Elf32_Phdr *phdr);
65  Elf32_Shdr *loadSectionHeaders(Elf32_Ehdr *ehdr);
66  int findSymbolTableSection(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
67  int loadSymbolTable(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr);
68  bool loadStringTable(Elf32_Shdr *shdr);
69  virtual void relocateSymbols(ptrdiff_t offset);
70  void discardSegment();
71 
72  // architecture specific
73 
81  virtual bool relocate(Elf32_Off offset, Elf32_Word size, byte *relSegment) = 0;
82  virtual bool relocateRels(Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) = 0;
83 
84  // platform specific
85  virtual void flushDataCache(void *ptr, uint32 len) const = 0;
86  virtual void *allocateMemory(uint32 align, uint32 size);
87  virtual void deallocateMemory(void *ptr, uint32 size);
88  virtual void protectMemory(void *ptr, uint32 len, int prot) const {};
89 
90 public:
91  DLObject();
92  virtual ~DLObject();
93 
98  void trackSize(const Common::Path &path);
99  bool open(const Common::Path &path);
100  bool close();
101  void *symbol(const char *name);
102  void discardSymtab();
103 };
104 
105 #endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) */
106 
107 #endif /* BACKENDS_PLUGINS_ELF_LOADER_H */
Definition: path.h:52
Definition: stream.h:745
Definition: dcloader.h:29