|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if !defined(__ELFFILE_H__) |
|
17 #define __ELFFILE_H__ |
|
18 #include <e32rom.h> |
|
19 #include "e32ldfmt.h" |
|
20 #include <tools/elfdefs.h> |
|
21 |
|
22 #define ELFADDR(rtype, p, o) (rtype *)(((char *)p) + o) |
|
23 |
|
24 // |
|
25 enum TImportStat {EImpError, EImpSuccess, EImpDone}; |
|
26 // |
|
27 class ELFFile |
|
28 { |
|
29 public: |
|
30 ELFFile(); |
|
31 ~ELFFile(); |
|
32 TBool Init(const TText * const aFileName); |
|
33 void Close(void); |
|
34 |
|
35 char *CreateImportSection(TInt &aSize); |
|
36 |
|
37 TBool GetRelocs(Elf32_Rel **aCodeRelocs, Elf32_Rel **aDataRelocs); |
|
38 TUint16 GetRelocType(Elf32_Rel* aReloc); |
|
39 |
|
40 TInt NumberOfImports() const; |
|
41 TInt NumberOfImportDlls() const; |
|
42 TInt NumberOfExports() const; |
|
43 TInt NumberOfRelocs(); |
|
44 |
|
45 |
|
46 |
|
47 TInt NumberOfCodeRelocs(); |
|
48 TInt NumberOfDataRelocs(); |
|
49 |
|
50 public: |
|
51 TUint iCodeSize; |
|
52 TUint iDataSize; |
|
53 TUint iBssSize; |
|
54 |
|
55 |
|
56 TUint GetCodeSize(); |
|
57 TBool HasInitialisedData(); |
|
58 TUint GetDataSize(); |
|
59 TBool HasBssData(); |
|
60 TUint GetBssSize(); |
|
61 |
|
62 |
|
63 Elf32_Phdr * GetSegment(TInt idx) {return &iPhdr[idx];} |
|
64 Elf32_Phdr * GetSegmentFromAddr(Elf32_Addr addr); |
|
65 |
|
66 char * GetCode() { return ELFADDR(char, iElfFile, iCodeSegmentHdr->p_offset); } |
|
67 char * GetData() { return ELFADDR(char, iElfFile, iDataSegmentHdr->p_offset); } |
|
68 TBool CodeSegmentP(Elf32_Phdr * s) { return (TBool)(s == iCodeSegmentHdr); } |
|
69 TBool CodeSegmentP(TInt idx) { return (TBool)(idx == iCodeSegmentIdx); } |
|
70 TInt CodeSegmentIndex() {return iCodeSegmentIdx;} |
|
71 TBool DataSegmentP(Elf32_Phdr * s) { return (TBool)(s == iDataSegmentHdr); } |
|
72 TBool DataSegmentP(TInt idx) { return (TBool)(idx == iDataSegmentIdx); } |
|
73 TInt DataSegmentIndex() {return iDataSegmentIdx;} |
|
74 |
|
75 TUint * CodePtrFromAddr(Elf32_Addr addr) { return PtrInSegment(iCodeSegmentHdr, addr); } |
|
76 TUint * DataPtrFromAddr(Elf32_Addr addr) { return PtrInSegment(iDataSegmentHdr, addr); } |
|
77 |
|
78 |
|
79 char * ELFFileBase() { return (char *) iElfFile; } |
|
80 |
|
81 TUint GetExportTableOffset(void); |
|
82 TUint GetEntryPointOffset(void) { return iElfFile->e_entry - iCodeSegmentHdr->p_vaddr; } |
|
83 |
|
84 TBool SymbolPresent(TText *s); |
|
85 Elf32_Sym * FindSymbol(const TText *); |
|
86 |
|
87 TBool GetExceptionIndexInfo(TUint32 &aOffset); |
|
88 TBool SetUpLookupTable(); |
|
89 void SetLookupTblBase(TInt); |
|
90 TInt GetLookupTblSize(); |
|
91 void GetExportSymInfoHeader(E32EpocExpSymInfoHdr& aSymInfoHdr); |
|
92 TUint GetSymLookupSection(char* aBuff); |
|
93 private: |
|
94 TBool InitHeaders(void); |
|
95 TBool InitDllData(void); |
|
96 |
|
97 TUint * PtrInSegment(Elf32_Phdr * phdr, Elf32_Addr addr) |
|
98 { |
|
99 return ELFADDR(TUint, ELFADDR(TUint, iElfFile, phdr->p_offset), (addr - phdr->p_vaddr)); |
|
100 } |
|
101 |
|
102 |
|
103 TBool IsValidFileHeader(Elf32_Ehdr * aElfHdr); |
|
104 void CopySectionData(TAny *source, TAny *dest, TUint32 fileLength, TUint32 memLength); |
|
105 TBool ProcessRelocData(TAny *relocData,TInt dataSize); |
|
106 ELFFile(const ELFFile&); |
|
107 const ELFFile & operator = (const ELFFile&); |
|
108 public: |
|
109 TBool iImageIsDll; |
|
110 TBool ImageIsDll() { return iImageIsDll; } |
|
111 Elf32_Addr iLinkedBase; |
|
112 |
|
113 TUint iEntryPoint; |
|
114 TUint iHeapCommittedSize; |
|
115 TUint iHeapReservedSize; |
|
116 TUint iStackCommittedSize; |
|
117 TUint iStackReservedSize; |
|
118 private: |
|
119 friend class E32ImageFile; |
|
120 friend class E32ImageFile_ELF; |
|
121 |
|
122 TText * iFileName; |
|
123 TInt32 iFileHandle; |
|
124 Elf32_Ehdr * iElfFile; |
|
125 Elf32_Phdr * iPhdr; |
|
126 Elf32_Phdr * iDynamicSegmentHdr; |
|
127 TInt iDynamicSegmentIdx; |
|
128 Elf32_Phdr * iCodeSegmentHdr; |
|
129 TInt iCodeSegmentIdx; |
|
130 Elf32_Phdr * iDataSegmentHdr; |
|
131 TInt iDataSegmentIdx; |
|
132 |
|
133 Elf32_Shdr * iSectionHeaderTable; |
|
134 TInt iSymIdx; |
|
135 Elf32_Sym * iSymTab; |
|
136 |
|
137 class ELFDllData; |
|
138 ELFDllData * iDllData; |
|
139 |
|
140 TCpu iCpu; |
|
141 |
|
142 |
|
143 }; |
|
144 #endif |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |