summaryrefslogtreecommitdiff
path: root/DevTools
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-16 00:23:02 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-16 00:24:11 +0200
commit67cdbe19254c6aedb0ebb5669f9ddb072f5aa497 (patch)
tree5c64050dd969889eb5cb4560bf99798334db1a3b /DevTools
parent862ab82c195a8e101962837f06497f3c43cd7c43 (diff)
downloadserenity-67cdbe19254c6aedb0ebb5669f9ddb072f5aa497.zip
UserspaceEmulator: Cache the location and size of "malloc" and "free"
This allows us to quickly skip some auditing checks while we're inside malloc/free themselves.
Diffstat (limited to 'DevTools')
-rw-r--r--DevTools/UserspaceEmulator/Emulator.cpp11
-rw-r--r--DevTools/UserspaceEmulator/Emulator.h5
2 files changed, 14 insertions, 2 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp
index d8ac88057e..fac2bf92b6 100644
--- a/DevTools/UserspaceEmulator/Emulator.cpp
+++ b/DevTools/UserspaceEmulator/Emulator.cpp
@@ -125,6 +125,14 @@ bool Emulator::load_elf()
});
m_cpu.set_eip(m_elf->image().entry().get());
+
+ auto malloc_symbol = m_elf->find_demangled_function("malloc");
+ auto free_symbol = m_elf->find_demangled_function("free");
+
+ m_malloc_symbol_start = malloc_symbol.value().value();
+ m_malloc_symbol_end = m_malloc_symbol_start + malloc_symbol.value().size();
+ m_free_symbol_start = free_symbol.value().value();
+ m_free_symbol_end = m_free_symbol_start + free_symbol.value().size();
return true;
}
@@ -170,8 +178,7 @@ int Emulator::exec()
bool Emulator::is_in_malloc_or_free() const
{
- auto symbol = m_elf->symbolicate(m_cpu.eip());
- return symbol.starts_with("malloc") || symbol.starts_with("free");
+ return (m_cpu.eip() >= m_malloc_symbol_start && m_cpu.eip() < m_malloc_symbol_end) || (m_cpu.eip() >= m_free_symbol_start && m_cpu.eip() < m_free_symbol_end);
}
static pid_t s_pid = getpid();
diff --git a/DevTools/UserspaceEmulator/Emulator.h b/DevTools/UserspaceEmulator/Emulator.h
index fbfcfee319..cd15c61400 100644
--- a/DevTools/UserspaceEmulator/Emulator.h
+++ b/DevTools/UserspaceEmulator/Emulator.h
@@ -117,6 +117,11 @@ private:
bool m_shutdown { false };
int m_exit_status { 0 };
+
+ FlatPtr m_malloc_symbol_start { 0 };
+ FlatPtr m_malloc_symbol_end { 0 };
+ FlatPtr m_free_symbol_start { 0 };
+ FlatPtr m_free_symbol_end { 0 };
};
}