diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-21 18:46:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-21 19:08:01 +0200 |
commit | d1dd5013ead09bf123e95d40404c970829190ad2 (patch) | |
tree | bb2941fab31248e32a51ec9702f865ba7fe89048 | |
parent | b820e4626c1a1bde87684807273a7464f160311d (diff) | |
download | serenity-d1dd5013ead09bf123e95d40404c970829190ad2.zip |
UserspaceEmulator: Remove unnecessary local getpid() caches
Now that LibC caches this for us, we can stop worrying.
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.cpp | 2 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.cpp | 28 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftCPU.cpp | 2 |
3 files changed, 14 insertions, 18 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index df24092a03..15f80f6d52 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -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); } -static pid_t s_pid = getpid(); - Vector<FlatPtr> Emulator::raw_backtrace() { Vector<FlatPtr> backtrace; diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp index 47c0e53ae1..31e3da0636 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -34,8 +34,6 @@ namespace UserspaceEmulator { -static pid_t s_pid = getpid(); - MallocTracer::MallocTracer() { } @@ -69,8 +67,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address) if (mallocation.address == address) { if (mallocation.freed) { dbgprintf("\n"); - dbgprintf("==%d== \033[31;1mDouble free()\033[0m, %p\n", s_pid, address); - dbgprintf("==%d== Address %p has already been passed to free()\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", getpid(), address); Emulator::the().dump_backtrace(); } else { mallocation.freed = true; @@ -80,8 +78,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address) } } dbgprintf("\n"); - dbgprintf("==%d== \033[31;1mInvalid free()\033[0m, %p\n", s_pid, address); - dbgprintf("==%d== Address %p has never been returned by malloc()\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", getpid(), address); Emulator::the().dump_backtrace(); } @@ -110,11 +108,11 @@ void MallocTracer::audit_read(FlatPtr address, size_t size) if (mallocation->freed) { 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(); - 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); - 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); return; } @@ -136,11 +134,11 @@ void MallocTracer::audit_write(FlatPtr address, size_t size) if (mallocation->freed) { 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(); - 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); - 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); return; } @@ -211,15 +209,15 @@ void MallocTracer::dump_leak_report() ++leaks_found; bytes_leaked += mallocation.size; 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); } dbgprintf("\n"); 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 - 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); } } diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index fa72c3a4ff..82b2bf1f44 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -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 { 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(); } } |