1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:28:13 +00:00

AK: Make MappedFile heap-allocated and ref-counted

Let's adapt this class a bit better to how it's actually being used.

Instead of having valid/invalid states and storing an error in case
it's invalid, a MappedFile is now always valid, and the factory
function that creates it will return an OSError if mapping fails.
This commit is contained in:
Andreas Kling 2021-01-10 15:55:54 +01:00
parent 70fce5c4c7
commit 2f3b901f7f
36 changed files with 184 additions and 199 deletions

View file

@ -38,13 +38,12 @@ namespace CoreDump {
class Reader {
AK_MAKE_NONCOPYABLE(Reader);
AK_MAKE_NONMOVABLE(Reader);
public:
static OwnPtr<Reader> create(const String&);
~Reader();
Reader(OwnPtr<MappedFile>&&);
const ELF::Core::ProcessInfo& process_info() const;
template<typename Func>
@ -61,7 +60,7 @@ public:
struct LibraryData {
String name;
FlatPtr base_address { 0 };
OwnPtr<MappedFile> file;
NonnullRefPtr<MappedFile> file;
ELF::Image lib_elf;
};
const LibraryData* library_containing(FlatPtr address) const;
@ -70,6 +69,8 @@ public:
const HashMap<String, String> metadata() const;
private:
Reader(NonnullRefPtr<MappedFile>);
class NotesEntryIterator {
public:
NotesEntryIterator(const u8* notes_data);
@ -85,7 +86,7 @@ private:
const u8* start { nullptr };
};
OwnPtr<MappedFile> m_coredump_file;
NonnullRefPtr<MappedFile> m_coredump_file;
ELF::Image m_coredump_image;
ssize_t m_notes_segment_index { -1 };
};