From 93d98d49769de22695f8cb4c96c5ad6f7ac39d83 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 6 Aug 2021 13:49:36 +0200 Subject: [PATCH] Kernel: Move Kernel/Memory/ code into Kernel::Memory namespace --- Kernel/ACPI/DynamicParser.h | 2 +- Kernel/ACPI/MultiProcessorParser.cpp | 6 +- Kernel/ACPI/Parser.cpp | 42 ++++++------- Kernel/Arch/PC/BIOS.cpp | 28 ++++----- Kernel/Arch/PC/BIOS.h | 4 +- Kernel/Arch/x86/PageDirectory.h | 6 +- Kernel/Arch/x86/Processor.h | 6 +- Kernel/Arch/x86/common/Processor.cpp | 14 ++--- Kernel/Bus/PCI/MMIOAccess.cpp | 8 +-- Kernel/Bus/PCI/MMIOAccess.h | 2 +- Kernel/Bus/PCI/WindowedMMIOAccess.cpp | 4 +- Kernel/Bus/PCI/WindowedMMIOAccess.h | 2 +- Kernel/Bus/USB/UHCIController.cpp | 12 ++-- Kernel/Bus/USB/UHCIController.h | 6 +- Kernel/Bus/USB/USBTransfer.cpp | 6 +- Kernel/Bus/USB/USBTransfer.h | 14 ++--- Kernel/Devices/KCOVDevice.cpp | 2 +- Kernel/Devices/KCOVDevice.h | 2 +- Kernel/Devices/KCOVInstance.cpp | 6 +- Kernel/Devices/KCOVInstance.h | 4 +- Kernel/Devices/MemoryDevice.cpp | 4 +- Kernel/Devices/MemoryDevice.h | 4 +- Kernel/Devices/SB16.cpp | 4 +- Kernel/Devices/SB16.h | 2 +- Kernel/DoubleBuffer.cpp | 2 +- Kernel/FileSystem/AnonymousFile.cpp | 4 +- Kernel/FileSystem/AnonymousFile.h | 8 +-- Kernel/FileSystem/Ext2FileSystem.cpp | 4 +- Kernel/FileSystem/File.cpp | 2 +- Kernel/FileSystem/File.h | 2 +- Kernel/FileSystem/FileDescription.cpp | 2 +- Kernel/FileSystem/FileDescription.h | 2 +- Kernel/FileSystem/Inode.cpp | 4 +- Kernel/FileSystem/Inode.h | 6 +- Kernel/FileSystem/InodeFile.cpp | 8 +-- Kernel/FileSystem/InodeFile.h | 2 +- Kernel/FileSystem/Plan9FileSystem.cpp | 2 +- Kernel/Forward.h | 28 +++++---- Kernel/FutexQueue.h | 8 +-- Kernel/GlobalProcessExposed.cpp | 2 +- Kernel/Graphics/Bochs/GraphicsAdapter.cpp | 2 +- Kernel/Graphics/Bochs/GraphicsAdapter.h | 2 +- .../Console/ContiguousFramebufferConsole.cpp | 4 +- .../Console/ContiguousFramebufferConsole.h | 2 +- Kernel/Graphics/Console/VGAConsole.cpp | 2 +- Kernel/Graphics/Console/VGAConsole.h | 2 +- Kernel/Graphics/FramebufferDevice.cpp | 28 ++++----- Kernel/Graphics/FramebufferDevice.h | 14 ++--- Kernel/Graphics/GraphicsManagement.cpp | 2 +- Kernel/Graphics/GraphicsManagement.h | 2 +- .../Graphics/Intel/NativeGraphicsAdapter.cpp | 2 +- Kernel/Graphics/Intel/NativeGraphicsAdapter.h | 2 +- .../Graphics/VirtIOGPU/FrameBufferDevice.cpp | 10 ++-- Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h | 10 ++-- Kernel/Graphics/VirtIOGPU/GPU.cpp | 4 +- Kernel/Graphics/VirtIOGPU/GPU.h | 4 +- Kernel/Heap/SlabAllocator.cpp | 2 +- Kernel/Heap/kmalloc.cpp | 12 ++-- Kernel/Interrupts/APIC.cpp | 10 ++-- Kernel/Interrupts/APIC.h | 2 +- Kernel/Interrupts/IOAPIC.cpp | 2 +- Kernel/Interrupts/IOAPIC.h | 2 +- Kernel/Interrupts/InterruptManagement.cpp | 2 +- Kernel/KBuffer.h | 30 +++++----- Kernel/KBufferBuilder.cpp | 4 +- Kernel/Memory/AnonymousVMObject.cpp | 2 +- Kernel/Memory/AnonymousVMObject.h | 2 +- Kernel/Memory/InodeVMObject.cpp | 2 +- Kernel/Memory/InodeVMObject.h | 2 +- Kernel/Memory/MappedROM.h | 2 +- Kernel/Memory/MemoryManager.cpp | 4 +- Kernel/Memory/MemoryManager.h | 4 +- Kernel/Memory/PageDirectory.cpp | 2 +- Kernel/Memory/PageDirectory.h | 2 +- Kernel/Memory/PhysicalPage.cpp | 2 +- Kernel/Memory/PhysicalPage.h | 2 +- Kernel/Memory/PhysicalRegion.cpp | 2 +- Kernel/Memory/PhysicalRegion.h | 2 +- Kernel/Memory/PhysicalZone.cpp | 2 +- Kernel/Memory/PhysicalZone.h | 2 +- Kernel/Memory/PrivateInodeVMObject.cpp | 2 +- Kernel/Memory/PrivateInodeVMObject.h | 2 +- Kernel/Memory/Range.cpp | 2 +- Kernel/Memory/Range.h | 6 +- Kernel/Memory/RangeAllocator.cpp | 2 +- Kernel/Memory/RangeAllocator.h | 4 +- Kernel/Memory/Region.cpp | 2 +- Kernel/Memory/Region.h | 2 +- Kernel/Memory/RingBuffer.cpp | 2 +- Kernel/Memory/RingBuffer.h | 4 +- Kernel/Memory/ScatterGatherList.cpp | 2 +- Kernel/Memory/ScatterGatherList.h | 2 +- Kernel/Memory/SharedInodeVMObject.cpp | 2 +- Kernel/Memory/SharedInodeVMObject.h | 2 +- Kernel/Memory/Space.cpp | 2 +- Kernel/Memory/Space.h | 2 +- Kernel/Memory/TypedMapping.h | 2 +- Kernel/Memory/VMObject.cpp | 4 +- Kernel/Memory/VMObject.h | 4 +- Kernel/Net/E1000ENetworkAdapter.cpp | 2 +- Kernel/Net/E1000NetworkAdapter.cpp | 10 ++-- Kernel/Net/E1000NetworkAdapter.h | 10 ++-- Kernel/Net/NetworkAdapter.cpp | 4 +- Kernel/Net/NetworkTask.cpp | 2 +- Kernel/Net/RTL8139NetworkAdapter.cpp | 6 +- Kernel/Net/RTL8139NetworkAdapter.h | 6 +- Kernel/Net/RTL8168NetworkAdapter.cpp | 8 +-- Kernel/Net/RTL8168NetworkAdapter.h | 8 +-- Kernel/PerformanceEventBuffer.cpp | 2 +- Kernel/PerformanceManager.h | 4 +- Kernel/Process.cpp | 6 +- Kernel/Process.h | 8 +-- Kernel/ProcessSpecificExposed.cpp | 4 +- Kernel/Scheduler.cpp | 4 +- Kernel/StdLib.cpp | 34 +++++------ Kernel/Storage/AHCIController.cpp | 4 +- Kernel/Storage/AHCIController.h | 4 +- Kernel/Storage/AHCIPort.cpp | 16 ++--- Kernel/Storage/AHCIPort.h | 12 ++-- Kernel/Storage/AHCIPortHandler.h | 2 +- Kernel/Storage/BMIDEChannel.cpp | 4 +- Kernel/Storage/BMIDEChannel.h | 8 +-- Kernel/Storage/RamdiskController.cpp | 8 +-- Kernel/Storage/RamdiskDevice.cpp | 4 +- Kernel/Storage/RamdiskDevice.h | 6 +- Kernel/Syscalls/anon_create.cpp | 2 +- Kernel/Syscalls/execve.cpp | 40 ++++++------- Kernel/Syscalls/fork.cpp | 2 +- Kernel/Syscalls/futex.cpp | 20 +++---- Kernel/Syscalls/get_stack_bounds.cpp | 2 +- Kernel/Syscalls/mmap.cpp | 60 +++++++++---------- Kernel/Syscalls/module.cpp | 2 +- Kernel/Syscalls/ptrace.cpp | 8 +-- Kernel/Syscalls/purge.cpp | 6 +- Kernel/TTY/VirtualConsole.cpp | 4 +- Kernel/TTY/VirtualConsole.h | 2 +- Kernel/Thread.cpp | 10 ++-- Kernel/Thread.h | 10 ++-- Kernel/Time/HPET.cpp | 12 ++-- Kernel/Time/HPET.h | 2 +- Kernel/UserOrKernelBuffer.cpp | 12 ++-- Kernel/UserOrKernelBuffer.h | 6 +- Kernel/VirtIO/VirtIO.cpp | 2 +- Kernel/VirtIO/VirtIO.h | 2 +- Kernel/VirtIO/VirtIOConsole.cpp | 4 +- Kernel/VirtIO/VirtIOConsole.h | 4 +- Kernel/VirtIO/VirtIOConsolePort.cpp | 4 +- Kernel/VirtIO/VirtIOConsolePort.h | 4 +- Kernel/VirtIO/VirtIOQueue.cpp | 6 +- Kernel/VirtIO/VirtIOQueue.h | 2 +- Kernel/VirtIO/VirtIORNG.cpp | 2 +- Kernel/VirtIO/VirtIORNG.h | 2 +- Kernel/init.cpp | 4 +- 153 files changed, 473 insertions(+), 467 deletions(-) diff --git a/Kernel/ACPI/DynamicParser.h b/Kernel/ACPI/DynamicParser.h index ecbb0829c1f..35693c336e5 100644 --- a/Kernel/ACPI/DynamicParser.h +++ b/Kernel/ACPI/DynamicParser.h @@ -37,7 +37,7 @@ private: // ^IRQHandler virtual bool handle_irq(const RegisterState&) override; - OwnPtr m_acpi_namespace; + OwnPtr m_acpi_namespace; }; } diff --git a/Kernel/ACPI/MultiProcessorParser.cpp b/Kernel/ACPI/MultiProcessorParser.cpp index 4e765acb397..bc9df205269 100644 --- a/Kernel/ACPI/MultiProcessorParser.cpp +++ b/Kernel/ACPI/MultiProcessorParser.cpp @@ -36,15 +36,15 @@ UNMAP_AFTER_INIT MultiProcessorParser::MultiProcessorParser(PhysicalAddress floa UNMAP_AFTER_INIT void MultiProcessorParser::parse_floating_pointer_data() { - auto floating_pointer = map_typed(m_floating_pointer); + auto floating_pointer = Memory::map_typed(m_floating_pointer); m_configuration_table = PhysicalAddress(floating_pointer->physical_address_ptr); dbgln("Features {}, IMCR? {}", floating_pointer->feature_info[0], (floating_pointer->feature_info[0] & (1 << 7))); } UNMAP_AFTER_INIT void MultiProcessorParser::parse_configuration_table() { - auto configuration_table_length = map_typed(m_configuration_table)->length; - auto config_table = map_typed(m_configuration_table, configuration_table_length); + auto configuration_table_length = Memory::map_typed(m_configuration_table)->length; + auto config_table = Memory::map_typed(m_configuration_table, configuration_table_length); size_t entry_count = config_table->entry_count; auto* entry = config_table->entries; diff --git a/Kernel/ACPI/Parser.cpp b/Kernel/ACPI/Parser.cpp index 5c903df14d7..8e1404440d5 100644 --- a/Kernel/ACPI/Parser.cpp +++ b/Kernel/ACPI/Parser.cpp @@ -48,7 +48,7 @@ KResultOr ACPISysFSComponent::read_bytes(off_t offset, size_t count, Use OwnPtr ACPISysFSComponent::try_to_generate_buffer() const { - auto acpi_blob = map_typed((m_paddr), m_length); + auto acpi_blob = Memory::map_typed((m_paddr), m_length); return KBuffer::try_create_with_bytes(Span { acpi_blob.ptr(), m_length }); } @@ -80,10 +80,10 @@ UNMAP_AFTER_INIT ACPISysFSDirectory::ACPISysFSDirectory() }); m_components = components; - auto rsdp = map_typed(ACPI::Parser::the()->rsdp()); + auto rsdp = Memory::map_typed(ACPI::Parser::the()->rsdp()); m_components.append(ACPISysFSComponent::create("RSDP", ACPI::Parser::the()->rsdp(), rsdp->base.revision == 0 ? sizeof(Structures::RSDPDescriptor) : rsdp->length)); - auto main_system_description_table = map_typed(ACPI::Parser::the()->main_system_description_table()); + auto main_system_description_table = Memory::map_typed(ACPI::Parser::the()->main_system_description_table()); if (ACPI::Parser::the()->is_xsdt_supported()) { m_components.append(ACPISysFSComponent::create("XSDT", ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length)); } else { @@ -94,7 +94,7 @@ UNMAP_AFTER_INIT ACPISysFSDirectory::ACPISysFSDirectory() void Parser::enumerate_static_tables(Function callback) { for (auto& p_table : m_sdt_pointers) { - auto table = map_typed(p_table); + auto table = Memory::map_typed(p_table); callback({ table->sig, 4 }, p_table, table->length); } } @@ -122,7 +122,7 @@ UNMAP_AFTER_INIT PhysicalAddress Parser::find_table(const StringView& signature) { dbgln_if(ACPI_DEBUG, "ACPI: Calling Find Table method!"); for (auto p_sdt : m_sdt_pointers) { - auto sdt = map_typed(p_sdt); + auto sdt = Memory::map_typed(p_sdt); dbgln_if(ACPI_DEBUG, "ACPI: Examining Table @ {}", p_sdt); if (!strncmp(sdt->sig, signature.characters_without_null_termination(), 4)) { dbgln_if(ACPI_DEBUG, "ACPI: Found Table @ {}", p_sdt); @@ -145,7 +145,7 @@ UNMAP_AFTER_INIT void Parser::init_fadt() m_fadt = find_table("FACP"); VERIFY(!m_fadt.is_null()); - auto sdt = map_typed(m_fadt); + auto sdt = Memory::map_typed(m_fadt); dbgln_if(ACPI_DEBUG, "ACPI: FADT @ V{}, {}", &sdt, m_fadt); @@ -188,7 +188,7 @@ UNMAP_AFTER_INIT void Parser::init_fadt() bool Parser::can_reboot() { - auto fadt = map_typed(m_fadt); + auto fadt = Memory::map_typed(m_fadt); if (fadt->h.revision < 2) return false; return m_hardware_flags.reset_register_supported; @@ -224,16 +224,16 @@ void Parser::access_generic_address(const Structures::GenericAddressStructure& s dbgln("ACPI: Sending value {:x} to {}", value, PhysicalAddress(structure.address)); switch ((GenericAddressStructure::AccessSize)structure.access_size) { case GenericAddressStructure::AccessSize::Byte: - *map_typed(PhysicalAddress(structure.address)) = value; + *Memory::map_typed(PhysicalAddress(structure.address)) = value; break; case GenericAddressStructure::AccessSize::Word: - *map_typed(PhysicalAddress(structure.address)) = value; + *Memory::map_typed(PhysicalAddress(structure.address)) = value; break; case GenericAddressStructure::AccessSize::DWord: - *map_typed(PhysicalAddress(structure.address)) = value; + *Memory::map_typed(PhysicalAddress(structure.address)) = value; break; case GenericAddressStructure::AccessSize::QWord: { - *map_typed(PhysicalAddress(structure.address)) = value; + *Memory::map_typed(PhysicalAddress(structure.address)) = value; break; } default: @@ -265,7 +265,7 @@ bool Parser::validate_reset_register() { // According to https://uefi.org/specs/ACPI/6.4/04_ACPI_Hardware_Specification/ACPI_Hardware_Specification.html#reset-register, // the reset register can only be located in I/O bus, PCI bus or memory-mapped. - auto fadt = map_typed(m_fadt); + auto fadt = Memory::map_typed(m_fadt); return (fadt->reset_reg.address_space == (u8)GenericAddressStructure::AddressSpace::PCIConfigurationSpace || fadt->reset_reg.address_space == (u8)GenericAddressStructure::AddressSpace::SystemMemory || fadt->reset_reg.address_space == (u8)GenericAddressStructure::AddressSpace::SystemIO); } @@ -278,7 +278,7 @@ void Parser::try_acpi_reboot() } dbgln_if(ACPI_DEBUG, "ACPI: Rebooting, probing FADT ({})", m_fadt); - auto fadt = map_typed(m_fadt); + auto fadt = Memory::map_typed(m_fadt); VERIFY(validate_reset_register()); access_generic_address(fadt->reset_reg, fadt->reset_value); Processor::halt(); @@ -293,14 +293,14 @@ size_t Parser::get_table_size(PhysicalAddress table_header) { InterruptDisabler disabler; dbgln_if(ACPI_DEBUG, "ACPI: Checking SDT Length"); - return map_typed(table_header)->length; + return Memory::map_typed(table_header)->length; } u8 Parser::get_table_revision(PhysicalAddress table_header) { InterruptDisabler disabler; dbgln_if(ACPI_DEBUG, "ACPI: Checking SDT Revision"); - return map_typed(table_header)->revision; + return Memory::map_typed(table_header)->revision; } UNMAP_AFTER_INIT void Parser::initialize_main_system_description_table() @@ -310,7 +310,7 @@ UNMAP_AFTER_INIT void Parser::initialize_main_system_description_table() auto length = get_table_size(m_main_system_description_table); auto revision = get_table_revision(m_main_system_description_table); - auto sdt = map_typed(m_main_system_description_table, length); + auto sdt = Memory::map_typed(m_main_system_description_table, length); dmesgln("ACPI: Main Description Table valid? {}", validate_table(*sdt, length)); @@ -337,7 +337,7 @@ UNMAP_AFTER_INIT void Parser::initialize_main_system_description_table() UNMAP_AFTER_INIT void Parser::locate_main_system_description_table() { - auto rsdp = map_typed(m_rsdp); + auto rsdp = Memory::map_typed(m_rsdp); if (rsdp->base.revision == 0) { m_xsdt_supported = false; } else if (rsdp->base.revision >= 2) { @@ -387,7 +387,7 @@ UNMAP_AFTER_INIT PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_ // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. VERIFY(signature.length() == 4); - auto rsdp = map_typed(rsdp_address); + auto rsdp = Memory::map_typed(rsdp_address); if (rsdp->base.revision == 0) return search_table_in_rsdt(PhysicalAddress(rsdp->base.rsdt_ptr), signature); @@ -405,7 +405,7 @@ UNMAP_AFTER_INIT static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsd // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. VERIFY(signature.length() == 4); - auto xsdt = map_typed(xsdt_address); + auto xsdt = Memory::map_typed(xsdt_address); for (size_t i = 0; i < ((xsdt->h.length - sizeof(Structures::SDTHeader)) / sizeof(u64)); ++i) { if (match_table_signature(PhysicalAddress((PhysicalPtr)xsdt->table_ptrs[i]), signature)) @@ -419,7 +419,7 @@ static bool match_table_signature(PhysicalAddress table_header, const StringView // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. VERIFY(signature.length() == 4); - auto table = map_typed(table_header); + auto table = Memory::map_typed(table_header); return !strncmp(table->h.sig, signature.characters_without_null_termination(), 4); } @@ -428,7 +428,7 @@ UNMAP_AFTER_INIT static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsd // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. VERIFY(signature.length() == 4); - auto rsdt = map_typed(rsdt_address); + auto rsdt = Memory::map_typed(rsdt_address); for (u32 i = 0; i < ((rsdt->h.length - sizeof(Structures::SDTHeader)) / sizeof(u32)); i++) { if (match_table_signature(PhysicalAddress((PhysicalPtr)rsdt->table_ptrs[i]), signature)) diff --git a/Kernel/Arch/PC/BIOS.cpp b/Kernel/Arch/PC/BIOS.cpp index 784e773df34..2b95be03adf 100644 --- a/Kernel/Arch/PC/BIOS.cpp +++ b/Kernel/Arch/PC/BIOS.cpp @@ -53,7 +53,7 @@ UNMAP_AFTER_INIT DMIEntryPointExposedBlob::DMIEntryPointExposedBlob(PhysicalAddr OwnPtr DMIEntryPointExposedBlob::try_to_generate_buffer() const { - auto dmi_blob = map_typed((m_dmi_entry_point), m_dmi_entry_point_length); + auto dmi_blob = Memory::map_typed((m_dmi_entry_point), m_dmi_entry_point_length); return KBuffer::try_create_with_bytes(Span { dmi_blob.ptr(), m_dmi_entry_point_length }); } @@ -71,14 +71,14 @@ UNMAP_AFTER_INIT SMBIOSExposedTable::SMBIOSExposedTable(PhysicalAddress smbios_s OwnPtr SMBIOSExposedTable::try_to_generate_buffer() const { - auto dmi_blob = map_typed((m_smbios_structure_table), m_smbios_structure_table_length); + auto dmi_blob = Memory::map_typed((m_smbios_structure_table), m_smbios_structure_table_length); return KBuffer::try_create_with_bytes(Span { dmi_blob.ptr(), m_smbios_structure_table_length }); } UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_64_bit_entry_initialization_values() { dbgln("BIOSSysFSDirectory: SMBIOS 64bit Entry point @ {}", m_dmi_entry_point); - auto smbios_entry = map_typed(m_dmi_entry_point, SMBIOS_SEARCH_AREA_SIZE); + auto smbios_entry = Memory::map_typed(m_dmi_entry_point, SMBIOS_SEARCH_AREA_SIZE); m_smbios_structure_table = PhysicalAddress(smbios_entry.ptr()->table_ptr); m_dmi_entry_point_length = smbios_entry.ptr()->length; m_smbios_structure_table_length = smbios_entry.ptr()->table_maximum_size; @@ -87,7 +87,7 @@ UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_64_bit_entry_initialization_va UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_32_bit_entry_initialization_values() { dbgln("BIOSSysFSDirectory: SMBIOS 32bit Entry point @ {}", m_dmi_entry_point); - auto smbios_entry = map_typed(m_dmi_entry_point, SMBIOS_SEARCH_AREA_SIZE); + auto smbios_entry = Memory::map_typed(m_dmi_entry_point, SMBIOS_SEARCH_AREA_SIZE); m_smbios_structure_table = PhysicalAddress(smbios_entry.ptr()->legacy_structure.smbios_table_ptr); m_dmi_entry_point_length = smbios_entry.ptr()->length; m_smbios_structure_table_length = smbios_entry.ptr()->legacy_structure.smboios_table_length; @@ -130,7 +130,7 @@ UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer() OwnPtr BIOSSysFSDirectory::smbios_structure_table() const { - auto dmi_blob = map_typed(m_smbios_structure_table, m_smbios_structure_table_length); + auto dmi_blob = Memory::map_typed(m_smbios_structure_table, m_smbios_structure_table_length); return KBuffer::try_create_with_bytes(Span { dmi_blob.ptr(), m_smbios_structure_table_length }); } @@ -160,26 +160,26 @@ UNMAP_AFTER_INIT Optional BIOSSysFSDirectory::find_dmi_entry32b return map_bios().find_chunk_starting_with("_SM_", 16); } -MappedROM map_bios() +Memory::MappedROM map_bios() { - MappedROM mapping; + Memory::MappedROM mapping; mapping.size = 128 * KiB; mapping.paddr = PhysicalAddress(0xe0000); - mapping.region = MM.allocate_kernel_region(mapping.paddr, page_round_up(mapping.size), {}, Region::Access::Read); + mapping.region = MM.allocate_kernel_region(mapping.paddr, Memory::page_round_up(mapping.size), {}, Memory::Region::Access::Read); return mapping; } -MappedROM map_ebda() +Memory::MappedROM map_ebda() { - auto ebda_segment_ptr = map_typed(PhysicalAddress(0x40e)); - auto ebda_length_ptr_b0 = map_typed(PhysicalAddress(0x413)); - auto ebda_length_ptr_b1 = map_typed(PhysicalAddress(0x414)); + auto ebda_segment_ptr = Memory::map_typed(PhysicalAddress(0x40e)); + auto ebda_length_ptr_b0 = Memory::map_typed(PhysicalAddress(0x413)); + auto ebda_length_ptr_b1 = Memory::map_typed(PhysicalAddress(0x414)); PhysicalAddress ebda_paddr(*ebda_segment_ptr << 4); size_t ebda_size = (*ebda_length_ptr_b1 << 8) | *ebda_length_ptr_b0; - MappedROM mapping; - mapping.region = MM.allocate_kernel_region(ebda_paddr.page_base(), page_round_up(ebda_size), {}, Region::Access::Read); + Memory::MappedROM mapping; + mapping.region = MM.allocate_kernel_region(ebda_paddr.page_base(), Memory::page_round_up(ebda_size), {}, Memory::Region::Access::Read); mapping.offset = ebda_paddr.offset_in_page(); mapping.size = ebda_size; mapping.paddr = ebda_paddr; diff --git a/Kernel/Arch/PC/BIOS.h b/Kernel/Arch/PC/BIOS.h index 54ad1f1aa0d..e251d817a50 100644 --- a/Kernel/Arch/PC/BIOS.h +++ b/Kernel/Arch/PC/BIOS.h @@ -55,8 +55,8 @@ struct [[gnu::packed]] EntryPoint64bit { namespace Kernel { -MappedROM map_bios(); -MappedROM map_ebda(); +Memory::MappedROM map_bios(); +Memory::MappedROM map_ebda(); class BIOSSysFSComponent : public SysFSComponent { public: diff --git a/Kernel/Arch/x86/PageDirectory.h b/Kernel/Arch/x86/PageDirectory.h index c33c06f93aa..f965e600b24 100644 --- a/Kernel/Arch/x86/PageDirectory.h +++ b/Kernel/Arch/x86/PageDirectory.h @@ -8,13 +8,11 @@ #include #include +#include #include namespace Kernel { -class PageDirectory; -class PageTableEntry; - class PageDirectoryEntry { public: PhysicalPtr page_table_base() const { return PhysicalAddress::physical_page_base(m_raw); } @@ -28,7 +26,7 @@ public: void clear() { m_raw = 0; } u64 raw() const { return m_raw; } - void copy_from(Badge, const PageDirectoryEntry& other) { m_raw = other.m_raw; } + void copy_from(Badge, const PageDirectoryEntry& other) { m_raw = other.m_raw; } enum Flags { Present = 1 << 0, diff --git a/Kernel/Arch/x86/Processor.h b/Kernel/Arch/x86/Processor.h index 7a114456496..beaf4ec122b 100644 --- a/Kernel/Arch/x86/Processor.h +++ b/Kernel/Arch/x86/Processor.h @@ -57,7 +57,7 @@ struct ProcessorMessage { ProcessorMessage* next; // only valid while in the pool alignas(CallbackFunction) u8 callback_storage[sizeof(CallbackFunction)]; struct { - const PageDirectory* page_directory; + Memory::PageDirectory const* page_directory; u8* ptr; size_t page_count; } flush_tlb; @@ -211,7 +211,7 @@ public: } static void flush_tlb_local(VirtualAddress vaddr, size_t page_count); - static void flush_tlb(const PageDirectory*, VirtualAddress, size_t); + static void flush_tlb(Memory::PageDirectory const*, VirtualAddress, size_t); Descriptor& get_gdt_entry(u16 selector); void flush_gdt(); @@ -391,7 +391,7 @@ public: bool smp_process_pending_messages(); static void smp_unicast(u32 cpu, Function, bool async); - static void smp_broadcast_flush_tlb(const PageDirectory*, VirtualAddress, size_t); + static void smp_broadcast_flush_tlb(Memory::PageDirectory const*, VirtualAddress, size_t); static u32 smp_wake_n_idle_processors(u32 wake_count); static void deferred_call_queue(Function callback); diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index e626d4d2110..a15cfb32a4b 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -469,7 +469,7 @@ Vector Processor::capture_stack_trace(Thread& thread, size_t max_frames if (max_frames != 0 && count > max_frames) break; - if (is_user_range(VirtualAddress(stack_ptr), sizeof(FlatPtr) * 2)) { + if (Memory::is_user_range(VirtualAddress(stack_ptr), sizeof(FlatPtr) * 2)) { if (!copy_from_user(&retaddr, &((FlatPtr*)stack_ptr)[1]) || !retaddr) break; stack_trace.append(retaddr); @@ -545,7 +545,7 @@ Vector Processor::capture_stack_trace(Thread& thread, size_t max_frames ProcessPagingScope paging_scope(thread.process()); auto& regs = thread.regs(); FlatPtr* stack_top = reinterpret_cast(regs.sp()); - if (is_user_range(VirtualAddress(stack_top), sizeof(FlatPtr))) { + if (Memory::is_user_range(VirtualAddress(stack_top), sizeof(FlatPtr))) { if (!copy_from_user(&frame_ptr, &((FlatPtr*)stack_top)[0])) frame_ptr = 0; } else { @@ -657,9 +657,9 @@ void Processor::flush_tlb_local(VirtualAddress vaddr, size_t page_count) } } -void Processor::flush_tlb(const PageDirectory* page_directory, VirtualAddress vaddr, size_t page_count) +void Processor::flush_tlb(Memory::PageDirectory const* page_directory, VirtualAddress vaddr, size_t page_count) { - if (s_smp_enabled && (!is_user_address(vaddr) || Process::current()->thread_count() > 1)) + if (s_smp_enabled && (!Memory::is_user_address(vaddr) || Process::current()->thread_count() > 1)) smp_broadcast_flush_tlb(page_directory, vaddr, page_count); else flush_tlb_local(vaddr, page_count); @@ -818,9 +818,9 @@ bool Processor::smp_process_pending_messages() msg->invoke_callback(); break; case ProcessorMessage::FlushTlb: - if (is_user_address(VirtualAddress(msg->flush_tlb.ptr))) { + if (Memory::is_user_address(VirtualAddress(msg->flush_tlb.ptr))) { // We assume that we don't cross into kernel land! - VERIFY(is_user_range(VirtualAddress(msg->flush_tlb.ptr), msg->flush_tlb.page_count * PAGE_SIZE)); + VERIFY(Memory::is_user_range(VirtualAddress(msg->flush_tlb.ptr), msg->flush_tlb.page_count * PAGE_SIZE)); if (read_cr3() != msg->flush_tlb.page_directory->cr3()) { // This processor isn't using this page directory right now, we can ignore this request dbgln_if(SMP_DEBUG, "SMP[{}]: No need to flush {} pages at {}", id(), msg->flush_tlb.page_count, VirtualAddress(msg->flush_tlb.ptr)); @@ -949,7 +949,7 @@ void Processor::smp_unicast(u32 cpu, Function callback, bool async) smp_unicast_message(cpu, msg, async); } -void Processor::smp_broadcast_flush_tlb(const PageDirectory* page_directory, VirtualAddress vaddr, size_t page_count) +void Processor::smp_broadcast_flush_tlb(Memory::PageDirectory const* page_directory, VirtualAddress vaddr, size_t page_count) { auto& msg = smp_get_from_pool(); msg.async = false; diff --git a/Kernel/Bus/PCI/MMIOAccess.cpp b/Kernel/Bus/PCI/MMIOAccess.cpp index 6811f4df8c7..e5475fafdae 100644 --- a/Kernel/Bus/PCI/MMIOAccess.cpp +++ b/Kernel/Bus/PCI/MMIOAccess.cpp @@ -57,7 +57,7 @@ UNMAP_AFTER_INIT MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg) { dmesgln("PCI: Using MMIO for PCI configuration space access"); - auto checkup_region = MM.allocate_kernel_region(p_mcfg.page_base(), (PAGE_SIZE * 2), "PCI MCFG Checkup", Region::Access::Read | Region::Access::Write); + auto checkup_region = MM.allocate_kernel_region(p_mcfg.page_base(), (PAGE_SIZE * 2), "PCI MCFG Checkup", Memory::Region::Access::Read | Memory::Region::Access::Write); dbgln_if(PCI_DEBUG, "PCI: Checking MCFG Table length to choose the correct mapping size"); auto* sdt = (ACPI::Structures::SDTHeader*)checkup_region->vaddr().offset(p_mcfg.offset_in_page()).as_ptr(); u32 length = sdt->length; @@ -66,7 +66,7 @@ UNMAP_AFTER_INIT MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg) dbgln("PCI: MCFG, length: {}, revision: {}", length, revision); checkup_region->unmap(); - auto mcfg_region = MM.allocate_kernel_region(p_mcfg.page_base(), page_round_up(length) + PAGE_SIZE, "PCI Parsing MCFG", Region::Access::Read | Region::Access::Write); + auto mcfg_region = MM.allocate_kernel_region(p_mcfg.page_base(), Memory::page_round_up(length) + PAGE_SIZE, "PCI Parsing MCFG", Memory::Region::Access::Read | Memory::Region::Access::Write); auto& mcfg = *(ACPI::Structures::MCFG*)mcfg_region->vaddr().offset(p_mcfg.offset_in_page()).as_ptr(); dbgln_if(PCI_DEBUG, "PCI: Checking MCFG @ {}, {}", VirtualAddress(&mcfg), PhysicalAddress(p_mcfg.get())); @@ -89,7 +89,7 @@ UNMAP_AFTER_INIT MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg) // PCI::PhysicalID objects to the vector, because get_capabilities calls // PCI::read16 which will need this region to be mapped. u8 start_bus = m_segments.get(0).value().get_start_bus(); - m_mapped_region = MM.allocate_kernel_region(determine_memory_mapped_bus_region(0, start_bus), MEMORY_RANGE_PER_BUS, "PCI ECAM", Region::Access::Read | Region::Access::Write); + m_mapped_region = MM.allocate_kernel_region(determine_memory_mapped_bus_region(0, start_bus), MEMORY_RANGE_PER_BUS, "PCI ECAM", Memory::Region::Access::Read | Memory::Region::Access::Write); m_mapped_bus = start_bus; dbgln_if(PCI_DEBUG, "PCI: First PCI ECAM Mapped region for starting bus {} @ {} {}", start_bus, m_mapped_region->vaddr(), m_mapped_region->physical_page(0)->paddr()); @@ -102,7 +102,7 @@ void MMIOAccess::map_bus_region(u32 segment, u8 bus) VERIFY(m_access_lock.is_locked()); if (m_mapped_bus == bus) return; - m_mapped_region = MM.allocate_kernel_region(determine_memory_mapped_bus_region(segment, bus), MEMORY_RANGE_PER_BUS, "PCI ECAM", Region::Access::Read | Region::Access::Write); + m_mapped_region = MM.allocate_kernel_region(determine_memory_mapped_bus_region(segment, bus), MEMORY_RANGE_PER_BUS, "PCI ECAM", Memory::Region::Access::Read | Memory::Region::Access::Write); m_mapped_bus = bus; dbgln_if(PCI_DEBUG, "PCI: New PCI ECAM Mapped region for bus {} @ {} {}", bus, m_mapped_region->vaddr(), m_mapped_region->physical_page(0)->paddr()); } diff --git a/Kernel/Bus/PCI/MMIOAccess.h b/Kernel/Bus/PCI/MMIOAccess.h index fd94b4b65cf..c110161f84c 100644 --- a/Kernel/Bus/PCI/MMIOAccess.h +++ b/Kernel/Bus/PCI/MMIOAccess.h @@ -46,7 +46,7 @@ private: VirtualAddress get_device_configuration_space(Address address); SpinLock m_access_lock; u8 m_mapped_bus { 0 }; - OwnPtr m_mapped_region; + OwnPtr m_mapped_region; protected: explicit MMIOAccess(PhysicalAddress mcfg); diff --git a/Kernel/Bus/PCI/WindowedMMIOAccess.cpp b/Kernel/Bus/PCI/WindowedMMIOAccess.cpp index 9f7af0feb54..6b84d18893c 100644 --- a/Kernel/Bus/PCI/WindowedMMIOAccess.cpp +++ b/Kernel/Bus/PCI/WindowedMMIOAccess.cpp @@ -18,12 +18,12 @@ namespace PCI { UNMAP_AFTER_INIT DeviceConfigurationSpaceMapping::DeviceConfigurationSpaceMapping(Address device_address, const MMIOAccess::MMIOSegment& mmio_segment) : m_device_address(device_address) - , m_mapped_region(MM.allocate_kernel_region(page_round_up(PCI_MMIO_CONFIG_SPACE_SIZE), "PCI MMIO Device Access", Region::Access::Read | Region::Access::Write).release_nonnull()) + , m_mapped_region(MM.allocate_kernel_region(Memory::page_round_up(PCI_MMIO_CONFIG_SPACE_SIZE), "PCI MMIO Device Access", Memory::Region::Access::Read | Memory::Region::Access::Write).release_nonnull()) { PhysicalAddress segment_lower_addr = mmio_segment.get_paddr(); PhysicalAddress device_physical_mmio_space = segment_lower_addr.offset( PCI_MMIO_CONFIG_SPACE_SIZE * m_device_address.function() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE) * m_device_address.device() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE * PCI_MAX_DEVICES_PER_BUS) * (m_device_address.bus() - mmio_segment.get_start_bus())); - m_mapped_region->physical_page_slot(0) = PhysicalPage::create(device_physical_mmio_space, MayReturnToFreeList::No); + m_mapped_region->physical_page_slot(0) = Memory::PhysicalPage::create(device_physical_mmio_space, Memory::MayReturnToFreeList::No); m_mapped_region->remap(); } diff --git a/Kernel/Bus/PCI/WindowedMMIOAccess.h b/Kernel/Bus/PCI/WindowedMMIOAccess.h index 4c7b2789d40..0f4a51b5b73 100644 --- a/Kernel/Bus/PCI/WindowedMMIOAccess.h +++ b/Kernel/Bus/PCI/WindowedMMIOAccess.h @@ -30,7 +30,7 @@ public: private: Address m_device_address; - NonnullOwnPtr m_mapped_region; + NonnullOwnPtr m_mapped_region; }; class WindowedMMIOAccess final : public MMIOAccess { diff --git a/Kernel/Bus/USB/UHCIController.cpp b/Kernel/Bus/USB/UHCIController.cpp index e1032254c77..98e544c61fb 100644 --- a/Kernel/Bus/USB/UHCIController.cpp +++ b/Kernel/Bus/USB/UHCIController.cpp @@ -289,8 +289,8 @@ void UHCIController::reset() } // Let's allocate the physical page for the Frame List (which is 4KiB aligned) - auto framelist_vmobj = AnonymousVMObject::try_create_physically_contiguous_with_size(PAGE_SIZE); - m_framelist = MemoryManager::the().allocate_kernel_region_with_vmobject(*framelist_vmobj, PAGE_SIZE, "UHCI Framelist", Region::Access::Write); + auto framelist_vmobj = Memory::AnonymousVMObject::try_create_physically_contiguous_with_size(PAGE_SIZE); + m_framelist = MM.allocate_kernel_region_with_vmobject(*framelist_vmobj, PAGE_SIZE, "UHCI Framelist", Memory::Region::Access::Write); dbgln("UHCI: Allocated framelist at physical address {}", m_framelist->physical_page(0)->paddr()); dbgln("UHCI: Framelist is at virtual address {}", m_framelist->vaddr()); write_sofmod(64); // 1mS frame time @@ -311,8 +311,8 @@ UNMAP_AFTER_INIT void UHCIController::create_structures() { // Let's allocate memory for both the QH and TD pools // First the QH pool and all of the Interrupt QH's - auto qh_pool_vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(2 * PAGE_SIZE); - m_qh_pool = MemoryManager::the().allocate_kernel_region_with_vmobject(*qh_pool_vmobject, 2 * PAGE_SIZE, "UHCI Queue Head Pool", Region::Access::Write); + auto qh_pool_vmobject = Memory::AnonymousVMObject::try_create_physically_contiguous_with_size(2 * PAGE_SIZE); + m_qh_pool = MM.allocate_kernel_region_with_vmobject(*qh_pool_vmobject, 2 * PAGE_SIZE, "UHCI Queue Head Pool", Memory::Region::Access::Write); memset(m_qh_pool->vaddr().as_ptr(), 0, 2 * PAGE_SIZE); // Zero out both pages // Let's populate our free qh list (so we have some we can allocate later on) @@ -331,8 +331,8 @@ UNMAP_AFTER_INIT void UHCIController::create_structures() m_dummy_qh = allocate_queue_head(); // Now the Transfer Descriptor pool - auto td_pool_vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(2 * PAGE_SIZE); - m_td_pool = MemoryManager::the().allocate_kernel_region_with_vmobject(*td_pool_vmobject, 2 * PAGE_SIZE, "UHCI Transfer Descriptor Pool", Region::Access::Write); + auto td_pool_vmobject = Memory::AnonymousVMObject::try_create_physically_contiguous_with_size(2 * PAGE_SIZE); + m_td_pool = MM.allocate_kernel_region_with_vmobject(*td_pool_vmobject, 2 * PAGE_SIZE, "UHCI Transfer Descriptor Pool", Memory::Region::Access::Write); memset(m_td_pool->vaddr().as_ptr(), 0, 2 * PAGE_SIZE); // Set up the Isochronous Transfer Descriptor list diff --git a/Kernel/Bus/USB/UHCIController.h b/Kernel/Bus/USB/UHCIController.h index 7adecd67b4a..8594c0f0242 100644 --- a/Kernel/Bus/USB/UHCIController.h +++ b/Kernel/Bus/USB/UHCIController.h @@ -90,9 +90,9 @@ private: QueueHead* m_bulk_qh; QueueHead* m_dummy_qh; // Needed for PIIX4 hack - OwnPtr m_framelist; - OwnPtr m_qh_pool; - OwnPtr m_td_pool; + OwnPtr m_framelist; + OwnPtr m_qh_pool; + OwnPtr m_td_pool; Array, 2> m_devices; // Devices connected to the root ports (of which there are two) }; diff --git a/Kernel/Bus/USB/USBTransfer.cpp b/Kernel/Bus/USB/USBTransfer.cpp index 51f26c91a8d..e3e5f0f0356 100644 --- a/Kernel/Bus/USB/USBTransfer.cpp +++ b/Kernel/Bus/USB/USBTransfer.cpp @@ -11,20 +11,20 @@ namespace Kernel::USB { RefPtr Transfer::try_create(Pipe& pipe, u16 len) { - auto vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(PAGE_SIZE); + auto vmobject = Memory::AnonymousVMObject::try_create_physically_contiguous_with_size(PAGE_SIZE); if (!vmobject) return nullptr; return AK::try_create(pipe, len, *vmobject); } -Transfer::Transfer(Pipe& pipe, u16 len, AnonymousVMObject& vmobject) +Transfer::Transfer(Pipe& pipe, u16 len, Memory::AnonymousVMObject& vmobject) : m_pipe(pipe) , m_transfer_data_size(len) { // Initialize data buffer for transfer // This will definitely need to be refactored in the future, I doubt this will scale well... - m_data_buffer = MemoryManager::the().allocate_kernel_region_with_vmobject(vmobject, PAGE_SIZE, "USB Transfer Buffer", Region::Access::Read | Region::Access::Write); + m_data_buffer = MM.allocate_kernel_region_with_vmobject(vmobject, PAGE_SIZE, "USB Transfer Buffer", Memory::Region::Access::Read | Memory::Region::Access::Write); } Transfer::~Transfer() diff --git a/Kernel/Bus/USB/USBTransfer.h b/Kernel/Bus/USB/USBTransfer.h index 796407c206a..9afead95e9f 100644 --- a/Kernel/Bus/USB/USBTransfer.h +++ b/Kernel/Bus/USB/USBTransfer.h @@ -23,7 +23,7 @@ public: public: Transfer() = delete; - Transfer(Pipe& pipe, u16 len, AnonymousVMObject&); + Transfer(Pipe& pipe, u16 len, Memory::AnonymousVMObject&); ~Transfer(); void set_setup_packet(const USBRequestData& request); @@ -41,11 +41,11 @@ public: bool error_occurred() const { return m_error_occurred; } private: - Pipe& m_pipe; // Pipe that initiated this transfer - USBRequestData m_request; // USB request - OwnPtr m_data_buffer; // DMA Data buffer for transaction - u16 m_transfer_data_size { 0 }; // Size of the transfer's data stage - bool m_complete { false }; // Has this transfer been completed? - bool m_error_occurred { false }; // Did an error occur during this transfer? + Pipe& m_pipe; // Pipe that initiated this transfer + USBRequestData m_request; // USB request + OwnPtr m_data_buffer; // DMA Data buffer for transaction + u16 m_transfer_data_size { 0 }; // Size of the transfer's data stage + bool m_complete { false }; // Has this transfer been completed? + bool m_error_occurred { false }; // Did an error occur during this transfer? }; } diff --git a/Kernel/Devices/KCOVDevice.cpp b/Kernel/Devices/KCOVDevice.cpp index 85e9e97d9a9..1b69f02960e 100644 --- a/Kernel/Devices/KCOVDevice.cpp +++ b/Kernel/Devices/KCOVDevice.cpp @@ -129,7 +129,7 @@ KResult KCOVDevice::ioctl(FileDescription&, unsigned request, Userspace a return return_value; } -KResultOr KCOVDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared) +KResultOr KCOVDevice::mmap(Process& process, FileDescription&, Memory::Range const& range, u64 offset, int prot, bool shared) { auto pid = process.pid(); auto maybe_kcov_instance = proc_instance->get(pid); diff --git a/Kernel/Devices/KCOVDevice.h b/Kernel/Devices/KCOVDevice.h index dcfcfd69689..ba2dd92bece 100644 --- a/Kernel/Devices/KCOVDevice.h +++ b/Kernel/Devices/KCOVDevice.h @@ -22,7 +22,7 @@ public: static void free_process(); // ^File - KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; + KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared) override; KResultOr> open(int options) override; // ^Device diff --git a/Kernel/Devices/KCOVInstance.cpp b/Kernel/Devices/KCOVInstance.cpp index 098504826f6..3e734c893e1 100644 --- a/Kernel/Devices/KCOVInstance.cpp +++ b/Kernel/Devices/KCOVInstance.cpp @@ -22,20 +22,20 @@ KResult KCOVInstance::buffer_allocate(size_t buffer_size_in_entries) // first entry contains index of last PC this->m_buffer_size_in_entries = buffer_size_in_entries - 1; - this->m_buffer_size_in_bytes = page_round_up(buffer_size_in_entries * KCOV_ENTRY_SIZE); + this->m_buffer_size_in_bytes = Memory::page_round_up(buffer_size_in_entries * KCOV_ENTRY_SIZE); // one single vmobject is representing the buffer // - we allocate one kernel region using that vmobject // - when an mmap call comes in, we allocate another userspace region, // backed by the same vmobject - this->vmobject = AnonymousVMObject::try_create_with_size( + this->vmobject = Memory::AnonymousVMObject::try_create_with_size( this->m_buffer_size_in_bytes, AllocationStrategy::AllocateNow); if (!this->vmobject) return ENOMEM; this->m_kernel_region = MM.allocate_kernel_region_with_vmobject( *this->vmobject, this->m_buffer_size_in_bytes, String::formatted("kcov_{}", this->m_pid), - Region::Access::Read | Region::Access::Write); + Memory::Region::Access::Read | Memory::Region::Access::Write); if (!this->m_kernel_region) return ENOMEM; diff --git a/Kernel/Devices/KCOVInstance.h b/Kernel/Devices/KCOVInstance.h index 3a585af1925..cb56d1250b0 100644 --- a/Kernel/Devices/KCOVInstance.h +++ b/Kernel/Devices/KCOVInstance.h @@ -42,7 +42,7 @@ public: TRACING = 2, } state; - RefPtr vmobject; + RefPtr vmobject; private: ProcessID m_pid = { 0 }; @@ -51,7 +51,7 @@ private: kcov_pc_t* m_buffer = { nullptr }; // Here to ensure it's not garbage collected at the end of open() - OwnPtr m_kernel_region; + OwnPtr m_kernel_region; }; } diff --git a/Kernel/Devices/MemoryDevice.cpp b/Kernel/Devices/MemoryDevice.cpp index 5b03516994c..8ce29f13452 100644 --- a/Kernel/Devices/MemoryDevice.cpp +++ b/Kernel/Devices/MemoryDevice.cpp @@ -37,7 +37,7 @@ void MemoryDevice::did_seek(FileDescription&, off_t) TODO(); } -KResultOr MemoryDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared) +KResultOr MemoryDevice::mmap(Process& process, FileDescription&, Memory::Range const& range, u64 offset, int prot, bool shared) { auto viewed_address = PhysicalAddress(offset); @@ -47,7 +47,7 @@ KResultOr MemoryDevice::mmap(Process& process, FileDescription&, const return EINVAL; } - auto vmobject = AnonymousVMObject::try_create_for_physical_range(viewed_address, range.size()); + auto vmobject = Memory::AnonymousVMObject::try_create_for_physical_range(viewed_address, range.size()); if (!vmobject) return ENOMEM; dbgln("MemoryDevice: Mapped physical memory at {} for range of {} bytes", viewed_address, range.size()); diff --git a/Kernel/Devices/MemoryDevice.h b/Kernel/Devices/MemoryDevice.h index cf5ff1f472e..366453599ca 100644 --- a/Kernel/Devices/MemoryDevice.h +++ b/Kernel/Devices/MemoryDevice.h @@ -19,7 +19,7 @@ public: static NonnullRefPtr must_create(); ~MemoryDevice(); - virtual KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; + virtual KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared) override; // ^Device virtual mode_t required_mode() const override { return 0660; } @@ -36,7 +36,7 @@ private: virtual void did_seek(FileDescription&, off_t) override; - bool is_allowed_range(PhysicalAddress, const Range&) const; + bool is_allowed_range(PhysicalAddress, Memory::Range const&) const; }; } diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index d495dc47ed4..c390c19082d 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -238,10 +238,10 @@ KResultOr SB16::write(FileDescription&, u64, const UserOrKernelBuffer& d if (!page) return ENOMEM; auto nonnull_page = page.release_nonnull(); - auto vmobject = AnonymousVMObject::try_create_with_physical_pages({ &nonnull_page, 1 }); + auto vmobject = Memory::AnonymousVMObject::try_create_with_physical_pages({ &nonnull_page, 1 }); if (!vmobject) return ENOMEM; - m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Region::Access::Write); + m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Memory::Region::Access::Write); if (!m_dma_region) return ENOMEM; } diff --git a/Kernel/Devices/SB16.h b/Kernel/Devices/SB16.h index 32b8c7712c3..523d2d980a5 100644 --- a/Kernel/Devices/SB16.h +++ b/Kernel/Devices/SB16.h @@ -55,7 +55,7 @@ private: void set_irq_register(u8 irq_number); void set_irq_line(u8 irq_number); - OwnPtr m_dma_region; + OwnPtr m_dma_region; int m_major_version { 0 }; WaitQueue m_irq_queue; diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp index 3fe605713e4..b5c11950e54 100644 --- a/Kernel/DoubleBuffer.cpp +++ b/Kernel/DoubleBuffer.cpp @@ -19,7 +19,7 @@ inline void DoubleBuffer::compute_lockfree_metadata() OwnPtr DoubleBuffer::try_create(size_t capacity) { - auto storage = KBuffer::try_create_with_size(capacity * 2, Region::Access::Read | Region::Access::Write, "DoubleBuffer"); + auto storage = KBuffer::try_create_with_size(capacity * 2, Memory::Region::Access::Read | Memory::Region::Access::Write, "DoubleBuffer"); if (!storage) return {}; diff --git a/Kernel/FileSystem/AnonymousFile.cpp b/Kernel/FileSystem/AnonymousFile.cpp index 580a5906f4b..e21c3298324 100644 --- a/Kernel/FileSystem/AnonymousFile.cpp +++ b/Kernel/FileSystem/AnonymousFile.cpp @@ -10,7 +10,7 @@ namespace Kernel { -AnonymousFile::AnonymousFile(NonnullRefPtr vmobject) +AnonymousFile::AnonymousFile(NonnullRefPtr vmobject) : m_vmobject(move(vmobject)) { } @@ -19,7 +19,7 @@ AnonymousFile::~AnonymousFile() { } -KResultOr AnonymousFile::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared) +KResultOr AnonymousFile::mmap(Process& process, FileDescription&, Memory::Range const& range, u64 offset, int prot, bool shared) { if (offset != 0) return EINVAL; diff --git a/Kernel/FileSystem/AnonymousFile.h b/Kernel/FileSystem/AnonymousFile.h index 361143ba67e..e6b25fc15e3 100644 --- a/Kernel/FileSystem/AnonymousFile.h +++ b/Kernel/FileSystem/AnonymousFile.h @@ -13,14 +13,14 @@ namespace Kernel { class AnonymousFile final : public File { public: - static RefPtr create(NonnullRefPtr vmobject) + static RefPtr create(NonnullRefPtr vmobject) { return adopt_ref_if_nonnull(new (nothrow) AnonymousFile(move(vmobject))); } virtual ~AnonymousFile() override; - virtual KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; + virtual KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared) override; private: virtual StringView class_name() const override { return "AnonymousFile"; } @@ -30,9 +30,9 @@ private: virtual KResultOr read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; } virtual KResultOr write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return ENOTSUP; } - explicit AnonymousFile(NonnullRefPtr); + explicit AnonymousFile(NonnullRefPtr); - NonnullRefPtr m_vmobject; + NonnullRefPtr m_vmobject; }; } diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 2bd8ddb7cea..00f20c085b8 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -132,7 +132,7 @@ bool Ext2FS::initialize() auto blocks_to_read = ceil_div(m_block_group_count * sizeof(ext2_group_desc), block_size()); BlockIndex first_block_of_bgdt = block_size() == 1024 ? 2 : 1; - m_cached_group_descriptor_table = KBuffer::try_create_with_size(block_size() * blocks_to_read, Region::Access::Read | Region::Access::Write, "Ext2FS: Block group descriptors"); + m_cached_group_descriptor_table = KBuffer::try_create_with_size(block_size() * blocks_to_read, Memory::Region::Access::Read | Memory::Region::Access::Write, "Ext2FS: Block group descriptors"); if (!m_cached_group_descriptor_table) { dbgln("Ext2FS: Failed to allocate memory for group descriptor table"); return false; @@ -1505,7 +1505,7 @@ KResultOr Ext2FS::get_bitmap_block(BlockIndex bitmap_bloc return cached_bitmap; } - auto block = KBuffer::try_create_with_size(block_size(), Region::Access::Read | Region::Access::Write, "Ext2FS: Cached bitmap block"); + auto block = KBuffer::try_create_with_size(block_size(), Memory::Region::Access::Read | Memory::Region::Access::Write, "Ext2FS: Cached bitmap block"); if (!block) return ENOMEM; auto buffer = UserOrKernelBuffer::for_kernel_buffer(block->data()); diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index 355b6ed56df..07226edbcfd 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -40,7 +40,7 @@ KResult File::ioctl(FileDescription&, unsigned, Userspace) return ENOTTY; } -KResultOr File::mmap(Process&, FileDescription&, const Range&, u64, int, bool) +KResultOr File::mmap(Process&, FileDescription&, Memory::Range const&, u64, int, bool) { return ENODEV; } diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 6410d1e1cb2..0e719f291fd 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -88,7 +88,7 @@ public: virtual KResultOr read(FileDescription&, u64, UserOrKernelBuffer&, size_t) = 0; virtual KResultOr write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0; virtual KResult ioctl(FileDescription&, unsigned request, Userspace arg); - virtual KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared); + virtual KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared); virtual KResult stat(::stat&) const { return EBADF; } virtual String absolute_path(const FileDescription&) const = 0; diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 6d795f81bcd..19822a83090 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -380,7 +380,7 @@ InodeMetadata FileDescription::metadata() const return {}; } -KResultOr FileDescription::mmap(Process& process, const Range& range, u64 offset, int prot, bool shared) +KResultOr FileDescription::mmap(Process& process, Memory::Range const& range, u64 offset, int prot, bool shared) { MutexLocker locker(m_lock); return m_file->mmap(process, *this, range, offset, prot, shared); diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h index c22e8a9d221..e1a05d293d9 100644 --- a/Kernel/FileSystem/FileDescription.h +++ b/Kernel/FileSystem/FileDescription.h @@ -96,7 +96,7 @@ public: Custody* custody() { return m_custody.ptr(); } const Custody* custody() const { return m_custody.ptr(); } - KResultOr mmap(Process&, const Range&, u64 offset, int prot, bool shared); + KResultOr mmap(Process&, Memory::Range const&, u64 offset, int prot, bool shared); bool is_blocking() const { return m_is_blocking; } void set_blocking(bool b) { m_is_blocking = b; } diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 37b20b1c66e..9db65ef1dd5 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -141,7 +141,7 @@ KResult Inode::decrement_link_count() return ENOTIMPL; } -void Inode::set_shared_vmobject(SharedInodeVMObject& vmobject) +void Inode::set_shared_vmobject(Memory::SharedInodeVMObject& vmobject) { MutexLocker locker(m_inode_lock); m_shared_vmobject = vmobject; @@ -271,7 +271,7 @@ KResult Inode::prepare_to_write_data() return KSuccess; } -RefPtr Inode::shared_vmobject() const +RefPtr Inode::shared_vmobject() const { MutexLocker locker(m_inode_lock); return m_shared_vmobject.strong_ref(); diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index f35a27e71ba..1b21564ad57 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -84,8 +84,8 @@ public: void will_be_destroyed(); - void set_shared_vmobject(SharedInodeVMObject&); - RefPtr shared_vmobject() const; + void set_shared_vmobject(Memory::SharedInodeVMObject&); + RefPtr shared_vmobject() const; static void sync(); @@ -116,7 +116,7 @@ protected: private: FileSystem& m_file_system; InodeIndex m_index { 0 }; - WeakPtr m_shared_vmobject; + WeakPtr m_shared_vmobject; RefPtr m_socket; HashTable m_watchers; bool m_metadata_dirty { false }; diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 876224b1658..9b40bc730d3 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -93,14 +93,14 @@ KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspa } } -KResultOr InodeFile::mmap(Process& process, FileDescription& description, const Range& range, u64 offset, int prot, bool shared) +KResultOr InodeFile::mmap(Process& process, FileDescription& description, Memory::Range const& range, u64 offset, int prot, bool shared) { // FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec. - RefPtr vmobject; + RefPtr vmobject; if (shared) - vmobject = SharedInodeVMObject::try_create_with_inode(inode()); + vmobject = Memory::SharedInodeVMObject::try_create_with_inode(inode()); else - vmobject = PrivateInodeVMObject::try_create_with_inode(inode()); + vmobject = Memory::PrivateInodeVMObject::try_create_with_inode(inode()); if (!vmobject) return ENOMEM; return process.space().allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, description.absolute_path(), prot, shared); diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index 5fe928a21de..2a206735939 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -33,7 +33,7 @@ public: virtual KResultOr read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual KResultOr write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override; virtual KResult ioctl(FileDescription&, unsigned request, Userspace arg) override; - virtual KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; + virtual KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared) override; virtual KResult stat(::stat& buffer) const override { return inode().metadata().stat(buffer); } virtual String absolute_path(const FileDescription&) const override; diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index b21c81143ab..6b73dc98c96 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -560,7 +560,7 @@ KResult Plan9FS::read_and_dispatch_one_message() if (result.is_error()) return result; - auto buffer = KBuffer::try_create_with_size(header.size, Region::Access::Read | Region::Access::Write); + auto buffer = KBuffer::try_create_with_size(header.size, Memory::Region::Access::Read | Memory::Region::Access::Write); if (!buffer) return ENOMEM; // Copy the already read header into the buffer. diff --git a/Kernel/Forward.h b/Kernel/Forward.h index 7d8330ce74c..e7047343e8d 100644 --- a/Kernel/Forward.h +++ b/Kernel/Forward.h @@ -31,15 +31,10 @@ class InodeWatcher; class KBuffer; class KResult; class LocalSocket; -class MemoryManager; class Mutex; -class MappedROM; class MasterPTY; class Mount; -class PageDirectory; class PerformanceEventBuffer; -class PhysicalPage; -class PhysicalRegion; class ProcFS; class ProcFSDirectoryInode; class ProcFSExposedComponent; @@ -51,15 +46,10 @@ class ProcFSSystemBoolean; class ProcFSSystemDirectory; class Process; class ProcessGroup; -class Range; -class RangeAllocator; class RecursiveSpinLock; -class Region; class Scheduler; class SchedulerData; -class SharedInodeVMObject; class Socket; -class Space; class SysFS; class SysFSDirectory; class SysFSBusDirectory; @@ -71,11 +61,27 @@ class Thread; class ThreadTracer; class UDPSocket; class UserOrKernelBuffer; -class VMObject; class VirtualFileSystem; class WaitQueue; class WorkQueue; +namespace Memory { +class AnonymousVMObject; +class InodeVMObject; +class MappedROM; +class MemoryManager; +class PageDirectory; +class PhysicalPage; +class PhysicalRegion; +class PrivateInodeVMObject; +class Range; +class RangeAllocator; +class Region; +class SharedInodeVMObject; +class Space; +class VMObject; +} + template class SpinLock; template diff --git a/Kernel/FutexQueue.h b/Kernel/FutexQueue.h index cc8a144f99c..5cad5e3b18c 100644 --- a/Kernel/FutexQueue.h +++ b/Kernel/FutexQueue.h @@ -16,9 +16,9 @@ namespace Kernel { class FutexQueue : public Thread::BlockCondition , public RefCounted - , public VMObjectDeletedHandler { + , public Memory::VMObjectDeletedHandler { public: - FutexQueue(FlatPtr user_address_or_offset, VMObject* vmobject = nullptr); + FutexQueue(FlatPtr user_address_or_offset, Memory::VMObject* vmobject = nullptr); virtual ~FutexQueue(); u32 wake_n_requeue(u32, const Function&, u32, bool&, bool&); @@ -31,7 +31,7 @@ public: return Thread::current()->block(timeout, *this, forward(args)...); } - virtual void vmobject_deleted(VMObject&) override; + virtual void vmobject_deleted(Memory::VMObject&) override; bool queue_imminent_wait(); void did_remove(); @@ -51,7 +51,7 @@ private: // For private futexes we just use the user space address. // But for global futexes we use the offset into the VMObject const FlatPtr m_user_address_or_offset; - WeakPtr m_vmobject; + WeakPtr m_vmobject; const bool m_is_global; size_t m_imminent_waits { 1 }; // We only create this object if we're going to be waiting, so start out with 1 bool m_was_removed { false }; diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp index 5fc351509dc..87c9e936df0 100644 --- a/Kernel/GlobalProcessExposed.cpp +++ b/Kernel/GlobalProcessExposed.cpp @@ -376,7 +376,7 @@ private: kmalloc_stats stats; get_kmalloc_stats(stats); - auto system_memory = MemoryManager::the().get_system_memory_info(); + auto system_memory = MM.get_system_memory_info(); JsonObjectSerializer json { builder }; json.add("kmalloc_allocated", stats.bytes_allocated); diff --git a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp index 0c6df230498..baacaf12cff 100644 --- a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp +++ b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp @@ -65,7 +65,7 @@ UNMAP_AFTER_INIT NonnullRefPtr BochsGraphicsAdapter::initi UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::Address pci_address) : PCI::DeviceController(pci_address) , m_mmio_registers(PCI::get_BAR2(pci_address) & 0xfffffff0) - , m_registers(map_typed_writable(m_mmio_registers)) + , m_registers(Memory::map_typed_writable(m_mmio_registers)) { // We assume safe resolutio is 1024x768x32 m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(PhysicalAddress(PCI::get_BAR0(pci_address) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32)); diff --git a/Kernel/Graphics/Bochs/GraphicsAdapter.h b/Kernel/Graphics/Bochs/GraphicsAdapter.h index a10c3f1fb46..e8fddd3f598 100644 --- a/Kernel/Graphics/Bochs/GraphicsAdapter.h +++ b/Kernel/Graphics/Bochs/GraphicsAdapter.h @@ -57,7 +57,7 @@ private: void set_y_offset(size_t); PhysicalAddress m_mmio_registers; - TypedMapping m_registers; + Memory::TypedMapping m_registers; RefPtr m_framebuffer_device; RefPtr m_framebuffer_console; SpinLock m_console_mode_switch_lock; diff --git a/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp b/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp index 12a7cd45cad..fe74603f727 100644 --- a/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp +++ b/Kernel/Graphics/Console/ContiguousFramebufferConsole.cpp @@ -27,8 +27,8 @@ void ContiguousFramebufferConsole::set_resolution(size_t width, size_t height, s m_height = height; m_pitch = pitch; - dbgln("Framebuffer Console: taking {} bytes", page_round_up(pitch * height)); - m_framebuffer_region = MM.allocate_kernel_region(m_framebuffer_address, page_round_up(pitch * height), "Framebuffer Console", Region::Access::Read | Region::Access::Write, Region::Cacheable::Yes); + dbgln("Framebuffer Console: taking {} bytes", Memory::page_round_up(pitch * height)); + m_framebuffer_region = MM.allocate_kernel_region(m_framebuffer_address, Memory::page_round_up(pitch * height), "Framebuffer Console", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::Yes); VERIFY(m_framebuffer_region); // Just to start cleanly, we clean the entire framebuffer diff --git a/Kernel/Graphics/Console/ContiguousFramebufferConsole.h b/Kernel/Graphics/Console/ContiguousFramebufferConsole.h index 6d8159f814f..692631635fb 100644 --- a/Kernel/Graphics/Console/ContiguousFramebufferConsole.h +++ b/Kernel/Graphics/Console/ContiguousFramebufferConsole.h @@ -22,7 +22,7 @@ private: { return m_framebuffer_region->vaddr().as_ptr(); } - OwnPtr m_framebuffer_region; + OwnPtr m_framebuffer_region; ContiguousFramebufferConsole(PhysicalAddress, size_t width, size_t height, size_t pitch); PhysicalAddress m_framebuffer_address; }; diff --git a/Kernel/Graphics/Console/VGAConsole.cpp b/Kernel/Graphics/Console/VGAConsole.cpp index 73bcabb7e2f..cdd5e08db39 100644 --- a/Kernel/Graphics/Console/VGAConsole.cpp +++ b/Kernel/Graphics/Console/VGAConsole.cpp @@ -11,7 +11,7 @@ namespace Kernel::Graphics { UNMAP_AFTER_INIT VGAConsole::VGAConsole(const VGACompatibleAdapter& adapter, Mode mode, size_t width, size_t height) : Console(width, height) - , m_vga_region(MM.allocate_kernel_region(PhysicalAddress(0xa0000), page_round_up(0xc0000 - 0xa0000), "VGA Display", Region::Access::Read | Region::Access::Write).release_nonnull()) + , m_vga_region(MM.allocate_kernel_region(PhysicalAddress(0xa0000), Memory::page_round_up(0xc0000 - 0xa0000), "VGA Display", Memory::Region::Access::Read | Memory::Region::Access::Write).release_nonnull()) , m_adapter(adapter) , m_mode(mode) { diff --git a/Kernel/Graphics/Console/VGAConsole.h b/Kernel/Graphics/Console/VGAConsole.h index b10f5110c8b..7c2b4cb49c1 100644 --- a/Kernel/Graphics/Console/VGAConsole.h +++ b/Kernel/Graphics/Console/VGAConsole.h @@ -33,7 +33,7 @@ public: protected: VGAConsole(const VGACompatibleAdapter&, Mode, size_t width, size_t height); - NonnullOwnPtr m_vga_region; + NonnullOwnPtr m_vga_region; NonnullRefPtr m_adapter; const Mode m_mode; }; diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index e4a1061a43f..e9e7def17af 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -25,7 +25,7 @@ NonnullRefPtr FramebufferDevice::create(const GraphicsDevice& return adopt_ref(*new FramebufferDevice(adapter, output_port_index, paddr, width, height, pitch)); } -KResultOr FramebufferDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared) +KResultOr FramebufferDevice::mmap(Process& process, FileDescription&, Memory::Range const& range, u64 offset, int prot, bool shared) { ScopedSpinLock lock(m_activation_lock); REQUIRE_PROMISE(video); @@ -33,31 +33,31 @@ KResultOr FramebufferDevice::mmap(Process& process, FileDescription&, c return ENODEV; if (offset != 0) return ENXIO; - if (range.size() != page_round_up(framebuffer_size_in_bytes())) + if (range.size() != Memory::page_round_up(framebuffer_size_in_bytes())) return EOVERFLOW; - auto vmobject = AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, page_round_up(framebuffer_size_in_bytes())); + auto vmobject = Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, Memory::page_round_up(framebuffer_size_in_bytes())); if (!vmobject) return ENOMEM; m_userspace_real_framebuffer_vmobject = vmobject; - m_real_framebuffer_vmobject = AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, page_round_up(framebuffer_size_in_bytes())); + m_real_framebuffer_vmobject = Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, Memory::page_round_up(framebuffer_size_in_bytes())); if (!m_real_framebuffer_vmobject) return ENOMEM; - m_swapped_framebuffer_vmobject = AnonymousVMObject::try_create_with_size(page_round_up(framebuffer_size_in_bytes()), AllocationStrategy::AllocateNow); + m_swapped_framebuffer_vmobject = Memory::AnonymousVMObject::try_create_with_size(Memory::page_round_up(framebuffer_size_in_bytes()), AllocationStrategy::AllocateNow); if (!m_swapped_framebuffer_vmobject) return ENOMEM; - m_real_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer", Region::Access::Read | Region::Access::Write); + m_real_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, Memory::page_round_up(framebuffer_size_in_bytes()), "Framebuffer", Memory::Region::Access::Read | Memory::Region::Access::Write); if (!m_real_framebuffer_region) return ENOMEM; - m_swapped_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer Swap (Blank)", Region::Access::Read | Region::Access::Write); + m_swapped_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, Memory::page_round_up(framebuffer_size_in_bytes()), "Framebuffer Swap (Blank)", Memory::Region::Access::Read | Memory::Region::Access::Write); if (!m_swapped_framebuffer_region) return ENOMEM; - RefPtr chosen_vmobject; + RefPtr chosen_vmobject; if (m_graphical_writes_enabled) { chosen_vmobject = m_real_framebuffer_vmobject; } else { @@ -81,7 +81,7 @@ void FramebufferDevice::deactivate_writes() ScopedSpinLock lock(m_activation_lock); if (!m_userspace_framebuffer_region) return; - memcpy(m_swapped_framebuffer_region->vaddr().as_ptr(), m_real_framebuffer_region->vaddr().as_ptr(), page_round_up(framebuffer_size_in_bytes())); + memcpy(m_swapped_framebuffer_region->vaddr().as_ptr(), m_real_framebuffer_region->vaddr().as_ptr(), Memory::page_round_up(framebuffer_size_in_bytes())); auto vmobject = m_swapped_framebuffer_vmobject; m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull()); m_userspace_framebuffer_region->remap(); @@ -95,7 +95,7 @@ void FramebufferDevice::activate_writes() // restore the image we had in the void area // FIXME: if we happen to have multiple Framebuffers that are writing to that location // we will experience glitches... - memcpy(m_real_framebuffer_region->vaddr().as_ptr(), m_swapped_framebuffer_region->vaddr().as_ptr(), page_round_up(framebuffer_size_in_bytes())); + memcpy(m_real_framebuffer_region->vaddr().as_ptr(), m_swapped_framebuffer_region->vaddr().as_ptr(), Memory::page_round_up(framebuffer_size_in_bytes())); auto vmobject = m_userspace_real_framebuffer_vmobject; m_userspace_framebuffer_region->set_vmobject(vmobject.release_nonnull()); m_userspace_framebuffer_region->remap(); @@ -109,13 +109,13 @@ String FramebufferDevice::device_name() const UNMAP_AFTER_INIT void FramebufferDevice::initialize() { - m_real_framebuffer_vmobject = AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, page_round_up(framebuffer_size_in_bytes())); + m_real_framebuffer_vmobject = Memory::AnonymousVMObject::try_create_for_physical_range(m_framebuffer_address, Memory::page_round_up(framebuffer_size_in_bytes())); VERIFY(m_real_framebuffer_vmobject); - m_real_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer", Region::Access::Read | Region::Access::Write); + m_real_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, Memory::page_round_up(framebuffer_size_in_bytes()), "Framebuffer", Memory::Region::Access::Read | Memory::Region::Access::Write); VERIFY(m_real_framebuffer_region); - m_swapped_framebuffer_vmobject = AnonymousVMObject::try_create_with_size(page_round_up(framebuffer_size_in_bytes()), AllocationStrategy::AllocateNow); + m_swapped_framebuffer_vmobject = Memory::AnonymousVMObject::try_create_with_size(Memory::page_round_up(framebuffer_size_in_bytes()), AllocationStrategy::AllocateNow); VERIFY(m_swapped_framebuffer_vmobject); - m_swapped_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, page_round_up(framebuffer_size_in_bytes()), "Framebuffer Swap (Blank)", Region::Access::Read | Region::Access::Write); + m_swapped_framebuffer_region = MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, Memory::page_round_up(framebuffer_size_in_bytes()), "Framebuffer Swap (Blank)", Memory::Region::Access::Read | Memory::Region::Access::Write); VERIFY(m_swapped_framebuffer_region); } diff --git a/Kernel/Graphics/FramebufferDevice.h b/Kernel/Graphics/FramebufferDevice.h index e240d10a415..26a39da6936 100644 --- a/Kernel/Graphics/FramebufferDevice.h +++ b/Kernel/Graphics/FramebufferDevice.h @@ -23,7 +23,7 @@ public: static NonnullRefPtr create(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t); virtual KResult ioctl(FileDescription&, unsigned request, Userspace arg) override; - virtual KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; + virtual KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared) override; // ^Device virtual mode_t required_mode() const override { return 0660; } @@ -55,15 +55,15 @@ private: SpinLock m_activation_lock; - RefPtr m_real_framebuffer_vmobject; - RefPtr m_swapped_framebuffer_vmobject; - OwnPtr m_real_framebuffer_region; - OwnPtr m_swapped_framebuffer_region; + RefPtr m_real_framebuffer_vmobject; + RefPtr m_swapped_framebuffer_vmobject; + OwnPtr m_real_framebuffer_region; + OwnPtr m_swapped_framebuffer_region; bool m_graphical_writes_enabled { true }; - RefPtr m_userspace_real_framebuffer_vmobject; - Region* m_userspace_framebuffer_region { nullptr }; + RefPtr m_userspace_real_framebuffer_vmobject; + Memory::Region* m_userspace_framebuffer_region { nullptr }; size_t m_y_offset { 0 }; size_t m_output_port_index; diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index 5e5b4b63a53..438fc544866 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -32,7 +32,7 @@ bool GraphicsManagement::is_initialized() } UNMAP_AFTER_INIT GraphicsManagement::GraphicsManagement() - : m_vga_font_region(MM.allocate_kernel_region(PAGE_SIZE, "VGA font", Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow).release_nonnull()) + : m_vga_font_region(MM.allocate_kernel_region(PAGE_SIZE, "VGA font", Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow).release_nonnull()) , m_framebuffer_devices_allowed(!kernel_command_line().is_no_framebuffer_devices_mode()) { } diff --git a/Kernel/Graphics/GraphicsManagement.h b/Kernel/Graphics/GraphicsManagement.h index ca39d787b63..ebfda332ee9 100644 --- a/Kernel/Graphics/GraphicsManagement.h +++ b/Kernel/Graphics/GraphicsManagement.h @@ -49,7 +49,7 @@ public: private: bool determine_and_initialize_graphics_device(const PCI::Address& address, PCI::ID id); NonnullRefPtrVector m_graphics_devices; - NonnullOwnPtr m_vga_font_region; + NonnullOwnPtr m_vga_font_region; RefPtr m_console; // Note: there could be multiple VGA adapters, but only one can operate in VGA mode diff --git a/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp b/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp index f3a16ecc5a4..0d189505e7f 100644 --- a/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp +++ b/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp @@ -189,7 +189,7 @@ IntelNativeGraphicsAdapter::IntelNativeGraphicsAdapter(PCI::Address address) VERIFY(bar0_space_size == 0x80000); dmesgln("Intel Native Graphics Adapter @ {}, MMIO @ {}, space size is {:x} bytes", address, PhysicalAddress(PCI::get_BAR0(address)), bar0_space_size); dmesgln("Intel Native Graphics Adapter @ {}, framebuffer @ {}", address, PhysicalAddress(PCI::get_BAR2(address))); - m_registers_region = MM.allocate_kernel_region(PhysicalAddress(PCI::get_BAR0(address)).page_base(), bar0_space_size, "Intel Native Graphics Registers", Region::Access::Read | Region::Access::Write); + m_registers_region = MM.allocate_kernel_region(PhysicalAddress(PCI::get_BAR0(address)).page_base(), bar0_space_size, "Intel Native Graphics Registers", Memory::Region::Access::Read | Memory::Region::Access::Write); PCI::enable_bus_mastering(address); { ScopedSpinLock control_lock(m_control_lock); diff --git a/Kernel/Graphics/Intel/NativeGraphicsAdapter.h b/Kernel/Graphics/Intel/NativeGraphicsAdapter.h index 2cd87ad440a..6768d9f9cb6 100644 --- a/Kernel/Graphics/Intel/NativeGraphicsAdapter.h +++ b/Kernel/Graphics/Intel/NativeGraphicsAdapter.h @@ -168,7 +168,7 @@ private: Graphics::VideoInfoBlock m_crt_edid; const PhysicalAddress m_registers; const PhysicalAddress m_framebuffer_addr; - OwnPtr m_registers_region; + OwnPtr m_registers_region; }; } diff --git a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp index eb312811df2..df8f8ea94bd 100644 --- a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp +++ b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp @@ -32,15 +32,15 @@ void FrameBufferDevice::create_framebuffer() // Allocate frame buffer for both front and back auto& info = display_info(); m_buffer_size = calculate_framebuffer_size(info.rect.width, info.rect.height); - m_framebuffer = MM.allocate_kernel_region(m_buffer_size * 2, String::formatted("VirtGPU FrameBuffer #{}", m_scanout.value()), Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); - auto write_sink_page = MM.allocate_user_physical_page(MemoryManager::ShouldZeroFill::No).release_nonnull(); + m_framebuffer = MM.allocate_kernel_region(m_buffer_size * 2, String::formatted("VirtGPU FrameBuffer #{}", m_scanout.value()), Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); + auto write_sink_page = MM.allocate_user_physical_page(Memory::MemoryManager::ShouldZeroFill::No).release_nonnull(); auto num_needed_pages = m_framebuffer->vmobject().page_count(); - NonnullRefPtrVector pages; + NonnullRefPtrVector pages; for (auto i = 0u; i < num_needed_pages; ++i) { pages.append(write_sink_page); } - m_framebuffer_sink_vmobject = AnonymousVMObject::try_create_with_physical_pages(pages.span()); + m_framebuffer_sink_vmobject = Memory::AnonymousVMObject::try_create_with_physical_pages(pages.span()); MutexLocker locker(m_gpu.operation_lock()); m_current_buffer = &buffer_from_index(m_last_set_buffer_index.load()); @@ -241,7 +241,7 @@ KResult FrameBufferDevice::ioctl(FileDescription&, unsigned request, Userspace FrameBufferDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared) +KResultOr FrameBufferDevice::mmap(Process& process, FileDescription&, Memory::Range const& range, u64 offset, int prot, bool shared) { REQUIRE_PROMISE(video); if (!shared) diff --git a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h index 54b765a40cb..efbc98aff6a 100644 --- a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h +++ b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h @@ -39,7 +39,7 @@ public: static size_t calculate_framebuffer_size(size_t width, size_t height) { // VirtIO resources can only map on page boundaries! - return page_round_up(sizeof(u32) * width * height); + return Memory::page_round_up(sizeof(u32) * width * height); } void flush_dirty_window(Protocol::Rect const&, Buffer&); @@ -61,7 +61,7 @@ private: void set_buffer(int); virtual KResult ioctl(FileDescription&, unsigned request, Userspace arg) override; - virtual KResultOr mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; + virtual KResultOr mmap(Process&, FileDescription&, Memory::Range const&, u64 offset, int prot, bool shared) override; virtual bool can_read(const FileDescription&, size_t) const override { return true; } virtual KResultOr read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; } virtual bool can_write(const FileDescription&, size_t) const override { return true; } @@ -88,12 +88,12 @@ private: Atomic m_last_set_buffer_index { 0 }; Buffer m_main_buffer; Buffer m_back_buffer; - OwnPtr m_framebuffer; - RefPtr m_framebuffer_sink_vmobject; + OwnPtr m_framebuffer; + RefPtr m_framebuffer_sink_vmobject; size_t m_buffer_size { 0 }; bool m_are_writes_active { true }; // FIXME: This needs to be cleaned up if the WindowServer exits while we are in a tty - WeakPtr m_userspace_mmap_region; + WeakPtr m_userspace_mmap_region; }; } diff --git a/Kernel/Graphics/VirtIOGPU/GPU.cpp b/Kernel/Graphics/VirtIOGPU/GPU.cpp index 15eb5bdafcd..1600d015313 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU.cpp +++ b/Kernel/Graphics/VirtIOGPU/GPU.cpp @@ -17,7 +17,7 @@ namespace Kernel::Graphics::VirtIOGPU { GPU::GPU(PCI::Address address) : VirtIODevice(address, "GPU") - , m_scratch_space(MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Region::Access::Read | Region::Access::Write)) + , m_scratch_space(MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Memory::Region::Access::Read | Memory::Region::Access::Write)) { VERIFY(!!m_scratch_space); if (auto cfg = get_config(ConfigurationType::Device)) { @@ -138,7 +138,7 @@ ResourceID GPU::create_2d_resource(Protocol::Rect rect) return resource_id; } -void GPU::ensure_backing_storage(Region const& region, size_t buffer_offset, size_t buffer_length, ResourceID resource_id) +void GPU::ensure_backing_storage(Memory::Region const& region, size_t buffer_offset, size_t buffer_length, ResourceID resource_id) { VERIFY(m_operation_lock.is_locked()); diff --git a/Kernel/Graphics/VirtIOGPU/GPU.h b/Kernel/Graphics/VirtIOGPU/GPU.h index 86c75f02ca3..11a55adc673 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU.h +++ b/Kernel/Graphics/VirtIOGPU/GPU.h @@ -102,7 +102,7 @@ private: void query_display_information(); ResourceID create_2d_resource(Protocol::Rect rect); void delete_resource(ResourceID resource_id); - void ensure_backing_storage(Region const& region, size_t buffer_offset, size_t buffer_length, ResourceID resource_id); + void ensure_backing_storage(Memory::Region const& region, size_t buffer_offset, size_t buffer_length, ResourceID resource_id); void detach_backing_storage(ResourceID resource_id); void set_scanout_resource(ScanoutID scanout, ResourceID resource_id, Protocol::Rect rect); void transfer_framebuffer_data_to_host(ScanoutID scanout, Protocol::Rect const& rect, ResourceID resource_id); @@ -118,7 +118,7 @@ private: // Synchronous commands WaitQueue m_outstanding_request; Mutex m_operation_lock; - OwnPtr m_scratch_space; + OwnPtr m_scratch_space; }; } diff --git a/Kernel/Heap/SlabAllocator.cpp b/Kernel/Heap/SlabAllocator.cpp index 4057cbafcc4..c20f676bada 100644 --- a/Kernel/Heap/SlabAllocator.cpp +++ b/Kernel/Heap/SlabAllocator.cpp @@ -112,7 +112,7 @@ static SlabAllocator<128> s_slab_allocator_128; static SlabAllocator<256> s_slab_allocator_256; #if ARCH(I386) -static_assert(sizeof(Region) <= s_slab_allocator_128.slab_size()); +static_assert(sizeof(Memory::Region) <= s_slab_allocator_128.slab_size()); #endif template diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp index 89257ee798a..55ee04f7d10 100644 --- a/Kernel/Heap/kmalloc.cpp +++ b/Kernel/Heap/kmalloc.cpp @@ -47,7 +47,7 @@ struct KmallocGlobalHeap { bool m_adding { false }; bool add_memory(size_t allocation_request) { - if (!MemoryManager::is_initialized()) { + if (!Memory::MemoryManager::is_initialized()) { if constexpr (KMALLOC_DEBUG) { dmesgln("kmalloc: Cannot expand heap before MM is initialized!"); } @@ -94,12 +94,12 @@ struct KmallocGlobalHeap { // was big enough to likely satisfy the request if (subheap.free_bytes() < allocation_request) { // Looks like we probably need more - size_t memory_size = page_round_up(decltype(m_global_heap.m_heap)::calculate_memory_for_bytes(allocation_request)); + size_t memory_size = Memory::page_round_up(decltype(m_global_heap.m_heap)::calculate_memory_for_bytes(allocation_request)); // Add some more to the new heap. We're already using it for other // allocations not including the original allocation_request // that triggered heap expansion. If we don't allocate memory_size += 1 * MiB; - region = MM.allocate_kernel_region(memory_size, "kmalloc subheap", Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); + region = MM.allocate_kernel_region(memory_size, "kmalloc subheap", Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); if (region) { dbgln("kmalloc: Adding even more memory to heap at {}, bytes: {}", region->vaddr(), region->size()); @@ -162,8 +162,8 @@ struct KmallocGlobalHeap { typedef ExpandableHeap HeapType; HeapType m_heap; - NonnullOwnPtrVector m_subheap_memory; - OwnPtr m_backup_memory; + NonnullOwnPtrVector m_subheap_memory; + OwnPtr m_backup_memory; KmallocGlobalHeap(u8* memory, size_t memory_size) : m_heap(memory, memory_size, ExpandGlobalHeap(*this)) @@ -173,7 +173,7 @@ struct KmallocGlobalHeap { { if (m_backup_memory) return; - m_backup_memory = MM.allocate_kernel_region(1 * MiB, "kmalloc subheap", Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); + m_backup_memory = MM.allocate_kernel_region(1 * MiB, "kmalloc subheap", Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); } size_t backup_memory_bytes() const diff --git a/Kernel/Interrupts/APIC.cpp b/Kernel/Interrupts/APIC.cpp index 714c85791ee..cd7f04f0687 100644 --- a/Kernel/Interrupts/APIC.cpp +++ b/Kernel/Interrupts/APIC.cpp @@ -228,7 +228,7 @@ UNMAP_AFTER_INIT bool APIC::init_bsp() dbgln_if(APIC_DEBUG, "Initializing APIC, base: {}", apic_base); set_base(apic_base); - m_apic_base = MM.allocate_kernel_region(apic_base.page_base(), PAGE_SIZE, {}, Region::Access::Read | Region::Access::Write); + m_apic_base = MM.allocate_kernel_region(apic_base.page_base(), PAGE_SIZE, {}, Memory::Region::Access::Read | Memory::Region::Access::Write); if (!m_apic_base) { dbgln("APIC: Failed to allocate memory for APIC base"); return false; @@ -245,7 +245,7 @@ UNMAP_AFTER_INIT bool APIC::init_bsp() return false; } - auto madt = map_typed(madt_address); + auto madt = Memory::map_typed(madt_address); size_t entry_index = 0; size_t entries_length = madt->h.length - sizeof(ACPI::Structures::MADT); auto* madt_entry = madt->entries; @@ -283,13 +283,13 @@ UNMAP_AFTER_INIT void APIC::do_boot_aps() // Also account for the data appended to: // * aps_to_enable u32 values for ap_cpu_init_stacks // * aps_to_enable u32 values for ap_cpu_init_processor_info_array - auto apic_startup_region = MM.allocate_kernel_region_identity(PhysicalAddress(0x8000), page_round_up(apic_ap_start_size + (2 * aps_to_enable * sizeof(u32))), {}, Region::Access::Read | Region::Access::Write | Region::Access::Execute); + auto apic_startup_region = MM.allocate_kernel_region_identity(PhysicalAddress(0x8000), Memory::page_round_up(apic_ap_start_size + (2 * aps_to_enable * sizeof(u32))), {}, Memory::Region::Access::Read | Memory::Region::Access::Write | Memory::Region::Access::Execute); memcpy(apic_startup_region->vaddr().as_ptr(), reinterpret_cast(apic_ap_start), apic_ap_start_size); // Allocate enough stacks for all APs - Vector> apic_ap_stacks; + Vector> apic_ap_stacks; for (u32 i = 0; i < aps_to_enable; i++) { - auto stack_region = MM.allocate_kernel_region(Thread::default_kernel_stack_size, {}, Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); + auto stack_region = MM.allocate_kernel_region(Thread::default_kernel_stack_size, {}, Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); if (!stack_region) { dbgln("APIC: Failed to allocate stack for AP #{}", i); return; diff --git a/Kernel/Interrupts/APIC.h b/Kernel/Interrupts/APIC.h index 507dd8e0b2a..e59ef335647 100644 --- a/Kernel/Interrupts/APIC.h +++ b/Kernel/Interrupts/APIC.h @@ -89,7 +89,7 @@ private: u32 high() const { return m_high; } }; - OwnPtr m_apic_base; + OwnPtr m_apic_base; Vector> m_ap_processor_info; Vector m_ap_idle_threads; Atomic m_apic_ap_count { 0 }; diff --git a/Kernel/Interrupts/IOAPIC.cpp b/Kernel/Interrupts/IOAPIC.cpp index 1bdf548515f..f90433e0689 100644 --- a/Kernel/Interrupts/IOAPIC.cpp +++ b/Kernel/Interrupts/IOAPIC.cpp @@ -25,7 +25,7 @@ enum DeliveryMode { UNMAP_AFTER_INIT IOAPIC::IOAPIC(PhysicalAddress address, u32 gsi_base) : m_address(address) - , m_regs(map_typed_writable(m_address)) + , m_regs(Memory::map_typed_writable(m_address)) , m_gsi_base(gsi_base) , m_id((read_register(0x0) >> 24) & 0xFF) , m_version(read_register(0x1) & 0xFF) diff --git a/Kernel/Interrupts/IOAPIC.h b/Kernel/Interrupts/IOAPIC.h index 1e71e78a32d..4977668664f 100644 --- a/Kernel/Interrupts/IOAPIC.h +++ b/Kernel/Interrupts/IOAPIC.h @@ -78,7 +78,7 @@ private: void isa_identity_map(int index); PhysicalAddress m_address; - mutable TypedMapping m_regs; + mutable Memory::TypedMapping m_regs; u32 m_gsi_base; u8 m_id; u8 m_version; diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index 0101e1fd6ea..d1bc0e82930 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -183,7 +183,7 @@ UNMAP_AFTER_INIT void InterruptManagement::switch_to_ioapic_mode() UNMAP_AFTER_INIT void InterruptManagement::locate_apic_data() { VERIFY(!m_madt.is_null()); - auto madt = map_typed(m_madt); + auto madt = Memory::map_typed(m_madt); int irq_controller_count = 0; if (madt->flags & PCAT_COMPAT_FLAG) { diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h index 218925f2166..a2ce51cfbbe 100644 --- a/Kernel/KBuffer.h +++ b/Kernel/KBuffer.h @@ -27,17 +27,17 @@ namespace Kernel { class KBufferImpl : public RefCounted { public: - static RefPtr try_create_with_size(size_t size, Region::Access access, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) + static RefPtr try_create_with_size(size_t size, Memory::Region::Access access, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { - auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy); + auto region = MM.allocate_kernel_region(Memory::page_round_up(size), name, access, strategy); if (!region) return nullptr; return adopt_ref_if_nonnull(new (nothrow) KBufferImpl(region.release_nonnull(), size, strategy)); } - static RefPtr try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) + static RefPtr try_create_with_bytes(ReadonlyBytes bytes, Memory::Region::Access access, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { - auto region = MM.allocate_kernel_region(page_round_up(bytes.size()), name, access, strategy); + auto region = MM.allocate_kernel_region(Memory::page_round_up(bytes.size()), name, access, strategy); if (!region) return nullptr; memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size()); @@ -45,12 +45,12 @@ public: return adopt_ref_if_nonnull(new (nothrow) KBufferImpl(region.release_nonnull(), bytes.size(), strategy)); } - static RefPtr create_with_size(size_t size, Region::Access access, StringView name, AllocationStrategy strategy = AllocationStrategy::Reserve) + static RefPtr create_with_size(size_t size, Memory::Region::Access access, StringView name, AllocationStrategy strategy = AllocationStrategy::Reserve) { return try_create_with_size(size, access, name, strategy); } - static RefPtr copy(const void* data, size_t size, Region::Access access, StringView name) + static RefPtr copy(const void* data, size_t size, Memory::Region::Access access, StringView name) { auto buffer = create_with_size(size, access, name, AllocationStrategy::AllocateNow); if (!buffer) @@ -61,7 +61,7 @@ public: [[nodiscard]] bool expand(size_t new_capacity) { - auto new_region = MM.allocate_kernel_region(page_round_up(new_capacity), m_region->name(), m_region->access(), m_allocation_strategy); + auto new_region = MM.allocate_kernel_region(Memory::page_round_up(new_capacity), m_region->name(), m_region->access(), m_allocation_strategy); if (!new_region) return false; if (m_size > 0) @@ -81,11 +81,11 @@ public: m_size = size; } - [[nodiscard]] const Region& region() const { return *m_region; } - [[nodiscard]] Region& region() { return *m_region; } + [[nodiscard]] Memory::Region const& region() const { return *m_region; } + [[nodiscard]] Memory::Region& region() { return *m_region; } private: - explicit KBufferImpl(NonnullOwnPtr&& region, size_t size, AllocationStrategy strategy) + explicit KBufferImpl(NonnullOwnPtr&& region, size_t size, AllocationStrategy strategy) : m_size(size) , m_allocation_strategy(strategy) , m_region(move(region)) @@ -94,7 +94,7 @@ private: size_t m_size { 0 }; AllocationStrategy m_allocation_strategy { AllocationStrategy::Reserve }; - NonnullOwnPtr m_region; + NonnullOwnPtr m_region; }; class [[nodiscard]] KBuffer { @@ -104,7 +104,7 @@ public: { } - [[nodiscard]] static OwnPtr try_create_with_size(size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) + [[nodiscard]] static OwnPtr try_create_with_size(size_t size, Memory::Region::Access access = Memory::Region::Access::Read | Memory::Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy); if (!impl) @@ -112,7 +112,7 @@ public: return adopt_own_if_nonnull(new (nothrow) KBuffer(impl.release_nonnull())); } - [[nodiscard]] static OwnPtr try_create_with_bytes(ReadonlyBytes bytes, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) + [[nodiscard]] static OwnPtr try_create_with_bytes(ReadonlyBytes bytes, Memory::Region::Access access = Memory::Region::Access::Read | Memory::Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy); if (!impl) @@ -120,7 +120,7 @@ public: return adopt_own_if_nonnull(new (nothrow) KBuffer(impl.release_nonnull())); } - [[nodiscard]] static KBuffer copy(const void* data, size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer") + [[nodiscard]] static KBuffer copy(const void* data, size_t size, Memory::Region::Access access = Memory::Region::Access::Read | Memory::Region::Access::Write, StringView name = "KBuffer") { return KBuffer(KBufferImpl::copy(data, size, access, name)); } @@ -141,7 +141,7 @@ public: [[nodiscard]] const KBufferImpl& impl() const { return *m_impl; } [[nodiscard]] RefPtr take_impl() { return move(m_impl); } - KBuffer(const ByteBuffer& buffer, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer") + KBuffer(const ByteBuffer& buffer, Memory::Region::Access access = Memory::Region::Access::Read | Memory::Region::Access::Write, StringView name = "KBuffer") : m_impl(KBufferImpl::copy(buffer.data(), buffer.size(), access, name)) { } diff --git a/Kernel/KBufferBuilder.cpp b/Kernel/KBufferBuilder.cpp index 2c514b01fe6..d8982dda964 100644 --- a/Kernel/KBufferBuilder.cpp +++ b/Kernel/KBufferBuilder.cpp @@ -20,7 +20,7 @@ inline bool KBufferBuilder::check_expand(size_t size) size_t new_buffer_size = m_size + size; if (Checked::addition_would_overflow(new_buffer_size, 1 * MiB)) return false; - new_buffer_size = page_round_up(new_buffer_size + 1 * MiB); + new_buffer_size = Memory::page_round_up(new_buffer_size + 1 * MiB); return m_buffer->expand(new_buffer_size); } @@ -41,7 +41,7 @@ OwnPtr KBufferBuilder::build() } KBufferBuilder::KBufferBuilder() - : m_buffer(KBufferImpl::try_create_with_size(4 * MiB, Region::Access::Read | Region::Access::Write)) + : m_buffer(KBufferImpl::try_create_with_size(4 * MiB, Memory::Region::Access::Read | Memory::Region::Access::Write)) { } diff --git a/Kernel/Memory/AnonymousVMObject.cpp b/Kernel/Memory/AnonymousVMObject.cpp index 7c34d57c310..d576be58e36 100644 --- a/Kernel/Memory/AnonymousVMObject.cpp +++ b/Kernel/Memory/AnonymousVMObject.cpp @@ -11,7 +11,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { RefPtr AnonymousVMObject::try_clone() { diff --git a/Kernel/Memory/AnonymousVMObject.h b/Kernel/Memory/AnonymousVMObject.h index a0b4082c7ef..358dc3a49c3 100644 --- a/Kernel/Memory/AnonymousVMObject.h +++ b/Kernel/Memory/AnonymousVMObject.h @@ -12,7 +12,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class AnonymousVMObject final : public VMObject { public: diff --git a/Kernel/Memory/InodeVMObject.cpp b/Kernel/Memory/InodeVMObject.cpp index 44392cf616e..4f6deefb83f 100644 --- a/Kernel/Memory/InodeVMObject.cpp +++ b/Kernel/Memory/InodeVMObject.cpp @@ -7,7 +7,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { InodeVMObject::InodeVMObject(Inode& inode, size_t size) : VMObject(size) diff --git a/Kernel/Memory/InodeVMObject.h b/Kernel/Memory/InodeVMObject.h index f2f72ce5779..d8c46b7a2a0 100644 --- a/Kernel/Memory/InodeVMObject.h +++ b/Kernel/Memory/InodeVMObject.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class InodeVMObject : public VMObject { public: diff --git a/Kernel/Memory/MappedROM.h b/Kernel/Memory/MappedROM.h index 9f377df1b61..791cf3d43da 100644 --- a/Kernel/Memory/MappedROM.h +++ b/Kernel/Memory/MappedROM.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class MappedROM { public: diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 08fde5429bf..58fc808b7db 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -40,7 +40,7 @@ extern size_t multiboot_copy_boot_modules_count; // Treat the super pages as logically separate from .bss __attribute__((section(".super_pages"))) static u8 super_pages[1 * MiB]; -namespace Kernel { +namespace Kernel::Memory { // NOTE: We can NOT use AK::Singleton for this class, because // MemoryManager::initialize is called *before* global constructors are @@ -49,7 +49,7 @@ namespace Kernel { static MemoryManager* s_the; RecursiveSpinLock s_mm_lock; -MemoryManager& MM +MemoryManager& MemoryManager::the() { return *s_the; } diff --git a/Kernel/Memory/MemoryManager.h b/Kernel/Memory/MemoryManager.h index 1067e6e2d16..1ac00f58120 100644 --- a/Kernel/Memory/MemoryManager.h +++ b/Kernel/Memory/MemoryManager.h @@ -21,7 +21,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { constexpr bool page_round_up_would_wrap(FlatPtr x) { @@ -88,7 +88,7 @@ struct PhysicalMemoryRange { PhysicalSize length {}; }; -#define MM Kernel::MemoryManager::the() +#define MM Kernel::Memory::MemoryManager::the() struct MemoryManagerData { static ProcessorSpecificDataID processor_specific_data_id() { return ProcessorSpecificDataID::MemoryManager; } diff --git a/Kernel/Memory/PageDirectory.cpp b/Kernel/Memory/PageDirectory.cpp index 3b5fb07f08e..cf317ac5e05 100644 --- a/Kernel/Memory/PageDirectory.cpp +++ b/Kernel/Memory/PageDirectory.cpp @@ -15,7 +15,7 @@ extern u8 end_of_kernel_image[]; -namespace Kernel { +namespace Kernel::Memory { static AK::Singleton> s_cr3_map; diff --git a/Kernel/Memory/PageDirectory.h b/Kernel/Memory/PageDirectory.h index 2caabdc79e9..69636810461 100644 --- a/Kernel/Memory/PageDirectory.h +++ b/Kernel/Memory/PageDirectory.h @@ -13,7 +13,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class PageDirectory : public RefCounted { friend class MemoryManager; diff --git a/Kernel/Memory/PhysicalPage.cpp b/Kernel/Memory/PhysicalPage.cpp index fda876dc0da..b4890b5c4a3 100644 --- a/Kernel/Memory/PhysicalPage.cpp +++ b/Kernel/Memory/PhysicalPage.cpp @@ -8,7 +8,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { NonnullRefPtr PhysicalPage::create(PhysicalAddress paddr, MayReturnToFreeList may_return_to_freelist) { diff --git a/Kernel/Memory/PhysicalPage.h b/Kernel/Memory/PhysicalPage.h index ab22be35341..fe898c04a82 100644 --- a/Kernel/Memory/PhysicalPage.h +++ b/Kernel/Memory/PhysicalPage.h @@ -9,7 +9,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { enum class MayReturnToFreeList : bool { No, diff --git a/Kernel/Memory/PhysicalRegion.cpp b/Kernel/Memory/PhysicalRegion.cpp index f778fdfa392..134e908d20d 100644 --- a/Kernel/Memory/PhysicalRegion.cpp +++ b/Kernel/Memory/PhysicalRegion.cpp @@ -12,7 +12,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { static constexpr u32 next_power_of_two(u32 value) { diff --git a/Kernel/Memory/PhysicalRegion.h b/Kernel/Memory/PhysicalRegion.h index ba7b4957b9d..ec20e0029ce 100644 --- a/Kernel/Memory/PhysicalRegion.h +++ b/Kernel/Memory/PhysicalRegion.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class PhysicalRegion { AK_MAKE_ETERNAL; diff --git a/Kernel/Memory/PhysicalZone.cpp b/Kernel/Memory/PhysicalZone.cpp index 71cb9624ed9..f533a20d171 100644 --- a/Kernel/Memory/PhysicalZone.cpp +++ b/Kernel/Memory/PhysicalZone.cpp @@ -9,7 +9,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { PhysicalPageEntry& PhysicalZone::get_freelist_entry(ChunkIndex index) const { diff --git a/Kernel/Memory/PhysicalZone.h b/Kernel/Memory/PhysicalZone.h index bd3bba924e4..c5512f8f24e 100644 --- a/Kernel/Memory/PhysicalZone.h +++ b/Kernel/Memory/PhysicalZone.h @@ -9,7 +9,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { // A PhysicalZone is an allocator that manages a sub-area of a PhysicalRegion. // Its total size is always a power of two. diff --git a/Kernel/Memory/PrivateInodeVMObject.cpp b/Kernel/Memory/PrivateInodeVMObject.cpp index 143b351c000..6c3b3e8258f 100644 --- a/Kernel/Memory/PrivateInodeVMObject.cpp +++ b/Kernel/Memory/PrivateInodeVMObject.cpp @@ -7,7 +7,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { RefPtr PrivateInodeVMObject::try_create_with_inode(Inode& inode) { diff --git a/Kernel/Memory/PrivateInodeVMObject.h b/Kernel/Memory/PrivateInodeVMObject.h index 5e8c8f1372d..4d8438ac920 100644 --- a/Kernel/Memory/PrivateInodeVMObject.h +++ b/Kernel/Memory/PrivateInodeVMObject.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class PrivateInodeVMObject final : public InodeVMObject { AK_MAKE_NONMOVABLE(PrivateInodeVMObject); diff --git a/Kernel/Memory/Range.cpp b/Kernel/Memory/Range.cpp index 4b8ad0912d8..ad5ebdc9eaf 100644 --- a/Kernel/Memory/Range.cpp +++ b/Kernel/Memory/Range.cpp @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { Vector Range::carve(const Range& taken) const { diff --git a/Kernel/Memory/Range.h b/Kernel/Memory/Range.h index c2305acedcf..41b206af12b 100644 --- a/Kernel/Memory/Range.h +++ b/Kernel/Memory/Range.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class Range { friend class RangeAllocator; @@ -61,8 +61,8 @@ private: } template<> -struct AK::Formatter : Formatter { - void format(FormatBuilder& builder, Kernel::Range value) +struct AK::Formatter : Formatter { + void format(FormatBuilder& builder, Kernel::Memory::Range value) { return Formatter::format(builder, "{} - {} (size {:p})", value.base().as_ptr(), value.base().offset(value.size() - 1).as_ptr(), value.size()); } diff --git a/Kernel/Memory/RangeAllocator.cpp b/Kernel/Memory/RangeAllocator.cpp index 2014c22e348..5f931222b00 100644 --- a/Kernel/Memory/RangeAllocator.cpp +++ b/Kernel/Memory/RangeAllocator.cpp @@ -10,7 +10,7 @@ #define VM_GUARD_PAGES -namespace Kernel { +namespace Kernel::Memory { RangeAllocator::RangeAllocator() : m_total_range({}, 0) diff --git a/Kernel/Memory/RangeAllocator.h b/Kernel/Memory/RangeAllocator.h index c299e08ef36..cc6bcf36bbd 100644 --- a/Kernel/Memory/RangeAllocator.h +++ b/Kernel/Memory/RangeAllocator.h @@ -11,7 +11,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class RangeAllocator { public: @@ -42,7 +42,7 @@ private: namespace AK { template<> -struct Traits : public GenericTraits { +struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } }; } diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp index 0c63bea8d02..f080d5b30e6 100644 --- a/Kernel/Memory/Region.cpp +++ b/Kernel/Memory/Region.cpp @@ -17,7 +17,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { Region::Region(Range const& range, NonnullRefPtr vmobject, size_t offset_in_vmobject, OwnPtr name, Region::Access access, Cacheable cacheable, bool shared) : m_range(range) diff --git a/Kernel/Memory/Region.h b/Kernel/Memory/Region.h index 38cecb474c8..f4d1c7b3004 100644 --- a/Kernel/Memory/Region.h +++ b/Kernel/Memory/Region.h @@ -18,7 +18,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { enum class ShouldFlushTLB { No, diff --git a/Kernel/Memory/RingBuffer.cpp b/Kernel/Memory/RingBuffer.cpp index 9c62a53a9d5..4f7ea2dddc7 100644 --- a/Kernel/Memory/RingBuffer.cpp +++ b/Kernel/Memory/RingBuffer.cpp @@ -8,7 +8,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { RingBuffer::RingBuffer(String region_name, size_t capacity) : m_region(MM.allocate_contiguous_kernel_region(page_round_up(capacity), move(region_name), Region::Access::Read | Region::Access::Write)) diff --git a/Kernel/Memory/RingBuffer.h b/Kernel/Memory/RingBuffer.h index 8a748e4b653..58e4208a380 100644 --- a/Kernel/Memory/RingBuffer.h +++ b/Kernel/Memory/RingBuffer.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class RingBuffer { public: @@ -30,7 +30,7 @@ public: size_t bytes_till_end() const { return (m_capacity_in_bytes - ((m_start_of_used + m_num_used_bytes) % m_capacity_in_bytes)) % m_capacity_in_bytes; }; private: - OwnPtr m_region; + OwnPtr m_region; SpinLock m_lock; size_t m_start_of_used {}; size_t m_num_used_bytes {}; diff --git a/Kernel/Memory/ScatterGatherList.cpp b/Kernel/Memory/ScatterGatherList.cpp index c3b65f31dff..31514176078 100644 --- a/Kernel/Memory/ScatterGatherList.cpp +++ b/Kernel/Memory/ScatterGatherList.cpp @@ -6,7 +6,7 @@ #include -namespace Kernel { +namespace Kernel::Memory { RefPtr ScatterGatherList::try_create(AsyncBlockDeviceRequest& request, Span> allocated_pages, size_t device_block_size) { diff --git a/Kernel/Memory/ScatterGatherList.h b/Kernel/Memory/ScatterGatherList.h index a94ce00b721..f90876957a4 100644 --- a/Kernel/Memory/ScatterGatherList.h +++ b/Kernel/Memory/ScatterGatherList.h @@ -12,7 +12,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { // A Scatter-Gather List type that owns its buffers diff --git a/Kernel/Memory/SharedInodeVMObject.cpp b/Kernel/Memory/SharedInodeVMObject.cpp index 1c8c7b2ae3d..dd78f802080 100644 --- a/Kernel/Memory/SharedInodeVMObject.cpp +++ b/Kernel/Memory/SharedInodeVMObject.cpp @@ -7,7 +7,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { RefPtr SharedInodeVMObject::try_create_with_inode(Inode& inode) { diff --git a/Kernel/Memory/SharedInodeVMObject.h b/Kernel/Memory/SharedInodeVMObject.h index 05fb8968ebd..047d335074c 100644 --- a/Kernel/Memory/SharedInodeVMObject.h +++ b/Kernel/Memory/SharedInodeVMObject.h @@ -10,7 +10,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class SharedInodeVMObject final : public InodeVMObject { AK_MAKE_NONMOVABLE(SharedInodeVMObject); diff --git a/Kernel/Memory/Space.cpp b/Kernel/Memory/Space.cpp index 63fcf1814fc..dfb6a56a2aa 100644 --- a/Kernel/Memory/Space.cpp +++ b/Kernel/Memory/Space.cpp @@ -13,7 +13,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { OwnPtr Space::try_create(Process& process, Space const* parent) { diff --git a/Kernel/Memory/Space.h b/Kernel/Memory/Space.h index cdd8d51a015..5cfb7e55300 100644 --- a/Kernel/Memory/Space.h +++ b/Kernel/Memory/Space.h @@ -14,7 +14,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class Space { public: diff --git a/Kernel/Memory/TypedMapping.h b/Kernel/Memory/TypedMapping.h index ebc9c337701..22ac69992b0 100644 --- a/Kernel/Memory/TypedMapping.h +++ b/Kernel/Memory/TypedMapping.h @@ -9,7 +9,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { template struct TypedMapping { diff --git a/Kernel/Memory/VMObject.cpp b/Kernel/Memory/VMObject.cpp index b5e0459d48d..0ca76d0e317 100644 --- a/Kernel/Memory/VMObject.cpp +++ b/Kernel/Memory/VMObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,7 +7,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { VMObject::VMObject(VMObject const& other) : m_physical_pages(other.m_physical_pages) diff --git a/Kernel/Memory/VMObject.h b/Kernel/Memory/VMObject.h index 0184533325f..7cdd29cb2b3 100644 --- a/Kernel/Memory/VMObject.h +++ b/Kernel/Memory/VMObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,7 +17,7 @@ #include #include -namespace Kernel { +namespace Kernel::Memory { class VMObjectDeletedHandler { public: diff --git a/Kernel/Net/E1000ENetworkAdapter.cpp b/Kernel/Net/E1000ENetworkAdapter.cpp index 385ff6cffc3..54d1593a476 100644 --- a/Kernel/Net/E1000ENetworkAdapter.cpp +++ b/Kernel/Net/E1000ENetworkAdapter.cpp @@ -204,7 +204,7 @@ UNMAP_AFTER_INIT bool E1000ENetworkAdapter::initialize() enable_bus_mastering(pci_address()); size_t mmio_base_size = PCI::get_BAR_space_size(pci_address(), 0); - m_mmio_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR0(pci_address()))), page_round_up(mmio_base_size), "E1000e MMIO", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); + m_mmio_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR0(pci_address()))), Memory::page_round_up(mmio_base_size), "E1000e MMIO", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::No); if (!m_mmio_region) return false; m_mmio_base = m_mmio_region->vaddr(); diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index 568715ecce3..f3389aba4b6 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -195,7 +195,7 @@ UNMAP_AFTER_INIT bool E1000NetworkAdapter::initialize() m_io_base = IOAddress(PCI::get_BAR1(pci_address()) & ~1); size_t mmio_base_size = PCI::get_BAR_space_size(pci_address(), 0); - m_mmio_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR0(pci_address()))), page_round_up(mmio_base_size), "E1000 MMIO", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); + m_mmio_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR0(pci_address()))), Memory::page_round_up(mmio_base_size), "E1000 MMIO", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::No); if (!m_mmio_region) return false; m_mmio_base = m_mmio_region->vaddr(); @@ -221,8 +221,8 @@ UNMAP_AFTER_INIT bool E1000NetworkAdapter::initialize() UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address, u8 irq) : PCI::Device(address, irq) - , m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX Descriptors", Region::Access::Read | Region::Access::Write)) - , m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX Descriptors", Region::Access::Read | Region::Access::Write)) + , m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX Descriptors", Memory::Region::Access::Read | Memory::Region::Access::Write)) + , m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX Descriptors", Memory::Region::Access::Read | Memory::Region::Access::Write)) { set_interface_name(pci_address()); } @@ -320,7 +320,7 @@ UNMAP_AFTER_INIT void E1000NetworkAdapter::initialize_rx_descriptors() constexpr auto rx_buffer_size = 8192; constexpr auto rx_buffer_page_count = rx_buffer_size / PAGE_SIZE; - m_rx_buffer_region = MM.allocate_contiguous_kernel_region(rx_buffer_size * number_of_rx_descriptors, "E1000 RX buffers", Region::Access::Read | Region::Access::Write); + m_rx_buffer_region = MM.allocate_contiguous_kernel_region(rx_buffer_size * number_of_rx_descriptors, "E1000 RX buffers", Memory::Region::Access::Read | Memory::Region::Access::Write); for (size_t i = 0; i < number_of_rx_descriptors; ++i) { auto& descriptor = rx_descriptors[i]; m_rx_buffers[i] = m_rx_buffer_region->vaddr().as_ptr() + rx_buffer_size * i; @@ -343,7 +343,7 @@ UNMAP_AFTER_INIT void E1000NetworkAdapter::initialize_tx_descriptors() constexpr auto tx_buffer_size = 8192; constexpr auto tx_buffer_page_count = tx_buffer_size / PAGE_SIZE; - m_tx_buffer_region = MM.allocate_contiguous_kernel_region(tx_buffer_size * number_of_tx_descriptors, "E1000 TX buffers", Region::Access::Read | Region::Access::Write); + m_tx_buffer_region = MM.allocate_contiguous_kernel_region(tx_buffer_size * number_of_tx_descriptors, "E1000 TX buffers", Memory::Region::Access::Read | Memory::Region::Access::Write); for (size_t i = 0; i < number_of_tx_descriptors; ++i) { auto& descriptor = tx_descriptors[i]; diff --git a/Kernel/Net/E1000NetworkAdapter.h b/Kernel/Net/E1000NetworkAdapter.h index 2475d4d1446..dad0f45ebfa 100644 --- a/Kernel/Net/E1000NetworkAdapter.h +++ b/Kernel/Net/E1000NetworkAdapter.h @@ -83,13 +83,13 @@ protected: IOAddress m_io_base; VirtualAddress m_mmio_base; - OwnPtr m_rx_descriptors_region; - OwnPtr m_tx_descriptors_region; - OwnPtr m_rx_buffer_region; - OwnPtr m_tx_buffer_region; + OwnPtr m_rx_descriptors_region; + OwnPtr m_tx_descriptors_region; + OwnPtr m_rx_buffer_region; + OwnPtr m_tx_buffer_region; Array m_rx_buffers; Array m_tx_buffers; - OwnPtr m_mmio_region; + OwnPtr m_mmio_region; u8 m_interrupt_line { 0 }; bool m_has_eeprom { false }; bool m_use_mmio { false }; diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index 194a471c499..8ad76a234a8 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -112,7 +112,7 @@ RefPtr NetworkAdapter::acquire_packet_buffer(size_t size) { InterruptDisabler disabler; if (m_unused_packets.is_empty()) { - auto buffer = KBuffer::try_create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow); + auto buffer = KBuffer::try_create_with_size(size, Memory::Region::Access::Read | Memory::Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow); if (!buffer) return {}; auto packet = adopt_ref_if_nonnull(new (nothrow) PacketWithTimestamp { buffer.release_nonnull(), kgettimeofday() }); @@ -129,7 +129,7 @@ RefPtr NetworkAdapter::acquire_packet_buffer(size_t size) return packet; } - auto buffer = KBuffer::try_create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow); + auto buffer = KBuffer::try_create_with_size(size, Memory::Region::Access::Read | Memory::Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow); if (!buffer) return {}; packet = adopt_ref_if_nonnull(new (nothrow) PacketWithTimestamp { buffer.release_nonnull(), kgettimeofday() }); diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 04b3d4d71ec..143763c3d97 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -87,7 +87,7 @@ void NetworkTask_main(void*) }; size_t buffer_size = 64 * KiB; - auto buffer_region = MM.allocate_kernel_region(buffer_size, "Kernel Packet Buffer", Region::Access::Read | Region::Access::Write); + auto buffer_region = MM.allocate_kernel_region(buffer_size, "Kernel Packet Buffer", Memory::Region::Access::Read | Memory::Region::Access::Write); auto buffer = (u8*)buffer_region->vaddr().get(); Time packet_timestamp; diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp index be85fdf511a..6778bf3b244 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.cpp +++ b/Kernel/Net/RTL8139NetworkAdapter.cpp @@ -124,8 +124,8 @@ UNMAP_AFTER_INIT RefPtr RTL8139NetworkAdapter::try_to_ini UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq) : PCI::Device(address, irq) , m_io_base(PCI::get_BAR0(pci_address()) & ~1) - , m_rx_buffer(MM.allocate_contiguous_kernel_region(page_round_up(RX_BUFFER_SIZE + PACKET_SIZE_MAX), "RTL8139 RX", Region::Access::Read | Region::Access::Write)) - , m_packet_buffer(MM.allocate_contiguous_kernel_region(page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Region::Access::Read | Region::Access::Write)) + , m_rx_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(RX_BUFFER_SIZE + PACKET_SIZE_MAX), "RTL8139 RX", Memory::Region::Access::Read | Memory::Region::Access::Write)) + , m_packet_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Memory::Region::Access::Read | Memory::Region::Access::Write)) { m_tx_buffers.ensure_capacity(RTL8139_TX_BUFFER_COUNT); set_interface_name(address); @@ -144,7 +144,7 @@ UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address addre dbgln("RTL8139: RX buffer: {}", m_rx_buffer->physical_page(0)->paddr()); for (int i = 0; i < RTL8139_TX_BUFFER_COUNT; i++) { - m_tx_buffers.append(MM.allocate_contiguous_kernel_region(page_round_up(TX_BUFFER_SIZE), "RTL8139 TX", Region::Access::Write | Region::Access::Read)); + m_tx_buffers.append(MM.allocate_contiguous_kernel_region(Memory::page_round_up(TX_BUFFER_SIZE), "RTL8139 TX", Memory::Region::Access::Write | Memory::Region::Access::Read)); dbgln("RTL8139: TX buffer {}: {}", i, m_tx_buffers[i]->physical_page(0)->paddr()); } diff --git a/Kernel/Net/RTL8139NetworkAdapter.h b/Kernel/Net/RTL8139NetworkAdapter.h index d42e6a505ed..988402af842 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.h +++ b/Kernel/Net/RTL8139NetworkAdapter.h @@ -50,11 +50,11 @@ private: IOAddress m_io_base; u8 m_interrupt_line { 0 }; - OwnPtr m_rx_buffer; + OwnPtr m_rx_buffer; u16 m_rx_buffer_offset { 0 }; - Vector> m_tx_buffers; + Vector> m_tx_buffers; u8 m_tx_next_buffer { 0 }; - OwnPtr m_packet_buffer; + OwnPtr m_packet_buffer; bool m_link_up { false }; EntropySource m_entropy_source; }; diff --git a/Kernel/Net/RTL8168NetworkAdapter.cpp b/Kernel/Net/RTL8168NetworkAdapter.cpp index 6563e6555f5..6020999205d 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.cpp +++ b/Kernel/Net/RTL8168NetworkAdapter.cpp @@ -194,8 +194,8 @@ UNMAP_AFTER_INIT RefPtr RTL8168NetworkAdapter::try_to_ini UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq) : PCI::Device(address, irq) , m_io_base(PCI::get_BAR0(pci_address()) & ~1) - , m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(page_round_up(sizeof(TXDescriptor) * (number_of_rx_descriptors + 1)), "RTL8168 RX", Region::Access::Read | Region::Access::Write)) - , m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(page_round_up(sizeof(RXDescriptor) * (number_of_tx_descriptors + 1)), "RTL8168 TX", Region::Access::Read | Region::Access::Write)) + , m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(TXDescriptor) * (number_of_rx_descriptors + 1)), "RTL8168 RX", Memory::Region::Access::Read | Memory::Region::Access::Write)) + , m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(RXDescriptor) * (number_of_tx_descriptors + 1)), "RTL8168 TX", Memory::Region::Access::Read | Memory::Region::Access::Write)) { set_interface_name(address); @@ -1042,7 +1042,7 @@ UNMAP_AFTER_INIT void RTL8168NetworkAdapter::initialize_rx_descriptors() auto* rx_descriptors = (RXDescriptor*)m_rx_descriptors_region->vaddr().as_ptr(); for (size_t i = 0; i < number_of_rx_descriptors; ++i) { auto& descriptor = rx_descriptors[i]; - auto region = MM.allocate_contiguous_kernel_region(page_round_up(RX_BUFFER_SIZE), "RTL8168 RX buffer", Region::Access::Read | Region::Access::Write); + auto region = MM.allocate_contiguous_kernel_region(Memory::page_round_up(RX_BUFFER_SIZE), "RTL8168 RX buffer", Memory::Region::Access::Read | Memory::Region::Access::Write); VERIFY(region); memset(region->vaddr().as_ptr(), 0, region->size()); // MM already zeros out newly allocated pages, but we do it again in case that ever changes m_rx_buffers_regions.append(region.release_nonnull()); @@ -1061,7 +1061,7 @@ UNMAP_AFTER_INIT void RTL8168NetworkAdapter::initialize_tx_descriptors() auto* tx_descriptors = (TXDescriptor*)m_tx_descriptors_region->vaddr().as_ptr(); for (size_t i = 0; i < number_of_tx_descriptors; ++i) { auto& descriptor = tx_descriptors[i]; - auto region = MM.allocate_contiguous_kernel_region(page_round_up(TX_BUFFER_SIZE), "RTL8168 TX buffer", Region::Access::Read | Region::Access::Write); + auto region = MM.allocate_contiguous_kernel_region(Memory::page_round_up(TX_BUFFER_SIZE), "RTL8168 TX buffer", Memory::Region::Access::Read | Memory::Region::Access::Write); VERIFY(region); memset(region->vaddr().as_ptr(), 0, region->size()); // MM already zeros out newly allocated pages, but we do it again in case that ever changes m_tx_buffers_regions.append(region.release_nonnull()); diff --git a/Kernel/Net/RTL8168NetworkAdapter.h b/Kernel/Net/RTL8168NetworkAdapter.h index ae71976fc99..cc4d8497dd7 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.h +++ b/Kernel/Net/RTL8168NetworkAdapter.h @@ -197,11 +197,11 @@ private: bool m_version_uncertain { true }; IOAddress m_io_base; u32 m_ocp_base_address { 0 }; - OwnPtr m_rx_descriptors_region; - NonnullOwnPtrVector m_rx_buffers_regions; + OwnPtr m_rx_descriptors_region; + NonnullOwnPtrVector m_rx_buffers_regions; u16 m_rx_free_index { 0 }; - OwnPtr m_tx_descriptors_region; - NonnullOwnPtrVector m_tx_buffers_regions; + OwnPtr m_tx_descriptors_region; + NonnullOwnPtrVector m_tx_buffers_regions; u16 m_tx_free_index { 0 }; bool m_link_up { false }; EntropySource m_entropy_source; diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 0e329212e7b..da5a95be923 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -253,7 +253,7 @@ bool PerformanceEventBuffer::to_json(KBufferBuilder& builder) const OwnPtr PerformanceEventBuffer::try_create_with_size(size_t buffer_size) { - auto buffer = KBuffer::try_create_with_size(buffer_size, Region::Access::Read | Region::Access::Write, "Performance events", AllocationStrategy::AllocateNow); + auto buffer = KBuffer::try_create_with_size(buffer_size, Memory::Region::Access::Read | Memory::Region::Access::Write, "Performance events", AllocationStrategy::AllocateNow); if (!buffer) return {}; return adopt_own_if_nonnull(new (nothrow) PerformanceEventBuffer(buffer.release_nonnull())); diff --git a/Kernel/PerformanceManager.h b/Kernel/PerformanceManager.h index caa7940c0ef..dda2dbf75cd 100644 --- a/Kernel/PerformanceManager.h +++ b/Kernel/PerformanceManager.h @@ -67,14 +67,14 @@ public: } } - inline static void add_mmap_perf_event(Process& current_process, Region const& region) + inline static void add_mmap_perf_event(Process& current_process, Memory::Region const& region) { if (auto* event_buffer = current_process.current_perf_events_buffer()) { [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MMAP, region.vaddr().get(), region.size(), region.name()); } } - inline static void add_unmap_perf_event(Process& current_process, Range const& region) + inline static void add_unmap_perf_event(Process& current_process, Memory::Range const& region) { if (auto* event_buffer = current_process.current_perf_events_buffer()) { [[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MUNMAP, region.base().get(), region.size(), nullptr); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index e0a4f799a65..f2ebe0ac4af 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -48,7 +48,7 @@ READONLY_AFTER_INIT Process::List* g_processes; READONLY_AFTER_INIT String* g_hostname; READONLY_AFTER_INIT Mutex* g_hostname_lock; READONLY_AFTER_INIT HashMap>* g_modules; -READONLY_AFTER_INIT Region* g_signal_trampoline_region; +READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region; ProcessID Process::allocate_pid() { @@ -267,7 +267,7 @@ Process::Process(const String& name, uid_t uid, gid_t gid, ProcessID ppid, bool KResult Process::attach_resources(RefPtr& first_thread, Process* fork_parent) { - m_space = Space::try_create(*this, fork_parent ? &fork_parent->space() : nullptr); + m_space = Memory::Space::try_create(*this, fork_parent ? &fork_parent->space() : nullptr); if (!m_space) return ENOMEM; @@ -361,7 +361,7 @@ extern "C" char const asm_signal_trampoline_end[]; void create_signal_trampoline() { // NOTE: We leak this region. - g_signal_trampoline_region = MM.allocate_kernel_region(PAGE_SIZE, "Signal trampolines", Region::Access::Read | Region::Access::Write).leak_ptr(); + g_signal_trampoline_region = MM.allocate_kernel_region(PAGE_SIZE, "Signal trampolines", Memory::Region::Access::Read | Memory::Region::Access::Write).leak_ptr(); g_signal_trampoline_region->set_syscall_region(true); size_t trampoline_size = asm_signal_trampoline_end - asm_signal_trampoline; diff --git a/Kernel/Process.h b/Kernel/Process.h index b252fa702b6..eef1c5c765e 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -515,8 +515,8 @@ public: PerformanceEventBuffer* perf_events() { return m_perf_event_buffer; } - Space& space() { return *m_space; } - const Space& space() const { return *m_space; } + Memory::Space& space() { return *m_space; } + Memory::Space const& space() const { return *m_space; } VirtualAddress signal_trampoline() const { return m_signal_trampoline; } @@ -582,7 +582,7 @@ private: String m_name; - OwnPtr m_space; + OwnPtr m_space; RefPtr m_pg; @@ -741,7 +741,7 @@ private: RefPtr m_tty; - WeakPtr m_master_tls_region; + WeakPtr m_master_tls_region; size_t m_master_tls_size { 0 }; size_t m_master_tls_alignment { 0 }; diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp index 046dd88032b..9685cfd33a7 100644 --- a/Kernel/ProcessSpecificExposed.cpp +++ b/Kernel/ProcessSpecificExposed.cpp @@ -37,7 +37,7 @@ private: bool show_kernel_addresses = Process::current()->is_superuser(); bool kernel_address_added = false; for (auto address : Processor::capture_stack_trace(*m_associated_thread, 1024)) { - if (!show_kernel_addresses && !is_user_address(VirtualAddress { address })) { + if (!show_kernel_addresses && !Memory::is_user_address(VirtualAddress { address })) { if (kernel_address_added) continue; address = 0xdeadc0de; @@ -456,7 +456,7 @@ private: region_object.add("syscall", region->is_syscall_region()); region_object.add("purgeable", region->vmobject().is_anonymous()); if (region->vmobject().is_anonymous()) { - region_object.add("volatile", static_cast(region->vmobject()).is_volatile()); + region_object.add("volatile", static_cast(region->vmobject()).is_volatile()); } region_object.add("cacheable", region->is_cacheable()); region_object.add("address", region->vaddr().get()); diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index f84415d26dd..1c833fbc359 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -272,8 +272,8 @@ bool Scheduler::yield() bool Scheduler::context_switch(Thread* thread) { - if (s_mm_lock.own_lock()) { - PANIC("In context switch while holding s_mm_lock"); + if (Memory::s_mm_lock.own_lock()) { + PANIC("In context switch while holding Memory::s_mm_lock"); } thread->did_schedule(); diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index c4460918d37..838dd01465b 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -15,7 +15,7 @@ String copy_string_from_user(const char* user_str, size_t user_str_size) { - bool is_user = Kernel::is_user_range(VirtualAddress(user_str), user_str_size); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(user_str), user_str_size); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -44,7 +44,7 @@ String copy_string_from_user(Userspace user_str, size_t user_str_si Kernel::KResultOr> try_copy_kstring_from_user(const char* user_str, size_t user_str_size) { - bool is_user = Kernel::is_user_range(VirtualAddress(user_str), user_str_size); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(user_str), user_str_size); if (!is_user) return EFAULT; Kernel::SmapDisabler disabler; @@ -106,7 +106,7 @@ Optional user_atomic_fetch_add_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -117,7 +117,7 @@ Optional user_atomic_exchange_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -128,7 +128,7 @@ Optional user_atomic_load_relaxed(volatile u32* var) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -139,7 +139,7 @@ bool user_atomic_store_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return false; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return false; Kernel::SmapDisabler disabler; @@ -150,8 +150,8 @@ Optional user_atomic_compare_exchange_relaxed(volatile u32* var, u32& expe { if (FlatPtr(var) & 3) return {}; // not aligned! - VERIFY(!Kernel::is_user_range(VirtualAddress(&expected), sizeof(expected))); - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + VERIFY(!Kernel::Memory::is_user_range(VirtualAddress(&expected), sizeof(expected))); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -162,7 +162,7 @@ Optional user_atomic_fetch_and_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -173,7 +173,7 @@ Optional user_atomic_fetch_and_not_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -184,7 +184,7 @@ Optional user_atomic_fetch_or_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -195,7 +195,7 @@ Optional user_atomic_fetch_xor_relaxed(volatile u32* var, u32 val) { if (FlatPtr(var) & 3) return {}; // not aligned! - bool is_user = Kernel::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(FlatPtr(var)), sizeof(*var)); if (!is_user) return {}; Kernel::SmapDisabler disabler; @@ -206,10 +206,10 @@ extern "C" { bool copy_to_user(void* dest_ptr, const void* src_ptr, size_t n) { - bool is_user = Kernel::is_user_range(VirtualAddress(dest_ptr), n); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(dest_ptr), n); if (!is_user) return false; - VERIFY(!Kernel::is_user_range(VirtualAddress(src_ptr), n)); + VERIFY(!Kernel::Memory::is_user_range(VirtualAddress(src_ptr), n)); Kernel::SmapDisabler disabler; void* fault_at; if (!Kernel::safe_memcpy(dest_ptr, src_ptr, n, fault_at)) { @@ -222,10 +222,10 @@ bool copy_to_user(void* dest_ptr, const void* src_ptr, size_t n) bool copy_from_user(void* dest_ptr, const void* src_ptr, size_t n) { - bool is_user = Kernel::is_user_range(VirtualAddress(src_ptr), n); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(src_ptr), n); if (!is_user) return false; - VERIFY(!Kernel::is_user_range(VirtualAddress(dest_ptr), n)); + VERIFY(!Kernel::Memory::is_user_range(VirtualAddress(dest_ptr), n)); Kernel::SmapDisabler disabler; void* fault_at; if (!Kernel::safe_memcpy(dest_ptr, src_ptr, n, fault_at)) { @@ -243,7 +243,7 @@ const void* memmem(const void* haystack, size_t haystack_length, const void* nee [[nodiscard]] bool memset_user(void* dest_ptr, int c, size_t n) { - bool is_user = Kernel::is_user_range(VirtualAddress(dest_ptr), n); + bool is_user = Kernel::Memory::is_user_range(VirtualAddress(dest_ptr), n); if (!is_user) return false; Kernel::SmapDisabler disabler; diff --git a/Kernel/Storage/AHCIController.cpp b/Kernel/Storage/AHCIController.cpp index f71172592da..038f178f600 100644 --- a/Kernel/Storage/AHCIController.cpp +++ b/Kernel/Storage/AHCIController.cpp @@ -124,9 +124,9 @@ AHCI::HBADefinedCapabilities AHCIController::capabilities() const }; } -NonnullOwnPtr AHCIController::default_hba_region() const +NonnullOwnPtr AHCIController::default_hba_region() const { - auto region = MM.allocate_kernel_region(PhysicalAddress(PCI::get_BAR5(pci_address())).page_base(), page_round_up(sizeof(AHCI::HBA)), "AHCI HBA", Region::Access::Read | Region::Access::Write); + auto region = MM.allocate_kernel_region(PhysicalAddress(PCI::get_BAR5(pci_address())).page_base(), Memory::page_round_up(sizeof(AHCI::HBA)), "AHCI HBA", Memory::Region::Access::Read | Memory::Region::Access::Write); return region.release_nonnull(); } diff --git a/Kernel/Storage/AHCIController.h b/Kernel/Storage/AHCIController.h index f873ddd15fc..a51ad85f389 100644 --- a/Kernel/Storage/AHCIController.h +++ b/Kernel/Storage/AHCIController.h @@ -48,10 +48,10 @@ private: RefPtr device_by_port(u32 index) const; volatile AHCI::PortRegisters& port(size_t port_number) const; - UNMAP_AFTER_INIT NonnullOwnPtr default_hba_region() const; + UNMAP_AFTER_INIT NonnullOwnPtr default_hba_region() const; volatile AHCI::HBA& hba() const; - NonnullOwnPtr m_hba_region; + NonnullOwnPtr m_hba_region; AHCI::HBADefinedCapabilities m_capabilities; NonnullRefPtrVector m_handlers; }; diff --git a/Kernel/Storage/AHCIPort.cpp b/Kernel/Storage/AHCIPort.cpp index e0fd9fb542d..dcfb83a52cf 100644 --- a/Kernel/Storage/AHCIPort.cpp +++ b/Kernel/Storage/AHCIPort.cpp @@ -50,7 +50,7 @@ AHCIPort::AHCIPort(const AHCIPortHandler& handler, volatile AHCI::PortRegisters& for (size_t index = 0; index < 1; index++) { m_command_table_pages.append(MM.allocate_supervisor_physical_page().release_nonnull()); } - m_command_list_region = MM.allocate_kernel_region(m_command_list_page->paddr(), PAGE_SIZE, "AHCI Port Command List", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); + m_command_list_region = MM.allocate_kernel_region(m_command_list_page->paddr(), PAGE_SIZE, "AHCI Port Command List", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::No); dbgln_if(AHCI_DEBUG, "AHCI Port {}: Command list region at {}", representative_port_index(), m_command_list_region->vaddr()); } @@ -159,7 +159,7 @@ void AHCIPort::eject() // handshake error bit in PxSERR register if CFL is incorrect. command_list_entries[unused_command_header.value()].attributes = (size_t)FIS::DwordCount::RegisterHostToDevice | AHCI::CommandHeaderAttributes::P | AHCI::CommandHeaderAttributes::C | AHCI::CommandHeaderAttributes::A; - auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); + auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), Memory::page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::No); auto& command_table = *(volatile AHCI::CommandTable*)command_table_region->vaddr().as_ptr(); memset(const_cast(command_table.command_fis), 0, 64); auto& fis = *(volatile FIS::HostToDevice::Register*)command_table.command_fis; @@ -268,7 +268,7 @@ bool AHCIPort::initialize(ScopedSpinLock>& main_lock) size_t physical_sector_size = 512; u64 max_addressable_sector = 0; if (identify_device(main_lock)) { - auto identify_block = map_typed(m_parent_handler->get_identify_metadata_physical_region(m_port_index)); + auto identify_block = Memory::map_typed(m_parent_handler->get_identify_metadata_physical_region(m_port_index)); // Check if word 106 is valid before using it! if ((identify_block->physical_sector_size_to_logical_sector_size >> 14) == 1) { if (identify_block->physical_sector_size_to_logical_sector_size & (1 << 12)) { @@ -422,7 +422,7 @@ void AHCIPort::set_sleep_state() const size_t AHCIPort::calculate_descriptors_count(size_t block_count) const { VERIFY(m_connected_device); - size_t needed_dma_regions_count = page_round_up((block_count * m_connected_device->block_size())) / PAGE_SIZE; + size_t needed_dma_regions_count = Memory::page_round_up((block_count * m_connected_device->block_size())) / PAGE_SIZE; VERIFY(needed_dma_regions_count <= m_dma_buffers.size()); return needed_dma_regions_count; } @@ -432,12 +432,12 @@ Optional AHCIPort::prepare_and_set_scatter_li VERIFY(m_lock.is_locked()); VERIFY(request.block_count() > 0); - NonnullRefPtrVector allocated_dma_regions; + NonnullRefPtrVector allocated_dma_regions; for (size_t index = 0; index < calculate_descriptors_count(request.block_count()); index++) { allocated_dma_regions.append(m_dma_buffers.at(index)); } - m_current_scatter_list = ScatterGatherList::try_create(request, allocated_dma_regions.span(), m_connected_device->block_size()); + m_current_scatter_list = Memory::ScatterGatherList::try_create(request, allocated_dma_regions.span(), m_connected_device->block_size()); if (!m_current_scatter_list) return AsyncDeviceRequest::Failure; if (request.request_type() == AsyncBlockDeviceRequest::Write) { @@ -526,7 +526,7 @@ bool AHCIPort::access_device(AsyncBlockDeviceRequest::RequestType direction, u64 dbgln_if(AHCI_DEBUG, "AHCI Port {}: CLE: ctba={:#08x}, ctbau={:#08x}, prdbc={:#08x}, prdtl={:#04x}, attributes={:#04x}", representative_port_index(), (u32)command_list_entries[unused_command_header.value()].ctba, (u32)command_list_entries[unused_command_header.value()].ctbau, (u32)command_list_entries[unused_command_header.value()].prdbc, (u16)command_list_entries[unused_command_header.value()].prdtl, (u16)command_list_entries[unused_command_header.value()].attributes); - auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); + auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), Memory::page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::No); auto& command_table = *(volatile AHCI::CommandTable*)command_table_region->vaddr().as_ptr(); dbgln_if(AHCI_DEBUG, "AHCI Port {}: Allocated command table at {}", representative_port_index(), command_table_region->vaddr()); @@ -610,7 +610,7 @@ bool AHCIPort::identify_device(ScopedSpinLock>& main_lock) // QEMU doesn't care if we don't set the correct CFL field in this register, real hardware will set an handshake error bit in PxSERR register. command_list_entries[unused_command_header.value()].attributes = (size_t)FIS::DwordCount::RegisterHostToDevice | AHCI::CommandHeaderAttributes::P; - auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Region::Access::Read | Region::Access::Write); + auto command_table_region = MM.allocate_kernel_region(m_command_table_pages[unused_command_header.value()].paddr().page_base(), Memory::page_round_up(sizeof(AHCI::CommandTable)), "AHCI Command Table", Memory::Region::Access::Read | Memory::Region::Access::Write); auto& command_table = *(volatile AHCI::CommandTable*)command_table_region->vaddr().as_ptr(); memset(const_cast(command_table.command_fis), 0, 64); command_table.descriptors[0].base_high = 0; diff --git a/Kernel/Storage/AHCIPort.h b/Kernel/Storage/AHCIPort.h index 488b095b124..fb7ffdc9b28 100644 --- a/Kernel/Storage/AHCIPort.h +++ b/Kernel/Storage/AHCIPort.h @@ -107,11 +107,11 @@ private: mutable bool m_wait_for_completion { false }; bool m_wait_connect_for_completion { false }; - NonnullRefPtrVector m_dma_buffers; - NonnullRefPtrVector m_command_table_pages; - RefPtr m_command_list_page; - OwnPtr m_command_list_region; - RefPtr m_fis_receive_page; + NonnullRefPtrVector m_dma_buffers; + NonnullRefPtrVector m_command_table_pages; + RefPtr m_command_list_page; + OwnPtr m_command_list_region; + RefPtr m_fis_receive_page; RefPtr m_connected_device; u32 m_port_index; @@ -120,7 +120,7 @@ private: AHCI::PortInterruptStatusBitField m_interrupt_status; AHCI::PortInterruptEnableBitField m_interrupt_enable; - RefPtr m_current_scatter_list; + RefPtr m_current_scatter_list; bool m_disabled_by_firmware { false }; }; } diff --git a/Kernel/Storage/AHCIPortHandler.h b/Kernel/Storage/AHCIPortHandler.h index d717eb740a7..227dc8ae9ca 100644 --- a/Kernel/Storage/AHCIPortHandler.h +++ b/Kernel/Storage/AHCIPortHandler.h @@ -66,7 +66,7 @@ private: // Data members HashMap> m_handled_ports; NonnullRefPtr m_parent_controller; - NonnullRefPtrVector m_identify_metadata_pages; + NonnullRefPtrVector m_identify_metadata_pages; AHCI::MaskedBitField m_taken_ports; AHCI::MaskedBitField m_pending_ports_interrupts; }; diff --git a/Kernel/Storage/BMIDEChannel.cpp b/Kernel/Storage/BMIDEChannel.cpp index cbbb6eccedc..c35151f7fe1 100644 --- a/Kernel/Storage/BMIDEChannel.cpp +++ b/Kernel/Storage/BMIDEChannel.cpp @@ -43,8 +43,8 @@ UNMAP_AFTER_INIT void BMIDEChannel::initialize() m_dma_buffer_page = MM.allocate_supervisor_physical_page(); if (m_dma_buffer_page.is_null() || m_prdt_page.is_null()) return; - m_prdt_region = MM.allocate_kernel_region(m_prdt_page->paddr(), PAGE_SIZE, "IDE PRDT", Region::Access::Read | Region::Access::Write); - m_dma_buffer_region = MM.allocate_kernel_region(m_dma_buffer_page->paddr(), PAGE_SIZE, "IDE DMA region", Region::Access::Read | Region::Access::Write); + m_prdt_region = MM.allocate_kernel_region(m_prdt_page->paddr(), PAGE_SIZE, "IDE PRDT", Memory::Region::Access::Read | Memory::Region::Access::Write); + m_dma_buffer_region = MM.allocate_kernel_region(m_dma_buffer_page->paddr(), PAGE_SIZE, "IDE DMA region", Memory::Region::Access::Read | Memory::Region::Access::Write); prdt().end_of_table = 0x8000; // clear bus master interrupt status diff --git a/Kernel/Storage/BMIDEChannel.h b/Kernel/Storage/BMIDEChannel.h index 7810212d73e..c72e0a3da56 100644 --- a/Kernel/Storage/BMIDEChannel.h +++ b/Kernel/Storage/BMIDEChannel.h @@ -47,9 +47,9 @@ private: virtual void ata_write_sectors(bool, u16) override; PhysicalRegionDescriptor& prdt() { return *reinterpret_cast(m_prdt_region->vaddr().as_ptr()); } - OwnPtr m_prdt_region; - OwnPtr m_dma_buffer_region; - RefPtr m_prdt_page; - RefPtr m_dma_buffer_page; + OwnPtr m_prdt_region; + OwnPtr m_dma_buffer_region; + RefPtr m_prdt_page; + RefPtr m_dma_buffer_page; }; } diff --git a/Kernel/Storage/RamdiskController.cpp b/Kernel/Storage/RamdiskController.cpp index 69e61b31f1e..dca4f083d71 100644 --- a/Kernel/Storage/RamdiskController.cpp +++ b/Kernel/Storage/RamdiskController.cpp @@ -46,10 +46,10 @@ RamdiskController::RamdiskController() { // Populate ramdisk controllers from Multiboot boot modules, if any. size_t count = 0; - for (auto& used_memory_range : MemoryManager::the().used_memory_ranges()) { - if (used_memory_range.type == UsedMemoryRangeType::BootModule) { - size_t length = page_round_up(used_memory_range.end.get()) - used_memory_range.start.get(); - auto region = MemoryManager::the().allocate_kernel_region(used_memory_range.start, length, "Ramdisk", Region::Access::Read | Region::Access::Write); + for (auto& used_memory_range : MM.used_memory_ranges()) { + if (used_memory_range.type == Memory::UsedMemoryRangeType::BootModule) { + size_t length = Memory::page_round_up(used_memory_range.end.get()) - used_memory_range.start.get(); + auto region = MM.allocate_kernel_region(used_memory_range.start, length, "Ramdisk", Memory::Region::Access::Read | Memory::Region::Access::Write); if (!region) dmesgln("RamdiskController: Failed to allocate kernel region of size {}", length); else diff --git a/Kernel/Storage/RamdiskDevice.cpp b/Kernel/Storage/RamdiskDevice.cpp index 992b0cfece6..8b962df4d6b 100644 --- a/Kernel/Storage/RamdiskDevice.cpp +++ b/Kernel/Storage/RamdiskDevice.cpp @@ -12,12 +12,12 @@ namespace Kernel { -NonnullRefPtr RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr&& region, int major, int minor) +NonnullRefPtr RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr&& region, int major, int minor) { return adopt_ref(*new RamdiskDevice(controller, move(region), major, minor)); } -RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr&& region, int major, int minor) +RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr&& region, int major, int minor) : StorageDevice(controller, major, minor, 512, region->size() / 512) , m_region(move(region)) { diff --git a/Kernel/Storage/RamdiskDevice.h b/Kernel/Storage/RamdiskDevice.h index 41b5b4f3be4..12d3d39b3fb 100644 --- a/Kernel/Storage/RamdiskDevice.h +++ b/Kernel/Storage/RamdiskDevice.h @@ -17,8 +17,8 @@ class RamdiskDevice final : public StorageDevice { friend class RamdiskController; AK_MAKE_ETERNAL public: - static NonnullRefPtr create(const RamdiskController&, NonnullOwnPtr&& region, int major, int minor); - RamdiskDevice(const RamdiskController&, NonnullOwnPtr&&, int major, int minor); + static NonnullRefPtr create(const RamdiskController&, NonnullOwnPtr&& region, int major, int minor); + RamdiskDevice(const RamdiskController&, NonnullOwnPtr&&, int major, int minor); virtual ~RamdiskDevice() override; // ^BlockDevice @@ -32,7 +32,7 @@ public: Mutex m_lock { "RamdiskDevice" }; - NonnullOwnPtr m_region; + NonnullOwnPtr m_region; }; } diff --git a/Kernel/Syscalls/anon_create.cpp b/Kernel/Syscalls/anon_create.cpp index 2308d75aff2..6e3e252202b 100644 --- a/Kernel/Syscalls/anon_create.cpp +++ b/Kernel/Syscalls/anon_create.cpp @@ -29,7 +29,7 @@ KResultOr Process::sys$anon_create(size_t size, int options) if (new_fd_or_error.is_error()) return new_fd_or_error.error(); auto new_fd = new_fd_or_error.release_value(); - auto vmobject = AnonymousVMObject::try_create_purgeable_with_size(size, AllocationStrategy::Reserve); + auto vmobject = Memory::AnonymousVMObject::try_create_purgeable_with_size(size, AllocationStrategy::Reserve); if (!vmobject) return ENOMEM; diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 7f401837e9d..a8b4b10807e 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -27,17 +27,17 @@ namespace Kernel { -extern Region* g_signal_trampoline_region; +extern Memory::Region* g_signal_trampoline_region; struct LoadResult { - OwnPtr space; + OwnPtr space; FlatPtr load_base { 0 }; FlatPtr entry_eip { 0 }; size_t size { 0 }; - WeakPtr tls_region; + WeakPtr tls_region; size_t tls_size { 0 }; size_t tls_alignment { 0 }; - WeakPtr stack_region; + WeakPtr stack_region; }; static Vector generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, uid_t uid, uid_t euid, gid_t gid, gid_t egid, String executable_path, int main_program_fd); @@ -68,7 +68,7 @@ static bool validate_stack_size(const Vector& arguments, const Vector make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Region& region, Vector arguments, +static KResultOr make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Memory::Region& region, Vector arguments, Vector environment, Vector auxiliary_values) { FlatPtr new_sp = region.range().end().get(); @@ -162,7 +162,7 @@ struct RequiredLoadRange { static KResultOr get_required_load_range(FileDescription& program_description) { auto& inode = *(program_description.inode()); - auto vmobject = SharedInodeVMObject::try_create_with_inode(inode); + auto vmobject = Memory::SharedInodeVMObject::try_create_with_inode(inode); if (!vmobject) { dbgln("get_required_load_range: Unable to allocate SharedInodeVMObject"); return ENOMEM; @@ -170,7 +170,7 @@ static KResultOr get_required_load_range(FileDescription& pro size_t executable_size = inode.size(); - auto region = MM.allocate_kernel_region_with_vmobject(*vmobject, page_round_up(executable_size), "ELF memory range calculation", Region::Access::Read); + auto region = MM.allocate_kernel_region_with_vmobject(*vmobject, Memory::page_round_up(executable_size), "ELF memory range calculation", Memory::Region::Access::Read); if (!region) { dbgln("Could not allocate memory for ELF"); return ENOMEM; @@ -205,7 +205,7 @@ static KResultOr get_load_offset(const ElfW(Ehdr) & main_program_header constexpr FlatPtr minimum_load_offset_randomization_size = 10 * MiB; auto random_load_offset_in_range([](auto start, auto size) { - return page_round_down(start + get_good_random() % size); + return Memory::page_round_down(start + get_good_random() % size); }); if (main_program_header.e_type == ET_DYN) { @@ -263,11 +263,11 @@ enum class ShouldAllowSyscalls { Yes, }; -static KResultOr load_elf_object(NonnullOwnPtr new_space, FileDescription& object_description, +static KResultOr load_elf_object(NonnullOwnPtr new_space, FileDescription& object_description, FlatPtr load_offset, ShouldAllocateTls should_allocate_tls, ShouldAllowSyscalls should_allow_syscalls) { auto& inode = *(object_description.inode()); - auto vmobject = SharedInodeVMObject::try_create_with_inode(inode); + auto vmobject = Memory::SharedInodeVMObject::try_create_with_inode(inode); if (!vmobject) { dbgln("load_elf_object: Unable to allocate SharedInodeVMObject"); return ENOMEM; @@ -280,7 +280,7 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil size_t executable_size = inode.size(); - auto executable_region = MM.allocate_kernel_region_with_vmobject(*vmobject, page_round_up(executable_size), "ELF loading", Region::Access::Read); + auto executable_region = MM.allocate_kernel_region_with_vmobject(*vmobject, Memory::page_round_up(executable_size), "ELF loading", Memory::Region::Access::Read); if (!executable_region) { dbgln("Could not allocate memory for ELF loading"); return ENOMEM; @@ -291,7 +291,7 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil if (!elf_image.is_valid()) return ENOEXEC; - Region* master_tls_region { nullptr }; + Memory::Region* master_tls_region { nullptr }; size_t master_tls_size = 0; size_t master_tls_alignment = 0; FlatPtr load_base_address = 0; @@ -299,7 +299,7 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil String elf_name = object_description.absolute_path(); VERIFY(!Processor::current().in_critical()); - MemoryManager::enter_space(*new_space); + Memory::MemoryManager::enter_space(*new_space); KResult ph_load_result = KSuccess; elf_image.for_each_program_header([&](const ELF::Image::ProgramHeader& program_header) { @@ -356,8 +356,8 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil prot |= PROT_WRITE; auto region_name = String::formatted("{} (data-{}{})", elf_name, program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : ""); - auto range_base = VirtualAddress { page_round_down(program_header.vaddr().offset(load_offset).get()) }; - auto range_end = VirtualAddress { page_round_up(program_header.vaddr().offset(load_offset).offset(program_header.size_in_memory()).get()) }; + auto range_base = VirtualAddress { Memory::page_round_down(program_header.vaddr().offset(load_offset).get()) }; + auto range_end = VirtualAddress { Memory::page_round_up(program_header.vaddr().offset(load_offset).offset(program_header.size_in_memory()).get()) }; auto range = new_space->allocate_range(range_base, range_end.get() - range_base.get()); if (!range.has_value()) { @@ -397,8 +397,8 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil if (program_header.is_executable()) prot |= PROT_EXEC; - auto range_base = VirtualAddress { page_round_down(program_header.vaddr().offset(load_offset).get()) }; - auto range_end = VirtualAddress { page_round_up(program_header.vaddr().offset(load_offset).offset(program_header.size_in_memory()).get()) }; + auto range_base = VirtualAddress { Memory::page_round_down(program_header.vaddr().offset(load_offset).get()) }; + auto range_end = VirtualAddress { Memory::page_round_up(program_header.vaddr().offset(load_offset).offset(program_header.size_in_memory()).get()) }; auto range = new_space->allocate_range(range_base, range_end.get() - range_base.get()); if (!range.has_value()) { ph_load_result = ENOMEM; @@ -453,12 +453,12 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil KResultOr Process::load(NonnullRefPtr main_program_description, RefPtr interpreter_description, const ElfW(Ehdr) & main_program_header) { - auto new_space = Space::try_create(*this, nullptr); + auto new_space = Memory::Space::try_create(*this, nullptr); if (!new_space) return ENOMEM; ScopeGuard space_guard([&]() { - MemoryManager::enter_process_paging_scope(*this); + Memory::MemoryManager::enter_process_paging_scope(*this); }); auto load_offset = get_load_offset(main_program_header, main_program_description, interpreter_description); @@ -560,7 +560,7 @@ KResult Process::do_exec(NonnullRefPtr main_program_description TemporaryChange global_profiling_disabler(g_profiling_all_threads, false); m_space = load_result.space.release_nonnull(); } - MemoryManager::enter_space(*m_space); + Memory::MemoryManager::enter_space(*m_space); auto signal_trampoline_region = m_space->allocate_region_with_vmobject(signal_trampoline_range.value(), g_signal_trampoline_region->vmobject(), 0, "Signal trampoline", PROT_READ | PROT_EXEC, true); if (signal_trampoline_region.is_error()) { diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index fdb60742302..a36135b7767 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -108,7 +108,7 @@ KResultOr Process::sys$fork(RegisterState& regs) // TODO: tear down new process? return ENOMEM; } - child_region->map(child->space().page_directory(), ShouldFlushTLB::No); + child_region->map(child->space().page_directory(), Memory::ShouldFlushTLB::No); if (region == m_master_tls_region.unsafe_ptr()) child->m_master_tls_region = child_region; diff --git a/Kernel/Syscalls/futex.cpp b/Kernel/Syscalls/futex.cpp index 637cb6742be..2f43ce4f68b 100644 --- a/Kernel/Syscalls/futex.cpp +++ b/Kernel/Syscalls/futex.cpp @@ -12,9 +12,9 @@ namespace Kernel { static SpinLock g_global_futex_lock; -static AK::Singleton> g_global_futex_queues; +static AK::Singleton> g_global_futex_queues; -FutexQueue::FutexQueue(FlatPtr user_address_or_offset, VMObject* vmobject) +FutexQueue::FutexQueue(FlatPtr user_address_or_offset, Memory::VMObject* vmobject) : m_user_address_or_offset(user_address_or_offset) , m_is_global(vmobject != nullptr) { @@ -40,7 +40,7 @@ FutexQueue::~FutexQueue() m_is_global ? " (global)" : " (local)"); } -void FutexQueue::vmobject_deleted(VMObject& vmobject) +void FutexQueue::vmobject_deleted(Memory::VMObject& vmobject) { VERIFY(m_is_global); // If we got called we must be a global futex // Because we're taking ourselves out of the global queue, we need @@ -127,9 +127,9 @@ KResultOr Process::sys$futex(Userspace // If this is a global lock, look up the underlying VMObject *before* // acquiring the queue lock - RefPtr vmobject, vmobject2; + RefPtr vmobject, vmobject2; if (!is_private) { - auto region = space().find_region_containing(Range { VirtualAddress { user_address_or_offset }, sizeof(u32) }); + auto region = space().find_region_containing(Memory::Range { VirtualAddress { user_address_or_offset }, sizeof(u32) }); if (!region) return EFAULT; vmobject = region->vmobject(); @@ -139,7 +139,7 @@ KResultOr Process::sys$futex(Userspace case FUTEX_REQUEUE: case FUTEX_CMP_REQUEUE: case FUTEX_WAKE_OP: { - auto region2 = space().find_region_containing(Range { VirtualAddress { user_address_or_offset2 }, sizeof(u32) }); + auto region2 = space().find_region_containing(Memory::Range { VirtualAddress { user_address_or_offset2 }, sizeof(u32) }); if (!region2) return EFAULT; vmobject2 = region2->vmobject(); @@ -149,7 +149,7 @@ KResultOr Process::sys$futex(Userspace } } - auto find_global_futex_queues = [&](VMObject& vmobject, bool create_if_not_found) -> FutexQueues* { + auto find_global_futex_queues = [&](Memory::VMObject& vmobject, bool create_if_not_found) -> FutexQueues* { auto& global_queues = *g_global_futex_queues; auto it = global_queues.find(&vmobject); if (it != global_queues.end()) @@ -165,7 +165,7 @@ KResultOr Process::sys$futex(Userspace return nullptr; }; - auto find_futex_queue = [&](VMObject* vmobject, FlatPtr user_address_or_offset, bool create_if_not_found, bool* did_create = nullptr) -> RefPtr { + auto find_futex_queue = [&](Memory::VMObject* vmobject, FlatPtr user_address_or_offset, bool create_if_not_found, bool* did_create = nullptr) -> RefPtr { VERIFY(is_private || vmobject); VERIFY(!create_if_not_found || did_create != nullptr); auto* queues = is_private ? &m_futex_queues : find_global_futex_queues(*vmobject, create_if_not_found); @@ -184,7 +184,7 @@ KResultOr Process::sys$futex(Userspace return {}; }; - auto remove_futex_queue = [&](VMObject* vmobject, FlatPtr user_address_or_offset) { + auto remove_futex_queue = [&](Memory::VMObject* vmobject, FlatPtr user_address_or_offset) { auto* queues = is_private ? &m_futex_queues : find_global_futex_queues(*vmobject, false); if (queues) { if (auto it = queues->find(user_address_or_offset); it != queues->end()) { @@ -198,7 +198,7 @@ KResultOr Process::sys$futex(Userspace } }; - auto do_wake = [&](VMObject* vmobject, FlatPtr user_address_or_offset, u32 count, Optional bitmask) -> int { + auto do_wake = [&](Memory::VMObject* vmobject, FlatPtr user_address_or_offset, u32 count, Optional bitmask) -> int { if (count == 0) return 0; ScopedSpinLock lock(queue_lock); diff --git a/Kernel/Syscalls/get_stack_bounds.cpp b/Kernel/Syscalls/get_stack_bounds.cpp index f27e041dd93..7c680c008c9 100644 --- a/Kernel/Syscalls/get_stack_bounds.cpp +++ b/Kernel/Syscalls/get_stack_bounds.cpp @@ -14,7 +14,7 @@ KResultOr Process::sys$get_stack_bounds(Userspace user_stack_ VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); auto& regs = Thread::current()->get_register_dump_from_stack(); FlatPtr stack_pointer = regs.userspace_sp(); - auto* stack_region = space().find_region_containing(Range { VirtualAddress(stack_pointer), 1 }); + auto* stack_region = space().find_region_containing(Memory::Range { VirtualAddress(stack_pointer), 1 }); // The syscall handler should have killed us if we had an invalid stack pointer. VERIFY(stack_region); diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 2e85b1a7b37..aeab5264476 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -23,7 +23,7 @@ namespace Kernel { -static bool should_make_executable_exception_for_dynamic_loader(bool make_readable, bool make_writable, bool make_executable, const Region& region) +static bool should_make_executable_exception_for_dynamic_loader(bool make_readable, bool make_writable, bool make_executable, Memory::Region const& region) { // Normally we don't allow W -> X transitions, but we have to make an exception // for the dynamic loader, which needs to do this after performing text relocations. @@ -48,7 +48,7 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab if (!region.vmobject().is_private_inode()) return false; - auto& inode_vm = static_cast(region.vmobject()); + auto& inode_vm = static_cast(region.vmobject()); auto& inode = inode_vm.inode(); ElfW(Ehdr) header; @@ -69,7 +69,7 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab return true; } -static bool validate_mmap_prot(int prot, bool map_stack, bool map_anonymous, const Region* region = nullptr) +static bool validate_mmap_prot(int prot, bool map_stack, bool map_anonymous, Memory::Region const* region = nullptr) { bool make_readable = prot & PROT_READ; bool make_writable = prot & PROT_WRITE; @@ -154,10 +154,10 @@ KResultOr Process::sys$mmap(Userspace u if (alignment & ~PAGE_MASK) return EINVAL; - if (page_round_up_would_wrap(size)) + if (Memory::page_round_up_would_wrap(size)) return EINVAL; - if (!is_user_range(VirtualAddress(addr), page_round_up(size))) + if (!Memory::is_user_range(VirtualAddress(addr), Memory::page_round_up(size))) return EFAULT; OwnPtr name; @@ -198,11 +198,11 @@ KResultOr Process::sys$mmap(Userspace u if (map_stack && (!map_private || !map_anonymous)) return EINVAL; - Region* region = nullptr; - Optional range; + Memory::Region* region = nullptr; + Optional range; if (map_randomized) { - range = space().page_directory().range_allocator().allocate_randomized(page_round_up(size), alignment); + range = space().page_directory().range_allocator().allocate_randomized(Memory::page_round_up(size), alignment); } else { range = space().allocate_range(VirtualAddress(addr), size, alignment); if (!range.has_value()) { @@ -218,11 +218,11 @@ KResultOr Process::sys$mmap(Userspace u if (map_anonymous) { auto strategy = map_noreserve ? AllocationStrategy::None : AllocationStrategy::Reserve; - RefPtr vmobject; + RefPtr vmobject; if (flags & MAP_PURGEABLE) - vmobject = AnonymousVMObject::try_create_purgeable_with_size(page_round_up(size), strategy); + vmobject = Memory::AnonymousVMObject::try_create_purgeable_with_size(Memory::page_round_up(size), strategy); else - vmobject = AnonymousVMObject::try_create_with_size(page_round_up(size), strategy); + vmobject = Memory::AnonymousVMObject::try_create_with_size(Memory::page_round_up(size), strategy); if (!vmobject) return ENOMEM; auto region_or_error = space().allocate_region_with_vmobject(range.value(), vmobject.release_nonnull(), 0, {}, prot, map_shared); @@ -272,21 +272,21 @@ KResultOr Process::sys$mmap(Userspace u return region->vaddr().get(); } -static KResultOr expand_range_to_page_boundaries(FlatPtr address, size_t size) +static KResultOr expand_range_to_page_boundaries(FlatPtr address, size_t size) { - if (page_round_up_would_wrap(size)) + if (Memory::page_round_up_would_wrap(size)) return EINVAL; if ((address + size) < address) return EINVAL; - if (page_round_up_would_wrap(address + size)) + if (Memory::page_round_up_would_wrap(address + size)) return EINVAL; auto base = VirtualAddress { address }.page_base(); - auto end = page_round_up(address + size); + auto end = Memory::page_round_up(address + size); - return Range { base, end - base.get() }; + return Memory::Range { base, end - base.get() }; } KResultOr Process::sys$mprotect(Userspace addr, size_t size, int prot) @@ -314,10 +314,10 @@ KResultOr Process::sys$mprotect(Userspace addr, size_t size, int return EPERM; if (!validate_mmap_prot(prot, whole_region->is_stack(), whole_region->vmobject().is_anonymous(), whole_region)) return EINVAL; - if (whole_region->access() == prot_to_region_access_flags(prot)) + if (whole_region->access() == Memory::prot_to_region_access_flags(prot)) return 0; if (whole_region->vmobject().is_inode() - && !validate_inode_mmap_prot(*this, prot, static_cast(whole_region->vmobject()).inode(), whole_region->is_shared())) { + && !validate_inode_mmap_prot(*this, prot, static_cast(whole_region->vmobject()).inode(), whole_region->is_shared())) { return EACCES; } whole_region->set_readable(prot & PROT_READ); @@ -334,10 +334,10 @@ KResultOr Process::sys$mprotect(Userspace addr, size_t size, int return EPERM; if (!validate_mmap_prot(prot, old_region->is_stack(), old_region->vmobject().is_anonymous(), old_region)) return EINVAL; - if (old_region->access() == prot_to_region_access_flags(prot)) + if (old_region->access() == Memory::prot_to_region_access_flags(prot)) return 0; if (old_region->vmobject().is_inode() - && !validate_inode_mmap_prot(*this, prot, static_cast(old_region->vmobject()).inode(), old_region->is_shared())) { + && !validate_inode_mmap_prot(*this, prot, static_cast(old_region->vmobject()).inode(), old_region->is_shared())) { return EACCES; } @@ -346,7 +346,7 @@ KResultOr Process::sys$mprotect(Userspace addr, size_t size, int auto region = space().take_region(*old_region); // Unmap the old region here, specifying that we *don't* want the VM deallocated. - region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No); + region->unmap(Memory::Region::ShouldDeallocateVirtualMemoryRange::No); // This vector is the region(s) adjacent to our range. // We need to allocate a new region for the range we wanted to change permission bits on. @@ -380,10 +380,10 @@ KResultOr Process::sys$mprotect(Userspace addr, size_t size, int return EPERM; if (!validate_mmap_prot(prot, region->is_stack(), region->vmobject().is_anonymous(), region)) return EINVAL; - if (region->access() == prot_to_region_access_flags(prot)) + if (region->access() == Memory::prot_to_region_access_flags(prot)) return 0; if (region->vmobject().is_inode() - && !validate_inode_mmap_prot(*this, prot, static_cast(region->vmobject()).inode(), region->is_shared())) { + && !validate_inode_mmap_prot(*this, prot, static_cast(region->vmobject()).inode(), region->is_shared())) { return EACCES; } full_size_found += region->range().intersect(range_to_mprotect).size(); @@ -409,7 +409,7 @@ KResultOr Process::sys$mprotect(Userspace addr, size_t size, int auto region = space().take_region(*old_region); // Unmap the old region here, specifying that we *don't* want the VM deallocated. - region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No); + region->unmap(Memory::Region::ShouldDeallocateVirtualMemoryRange::No); // This vector is the region(s) adjacent to our range. // We need to allocate a new region for the range we wanted to change permission bits on. @@ -473,7 +473,7 @@ KResultOr Process::sys$madvise(Userspace address, size_t size, i if (set_volatile || set_nonvolatile) { if (!region->vmobject().is_anonymous()) return EINVAL; - auto& vmobject = static_cast(region->vmobject()); + auto& vmobject = static_cast(region->vmobject()); if (!vmobject.is_purgeable()) return EINVAL; bool was_purged = false; @@ -557,16 +557,16 @@ KResultOr Process::sys$mremap(Userspacerange(); auto old_prot = region_access_flags_to_prot(old_region->access()); auto old_offset = old_region->offset_in_vmobject(); - NonnullRefPtr inode = static_cast(old_region->vmobject()).inode(); + NonnullRefPtr inode = static_cast(old_region->vmobject()).inode(); - auto new_vmobject = PrivateInodeVMObject::try_create_with_inode(inode); + auto new_vmobject = Memory::PrivateInodeVMObject::try_create_with_inode(inode); if (!new_vmobject) return ENOMEM; auto old_name = old_region->take_name(); // Unmap without deallocating the VM range since we're going to reuse it. - old_region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No); + old_region->unmap(Memory::Region::ShouldDeallocateVirtualMemoryRange::No); space().deallocate_region(*old_region); auto new_region_or_error = space().allocate_region_with_vmobject(range, new_vmobject.release_nonnull(), old_offset, old_name->view(), old_prot, false); @@ -654,10 +654,10 @@ KResultOr Process::sys$msyscall(Userspace address) return 0; } - if (!is_user_address(VirtualAddress { address })) + if (!Memory::is_user_address(VirtualAddress { address })) return EFAULT; - auto* region = space().find_region_containing(Range { VirtualAddress { address }, 1 }); + auto* region = space().find_region_containing(Memory::Range { VirtualAddress { address }, 1 }); if (!region) return EINVAL; diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp index ad52c2b5393..9a677464d7e 100644 --- a/Kernel/Syscalls/module.cpp +++ b/Kernel/Syscalls/module.cpp @@ -55,7 +55,7 @@ KResultOr Process::sys$module_load(Userspace user_path, si elf_image->for_each_section_of_type(SHT_PROGBITS, [&](const ELF::Image::Section& section) { if (!section.size()) return; - auto section_storage = KBuffer::copy(section.raw_data(), section.size(), Region::Access::Read | Region::Access::Write | Region::Access::Execute); + auto section_storage = KBuffer::copy(section.raw_data(), section.size(), Memory::Region::Access::Read | Memory::Region::Access::Write | Memory::Region::Access::Execute); section_storage_by_name.set(section.name(), section_storage.data()); module->sections.append(move(section_storage)); }); diff --git a/Kernel/Syscalls/ptrace.cpp b/Kernel/Syscalls/ptrace.cpp index 1c98f20c1aa..2166fd80d3b 100644 --- a/Kernel/Syscalls/ptrace.cpp +++ b/Kernel/Syscalls/ptrace.cpp @@ -121,7 +121,7 @@ static KResultOr handle_ptrace(const Kernel::Syscall::SC_ptrace_params& par Kernel::Syscall::SC_ptrace_peek_params peek_params {}; if (!copy_from_user(&peek_params, reinterpret_cast(params.addr))) return EFAULT; - if (!is_user_address(VirtualAddress { peek_params.address })) + if (!Memory::is_user_address(VirtualAddress { peek_params.address })) return EFAULT; auto result = peer->process().peek_user_data(Userspace { (FlatPtr)peek_params.address }); if (result.is_error()) @@ -132,7 +132,7 @@ static KResultOr handle_ptrace(const Kernel::Syscall::SC_ptrace_params& par } case PT_POKE: - if (!is_user_address(VirtualAddress { params.addr })) + if (!Memory::is_user_address(VirtualAddress { params.addr })) return EFAULT; return peer->process().poke_user_data(Userspace { (FlatPtr)params.addr }, params.data); @@ -194,7 +194,7 @@ KResultOr Process::peek_user_data(Userspace address) KResult Process::poke_user_data(Userspace address, u32 data) { - Range range = { VirtualAddress(address), sizeof(u32) }; + Memory::Range range = { VirtualAddress(address), sizeof(u32) }; auto* region = space().find_region_containing(range); if (!region) return EFAULT; @@ -203,7 +203,7 @@ KResult Process::poke_user_data(Userspace address, u32 data) // If the region is shared, we change its vmobject to a PrivateInodeVMObject // to prevent the write operation from changing any shared inode data VERIFY(region->vmobject().is_shared_inode()); - auto vmobject = PrivateInodeVMObject::try_create_with_inode(static_cast(region->vmobject()).inode()); + auto vmobject = Memory::PrivateInodeVMObject::try_create_with_inode(static_cast(region->vmobject()).inode()); if (!vmobject) return ENOMEM; region->set_vmobject(vmobject.release_nonnull()); diff --git a/Kernel/Syscalls/purge.cpp b/Kernel/Syscalls/purge.cpp index ede1413eb7b..b13c099f8e6 100644 --- a/Kernel/Syscalls/purge.cpp +++ b/Kernel/Syscalls/purge.cpp @@ -20,7 +20,7 @@ KResultOr Process::sys$purge(int mode) return EPERM; size_t purged_page_count = 0; if (mode & PURGE_ALL_VOLATILE) { - NonnullRefPtrVector vmobjects; + NonnullRefPtrVector vmobjects; { KResult result(KSuccess); MM.for_each_vmobject([&](auto& vmobject) { @@ -43,14 +43,14 @@ KResultOr Process::sys$purge(int mode) } } if (mode & PURGE_ALL_CLEAN_INODE) { - NonnullRefPtrVector vmobjects; + NonnullRefPtrVector vmobjects; { KResult result(KSuccess); MM.for_each_vmobject([&](auto& vmobject) { if (vmobject.is_inode()) { // In the event that the append fails, only attempt to continue // the purge if we have already appended something successfully. - if (!vmobjects.try_append(static_cast(vmobject)) && vmobjects.is_empty()) { + if (!vmobjects.try_append(static_cast(vmobject)) && vmobjects.is_empty()) { result = ENOMEM; return IterationDecision::Break; } diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index f63f5371ea1..0b80db0ce2a 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -120,7 +120,7 @@ UNMAP_AFTER_INIT void VirtualConsole::initialize() // Allocate twice of the max row * max column * sizeof(Cell) to ensure we can have some sort of history mechanism... auto size = GraphicsManagement::the().console()->max_column() * GraphicsManagement::the().console()->max_row() * sizeof(Cell) * 2; - m_cells = MM.allocate_kernel_region(page_round_up(size), "Virtual Console Cells", Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); + m_cells = MM.allocate_kernel_region(Memory::page_round_up(size), "Virtual Console Cells", Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); // Add the lines, so we also ensure they will be flushed now for (size_t row = 0; row < rows(); row++) { @@ -139,7 +139,7 @@ void VirtualConsole::refresh_after_resolution_change() // Note: From now on, columns() and rows() are updated with the new settings. auto size = GraphicsManagement::the().console()->max_column() * GraphicsManagement::the().console()->max_row() * sizeof(Cell) * 2; - auto new_cells = MM.allocate_kernel_region(page_round_up(size), "Virtual Console Cells", Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); + auto new_cells = MM.allocate_kernel_region(Memory::page_round_up(size), "Virtual Console Cells", Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); if (rows() < old_rows_count) { m_lines.shrink(rows()); diff --git a/Kernel/TTY/VirtualConsole.h b/Kernel/TTY/VirtualConsole.h index 4491a176178..872eb99c446 100644 --- a/Kernel/TTY/VirtualConsole.h +++ b/Kernel/TTY/VirtualConsole.h @@ -146,7 +146,7 @@ private: void clear_in_line(u16 row, u16 first_column, u16 last_column); void put_character_at(unsigned row, unsigned column, u32 ch, const VT::Attribute&); - OwnPtr m_cells; + OwnPtr m_cells; Vector m_lines; ConsoleImpl m_console_impl; }; diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 8841819014a..7e2425d9bf9 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -39,7 +39,7 @@ UNMAP_AFTER_INIT void Thread::initialize() KResultOr> Thread::try_create(NonnullRefPtr process) { - auto kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, {}, Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow); + auto kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, {}, Memory::Region::Access::Read | Memory::Region::Access::Write, AllocationStrategy::AllocateNow); if (!kernel_stack_region) return ENOMEM; kernel_stack_region->set_stack(true); @@ -57,7 +57,7 @@ KResultOr> Thread::try_create(NonnullRefPtr proce return thread.release_nonnull(); } -Thread::Thread(NonnullRefPtr process, NonnullOwnPtr kernel_stack_region, NonnullRefPtr block_timer, OwnPtr name) +Thread::Thread(NonnullRefPtr process, NonnullOwnPtr kernel_stack_region, NonnullRefPtr block_timer, OwnPtr name) : m_process(move(process)) , m_kernel_stack_region(move(kernel_stack_region)) , m_name(move(name)) @@ -175,7 +175,7 @@ void Thread::block(Kernel::Mutex& lock, ScopedSpinLock>& lock_lock, VERIFY(!Processor::current().in_irq()); VERIFY(this == Thread::current()); ScopedCritical critical; - VERIFY(!s_mm_lock.own_lock()); + VERIFY(!Memory::s_mm_lock.own_lock()); ScopedSpinLock block_lock(m_block_lock); @@ -1155,7 +1155,7 @@ static bool symbolicate(RecognizedSymbol const& symbol, Process& process, String bool mask_kernel_addresses = !process.is_superuser(); if (!symbol.symbol) { - if (!is_user_address(VirtualAddress(symbol.address))) { + if (!Memory::is_user_address(VirtualAddress(symbol.address))) { builder.append("0xdeadc0de\n"); } else { if (auto* region = process.space().find_region_containing({ VirtualAddress(symbol.address), sizeof(FlatPtr) })) { @@ -1188,7 +1188,7 @@ String Thread::backtrace() VERIFY(!g_scheduler_lock.own_lock()); ProcessPagingScope paging_scope(process); for (auto& frame : stack_trace) { - if (is_user_range(VirtualAddress(frame), sizeof(FlatPtr) * 2)) { + if (Memory::is_user_range(VirtualAddress(frame), sizeof(FlatPtr) * 2)) { recognized_symbols.append({ frame }); } else { recognized_symbols.append({ frame, symbolicate_kernel_address(frame) }); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index e4d9de05873..a958c855edc 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -37,7 +37,9 @@ namespace Kernel { +namespace Memory { extern RecursiveSpinLock s_mm_lock; +} enum class DispatchSignalResult { Deferred = 0, @@ -847,7 +849,7 @@ public: VERIFY(!Processor::current().in_irq()); VERIFY(this == Thread::current()); ScopedCritical critical; - VERIFY(!s_mm_lock.own_lock()); + VERIFY(!Memory::s_mm_lock.own_lock()); ScopedSpinLock block_lock(m_block_lock); // We need to hold m_block_lock so that nobody can unblock a blocker as soon @@ -1215,7 +1217,7 @@ public: String backtrace(); private: - Thread(NonnullRefPtr, NonnullOwnPtr, NonnullRefPtr, OwnPtr); + Thread(NonnullRefPtr, NonnullOwnPtr, NonnullRefPtr, OwnPtr); IntrusiveListNode m_process_thread_list_node; int m_runnable_priority { -1 }; @@ -1304,9 +1306,9 @@ private: u32 m_signal_mask { 0 }; FlatPtr m_kernel_stack_base { 0 }; FlatPtr m_kernel_stack_top { 0 }; - OwnPtr m_kernel_stack_region; + OwnPtr m_kernel_stack_region; VirtualAddress m_thread_specific_data; - Optional m_thread_specific_range; + Optional m_thread_specific_range; Array m_signal_action_data; Blocker* m_blocker { nullptr }; Kernel::Mutex* m_blocking_lock { nullptr }; diff --git a/Kernel/Time/HPET.cpp b/Kernel/Time/HPET.cpp index 0dbb2bb24c9..b2d899ce4a6 100644 --- a/Kernel/Time/HPET.cpp +++ b/Kernel/Time/HPET.cpp @@ -124,7 +124,7 @@ UNMAP_AFTER_INIT bool HPET::test_and_initialize() return false; dmesgln("HPET @ {}", hpet); - auto sdt = map_typed(hpet); + auto sdt = Memory::map_typed(hpet); // Note: HPET is only usable from System Memory VERIFY(sdt->event_timer_block.address_space == (u8)ACPI::GenericAddressStructure::AddressSpace::SystemMemory); @@ -145,9 +145,9 @@ UNMAP_AFTER_INIT bool HPET::check_for_exisiting_periodic_timers() if (hpet.is_null()) return false; - auto sdt = map_typed(hpet); + auto sdt = Memory::map_typed(hpet); VERIFY(sdt->event_timer_block.address_space == 0); - auto registers = map_typed(PhysicalAddress(sdt->event_timer_block.address)); + auto registers = Memory::map_typed(PhysicalAddress(sdt->event_timer_block.address)); size_t timers_count = ((registers->capabilities.attributes >> 8) & 0x1f) + 1; for (size_t index = 0; index < timers_count; index++) { @@ -384,7 +384,7 @@ void HPET::set_comparators_to_optimal_interrupt_state(size_t) PhysicalAddress HPET::find_acpi_hpet_registers_block() { - auto sdt = map_typed(m_physical_acpi_hpet_table); + auto sdt = Memory::map_typed(m_physical_acpi_hpet_table); VERIFY(sdt->event_timer_block.address_space == (u8)ACPI::GenericAddressStructure::AddressSpace::SystemMemory); return PhysicalAddress(sdt->event_timer_block.address); } @@ -413,11 +413,11 @@ u64 HPET::ns_to_raw_counter_ticks(u64 ns) const UNMAP_AFTER_INIT HPET::HPET(PhysicalAddress acpi_hpet) : m_physical_acpi_hpet_table(acpi_hpet) , m_physical_acpi_hpet_registers(find_acpi_hpet_registers_block()) - , m_hpet_mmio_region(MM.allocate_kernel_region(m_physical_acpi_hpet_registers.page_base(), PAGE_SIZE, "HPET MMIO", Region::Access::Read | Region::Access::Write)) + , m_hpet_mmio_region(MM.allocate_kernel_region(m_physical_acpi_hpet_registers.page_base(), PAGE_SIZE, "HPET MMIO", Memory::Region::Access::Read | Memory::Region::Access::Write)) { s_hpet = this; // Make available as soon as possible so that IRQs can use it - auto sdt = map_typed(m_physical_acpi_hpet_table); + auto sdt = Memory::map_typed(m_physical_acpi_hpet_table); m_vendor_id = sdt->pci_vendor_id; m_minimum_tick = sdt->mininum_clock_tick; dmesgln("HPET: Minimum clock tick - {}", m_minimum_tick); diff --git a/Kernel/Time/HPET.h b/Kernel/Time/HPET.h index be92d9eb775..620219ec98c 100644 --- a/Kernel/Time/HPET.h +++ b/Kernel/Time/HPET.h @@ -65,7 +65,7 @@ private: explicit HPET(PhysicalAddress acpi_hpet); PhysicalAddress m_physical_acpi_hpet_table; PhysicalAddress m_physical_acpi_hpet_registers; - OwnPtr m_hpet_mmio_region; + OwnPtr m_hpet_mmio_region; u64 m_main_counter_last_read { 0 }; u64 m_main_counter_drift { 0 }; diff --git a/Kernel/UserOrKernelBuffer.cpp b/Kernel/UserOrKernelBuffer.cpp index 55b5abd8b96..6f8116acaee 100644 --- a/Kernel/UserOrKernelBuffer.cpp +++ b/Kernel/UserOrKernelBuffer.cpp @@ -11,14 +11,14 @@ namespace Kernel { bool UserOrKernelBuffer::is_kernel_buffer() const { - return !is_user_address(VirtualAddress(m_buffer)); + return !Memory::is_user_address(VirtualAddress(m_buffer)); } String UserOrKernelBuffer::copy_into_string(size_t size) const { if (!m_buffer) return {}; - if (is_user_address(VirtualAddress(m_buffer))) { + if (Memory::is_user_address(VirtualAddress(m_buffer))) { char* buffer; auto data_copy = StringImpl::create_uninitialized(size, buffer); if (!copy_from_user(buffer, m_buffer, size)) @@ -33,7 +33,7 @@ KResultOr> UserOrKernelBuffer::try_copy_into_kstring(size { if (!m_buffer) return EINVAL; - if (is_user_address(VirtualAddress(m_buffer))) { + if (Memory::is_user_address(VirtualAddress(m_buffer))) { char* buffer; auto kstring = KString::try_create_uninitialized(size, buffer); if (!kstring) @@ -54,7 +54,7 @@ bool UserOrKernelBuffer::write(const void* src, size_t offset, size_t len) if (!m_buffer) return false; - if (is_user_address(VirtualAddress(m_buffer))) + if (Memory::is_user_address(VirtualAddress(m_buffer))) return copy_to_user(m_buffer + offset, src, len); memcpy(m_buffer + offset, src, len); @@ -66,7 +66,7 @@ bool UserOrKernelBuffer::read(void* dest, size_t offset, size_t len) const if (!m_buffer) return false; - if (is_user_address(VirtualAddress(m_buffer))) + if (Memory::is_user_address(VirtualAddress(m_buffer))) return copy_from_user(dest, m_buffer + offset, len); memcpy(dest, m_buffer + offset, len); @@ -78,7 +78,7 @@ bool UserOrKernelBuffer::memset(int value, size_t offset, size_t len) if (!m_buffer) return false; - if (is_user_address(VirtualAddress(m_buffer))) + if (Memory::is_user_address(VirtualAddress(m_buffer))) return memset_user(m_buffer + offset, value, len); ::memset(m_buffer + offset, value, len); diff --git a/Kernel/UserOrKernelBuffer.h b/Kernel/UserOrKernelBuffer.h index 1357be4a9ad..799d8df9534 100644 --- a/Kernel/UserOrKernelBuffer.h +++ b/Kernel/UserOrKernelBuffer.h @@ -22,13 +22,13 @@ public: static UserOrKernelBuffer for_kernel_buffer(u8* kernel_buffer) { - VERIFY(!kernel_buffer || !is_user_address(VirtualAddress(kernel_buffer))); + VERIFY(!kernel_buffer || !Memory::is_user_address(VirtualAddress(kernel_buffer))); return UserOrKernelBuffer(kernel_buffer); } static Optional for_user_buffer(u8* user_buffer, size_t size) { - if (user_buffer && !is_user_range(VirtualAddress(user_buffer), size)) + if (user_buffer && !Memory::is_user_range(VirtualAddress(user_buffer), size)) return {}; return UserOrKernelBuffer(user_buffer); } @@ -36,7 +36,7 @@ public: template static Optional for_user_buffer(UserspaceType userspace, size_t size) { - if (!is_user_range(VirtualAddress(userspace.unsafe_userspace_ptr()), size)) + if (!Memory::is_user_range(VirtualAddress(userspace.unsafe_userspace_ptr()), size)) return {}; return UserOrKernelBuffer(const_cast((const u8*)userspace.unsafe_userspace_ptr())); } diff --git a/Kernel/VirtIO/VirtIO.cpp b/Kernel/VirtIO/VirtIO.cpp index d1a20a334a0..58553faa3ac 100644 --- a/Kernel/VirtIO/VirtIO.cpp +++ b/Kernel/VirtIO/VirtIO.cpp @@ -109,7 +109,7 @@ auto VirtIODevice::mapping_for_bar(u8 bar) -> MappedMMIO& auto& mapping = m_mmio[bar]; if (!mapping.base) { mapping.size = PCI::get_BAR_space_size(pci_address(), bar); - mapping.base = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR(pci_address(), bar))), page_round_up(mapping.size), "VirtIO MMIO", Region::Access::Read | Region::Access::Write, Region::Cacheable::No); + mapping.base = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR(pci_address(), bar))), Memory::page_round_up(mapping.size), "VirtIO MMIO", Memory::Region::Access::Read | Memory::Region::Access::Write, Memory::Region::Cacheable::No); if (!mapping.base) dbgln("{}: Failed to map bar {}", m_class_name, bar); } diff --git a/Kernel/VirtIO/VirtIO.h b/Kernel/VirtIO/VirtIO.h index c6d5faa320a..8d15c6820c2 100644 --- a/Kernel/VirtIO/VirtIO.h +++ b/Kernel/VirtIO/VirtIO.h @@ -93,7 +93,7 @@ protected: const String m_class_name; struct MappedMMIO { - OwnPtr base; + OwnPtr base; size_t size { 0 }; template diff --git a/Kernel/VirtIO/VirtIOConsole.cpp b/Kernel/VirtIO/VirtIOConsole.cpp index b1df8def1b8..2bf1eef65e9 100644 --- a/Kernel/VirtIO/VirtIOConsole.cpp +++ b/Kernel/VirtIO/VirtIOConsole.cpp @@ -108,8 +108,8 @@ void VirtIOConsole::handle_queue_update(u16 queue_index) void VirtIOConsole::setup_multiport() { - m_control_receive_buffer = make("VirtIOConsole control receive queue", CONTROL_BUFFER_SIZE); - m_control_transmit_buffer = make("VirtIOConsole control transmit queue", CONTROL_BUFFER_SIZE); + m_control_receive_buffer = make("VirtIOConsole control receive queue", CONTROL_BUFFER_SIZE); + m_control_transmit_buffer = make("VirtIOConsole control transmit queue", CONTROL_BUFFER_SIZE); auto& queue = get_queue(CONTROL_RECEIVEQ); ScopedSpinLock queue_lock(queue.lock()); diff --git a/Kernel/VirtIO/VirtIOConsole.h b/Kernel/VirtIO/VirtIOConsole.h index 3a056b39ad0..e22c69372b4 100644 --- a/Kernel/VirtIO/VirtIOConsole.h +++ b/Kernel/VirtIO/VirtIOConsole.h @@ -68,8 +68,8 @@ private: unsigned m_device_id; - OwnPtr m_control_transmit_buffer; - OwnPtr m_control_receive_buffer; + OwnPtr m_control_transmit_buffer; + OwnPtr m_control_receive_buffer; WaitQueue m_control_wait_queue; diff --git a/Kernel/VirtIO/VirtIOConsolePort.cpp b/Kernel/VirtIO/VirtIOConsolePort.cpp index 32c960c74a2..791d3ae8450 100644 --- a/Kernel/VirtIO/VirtIOConsolePort.cpp +++ b/Kernel/VirtIO/VirtIOConsolePort.cpp @@ -17,8 +17,8 @@ VirtIOConsolePort::VirtIOConsolePort(unsigned port, VirtIOConsole& console) , m_console(console) , m_port(port) { - m_receive_buffer = make("VirtIOConsolePort Receive", RINGBUFFER_SIZE); - m_transmit_buffer = make("VirtIOConsolePort Transmit", RINGBUFFER_SIZE); + m_receive_buffer = make("VirtIOConsolePort Receive", RINGBUFFER_SIZE); + m_transmit_buffer = make("VirtIOConsolePort Transmit", RINGBUFFER_SIZE); m_receive_queue = m_port == 0 ? 0 : m_port * 2 + 2; m_transmit_queue = m_port == 0 ? 1 : m_port * 2 + 3; init_receive_buffer(); diff --git a/Kernel/VirtIO/VirtIOConsolePort.h b/Kernel/VirtIO/VirtIOConsolePort.h index 9fbfe661eda..c866d3eafdc 100644 --- a/Kernel/VirtIO/VirtIOConsolePort.h +++ b/Kernel/VirtIO/VirtIOConsolePort.h @@ -50,8 +50,8 @@ private: u16 m_receive_queue {}; u16 m_transmit_queue {}; - OwnPtr m_receive_buffer; - OwnPtr m_transmit_buffer; + OwnPtr m_receive_buffer; + OwnPtr m_transmit_buffer; VirtIOConsole& m_console; unsigned m_port; diff --git a/Kernel/VirtIO/VirtIOQueue.cpp b/Kernel/VirtIO/VirtIOQueue.cpp index 4fa20856312..e142f9e85e0 100644 --- a/Kernel/VirtIO/VirtIOQueue.cpp +++ b/Kernel/VirtIO/VirtIOQueue.cpp @@ -17,11 +17,11 @@ VirtIOQueue::VirtIOQueue(u16 queue_size, u16 notify_offset) size_t size_of_descriptors = sizeof(VirtIOQueueDescriptor) * queue_size; size_t size_of_driver = sizeof(VirtIOQueueDriver) + queue_size * sizeof(u16); size_t size_of_device = sizeof(VirtIOQueueDevice) + queue_size * sizeof(VirtIOQueueDeviceItem); - auto queue_region_size = page_round_up(size_of_descriptors + size_of_driver + size_of_device); + auto queue_region_size = Memory::page_round_up(size_of_descriptors + size_of_driver + size_of_device); if (queue_region_size <= PAGE_SIZE) - m_queue_region = MM.allocate_kernel_region(queue_region_size, "VirtIO Queue", Region::Access::Read | Region::Access::Write); + m_queue_region = MM.allocate_kernel_region(queue_region_size, "VirtIO Queue", Memory::Region::Access::Read | Memory::Region::Access::Write); else - m_queue_region = MM.allocate_contiguous_kernel_region(queue_region_size, "VirtIO Queue", Region::Access::Read | Region::Access::Write); + m_queue_region = MM.allocate_contiguous_kernel_region(queue_region_size, "VirtIO Queue", Memory::Region::Access::Read | Memory::Region::Access::Write); VERIFY(m_queue_region); // TODO: ensure alignment!!! u8* ptr = m_queue_region->vaddr().as_ptr(); diff --git a/Kernel/VirtIO/VirtIOQueue.h b/Kernel/VirtIO/VirtIOQueue.h index 41d742cbc9d..b081c531bcf 100644 --- a/Kernel/VirtIO/VirtIOQueue.h +++ b/Kernel/VirtIO/VirtIOQueue.h @@ -93,7 +93,7 @@ private: OwnPtr m_descriptors { nullptr }; OwnPtr m_driver { nullptr }; OwnPtr m_device { nullptr }; - OwnPtr m_queue_region; + OwnPtr m_queue_region; SpinLock m_lock; friend class VirtIOQueueChain; diff --git a/Kernel/VirtIO/VirtIORNG.cpp b/Kernel/VirtIO/VirtIORNG.cpp index 87e5df815fa..85094745af5 100644 --- a/Kernel/VirtIO/VirtIORNG.cpp +++ b/Kernel/VirtIO/VirtIORNG.cpp @@ -21,7 +21,7 @@ UNMAP_AFTER_INIT VirtIORNG::VirtIORNG(PCI::Address address) } if (success) { finish_init(); - m_entropy_buffer = MM.allocate_contiguous_kernel_region(PAGE_SIZE, "VirtIORNG", Region::Access::Read | Region::Access::Write); + m_entropy_buffer = MM.allocate_contiguous_kernel_region(PAGE_SIZE, "VirtIORNG", Memory::Region::Access::Read | Memory::Region::Access::Write); if (m_entropy_buffer) { memset(m_entropy_buffer->vaddr().as_ptr(), 0, m_entropy_buffer->size()); request_entropy_from_host(); diff --git a/Kernel/VirtIO/VirtIORNG.h b/Kernel/VirtIO/VirtIORNG.h index 74826606dbc..8a4cd931488 100644 --- a/Kernel/VirtIO/VirtIORNG.h +++ b/Kernel/VirtIO/VirtIORNG.h @@ -36,7 +36,7 @@ private: virtual void handle_queue_update(u16 queue_index) override; void request_entropy_from_host(); - OwnPtr m_entropy_buffer; + OwnPtr m_entropy_buffer; EntropySource m_entropy_source; }; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 34cf9e82d9f..b82540966f4 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -186,7 +186,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) s_bsp_processor.initialize(0); CommandLine::initialize(); - MemoryManager::initialize(0); + Memory::MemoryManager::initialize(0); // Ensure that the safemem sections are not empty. This could happen if the linker accidentally discards the sections. VERIFY(start_of_safemem_text != end_of_safemem_text); @@ -236,7 +236,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init_ap(FlatPtr cpu, Processor* pr processor_info->early_initialize(cpu); processor_info->initialize(cpu); - MemoryManager::initialize(cpu); + Memory::MemoryManager::initialize(cpu); Scheduler::set_idle_thread(APIC::the().get_idle_thread(cpu));