From 58fb3ebf660e87a7ac93b5e8a7433ff441e30639 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Nov 2021 11:32:25 +0100 Subject: [PATCH] LibCore+AK: Move MappedFile from AK to LibCore MappedFile is strictly a userspace thing, so it doesn't belong in AK (which is supposed to be user/kernel agnostic.) --- Tests/LibGfx/TestImageDecoder.cpp | 18 +++++++++--------- Userland/Applications/Help/ManualModel.cpp | 2 +- Userland/Applications/Help/ManualModel.h | 2 +- .../Applications/ImageViewer/ViewWidget.cpp | 4 ++-- Userland/Applications/PixelPaint/Image.cpp | 2 +- .../Applications/PixelPaint/ProjectLoader.cpp | 4 ++-- .../HackStudio/Debugger/DisassemblyModel.cpp | 4 ++-- .../DevTools/Profiler/DisassemblyModel.cpp | 4 ++-- Userland/DevTools/Profiler/Process.cpp | 2 +- Userland/DevTools/Profiler/Process.h | 4 ++-- Userland/DevTools/Profiler/Profile.cpp | 4 ++-- Userland/DevTools/Profiler/Profile.h | 2 +- .../DevTools/UserspaceEmulator/Emulator.cpp | 8 ++++---- Userland/DevTools/UserspaceEmulator/Emulator.h | 4 ++-- Userland/Libraries/LibCore/CMakeLists.txt | 1 + .../Libraries/LibCore}/MappedFile.cpp | 4 ++-- .../Libraries/LibCore}/MappedFile.h | 6 ++---- Userland/Libraries/LibCoredump/Backtrace.cpp | 4 ++-- Userland/Libraries/LibCoredump/Backtrace.h | 4 ++-- Userland/Libraries/LibCoredump/Inspector.cpp | 2 +- Userland/Libraries/LibCoredump/Reader.cpp | 7 +++---- Userland/Libraries/LibCoredump/Reader.h | 8 ++++---- Userland/Libraries/LibDebug/DebugSession.cpp | 2 +- Userland/Libraries/LibDebug/DebugSession.h | 2 +- Userland/Libraries/LibDebug/LoadedLibrary.h | 6 +++--- Userland/Libraries/LibGUI/FileIconProvider.cpp | 4 ++-- Userland/Libraries/LibGUI/ImageWidget.cpp | 4 ++-- Userland/Libraries/LibGfx/Bitmap.cpp | 4 ++-- Userland/Libraries/LibGfx/BitmapFont.cpp | 2 +- Userland/Libraries/LibGfx/BitmapFont.h | 4 ++-- Userland/Libraries/LibGfx/Font.h | 2 +- .../Libraries/LibGfx/TrueTypeFont/Font.cpp | 4 ++-- Userland/Libraries/LibGfx/TrueTypeFont/Font.h | 2 +- Userland/Libraries/LibPCIDB/Database.cpp | 2 +- Userland/Libraries/LibPCIDB/Database.h | 6 +++--- .../LibSymbolication/Symbolication.cpp | 6 +++--- Userland/Libraries/LibUSBDB/Database.cpp | 2 +- Userland/Libraries/LibUSBDB/Database.h | 6 +++--- Userland/Libraries/LibVideo/MatroskaReader.cpp | 4 ++-- Userland/Services/CrashDaemon/main.cpp | 4 ++-- Userland/Services/WebServer/Client.cpp | 6 +++--- Userland/Services/WebServer/main.cpp | 2 +- Userland/Utilities/disasm.cpp | 4 ++-- Userland/Utilities/fdtdump.cpp | 4 ++-- Userland/Utilities/file.cpp | 8 ++++---- Userland/Utilities/gzip.cpp | 4 ++-- Userland/Utilities/readelf.cpp | 6 +++--- Userland/Utilities/unzip.cpp | 4 ++-- 48 files changed, 101 insertions(+), 103 deletions(-) rename {AK => Userland/Libraries/LibCore}/MappedFile.cpp (96%) rename {AK => Userland/Libraries/LibCore}/MappedFile.h (88%) diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 459bf6a4b5..ce6d024172 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -5,8 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include +#include #include #include #include @@ -23,7 +23,7 @@ TEST_CASE(test_bmp) { - auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgba32-1.bmp").release_value(); + auto file = Core::MappedFile::map("/res/html/misc/bmpsuite_files/rgba32-1.bmp").release_value(); auto bmp = Gfx::BMPImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(bmp.frame_count()); @@ -37,7 +37,7 @@ TEST_CASE(test_bmp) TEST_CASE(test_gif) { - auto file = MappedFile::map("/res/graphics/download-animation.gif").release_value(); + auto file = Core::MappedFile::map("/res/graphics/download-animation.gif").release_value(); auto gif = Gfx::GIFImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(gif.frame_count()); @@ -52,7 +52,7 @@ TEST_CASE(test_gif) TEST_CASE(test_ico) { // FIXME: Use an ico file - auto file = MappedFile::map("/res/graphics/buggie.png").release_value(); + auto file = Core::MappedFile::map("/res/graphics/buggie.png").release_value(); auto ico = Gfx::ICOImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(ico.frame_count()); @@ -65,7 +65,7 @@ TEST_CASE(test_ico) TEST_CASE(test_jpg) { - auto file = MappedFile::map("/res/html/misc/bmpsuite_files/rgb24.jpg").release_value(); + auto file = Core::MappedFile::map("/res/html/misc/bmpsuite_files/rgb24.jpg").release_value(); auto jpg = Gfx::JPGImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(jpg.frame_count()); @@ -79,7 +79,7 @@ TEST_CASE(test_jpg) TEST_CASE(test_pbm) { - auto file = MappedFile::map("/res/html/misc/pbmsuite_files/buggie-raw.pbm").release_value(); + auto file = Core::MappedFile::map("/res/html/misc/pbmsuite_files/buggie-raw.pbm").release_value(); auto pbm = Gfx::PBMImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(pbm.frame_count()); @@ -93,7 +93,7 @@ TEST_CASE(test_pbm) TEST_CASE(test_pgm) { - auto file = MappedFile::map("/res/html/misc/pgmsuite_files/buggie-raw.pgm").release_value(); + auto file = Core::MappedFile::map("/res/html/misc/pgmsuite_files/buggie-raw.pgm").release_value(); auto pgm = Gfx::PGMImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(pgm.frame_count()); @@ -107,7 +107,7 @@ TEST_CASE(test_pgm) TEST_CASE(test_png) { - auto file = MappedFile::map("/res/graphics/buggie.png").release_value(); + auto file = Core::MappedFile::map("/res/graphics/buggie.png").release_value(); auto png = Gfx::PNGImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(png.frame_count()); @@ -121,7 +121,7 @@ TEST_CASE(test_png) TEST_CASE(test_ppm) { - auto file = MappedFile::map("/res/html/misc/ppmsuite_files/buggie-raw.ppm").release_value(); + auto file = Core::MappedFile::map("/res/html/misc/ppmsuite_files/buggie-raw.ppm").release_value(); auto ppm = Gfx::PPMImageDecoderPlugin((u8 const*)file->data(), file->size()); EXPECT(ppm.frame_count()); diff --git a/Userland/Applications/Help/ManualModel.cpp b/Userland/Applications/Help/ManualModel.cpp index 2fd7324df6..94f01c833c 100644 --- a/Userland/Applications/Help/ManualModel.cpp +++ b/Userland/Applications/Help/ManualModel.cpp @@ -72,7 +72,7 @@ ErrorOr ManualModel::page_view(String const& path) const return StringView { mapped_file.value()->bytes() }; } - auto file = TRY(MappedFile::map(path)); + auto file = TRY(Core::MappedFile::map(path)); StringView view { file->bytes() }; m_mapped_files.set(path, move(file)); diff --git a/Userland/Applications/Help/ManualModel.h b/Userland/Applications/Help/ManualModel.h index f9a28110dc..d6d8921a33 100644 --- a/Userland/Applications/Help/ManualModel.h +++ b/Userland/Applications/Help/ManualModel.h @@ -41,5 +41,5 @@ private: GUI::Icon m_section_open_icon; GUI::Icon m_section_icon; GUI::Icon m_page_icon; - mutable HashMap> m_mapped_files; + mutable HashMap> m_mapped_files; }; diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp index 825a96aa77..802c4a0e65 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.cpp +++ b/Userland/Applications/ImageViewer/ViewWidget.cpp @@ -8,10 +8,10 @@ #include "ViewWidget.h" #include -#include #include #include #include +#include #include #include #include @@ -243,7 +243,7 @@ void ViewWidget::load_from_file(const String& path) GUI::MessageBox::show(window(), String::formatted("Failed to open {}", path), "Cannot open image", GUI::MessageBox::Type::Error); }; - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) { show_error(); return; diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index dbbbdce429..7fb809725d 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/Userland/Applications/PixelPaint/ProjectLoader.cpp b/Userland/Applications/PixelPaint/ProjectLoader.cpp index c7ada507d4..360da91984 100644 --- a/Userland/Applications/PixelPaint/ProjectLoader.cpp +++ b/Userland/Applications/PixelPaint/ProjectLoader.cpp @@ -8,10 +8,10 @@ #include "Image.h" #include "Layer.h" #include -#include #include #include #include +#include #include namespace PixelPaint { @@ -29,7 +29,7 @@ ErrorOr ProjectLoader::try_load_from_fd_and_close(int fd, StringView path) if (json_or_error.is_error()) { m_is_raw_image = true; - auto mapped_file = TRY(MappedFile::map_from_fd_and_close(fd, path)); + auto mapped_file = TRY(Core::MappedFile::map_from_fd_and_close(fd, path)); // FIXME: Find a way to avoid the memory copy here. auto bitmap = TRY(Image::try_decode_bitmap(mapped_file->bytes())); diff --git a/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp b/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp index fdc43da679..e98c7f5d71 100644 --- a/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp +++ b/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp @@ -5,8 +5,8 @@ */ #include "DisassemblyModel.h" -#include #include +#include #include #include #include @@ -33,7 +33,7 @@ DisassemblyModel::DisassemblyModel(const Debug::DebugSession& debug_session, con auto maybe_kernel_base = Symbolication::kernel_base(); if (maybe_kernel_base.has_value() && containing_function.value().address_low >= maybe_kernel_base.value()) { - auto file_or_error = MappedFile::map("/boot/Kernel.debug"); + auto file_or_error = Core::MappedFile::map("/boot/Kernel.debug"); if (file_or_error.is_error()) return; kernel_elf = make(file_or_error.value()->bytes()); diff --git a/Userland/DevTools/Profiler/DisassemblyModel.cpp b/Userland/DevTools/Profiler/DisassemblyModel.cpp index 749377b38c..9cb250262b 100644 --- a/Userland/DevTools/Profiler/DisassemblyModel.cpp +++ b/Userland/DevTools/Profiler/DisassemblyModel.cpp @@ -6,7 +6,7 @@ #include "DisassemblyModel.h" #include "Profile.h" -#include +#include #include #include #include @@ -40,7 +40,7 @@ static ELF::Image* try_load_kernel_binary() { if (s_kernel_binary.has_value()) return &s_kernel_binary->elf; - auto kernel_binary_or_error = MappedFile::map("/boot/Kernel"); + auto kernel_binary_or_error = Core::MappedFile::map("/boot/Kernel"); if (!kernel_binary_or_error.is_error()) { auto kernel_binary = kernel_binary_or_error.release_value(); s_kernel_binary = { { kernel_binary, ELF::Image(kernel_binary->bytes()) } }; diff --git a/Userland/DevTools/Profiler/Process.cpp b/Userland/DevTools/Profiler/Process.cpp index 0924ab8959..1d46c6323e 100644 --- a/Userland/DevTools/Profiler/Process.cpp +++ b/Userland/DevTools/Profiler/Process.cpp @@ -48,7 +48,7 @@ static MappedObject* get_or_create_mapped_object(const String& path) if (auto it = g_mapped_object_cache.find(path); it != g_mapped_object_cache.end()) return it->value.ptr(); - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) { g_mapped_object_cache.set(path, {}); return nullptr; diff --git a/Userland/DevTools/Profiler/Process.h b/Userland/DevTools/Profiler/Process.h index 322a5ff098..d63d2a7c61 100644 --- a/Userland/DevTools/Profiler/Process.h +++ b/Userland/DevTools/Profiler/Process.h @@ -8,16 +8,16 @@ #include "EventSerialNumber.h" #include -#include #include #include +#include #include #include namespace Profiler { struct MappedObject { - NonnullRefPtr file; + NonnullRefPtr file; ELF::Image elf; }; diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 5166773352..54c6c33fdb 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -10,12 +10,12 @@ #include "SamplesModel.h" #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -226,7 +226,7 @@ ErrorOr> Profile::load_from_perfcore_file(StringView path auto& object = json.value().as_object(); if (!g_kernel_debuginfo_object.has_value()) { - auto debuginfo_file_or_error = MappedFile::map("/boot/Kernel.debug"); + auto debuginfo_file_or_error = Core::MappedFile::map("/boot/Kernel.debug"); if (!debuginfo_file_or_error.is_error()) { auto debuginfo_file = debuginfo_file_or_error.release_value(); auto debuginfo_image = ELF::Image(debuginfo_file->bytes()); diff --git a/Userland/DevTools/Profiler/Profile.h b/Userland/DevTools/Profiler/Profile.h index 377a3a65af..1e6ac39a36 100644 --- a/Userland/DevTools/Profiler/Profile.h +++ b/Userland/DevTools/Profiler/Profile.h @@ -17,10 +17,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.cpp b/Userland/DevTools/UserspaceEmulator/Emulator.cpp index 0b9e4b2fcf..0ea461c761 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator.cpp @@ -13,9 +13,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -149,7 +149,7 @@ void Emulator::setup_stack(Vector aux_vector) bool Emulator::load_elf() { - auto file_or_error = MappedFile::map(m_executable_path); + auto file_or_error = Core::MappedFile::map(m_executable_path); if (file_or_error.is_error()) { reportln("Unable to map {}: {}", m_executable_path, file_or_error.error()); return false; @@ -172,7 +172,7 @@ bool Emulator::load_elf() VERIFY(!interpreter_path.is_null()); dbgln("interpreter: {}", interpreter_path); - auto interpreter_file_or_error = MappedFile::map(interpreter_path); + auto interpreter_file_or_error = Core::MappedFile::map(interpreter_path); VERIFY(!interpreter_file_or_error.is_error()); auto interpreter_image_data = interpreter_file_or_error.value()->bytes(); ELF::Image interpreter_image(interpreter_image_data); @@ -400,7 +400,7 @@ MmapRegion const* Emulator::load_library_from_address(FlatPtr address) lib_path = String::formatted("/usr/lib/{}", lib_path); if (!m_dynamic_library_cache.contains(lib_path)) { - auto file_or_error = MappedFile::map(lib_path); + auto file_or_error = Core::MappedFile::map(lib_path); if (file_or_error.is_error()) return {}; diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h index 0a71c286f6..ff54269edf 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.h +++ b/Userland/DevTools/UserspaceEmulator/Emulator.h @@ -13,8 +13,8 @@ #include "SoftCPU.h" #include "SoftMMU.h" #include -#include #include +#include #include #include #include @@ -273,7 +273,7 @@ private: Optional m_loader_text_size; struct CachedELF { - NonnullRefPtr mapped_file; + NonnullRefPtr mapped_file; NonnullOwnPtr debug_info; NonnullOwnPtr image; }; diff --git a/Userland/Libraries/LibCore/CMakeLists.txt b/Userland/Libraries/LibCore/CMakeLists.txt index b90062a5c0..d3e415e517 100644 --- a/Userland/Libraries/LibCore/CMakeLists.txt +++ b/Userland/Libraries/LibCore/CMakeLists.txt @@ -16,6 +16,7 @@ set(SOURCES LocalServer.cpp LocalSocket.cpp LockFile.cpp + MappedFile.cpp MimeData.cpp NetworkJob.cpp NetworkResponse.cpp diff --git a/AK/MappedFile.cpp b/Userland/Libraries/LibCore/MappedFile.cpp similarity index 96% rename from AK/MappedFile.cpp rename to Userland/Libraries/LibCore/MappedFile.cpp index 2e4adc5577..fc98c43834 100644 --- a/AK/MappedFile.cpp +++ b/Userland/Libraries/LibCore/MappedFile.cpp @@ -4,16 +4,16 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include +#include #include #include #include #include #include -namespace AK { +namespace Core { ErrorOr> MappedFile::map(String const& path) { diff --git a/AK/MappedFile.h b/Userland/Libraries/LibCore/MappedFile.h similarity index 88% rename from AK/MappedFile.h rename to Userland/Libraries/LibCore/MappedFile.h index 95bed66b30..7048caf995 100644 --- a/AK/MappedFile.h +++ b/Userland/Libraries/LibCore/MappedFile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,7 +12,7 @@ #include #include -namespace AK { +namespace Core { class MappedFile : public RefCounted { AK_MAKE_NONCOPYABLE(MappedFile); @@ -38,5 +38,3 @@ private: }; } - -using AK::MappedFile; diff --git a/Userland/Libraries/LibCoredump/Backtrace.cpp b/Userland/Libraries/LibCoredump/Backtrace.cpp index a0f9969d42..03d3e2238a 100644 --- a/Userland/Libraries/LibCoredump/Backtrace.cpp +++ b/Userland/Libraries/LibCoredump/Backtrace.cpp @@ -5,11 +5,11 @@ */ #include -#include #include #include #include #include +#include #include #include #include @@ -30,7 +30,7 @@ ELFObjectInfo const* Backtrace::object_info_for_region(ELF::Core::MemoryRegionIn if (!Core::File::exists(path)) return nullptr; - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return nullptr; diff --git a/Userland/Libraries/LibCoredump/Backtrace.h b/Userland/Libraries/LibCoredump/Backtrace.h index a8a300bd62..cd4586155f 100644 --- a/Userland/Libraries/LibCoredump/Backtrace.h +++ b/Userland/Libraries/LibCoredump/Backtrace.h @@ -14,14 +14,14 @@ namespace Coredump { struct ELFObjectInfo { - ELFObjectInfo(NonnullRefPtr file, NonnullOwnPtr&& debug_info, NonnullOwnPtr image) + ELFObjectInfo(NonnullRefPtr file, NonnullOwnPtr&& debug_info, NonnullOwnPtr image) : file(move(file)) , debug_info(move(debug_info)) , image(move(image)) { } - NonnullRefPtr file; + NonnullRefPtr file; NonnullOwnPtr debug_info; NonnullOwnPtr image; }; diff --git a/Userland/Libraries/LibCoredump/Inspector.cpp b/Userland/Libraries/LibCoredump/Inspector.cpp index d5b7935bc8..4eb3614332 100644 --- a/Userland/Libraries/LibCoredump/Inspector.cpp +++ b/Userland/Libraries/LibCoredump/Inspector.cpp @@ -41,7 +41,7 @@ void Inspector::parse_loaded_libraries(Function on_progress) if (on_progress) on_progress(library_index / (float)number_of_libraries); - auto file_or_error = MappedFile::map(library.path); + auto file_or_error = Core::MappedFile::map(library.path); if (file_or_error.is_error()) return; diff --git a/Userland/Libraries/LibCoredump/Reader.cpp b/Userland/Libraries/LibCoredump/Reader.cpp index db5ed3f60a..30273b13ed 100644 --- a/Userland/Libraries/LibCoredump/Reader.cpp +++ b/Userland/Libraries/LibCoredump/Reader.cpp @@ -17,7 +17,7 @@ namespace Coredump { OwnPtr Reader::create(StringView path) { - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return {}; @@ -38,7 +38,7 @@ Reader::Reader(ByteBuffer buffer) m_coredump_buffer = move(buffer); } -Reader::Reader(NonnullRefPtr file) +Reader::Reader(NonnullRefPtr file) : Reader(file->bytes()) { m_mapped_file = move(file); @@ -261,7 +261,6 @@ HashMap Reader::metadata() const struct LibraryData { String name; - OwnPtr file; ELF::Image lib_elf; }; @@ -282,7 +281,7 @@ const Reader::LibraryData* Reader::library_containing(FlatPtr address) const } if (!cached_libs.contains(path)) { - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return {}; auto image = ELF::Image(file_or_error.value()->bytes()); diff --git a/Userland/Libraries/LibCoredump/Reader.h b/Userland/Libraries/LibCoredump/Reader.h index b6241ba754..915c586553 100644 --- a/Userland/Libraries/LibCoredump/Reader.h +++ b/Userland/Libraries/LibCoredump/Reader.h @@ -7,9 +7,9 @@ #pragma once #include -#include #include #include +#include #include #include @@ -46,7 +46,7 @@ public: struct LibraryData { String name; FlatPtr base_address { 0 }; - NonnullRefPtr file; + NonnullRefPtr file; ELF::Image lib_elf; }; const LibraryData* library_containing(FlatPtr address) const; @@ -61,7 +61,7 @@ public: private: explicit Reader(ReadonlyBytes); explicit Reader(ByteBuffer); - explicit Reader(NonnullRefPtr); + explicit Reader(NonnullRefPtr); static Optional decompress_coredump(ReadonlyBytes); @@ -86,7 +86,7 @@ private: const JsonObject process_info() const; // For uncompressed coredumps, we keep the MappedFile - RefPtr m_mapped_file; + RefPtr m_mapped_file; // For compressed coredumps, we decompress them into a ByteBuffer ByteBuffer m_coredump_buffer; diff --git a/Userland/Libraries/LibDebug/DebugSession.cpp b/Userland/Libraries/LibDebug/DebugSession.cpp index 41b579dacf..487132c2d2 100644 --- a/Userland/Libraries/LibDebug/DebugSession.cpp +++ b/Userland/Libraries/LibDebug/DebugSession.cpp @@ -452,7 +452,7 @@ void DebugSession::update_loaded_libs() return IterationDecision::Continue; } - auto file_or_error = MappedFile::map(object_path.value()); + auto file_or_error = Core::MappedFile::map(object_path.value()); if (file_or_error.is_error()) return IterationDecision::Continue; diff --git a/Userland/Libraries/LibDebug/DebugSession.h b/Userland/Libraries/LibDebug/DebugSession.h index 43f05fb67f..0949ca47f7 100644 --- a/Userland/Libraries/LibDebug/DebugSession.h +++ b/Userland/Libraries/LibDebug/DebugSession.h @@ -8,12 +8,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibDebug/LoadedLibrary.h b/Userland/Libraries/LibDebug/LoadedLibrary.h index 15141bae88..2eb29f15c7 100644 --- a/Userland/Libraries/LibDebug/LoadedLibrary.h +++ b/Userland/Libraries/LibDebug/LoadedLibrary.h @@ -7,19 +7,19 @@ #pragma once #include "DebugInfo.h" -#include #include +#include #include namespace Debug { struct LoadedLibrary { String name; - NonnullRefPtr file; + NonnullRefPtr file; NonnullOwnPtr image; NonnullOwnPtr debug_info; FlatPtr base_address {}; - LoadedLibrary(String const& name, NonnullRefPtr file, NonnullOwnPtr image, NonnullOwnPtr&& debug_info, FlatPtr base_address) + LoadedLibrary(String const& name, NonnullRefPtr file, NonnullOwnPtr image, NonnullOwnPtr&& debug_info, FlatPtr base_address) : name(name) , file(move(file)) , image(move(image)) diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index 90eafe9404..8b2c14c778 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -5,10 +5,10 @@ */ #include -#include #include #include #include +#include #include #include #include @@ -147,7 +147,7 @@ Icon FileIconProvider::icon_for_executable(const String& path) // If the icon for an app isn't in the cache we attempt to load the file as an ELF image and extract // the serenity_app_icon_* sections which should contain the icons as raw PNG data. In the future it would // be better if the binary signalled the image format being used or we deduced it, e.g. using magic bytes. - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) { app_icon_cache.set(path, s_executable_icon); return s_executable_icon; diff --git a/Userland/Libraries/LibGUI/ImageWidget.cpp b/Userland/Libraries/LibGUI/ImageWidget.cpp index 03cc58e271..b28ee605a2 100644 --- a/Userland/Libraries/LibGUI/ImageWidget.cpp +++ b/Userland/Libraries/LibGUI/ImageWidget.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include #include @@ -73,7 +73,7 @@ void ImageWidget::animate() void ImageWidget::load_from_file(StringView path) { - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return; diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 06f2afe419..32ff60175c 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -6,13 +6,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include #include #include @@ -134,7 +134,7 @@ ErrorOr> Bitmap::try_load_from_file(String const& path, in ErrorOr> Bitmap::try_load_from_fd_and_close(int fd, String const& path) { - auto file = TRY(MappedFile::map_from_fd_and_close(fd, path)); + auto file = TRY(Core::MappedFile::map_from_fd_and_close(fd, path)); if (auto decoder = ImageDecoder::try_create(file->bytes())) { auto frame = TRY(decoder->frame(0)); if (auto& bitmap = frame.image) diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index a3c6dc06ea..c7db009236 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -202,7 +202,7 @@ RefPtr BitmapFont::load_from_file(String const& path) if (Core::File::is_device(path)) return nullptr; - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return nullptr; diff --git a/Userland/Libraries/LibGfx/BitmapFont.h b/Userland/Libraries/LibGfx/BitmapFont.h index 5734fe64ec..6adb4858c1 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.h +++ b/Userland/Libraries/LibGfx/BitmapFont.h @@ -7,12 +7,12 @@ #pragma once #include -#include #include #include #include #include #include +#include #include #include @@ -128,7 +128,7 @@ private: u8* m_rows { nullptr }; u8* m_glyph_widths { nullptr }; - RefPtr m_mapped_file; + RefPtr m_mapped_file; u8 m_glyph_width { 0 }; u8 m_glyph_height { 0 }; diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index f622724846..32facfa1f9 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -8,11 +8,11 @@ #include #include -#include #include #include #include #include +#include #include #include diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp b/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp index 6f5beddb8f..fe7e0b02e7 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp @@ -6,11 +6,11 @@ */ #include -#include #include #include #include #include +#include #include #include #include @@ -227,7 +227,7 @@ GlyphHorizontalMetrics Hmtx::get_glyph_horizontal_metrics(u32 glyph_id) const ErrorOr> Font::try_load_from_file(String path, unsigned index) { - auto file = TRY(MappedFile::map(path)); + auto file = TRY(Core::MappedFile::map(path)); auto font = TRY(try_load_from_externally_owned_memory(file->bytes(), index)); font->m_mapped_file = move(file); return font; diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h index a5cb528d04..3f4341d850 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h @@ -87,7 +87,7 @@ private: { } - RefPtr m_mapped_file; + RefPtr m_mapped_file; ReadonlyBytes m_buffer; diff --git a/Userland/Libraries/LibPCIDB/Database.cpp b/Userland/Libraries/LibPCIDB/Database.cpp index 4282afd84c..ce23b80994 100644 --- a/Userland/Libraries/LibPCIDB/Database.cpp +++ b/Userland/Libraries/LibPCIDB/Database.cpp @@ -14,7 +14,7 @@ namespace PCIDB { RefPtr Database::open(const String& filename) { - auto file_or_error = MappedFile::map(filename); + auto file_or_error = Core::MappedFile::map(filename); if (file_or_error.is_error()) return nullptr; auto res = adopt_ref(*new Database(file_or_error.release_value())); diff --git a/Userland/Libraries/LibPCIDB/Database.h b/Userland/Libraries/LibPCIDB/Database.h index 01a0073c8d..7577f55898 100644 --- a/Userland/Libraries/LibPCIDB/Database.h +++ b/Userland/Libraries/LibPCIDB/Database.h @@ -7,12 +7,12 @@ #pragma once #include -#include #include #include #include #include #include +#include namespace PCIDB { @@ -64,7 +64,7 @@ public: const StringView get_programming_interface(u8 class_id, u8 subclass_id, u8 programming_interface_id) const; private: - explicit Database(NonnullRefPtr file) + explicit Database(NonnullRefPtr file) : m_file(move(file)) { } @@ -77,7 +77,7 @@ private: ClassMode, }; - NonnullRefPtr m_file; + NonnullRefPtr m_file; StringView m_view {}; HashMap> m_vendors; HashMap> m_classes; diff --git a/Userland/Libraries/LibSymbolication/Symbolication.cpp b/Userland/Libraries/LibSymbolication/Symbolication.cpp index 3484958218..42852a0fb6 100644 --- a/Userland/Libraries/LibSymbolication/Symbolication.cpp +++ b/Userland/Libraries/LibSymbolication/Symbolication.cpp @@ -10,15 +10,15 @@ #include #include #include -#include #include +#include #include #include namespace Symbolication { struct CachedELF { - NonnullRefPtr mapped_file; + NonnullRefPtr mapped_file; NonnullOwnPtr debug_info; NonnullOwnPtr image; }; @@ -81,7 +81,7 @@ Optional symbolicate(String const& path, FlatPtr address, IncludeSourceP } } if (!s_cache.contains(full_path)) { - auto mapped_file = MappedFile::map(full_path); + auto mapped_file = Core::MappedFile::map(full_path); if (mapped_file.is_error()) { dbgln("Failed to map {}: {}", full_path, mapped_file.error()); s_cache.set(full_path, {}); diff --git a/Userland/Libraries/LibUSBDB/Database.cpp b/Userland/Libraries/LibUSBDB/Database.cpp index e42a0fa03f..140ca5bb65 100644 --- a/Userland/Libraries/LibUSBDB/Database.cpp +++ b/Userland/Libraries/LibUSBDB/Database.cpp @@ -14,7 +14,7 @@ namespace USBDB { RefPtr Database::open(const String& filename) { - auto file_or_error = MappedFile::map(filename); + auto file_or_error = Core::MappedFile::map(filename); if (file_or_error.is_error()) return nullptr; auto res = adopt_ref(*new Database(file_or_error.release_value())); diff --git a/Userland/Libraries/LibUSBDB/Database.h b/Userland/Libraries/LibUSBDB/Database.h index c1fa0cc9f1..207fedcc1e 100644 --- a/Userland/Libraries/LibUSBDB/Database.h +++ b/Userland/Libraries/LibUSBDB/Database.h @@ -7,12 +7,12 @@ #pragma once #include -#include #include #include #include #include #include +#include namespace USBDB { @@ -63,7 +63,7 @@ public: const StringView get_protocol(u8 class_id, u8 subclass_id, u8 protocol_id) const; private: - explicit Database(NonnullRefPtr file) + explicit Database(NonnullRefPtr file) : m_file(move(file)) { } @@ -76,7 +76,7 @@ private: ClassMode, }; - NonnullRefPtr m_file; + NonnullRefPtr m_file; StringView m_view {}; HashMap> m_vendors; HashMap> m_classes; diff --git a/Userland/Libraries/LibVideo/MatroskaReader.cpp b/Userland/Libraries/LibVideo/MatroskaReader.cpp index f7c0ddce14..ae51adb1fa 100644 --- a/Userland/Libraries/LibVideo/MatroskaReader.cpp +++ b/Userland/Libraries/LibVideo/MatroskaReader.cpp @@ -6,9 +6,9 @@ #include "MatroskaReader.h" #include -#include #include #include +#include namespace Video { @@ -43,7 +43,7 @@ constexpr u32 TIMESTAMP_ID = 0xE7; OwnPtr MatroskaReader::parse_matroska_from_file(StringView path) { - auto mapped_file_result = MappedFile::map(path); + auto mapped_file_result = Core::MappedFile::map(path); if (mapped_file_result.is_error()) return {}; diff --git a/Userland/Services/CrashDaemon/main.cpp b/Userland/Services/CrashDaemon/main.cpp index 76c9029797..f89a32d75f 100644 --- a/Userland/Services/CrashDaemon/main.cpp +++ b/Userland/Services/CrashDaemon/main.cpp @@ -5,9 +5,9 @@ */ #include -#include #include #include +#include #include #include #include @@ -72,7 +72,7 @@ int main() dbgln("New coredump file: {}", coredump_path); wait_until_coredump_is_ready(coredump_path); - auto file_or_error = MappedFile::map(coredump_path); + auto file_or_error = Core::MappedFile::map(coredump_path); if (file_or_error.is_error()) { dbgln("Unable to map coredump {}: {}", coredump_path, file_or_error.error()); continue; diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index 22078a5bb6..cf6e663f31 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -17,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -177,7 +177,7 @@ static String folder_image_data() { static String cache; if (cache.is_empty()) { - auto file_or_error = MappedFile::map("/res/icons/16x16/filetype-folder.png"); + auto file_or_error = Core::MappedFile::map("/res/icons/16x16/filetype-folder.png"); VERIFY(!file_or_error.is_error()); cache = encode_base64(file_or_error.value()->bytes()); } @@ -188,7 +188,7 @@ static String file_image_data() { static String cache; if (cache.is_empty()) { - auto file_or_error = MappedFile::map("/res/icons/16x16/filetype-unknown.png"); + auto file_or_error = Core::MappedFile::map("/res/icons/16x16/filetype-unknown.png"); VERIFY(!file_or_error.is_error()); cache = encode_base64(file_or_error.value()->bytes()); } diff --git a/Userland/Services/WebServer/main.cpp b/Userland/Services/WebServer/main.cpp index c2eb7d2cc3..d884e6c26f 100644 --- a/Userland/Services/WebServer/main.cpp +++ b/Userland/Services/WebServer/main.cpp @@ -5,10 +5,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include +#include #include #include #include diff --git a/Userland/Utilities/disasm.cpp b/Userland/Utilities/disasm.cpp index 77d6c73b86..8a67877daf 100644 --- a/Userland/Utilities/disasm.cpp +++ b/Userland/Utilities/disasm.cpp @@ -5,11 +5,11 @@ */ #include -#include #include #include #include #include +#include #include #include #include @@ -26,7 +26,7 @@ int main(int argc, char** argv) args_parser.add_positional_argument(path, "Path to i386 binary file", "path"); args_parser.parse(argc, argv); - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) { warnln("Could not map file: {}", file_or_error.error()); return 1; diff --git a/Userland/Utilities/fdtdump.cpp b/Userland/Utilities/fdtdump.cpp index 0bb0050f25..d5f22cbdf9 100644 --- a/Userland/Utilities/fdtdump.cpp +++ b/Userland/Utilities/fdtdump.cpp @@ -4,9 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include +#include #include #include @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) args.parse(argc, argv); // FIXME: Figure out how to do this sanely from stdin - auto maybe_file = MappedFile::map(filename); + auto maybe_file = Core::MappedFile::map(filename); if (maybe_file.is_error()) { warnln("Unable to dump device tree from file {}: {}", filename, maybe_file.error()); return 1; diff --git a/Userland/Utilities/file.cpp b/Userland/Utilities/file.cpp index c1e7adb011..0e7495531f 100644 --- a/Userland/Utilities/file.cpp +++ b/Userland/Utilities/file.cpp @@ -4,11 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include +#include #include #include #include @@ -25,7 +25,7 @@ static Optional description_only(String description, [[maybe_unused]] co // FIXME: Ideally Gfx::ImageDecoder could tell us the image type directly. static Optional image_details(const String& description, const String& path) { - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return {}; @@ -39,7 +39,7 @@ static Optional image_details(const String& description, const String& p static Optional gzip_details(String description, const String& path) { - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return {}; @@ -56,7 +56,7 @@ static Optional gzip_details(String description, const String& path) static Optional elf_details(String description, const String& path) { - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) return {}; auto& mapped_file = *file_or_error.value(); diff --git a/Userland/Utilities/gzip.cpp b/Userland/Utilities/gzip.cpp index a4b3ebdb3d..71bf648520 100644 --- a/Userland/Utilities/gzip.cpp +++ b/Userland/Utilities/gzip.cpp @@ -4,10 +4,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include +#include #include int main(int argc, char** argv) @@ -41,7 +41,7 @@ int main(int argc, char** argv) // We map the whole file instead of streaming to reduce size overhead (gzip header) and increase the deflate block size (better compression) // TODO: automatically fallback to buffered streaming for very large files - auto file_or_error = MappedFile::map(input_filename); + auto file_or_error = Core::MappedFile::map(input_filename); if (file_or_error.is_error()) { warnln("Failed opening input file for reading: {}", file_or_error.error()); return 1; diff --git a/Userland/Utilities/readelf.cpp b/Userland/Utilities/readelf.cpp index 90a091c912..743a10b4ec 100644 --- a/Userland/Utilities/readelf.cpp +++ b/Userland/Utilities/readelf.cpp @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include #include +#include #include #include #include @@ -283,7 +283,7 @@ int main(int argc, char** argv) display_hardening = true; } - auto file_or_error = MappedFile::map(path); + auto file_or_error = Core::MappedFile::map(path); if (file_or_error.is_error()) { warnln("Unable to map file {}: {}", path, file_or_error.error()); @@ -315,7 +315,7 @@ int main(int argc, char** argv) warnln("Warning: Dynamic ELF object has no interpreter path. Using: {}", interpreter_path); } - auto interpreter_file_or_error = MappedFile::map(interpreter_path); + auto interpreter_file_or_error = Core::MappedFile::map(interpreter_path); if (interpreter_file_or_error.is_error()) { warnln("Unable to map interpreter file {}: {}", interpreter_path, interpreter_file_or_error.error()); diff --git a/Userland/Utilities/unzip.cpp b/Userland/Utilities/unzip.cpp index 50a2a0c327..096c69e2c0 100644 --- a/Userland/Utilities/unzip.cpp +++ b/Userland/Utilities/unzip.cpp @@ -5,12 +5,12 @@ */ #include -#include #include #include #include #include #include +#include #include #include @@ -104,7 +104,7 @@ int main(int argc, char** argv) return 1; } - auto file_or_error = MappedFile::map(zip_file_path); + auto file_or_error = Core::MappedFile::map(zip_file_path); if (file_or_error.is_error()) { warnln("Failed to open {}: {}", zip_file_path, file_or_error.error()); return 1;