|
@@ -151,22 +151,6 @@ Optional<Image::Symbol> Loader::find_symbol(u32 address, u32* out_offset) const
|
|
return {};
|
|
return {};
|
|
|
|
|
|
SortedSymbol* sorted_symbols = nullptr;
|
|
SortedSymbol* sorted_symbols = nullptr;
|
|
-# ifdef KERNEL
|
|
|
|
- if (!m_sorted_symbols_region) {
|
|
|
|
- m_sorted_symbols_region = MM.allocate_kernel_region(PAGE_ROUND_UP(m_symbol_count * sizeof(SortedSymbol)), "Sorted symbols", Kernel::Region::Access::Read | Kernel::Region::Access::Write);
|
|
|
|
- sorted_symbols = (SortedSymbol*)m_sorted_symbols_region->vaddr().as_ptr();
|
|
|
|
- size_t index = 0;
|
|
|
|
- m_image.for_each_symbol([&](auto& symbol) {
|
|
|
|
- sorted_symbols[index++] = { symbol.value(), symbol.name() };
|
|
|
|
- return IterationDecision::Continue;
|
|
|
|
- });
|
|
|
|
- quick_sort(sorted_symbols, sorted_symbols + m_symbol_count, [](auto& a, auto& b) {
|
|
|
|
- return a.address < b.address;
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- sorted_symbols = (SortedSymbol*)m_sorted_symbols_region->vaddr().as_ptr();
|
|
|
|
- }
|
|
|
|
-# else
|
|
|
|
if (m_sorted_symbols.is_empty()) {
|
|
if (m_sorted_symbols.is_empty()) {
|
|
m_sorted_symbols.ensure_capacity(m_symbol_count);
|
|
m_sorted_symbols.ensure_capacity(m_symbol_count);
|
|
m_image.for_each_symbol([this](auto& symbol) {
|
|
m_image.for_each_symbol([this](auto& symbol) {
|
|
@@ -178,7 +162,6 @@ Optional<Image::Symbol> Loader::find_symbol(u32 address, u32* out_offset) const
|
|
});
|
|
});
|
|
}
|
|
}
|
|
sorted_symbols = m_sorted_symbols.data();
|
|
sorted_symbols = m_sorted_symbols.data();
|
|
-# endif
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_symbol_count; ++i) {
|
|
for (size_t i = 0; i < m_symbol_count; ++i) {
|
|
if (sorted_symbols[i].address > address) {
|
|
if (sorted_symbols[i].address > address) {
|
|
@@ -192,7 +175,6 @@ Optional<Image::Symbol> Loader::find_symbol(u32 address, u32* out_offset) const
|
|
}
|
|
}
|
|
return {};
|
|
return {};
|
|
}
|
|
}
|
|
-#endif
|
|
|
|
|
|
|
|
String Loader::symbolicate(u32 address, u32* out_offset) const
|
|
String Loader::symbolicate(u32 address, u32* out_offset) const
|
|
{
|
|
{
|
|
@@ -202,22 +184,7 @@ String Loader::symbolicate(u32 address, u32* out_offset) const
|
|
return "??";
|
|
return "??";
|
|
}
|
|
}
|
|
SortedSymbol* sorted_symbols = nullptr;
|
|
SortedSymbol* sorted_symbols = nullptr;
|
|
-#ifdef KERNEL
|
|
|
|
- if (!m_sorted_symbols_region) {
|
|
|
|
- m_sorted_symbols_region = MM.allocate_kernel_region(PAGE_ROUND_UP(m_symbol_count * sizeof(SortedSymbol)), "Sorted symbols", Kernel::Region::Access::Read | Kernel::Region::Access::Write);
|
|
|
|
- sorted_symbols = (SortedSymbol*)m_sorted_symbols_region->vaddr().as_ptr();
|
|
|
|
- size_t index = 0;
|
|
|
|
- m_image.for_each_symbol([&](auto& symbol) {
|
|
|
|
- sorted_symbols[index++] = { symbol.value(), symbol.name() };
|
|
|
|
- return IterationDecision::Continue;
|
|
|
|
- });
|
|
|
|
- quick_sort(sorted_symbols, sorted_symbols + m_symbol_count, [](auto& a, auto& b) {
|
|
|
|
- return a.address < b.address;
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- sorted_symbols = (SortedSymbol*)m_sorted_symbols_region->vaddr().as_ptr();
|
|
|
|
- }
|
|
|
|
-#else
|
|
|
|
|
|
+
|
|
if (m_sorted_symbols.is_empty()) {
|
|
if (m_sorted_symbols.is_empty()) {
|
|
m_sorted_symbols.ensure_capacity(m_symbol_count);
|
|
m_sorted_symbols.ensure_capacity(m_symbol_count);
|
|
m_image.for_each_symbol([this](auto& symbol) {
|
|
m_image.for_each_symbol([this](auto& symbol) {
|
|
@@ -229,7 +196,6 @@ String Loader::symbolicate(u32 address, u32* out_offset) const
|
|
});
|
|
});
|
|
}
|
|
}
|
|
sorted_symbols = m_sorted_symbols.data();
|
|
sorted_symbols = m_sorted_symbols.data();
|
|
-#endif
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_symbol_count; ++i) {
|
|
for (size_t i = 0; i < m_symbol_count; ++i) {
|
|
if (sorted_symbols[i].address > address) {
|
|
if (sorted_symbols[i].address > address) {
|
|
@@ -240,14 +206,10 @@ String Loader::symbolicate(u32 address, u32* out_offset) const
|
|
}
|
|
}
|
|
auto& symbol = sorted_symbols[i - 1];
|
|
auto& symbol = sorted_symbols[i - 1];
|
|
|
|
|
|
-#ifdef KERNEL
|
|
|
|
- auto demangled_name = demangle(symbol.name);
|
|
|
|
-#else
|
|
|
|
auto& demangled_name = symbol.demangled_name;
|
|
auto& demangled_name = symbol.demangled_name;
|
|
if (demangled_name.is_null()) {
|
|
if (demangled_name.is_null()) {
|
|
demangled_name = demangle(symbol.name);
|
|
demangled_name = demangle(symbol.name);
|
|
}
|
|
}
|
|
-#endif
|
|
|
|
|
|
|
|
if (out_offset) {
|
|
if (out_offset) {
|
|
*out_offset = address - symbol.address;
|
|
*out_offset = address - symbol.address;
|
|
@@ -261,4 +223,6 @@ String Loader::symbolicate(u32 address, u32* out_offset) const
|
|
return "??";
|
|
return "??";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#endif
|
|
|
|
+
|
|
} // end namespace ELF
|
|
} // end namespace ELF
|