2 * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef ELF_SYMBOL_LOOKUP_H
6 #define ELF_SYMBOL_LOOKUP_H
12 #include <runtime_loader.h>
15 // values for SymbolLookupInfo::flags
16 #define LOOKUP_FLAG_DEFAULT_VERSION 0x01
19 uint32
elf_hash(const char* name
);
22 struct SymbolLookupInfo
{
27 const elf_version_info
* version
;
28 elf_sym
* requestingSymbol
;
30 SymbolLookupInfo(const char* name
, int32 type
, uint32 hash
,
31 const elf_version_info
* version
= NULL
, uint32 flags
= 0,
32 elf_sym
* requestingSymbol
= NULL
)
39 requestingSymbol(requestingSymbol
)
43 SymbolLookupInfo(const char* name
, int32 type
,
44 const elf_version_info
* version
= NULL
, uint32 flags
= 0,
45 elf_sym
* requestingSymbol
= NULL
)
52 requestingSymbol(requestingSymbol
)
58 struct SymbolLookupCache
{
59 SymbolLookupCache(image_t
* image
)
61 fTableSize(image
->symhash
!= NULL
? image
->symhash
[1] : 0),
67 fValues
= (addr_t
*)malloc(sizeof(addr_t
) * fTableSize
);
68 fDSOs
= (image_t
**)malloc(sizeof(image_t
*) * fTableSize
);
70 size_t elementCount
= (fTableSize
+ 31) / 32;
71 fValuesResolved
= (uint32
*)malloc(4 * elementCount
);
72 memset(fValuesResolved
, 0, 4 * elementCount
);
74 if (fValues
== NULL
|| fDSOs
== NULL
|| fValuesResolved
== NULL
) {
75 free(fValuesResolved
);
85 free(fValuesResolved
);
90 bool IsSymbolValueCached(size_t index
) const
92 return index
< fTableSize
93 && (fValuesResolved
[index
/ 32] & (1 << (index
% 32))) != 0;
96 addr_t
SymbolValueAt(size_t index
) const
98 return fValues
[index
];
101 addr_t
SymbolValueAt(size_t index
, image_t
** image
) const
104 *image
= fDSOs
[index
];
105 return fValues
[index
];
108 void SetSymbolValueAt(size_t index
, addr_t value
, image_t
* image
)
110 if (index
< fTableSize
) {
111 fValues
[index
] = value
;
112 fDSOs
[index
] = image
;
113 fValuesResolved
[index
/ 32] |= 1 << (index
% 32);
121 uint32
* fValuesResolved
;
125 void patch_defined_symbol(image_t
* image
, const char* name
,
126 void** symbol
, int32
* type
);
127 void patch_undefined_symbol(image_t
* rootImage
, image_t
* image
,
128 const char* name
, image_t
** foundInImage
, void** symbol
,
131 elf_sym
* find_symbol(image_t
* image
, const SymbolLookupInfo
& lookupInfo
,
132 bool allowLocal
= false);
133 status_t
find_symbol(image_t
* image
, const SymbolLookupInfo
& lookupInfo
,
135 status_t
find_symbol_breadth_first(image_t
* image
,
136 const SymbolLookupInfo
& lookupInfo
, image_t
** _foundInImage
,
138 elf_sym
* find_undefined_symbol_beos(image_t
* rootImage
, image_t
* image
,
139 const SymbolLookupInfo
& lookupInfo
, image_t
** foundInImage
);
140 elf_sym
* find_undefined_symbol_global(image_t
* rootImage
, image_t
* image
,
141 const SymbolLookupInfo
& lookupInfo
, image_t
** foundInImage
);
142 elf_sym
* find_undefined_symbol_add_on(image_t
* rootImage
, image_t
* image
,
143 const SymbolLookupInfo
& lookupInfo
, image_t
** foundInImage
);
146 #endif // ELF_SYMBOL_LOOKUP_H