mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:07:35 +00:00
UserspaceEmulator: Remove unnecessary local getpid() caches
Now that LibC caches this for us, we can stop worrying.
This commit is contained in:
parent
b820e4626c
commit
d1dd5013ea
3 changed files with 14 additions and 18 deletions
|
@ -191,8 +191,6 @@ bool Emulator::is_in_malloc_or_free() const
|
||||||
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);
|
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();
|
|
||||||
|
|
||||||
Vector<FlatPtr> Emulator::raw_backtrace()
|
Vector<FlatPtr> Emulator::raw_backtrace()
|
||||||
{
|
{
|
||||||
Vector<FlatPtr> backtrace;
|
Vector<FlatPtr> backtrace;
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
|
|
||||||
namespace UserspaceEmulator {
|
namespace UserspaceEmulator {
|
||||||
|
|
||||||
static pid_t s_pid = getpid();
|
|
||||||
|
|
||||||
MallocTracer::MallocTracer()
|
MallocTracer::MallocTracer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -69,8 +67,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
|
||||||
if (mallocation.address == address) {
|
if (mallocation.address == address) {
|
||||||
if (mallocation.freed) {
|
if (mallocation.freed) {
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
dbgprintf("==%d== \033[31;1mDouble free()\033[0m, %p\n", s_pid, address);
|
dbgprintf("==%d== \033[31;1mDouble free()\033[0m, %p\n", getpid(), address);
|
||||||
dbgprintf("==%d== Address %p has already been passed to free()\n", s_pid, address);
|
dbgprintf("==%d== Address %p has already been passed to free()\n", getpid(), address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
} else {
|
} else {
|
||||||
mallocation.freed = true;
|
mallocation.freed = true;
|
||||||
|
@ -80,8 +78,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
dbgprintf("==%d== \033[31;1mInvalid free()\033[0m, %p\n", s_pid, address);
|
dbgprintf("==%d== \033[31;1mInvalid free()\033[0m, %p\n", getpid(), address);
|
||||||
dbgprintf("==%d== Address %p has never been returned by malloc()\n", s_pid, address);
|
dbgprintf("==%d== Address %p has never been returned by malloc()\n", getpid(), address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,11 +108,11 @@ void MallocTracer::audit_read(FlatPtr address, size_t size)
|
||||||
|
|
||||||
if (mallocation->freed) {
|
if (mallocation->freed) {
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
dbgprintf("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte read at address %p\n", s_pid, size, address);
|
dbgprintf("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte read at address %p\n", getpid(), size, address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
dbgprintf("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", s_pid, offset_into_mallocation, mallocation->size);
|
dbgprintf("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
||||||
dbgprintf("==%d== Later freed at:\n", s_pid, offset_into_mallocation, mallocation->size);
|
dbgprintf("==%d== Later freed at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,11 +134,11 @@ void MallocTracer::audit_write(FlatPtr address, size_t size)
|
||||||
|
|
||||||
if (mallocation->freed) {
|
if (mallocation->freed) {
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
dbgprintf("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte write at address %p\n", s_pid, size, address);
|
dbgprintf("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte write at address %p\n", getpid(), size, address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
dbgprintf("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", s_pid, offset_into_mallocation, mallocation->size);
|
dbgprintf("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
||||||
dbgprintf("==%d== Later freed at:\n", s_pid, offset_into_mallocation, mallocation->size);
|
dbgprintf("==%d== Later freed at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -211,15 +209,15 @@ void MallocTracer::dump_leak_report()
|
||||||
++leaks_found;
|
++leaks_found;
|
||||||
bytes_leaked += mallocation.size;
|
bytes_leaked += mallocation.size;
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
dbgprintf("==%d== \033[31;1mLeak\033[0m, %zu-byte allocation at address %p\n", s_pid, mallocation.size, mallocation.address);
|
dbgprintf("==%d== \033[31;1mLeak\033[0m, %zu-byte allocation at address %p\n", getpid(), mallocation.size, mallocation.address);
|
||||||
Emulator::the().dump_backtrace(mallocation.malloc_backtrace);
|
Emulator::the().dump_backtrace(mallocation.malloc_backtrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
if (!leaks_found)
|
if (!leaks_found)
|
||||||
dbgprintf("==%d== \033[32;1mNo leaks found!\033[0m\n", s_pid);
|
dbgprintf("==%d== \033[32;1mNo leaks found!\033[0m\n", getpid());
|
||||||
else
|
else
|
||||||
dbgprintf("==%d== \033[31;1m%zu leak(s) found: %zu byte(s) leaked\033[0m\n", s_pid, leaks_found, bytes_leaked);
|
dbgprintf("==%d== \033[31;1m%zu leak(s) found: %zu byte(s) leaked\033[0m\n", getpid(), leaks_found, bytes_leaked);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ void warn_if_uninitialized(T value_with_shadow, const char* message)
|
||||||
void SoftCPU::warn_if_flags_tainted(const char* message) const
|
void SoftCPU::warn_if_flags_tainted(const char* message) const
|
||||||
{
|
{
|
||||||
if (m_flags_tainted) {
|
if (m_flags_tainted) {
|
||||||
dbgprintf("\033[31;1mWarning! Conditional instruction depends on uninitialized data (%s)\033[0m\n", message);
|
dbgprintf("==%d== \033[31;1mConditional instruction depends on uninitialized data (%s)\033[0m\n", getpid(), message);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue