summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCoreDump
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-03-26 18:46:20 +0300
committerAndreas Kling <kling@serenityos.org>2021-03-28 20:42:33 +0200
commit9f656b6fa98439132bce394fe46f2691cb9afa90 (patch)
treeb4a17797700fba4685e2dbf8d26e8356c901bc22 /Userland/Libraries/LibCoreDump
parentb8f462a78b459466d34945ee82fb1e6bcea936ae (diff)
downloadserenity-9f656b6fa98439132bce394fe46f2691cb9afa90.zip
LibCoreDump+CrashDaemon: Compress coredumps
Most coredumps contain large amounts of consecutive null bytes and as such are a prime candidate for compression. This commit makes CrashDaemon compress files once the kernel finishes emitting them, as well as adds the functionality needed in LibCoreDump to then parse them.
Diffstat (limited to 'Userland/Libraries/LibCoreDump')
-rw-r--r--Userland/Libraries/LibCoreDump/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibCoreDump/Reader.cpp19
-rw-r--r--Userland/Libraries/LibCoreDump/Reader.h6
3 files changed, 20 insertions, 7 deletions
diff --git a/Userland/Libraries/LibCoreDump/CMakeLists.txt b/Userland/Libraries/LibCoreDump/CMakeLists.txt
index f6a9457d30..d1b05fed07 100644
--- a/Userland/Libraries/LibCoreDump/CMakeLists.txt
+++ b/Userland/Libraries/LibCoreDump/CMakeLists.txt
@@ -4,4 +4,4 @@ set(SOURCES
)
serenity_lib(LibCoreDump coredump)
-target_link_libraries(LibCoreDump LibC LibCore LibDebug)
+target_link_libraries(LibCoreDump LibC LibCompress LibCore LibDebug)
diff --git a/Userland/Libraries/LibCoreDump/Reader.cpp b/Userland/Libraries/LibCoreDump/Reader.cpp
index 24a97293fc..fee4fd2f6a 100644
--- a/Userland/Libraries/LibCoreDump/Reader.cpp
+++ b/Userland/Libraries/LibCoreDump/Reader.cpp
@@ -26,6 +26,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
+#include <LibCompress/Gzip.h>
#include <LibCoreDump/Reader.h>
#include <signal_numbers.h>
#include <string.h>
@@ -37,12 +38,12 @@ OwnPtr<Reader> Reader::create(const String& path)
auto file_or_error = MappedFile::map(path);
if (file_or_error.is_error())
return {};
- return adopt_own(*new Reader(file_or_error.release_value()));
+ return adopt_own(*new Reader(file_or_error.value()->bytes()));
}
-Reader::Reader(NonnullRefPtr<MappedFile> coredump_file)
- : m_coredump_file(move(coredump_file))
- , m_coredump_image(m_coredump_file->bytes())
+Reader::Reader(ReadonlyBytes coredump_bytes)
+ : m_coredump_buffer(decompress_coredump(coredump_bytes))
+ , m_coredump_image(m_coredump_buffer.bytes())
{
size_t index = 0;
m_coredump_image.for_each_program_header([this, &index](auto pheader) {
@@ -56,6 +57,16 @@ Reader::Reader(NonnullRefPtr<MappedFile> coredump_file)
VERIFY(m_notes_segment_index != -1);
}
+ByteBuffer Reader::decompress_coredump(const ReadonlyBytes& raw_coredump)
+{
+ if (!Compress::GzipDecompressor::is_likely_compressed(raw_coredump))
+ return ByteBuffer::copy(raw_coredump); // handle old format core dumps (uncompressed)
+ auto decompressed_coredump = Compress::GzipDecompressor::decompress_all(raw_coredump);
+ if (!decompressed_coredump.has_value())
+ return ByteBuffer::copy(raw_coredump); // if we didnt manage to decompress it, try and parse it as decompressed core dump
+ return decompressed_coredump.value();
+}
+
Reader::~Reader()
{
}
diff --git a/Userland/Libraries/LibCoreDump/Reader.h b/Userland/Libraries/LibCoreDump/Reader.h
index 7fd3aaf715..8cf111d759 100644
--- a/Userland/Libraries/LibCoreDump/Reader.h
+++ b/Userland/Libraries/LibCoreDump/Reader.h
@@ -70,7 +70,9 @@ public:
HashMap<String, String> metadata() const;
private:
- Reader(NonnullRefPtr<MappedFile>);
+ Reader(ReadonlyBytes);
+
+ static ByteBuffer decompress_coredump(const ReadonlyBytes&);
class NotesEntryIterator {
public:
@@ -92,7 +94,7 @@ private:
// as getters with the appropriate (non-JsonValue) types.
const JsonObject process_info() const;
- NonnullRefPtr<MappedFile> m_coredump_file;
+ ByteBuffer m_coredump_buffer;
ELF::Image m_coredump_image;
ssize_t m_notes_segment_index { -1 };
};