From b1058b33fb32cb398d1723eb6fe59c27dc7967cc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 8 Mar 2020 10:36:51 +0100 Subject: [PATCH] AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*) Use this instead of uintptr_t throughout the codebase. This makes it possible to pass a FlatPtr to something that has u32 and u64 overloads. --- AK/HashFunctions.h | 4 +-- AK/Types.h | 3 ++ DevTools/Inspector/RemoteObject.h | 4 +-- .../Inspector/RemoteObjectPropertyModel.cpp | 2 +- DevTools/Inspector/RemoteProcess.cpp | 10 +++--- DevTools/Inspector/RemoteProcess.h | 4 +-- DevTools/ProfileViewer/Profile.cpp | 8 ++--- DevTools/ProfileViewer/Profile.h | 2 +- Kernel/ACPI/ACPIStaticParser.cpp | 12 +++---- Kernel/ACPI/DMIDecoder.cpp | 8 ++--- Kernel/ACPI/MultiProcessorParser.cpp | 26 +++++++-------- Kernel/ACPI/MultiProcessorParser.h | 14 ++++---- Kernel/Arch/i386/CPU.h | 14 ++++---- Kernel/Heap/kmalloc.cpp | 2 +- Kernel/Net/E1000NetworkAdapter.cpp | 8 ++--- Kernel/Net/RTL8139NetworkAdapter.cpp | 6 ++-- Kernel/PerformanceEventBuffer.cpp | 12 +++---- Kernel/PerformanceEventBuffer.h | 8 ++--- Kernel/Process.cpp | 14 ++++---- Kernel/Process.h | 2 +- Kernel/Thread.cpp | 32 +++++++++---------- Kernel/Thread.h | 4 +-- Kernel/VM/MemoryManager.cpp | 20 ++++++------ Kernel/VM/PageDirectory.cpp | 12 +++---- Kernel/VM/PhysicalRegion.cpp | 4 +-- Kernel/VM/RangeAllocator.cpp | 4 +-- .../LibBareMetal/Memory/PhysicalAddress.h | 12 +++---- .../LibBareMetal/Memory/VirtualAddress.h | 14 ++++---- Libraries/LibC/malloc.cpp | 8 ++--- Libraries/LibC/serenity.cpp | 2 +- Libraries/LibCore/EventLoop.cpp | 8 ++--- Libraries/LibCore/Object.cpp | 4 +-- Libraries/LibELF/ELFDynamicObject.h | 20 ++++++------ Libraries/LibGUI/CppSyntaxHighlighter.cpp | 4 +-- Libraries/LibGUI/Layout.cpp | 2 +- Userland/syscall.cpp | 12 +++---- 36 files changed, 164 insertions(+), 161 deletions(-) diff --git a/AK/HashFunctions.h b/AK/HashFunctions.h index 458bad796c1..ffa21a0190d 100644 --- a/AK/HashFunctions.h +++ b/AK/HashFunctions.h @@ -51,7 +51,7 @@ inline unsigned u64_hash(u64 key) return pair_int_hash(first, last); } -inline unsigned ptr_hash(uintptr_t ptr) +inline unsigned ptr_hash(FlatPtr ptr) { if constexpr(sizeof(ptr) == 8) return u64_hash((u64)ptr); @@ -61,5 +61,5 @@ inline unsigned ptr_hash(uintptr_t ptr) inline unsigned ptr_hash(const void* ptr) { - return ptr_hash((uintptr_t)(ptr)); + return ptr_hash((FlatPtr)(ptr)); } diff --git a/AK/Types.h b/AK/Types.h index ce9e0f651ff..aab08774e5e 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -28,6 +28,7 @@ #include #include +#include #ifdef __serenity__ typedef unsigned char u8; @@ -89,6 +90,8 @@ typedef __PTRDIFF_TYPE__ __ptrdiff_t; #endif +typedef Conditional::Type FlatPtr; + constexpr unsigned KB = 1024; constexpr unsigned MB = KB * KB; constexpr unsigned GB = KB * KB * KB; diff --git a/DevTools/Inspector/RemoteObject.h b/DevTools/Inspector/RemoteObject.h index b8d5d680ca9..89c0e93f218 100644 --- a/DevTools/Inspector/RemoteObject.h +++ b/DevTools/Inspector/RemoteObject.h @@ -42,8 +42,8 @@ public: RemoteObject* parent { nullptr }; NonnullOwnPtrVector children; - uintptr_t address { 0 }; - uintptr_t parent_address { 0 }; + FlatPtr address { 0 }; + FlatPtr parent_address { 0 }; String class_name; String name; diff --git a/DevTools/Inspector/RemoteObjectPropertyModel.cpp b/DevTools/Inspector/RemoteObjectPropertyModel.cpp index c4e69a16f36..adb650235d2 100644 --- a/DevTools/Inspector/RemoteObjectPropertyModel.cpp +++ b/DevTools/Inspector/RemoteObjectPropertyModel.cpp @@ -75,7 +75,7 @@ void RemoteObjectPropertyModel::update() void RemoteObjectPropertyModel::set_data(const GUI::ModelIndex& index, const GUI::Variant& new_value) { auto& property = m_properties[index.row()]; - uintptr_t address = m_object.address; + FlatPtr address = m_object.address; RemoteProcess::the().set_property(address, property.name.to_string(), new_value.to_string()); property.value = new_value.to_string(); did_update(); diff --git a/DevTools/Inspector/RemoteProcess.cpp b/DevTools/Inspector/RemoteProcess.cpp index 9f3adab9a77..4c642ee45e5 100644 --- a/DevTools/Inspector/RemoteProcess.cpp +++ b/DevTools/Inspector/RemoteProcess.cpp @@ -65,14 +65,14 @@ void RemoteProcess::handle_get_all_objects_response(const JsonObject& response) auto& object_array = objects.as_array(); NonnullOwnPtrVector remote_objects; - HashMap objects_by_address; + HashMap objects_by_address; for (auto& value : object_array.values()) { ASSERT(value.is_object()); auto& object = value.as_object(); auto remote_object = make(); - remote_object->address = object.get("address").to_number(); - remote_object->parent_address = object.get("parent").to_number(); + remote_object->address = object.get("address").to_number(); + remote_object->parent_address = object.get("parent").to_number(); remote_object->name = object.get("name").to_string(); remote_object->class_name = object.get("class_name").to_string(); remote_object->json = object; @@ -105,7 +105,7 @@ void RemoteProcess::send_request(const JsonObject& request) m_socket->write(serialized); } -void RemoteProcess::set_inspected_object(uintptr_t address) +void RemoteProcess::set_inspected_object(FlatPtr address) { JsonObject request; request.set("type", "SetInspectedObject"); @@ -113,7 +113,7 @@ void RemoteProcess::set_inspected_object(uintptr_t address) send_request(request); } -void RemoteProcess::set_property(uintptr_t object, const StringView& name, const JsonValue& value) +void RemoteProcess::set_property(FlatPtr object, const StringView& name, const JsonValue& value) { JsonObject request; request.set("type", "SetProperty"); diff --git a/DevTools/Inspector/RemoteProcess.h b/DevTools/Inspector/RemoteProcess.h index 6e22e2444ac..d81ad4d9a3c 100644 --- a/DevTools/Inspector/RemoteProcess.h +++ b/DevTools/Inspector/RemoteProcess.h @@ -45,9 +45,9 @@ public: RemoteObjectGraphModel& object_graph_model() { return *m_object_graph_model; } const NonnullOwnPtrVector& roots() const { return m_roots; } - void set_inspected_object(uintptr_t); + void set_inspected_object(FlatPtr); - void set_property(uintptr_t object, const StringView& name, const JsonValue& value); + void set_property(FlatPtr object, const StringView& name, const JsonValue& value); Function on_update; diff --git a/DevTools/ProfileViewer/Profile.cpp b/DevTools/ProfileViewer/Profile.cpp index e4984b7babe..3e913a8eaef 100644 --- a/DevTools/ProfileViewer/Profile.cpp +++ b/DevTools/ProfileViewer/Profile.cpp @@ -84,7 +84,7 @@ void Profile::rebuild_tree() return new_root; }; - HashTable live_allocations; + HashTable live_allocations; for (auto& event : m_events) { if (has_timestamp_filter_range()) { @@ -207,10 +207,10 @@ OwnPtr Profile::load_from_perfcore_file(const StringView& path) event.type = perf_event.get("type").to_string(); if (event.type == "malloc") { - event.ptr = perf_event.get("ptr").to_number(); + event.ptr = perf_event.get("ptr").to_number(); event.size = perf_event.get("size").to_number(); } else if (event.type == "free") { - event.ptr = perf_event.get("ptr").to_number(); + event.ptr = perf_event.get("ptr").to_number(); } auto stack_array = perf_event.get("stack").as_array(); @@ -239,7 +239,7 @@ OwnPtr Profile::load_from_perfcore_file(const StringView& path) if (event.frames.size() < 2) continue; - uintptr_t innermost_frame_address = event.frames.at(1).address; + FlatPtr innermost_frame_address = event.frames.at(1).address; event.in_kernel = innermost_frame_address >= 0xc0000000; events.append(move(event)); diff --git a/DevTools/ProfileViewer/Profile.h b/DevTools/ProfileViewer/Profile.h index 3c509f463cb..04c96d9c569 100644 --- a/DevTools/ProfileViewer/Profile.h +++ b/DevTools/ProfileViewer/Profile.h @@ -120,7 +120,7 @@ public: struct Event { u64 timestamp { 0 }; String type; - uintptr_t ptr { 0 }; + FlatPtr ptr { 0 }; size_t size { 0 }; bool in_kernel { false }; Vector frames; diff --git a/Kernel/ACPI/ACPIStaticParser.cpp b/Kernel/ACPI/ACPIStaticParser.cpp index eb975185744..a55c16c7e00 100644 --- a/Kernel/ACPI/ACPIStaticParser.cpp +++ b/Kernel/ACPI/ACPIStaticParser.cpp @@ -247,7 +247,7 @@ namespace ACPI { dbg() << "ACPI: Looking for RSDP in EBDA @ V " << (void*)rsdp_str << ", P " << (void*)p_rsdp_str; #endif if (!strncmp("RSD PTR ", rsdp_str, strlen("RSD PTR "))) - return PhysicalAddress((uintptr_t)p_rsdp_str); + return PhysicalAddress((FlatPtr)p_rsdp_str); p_rsdp_str += 16; } return {}; @@ -262,7 +262,7 @@ namespace ACPI { dbg() << "ACPI: Looking for RSDP in BIOS ROM area @ V " << (void*)rsdp_str << ", P " << (void*)p_rsdp_str; #endif if (!strncmp("RSD PTR ", rsdp_str, strlen("RSD PTR "))) - return PhysicalAddress((uintptr_t)p_rsdp_str); + return PhysicalAddress((FlatPtr)p_rsdp_str); p_rsdp_str += 16; } return {}; @@ -320,8 +320,8 @@ namespace ACPI { auto main_sdt_region = MM.allocate_kernel_region(xsdt.page_base(), PAGE_SIZE, "ACPI Static Parsing search_table_in_xsdt()", Region::Access::Read, false, true); auto* xsdt_ptr = (volatile Structures::XSDT*)main_sdt_region->vaddr().offset(xsdt.offset_in_page().get()).as_ptr(); for (u32 i = 0; i < ((xsdt_ptr->h.length - sizeof(Structures::SDTHeader)) / sizeof(u64)); i++) { - if (match_table_signature(PhysicalAddress((uintptr_t)xsdt_ptr->table_ptrs[i]), signature)) - return PhysicalAddress((uintptr_t)xsdt_ptr->table_ptrs[i]); + if (match_table_signature(PhysicalAddress((FlatPtr)xsdt_ptr->table_ptrs[i]), signature)) + return PhysicalAddress((FlatPtr)xsdt_ptr->table_ptrs[i]); } return {}; } @@ -347,8 +347,8 @@ namespace ACPI { auto* rsdt_ptr = (volatile Structures::RSDT*)main_sdt_region->vaddr().offset(rsdt.offset_in_page().get()).as_ptr(); for (u32 i = 0; i < ((rsdt_ptr->h.length - sizeof(Structures::SDTHeader)) / sizeof(u32)); i++) { - if (match_table_signature(PhysicalAddress((uintptr_t)rsdt_ptr->table_ptrs[i]), signature)) - return PhysicalAddress((uintptr_t)rsdt_ptr->table_ptrs[i]); + if (match_table_signature(PhysicalAddress((FlatPtr)rsdt_ptr->table_ptrs[i]), signature)) + return PhysicalAddress((FlatPtr)rsdt_ptr->table_ptrs[i]); } return {}; } diff --git a/Kernel/ACPI/DMIDecoder.cpp b/Kernel/ACPI/DMIDecoder.cpp index 0c2ee75b6c2..9b6e3e23589 100644 --- a/Kernel/ACPI/DMIDecoder.cpp +++ b/Kernel/ACPI/DMIDecoder.cpp @@ -134,7 +134,7 @@ void DMIDecoder::enumerate_smbios_tables() size_t table_size = get_table_size(p_table); p_table = p_table.offset(table_size); - v_table_ptr = (SMBIOS::TableHeader*)((uintptr_t)v_table_ptr + table_size); + v_table_ptr = (SMBIOS::TableHeader*)((FlatPtr)v_table_ptr + table_size); #ifdef SMBIOS_DEBUG dbg() << "DMIDecoder: Next table @ P 0x" << p_table.get(); #endif @@ -221,7 +221,7 @@ PhysicalAddress DMIDecoder::find_entry64bit_point() dbg() << "DMI Decoder: Looking for 64 bit Entry point @ V " << (void*)entry_str << " P " << (void*)tested_physical_ptr; #endif if (!strncmp("_SM3_", entry_str, strlen("_SM3_"))) - return PhysicalAddress((uintptr_t)tested_physical_ptr); + return PhysicalAddress((FlatPtr)tested_physical_ptr); tested_physical_ptr += 16; } @@ -239,7 +239,7 @@ PhysicalAddress DMIDecoder::find_entry32bit_point() dbg() << "DMI Decoder: Looking for 32 bit Entry point @ V " << (void*)entry_str << " P " << (void*)tested_physical_ptr; #endif if (!strncmp("_SM_", entry_str, strlen("_SM_"))) - return PhysicalAddress((uintptr_t)tested_physical_ptr); + return PhysicalAddress((FlatPtr)tested_physical_ptr); tested_physical_ptr += 16; } @@ -264,7 +264,7 @@ u64 DMIDecoder::get_bios_characteristics() auto* bios_info = (SMBIOS::BIOSInfo*)get_smbios_physical_table_by_type(0).as_ptr(); ASSERT(bios_info != nullptr); - klog() << "DMIDecoder: BIOS info @ " << PhysicalAddress((uintptr_t)bios_info); + klog() << "DMIDecoder: BIOS info @ " << PhysicalAddress((FlatPtr)bios_info); return bios_info->bios_characteristics; } diff --git a/Kernel/ACPI/MultiProcessorParser.cpp b/Kernel/ACPI/MultiProcessorParser.cpp index 6e46ecbe041..0b405b95b1b 100644 --- a/Kernel/ACPI/MultiProcessorParser.cpp +++ b/Kernel/ACPI/MultiProcessorParser.cpp @@ -45,9 +45,9 @@ void MultiProcessorParser::initialize() MultiProcessorParser::MultiProcessorParser() : m_floating_pointer(search_floating_pointer()) - , m_operable((m_floating_pointer != (uintptr_t) nullptr)) + , m_operable((m_floating_pointer != (FlatPtr) nullptr)) { - if (m_floating_pointer != (uintptr_t) nullptr) { + if (m_floating_pointer != (FlatPtr) nullptr) { klog() << "MultiProcessor: Floating Pointer Structure @ " << PhysicalAddress(m_floating_pointer); parse_floating_pointer_data(); parse_configuration_table(); @@ -89,7 +89,7 @@ void MultiProcessorParser::parse_configuration_table() p_entry = (MultiProcessor::EntryHeader*)(u32)p_entry + (u8)MultiProcessor::ConfigurationTableEntryLength::Processor; break; case ((u8)MultiProcessor::ConfigurationTableEntryType::Bus): - m_bus_entries.append((uintptr_t)p_entry); + m_bus_entries.append((FlatPtr)p_entry); entry = (MultiProcessor::EntryHeader*)(u32)entry + (u8)MultiProcessor::ConfigurationTableEntryLength::Bus; p_entry = (MultiProcessor::EntryHeader*)(u32)p_entry + (u8)MultiProcessor::ConfigurationTableEntryLength::Bus; break; @@ -98,7 +98,7 @@ void MultiProcessorParser::parse_configuration_table() p_entry = (MultiProcessor::EntryHeader*)(u32)p_entry + (u8)MultiProcessor::ConfigurationTableEntryLength::IOAPIC; break; case ((u8)MultiProcessor::ConfigurationTableEntryType::IO_Interrupt_Assignment): - m_io_interrupt_redirection_entries.append((uintptr_t)p_entry); + m_io_interrupt_redirection_entries.append((FlatPtr)p_entry); entry = (MultiProcessor::EntryHeader*)(u32)entry + (u8)MultiProcessor::ConfigurationTableEntryLength::IO_Interrupt_Assignment; p_entry = (MultiProcessor::EntryHeader*)(u32)p_entry + (u8)MultiProcessor::ConfigurationTableEntryLength::IO_Interrupt_Assignment; break; @@ -124,20 +124,20 @@ void MultiProcessorParser::parse_configuration_table() } } -uintptr_t MultiProcessorParser::search_floating_pointer() +FlatPtr MultiProcessorParser::search_floating_pointer() { - uintptr_t mp_floating_pointer = (uintptr_t) nullptr; + FlatPtr mp_floating_pointer = (FlatPtr) nullptr; auto region = MM.allocate_kernel_region(PhysicalAddress(0), PAGE_SIZE, "MultiProcessor Parser Floating Pointer Structure Finding", Region::Access::Read); u16 ebda_seg = (u16) * ((uint16_t*)((region->vaddr().get() & PAGE_MASK) + 0x40e)); klog() << "MultiProcessor: Probing EBDA, Segment 0x" << String::format("%x", ebda_seg); mp_floating_pointer = search_floating_pointer_in_ebda(ebda_seg); - if (mp_floating_pointer != (uintptr_t) nullptr) + if (mp_floating_pointer != (FlatPtr) nullptr) return mp_floating_pointer; return search_floating_pointer_in_bios_area(); } -uintptr_t MultiProcessorParser::search_floating_pointer_in_ebda(u16 ebda_segment) +FlatPtr MultiProcessorParser::search_floating_pointer_in_ebda(u16 ebda_segment) { auto floating_pointer_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)(ebda_segment << 4))), PAGE_ROUND_UP(1024), "MultiProcessor Parser floating_pointer Finding #1", Region::Access::Read, false, true); char* p_floating_pointer_str = (char*)(PhysicalAddress(ebda_segment << 4).as_ptr()); @@ -146,12 +146,12 @@ uintptr_t MultiProcessorParser::search_floating_pointer_in_ebda(u16 ebda_segment dbg() << "MultiProcessor: Looking for floating pointer structure in EBDA @ V0x " << String::format("%x", floating_pointer_str) << ", P0x" << String::format("%x", p_floating_pointer_str); #endif if (!strncmp("_MP_", floating_pointer_str, strlen("_MP_"))) - return (uintptr_t)p_floating_pointer_str; + return (FlatPtr)p_floating_pointer_str; p_floating_pointer_str += 16; } - return (uintptr_t) nullptr; + return (FlatPtr) nullptr; } -uintptr_t MultiProcessorParser::search_floating_pointer_in_bios_area() +FlatPtr MultiProcessorParser::search_floating_pointer_in_bios_area() { auto floating_pointer_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)0xE0000)), PAGE_ROUND_UP(0xFFFFF - 0xE0000), "MultiProcessor Parser floating_pointer Finding #2", Region::Access::Read, false, true); char* p_floating_pointer_str = (char*)(PhysicalAddress(0xE0000).as_ptr()); @@ -160,10 +160,10 @@ uintptr_t MultiProcessorParser::search_floating_pointer_in_bios_area() dbg() << "MultiProcessor: Looking for floating pointer structure in BIOS area @ V0x " << String::format("%x", floating_pointer_str) << ", P0x" << String::format("%x", p_floating_pointer_str); #endif if (!strncmp("_MP_", floating_pointer_str, strlen("_MP_"))) - return (uintptr_t)p_floating_pointer_str; + return (FlatPtr)p_floating_pointer_str; p_floating_pointer_str += 16; } - return (uintptr_t) nullptr; + return (FlatPtr) nullptr; } Vector MultiProcessorParser::get_pci_bus_ids() diff --git a/Kernel/ACPI/MultiProcessorParser.h b/Kernel/ACPI/MultiProcessorParser.h index 21b031d12c8..1d035f749d2 100644 --- a/Kernel/ACPI/MultiProcessorParser.h +++ b/Kernel/ACPI/MultiProcessorParser.h @@ -225,14 +225,14 @@ protected: Vector get_pci_bus_ids(); - uintptr_t search_floating_pointer(); - uintptr_t search_floating_pointer_in_ebda(u16 ebda_segment); - uintptr_t search_floating_pointer_in_bios_area(); + FlatPtr search_floating_pointer(); + FlatPtr search_floating_pointer_in_ebda(u16 ebda_segment); + FlatPtr search_floating_pointer_in_bios_area(); - uintptr_t m_floating_pointer; - uintptr_t m_configuration_table; - Vector m_io_interrupt_redirection_entries; - Vector m_bus_entries; + FlatPtr m_floating_pointer; + FlatPtr m_configuration_table; + Vector m_io_interrupt_redirection_entries; + Vector m_bus_entries; bool m_operable; size_t m_configuration_table_length; diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index c9f59e3e40d..80a08ebd795 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -33,7 +33,7 @@ #define PAGE_SIZE 4096 #define GENERIC_INTERRUPT_HANDLERS_COUNT 128 -#define PAGE_MASK ((uintptr_t)0xfffff000u) +#define PAGE_MASK ((FlatPtr)0xfffff000u) namespace Kernel { @@ -451,24 +451,24 @@ struct [[gnu::aligned(16)]] FPUState u8 buffer[512]; }; -inline constexpr uintptr_t page_base_of(uintptr_t address) +inline constexpr FlatPtr page_base_of(FlatPtr address) { return address & PAGE_MASK; } -inline uintptr_t page_base_of(const void* address) +inline FlatPtr page_base_of(const void* address) { - return page_base_of((uintptr_t)address); + return page_base_of((FlatPtr)address); } -inline constexpr uintptr_t offset_in_page(uintptr_t address) +inline constexpr FlatPtr offset_in_page(FlatPtr address) { return address & (~PAGE_MASK); } -inline uintptr_t offset_in_page(const void* address) +inline FlatPtr offset_in_page(const void* address) { - return offset_in_page((uintptr_t)address); + return offset_in_page((FlatPtr)address); } u32 read_cr3(); diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp index f068a389121..4b5358d80ee 100644 --- a/Kernel/Heap/kmalloc.cpp +++ b/Kernel/Heap/kmalloc.cpp @@ -188,7 +188,7 @@ void kfree(void* ptr) ++g_kfree_call_count; auto* a = (AllocationHeader*)((((u8*)ptr) - sizeof(AllocationHeader))); - uintptr_t start = ((uintptr_t)a - (uintptr_t)BASE_PHYSICAL) / CHUNK_SIZE; + FlatPtr start = ((FlatPtr)a - (FlatPtr)BASE_PHYSICAL) / CHUNK_SIZE; for (size_t k = start; k < (start + a->allocation_size_in_chunks); ++k) alloc_map[k / 8] &= ~(1 << (k % 8)); diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index 156df22c831..c89186630b3 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -250,14 +250,14 @@ bool E1000NetworkAdapter::link_up() void E1000NetworkAdapter::initialize_rx_descriptors() { - auto ptr = (uintptr_t)kmalloc_eternal(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16); + auto ptr = (FlatPtr)kmalloc_eternal(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16); // Make sure it's 16-byte aligned. if (ptr % 16) ptr = (ptr + 16) - (ptr % 16); m_rx_descriptors = (e1000_rx_desc*)ptr; for (int i = 0; i < number_of_rx_descriptors; ++i) { auto& descriptor = m_rx_descriptors[i]; - auto addr = (uintptr_t)kmalloc_eternal(8192 + 16); + auto addr = (FlatPtr)kmalloc_eternal(8192 + 16); if (addr % 16) addr = (addr + 16) - (addr % 16); descriptor.addr = addr - 0xc0000000; @@ -275,14 +275,14 @@ void E1000NetworkAdapter::initialize_rx_descriptors() void E1000NetworkAdapter::initialize_tx_descriptors() { - auto ptr = (uintptr_t)kmalloc_eternal(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16); + auto ptr = (FlatPtr)kmalloc_eternal(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16); // Make sure it's 16-byte aligned. if (ptr % 16) ptr = (ptr + 16) - (ptr % 16); m_tx_descriptors = (e1000_tx_desc*)ptr; for (int i = 0; i < number_of_tx_descriptors; ++i) { auto& descriptor = m_tx_descriptors[i]; - auto addr = (uintptr_t)kmalloc_eternal(8192 + 16); + auto addr = (FlatPtr)kmalloc_eternal(8192 + 16); if (addr % 16) addr = (addr + 16) - (addr % 16); descriptor.addr = addr - 0xc0000000; diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp index 0a3bdd06218..83b48929a4a 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.cpp +++ b/Kernel/Net/RTL8139NetworkAdapter.cpp @@ -154,16 +154,16 @@ RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq) // we add space to account for overhang from the last packet - the rtl8139 // can optionally guarantee that packets will be contiguous by // purposefully overrunning the rx buffer - m_rx_buffer_addr = (uintptr_t)virtual_to_low_physical(kmalloc_aligned(RX_BUFFER_SIZE + PACKET_SIZE_MAX, 16)); + m_rx_buffer_addr = (FlatPtr)virtual_to_low_physical(kmalloc_aligned(RX_BUFFER_SIZE + PACKET_SIZE_MAX, 16)); klog() << "RTL8139: RX buffer: " << PhysicalAddress(m_rx_buffer_addr); - auto tx_buffer_addr = (uintptr_t)virtual_to_low_physical(kmalloc_aligned(TX_BUFFER_SIZE * 4, 16)); + auto tx_buffer_addr = (FlatPtr)virtual_to_low_physical(kmalloc_aligned(TX_BUFFER_SIZE * 4, 16)); for (int i = 0; i < RTL8139_TX_BUFFER_COUNT; i++) { m_tx_buffer_addr[i] = tx_buffer_addr + TX_BUFFER_SIZE * i; klog() << "RTL8139: TX buffer " << i << ": " << PhysicalAddress(m_tx_buffer_addr[i]); } - m_packet_buffer = (uintptr_t)kmalloc(PACKET_SIZE_MAX); + m_packet_buffer = (FlatPtr)kmalloc(PACKET_SIZE_MAX); reset(); diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 2a83f45a3e5..857ed8d7f70 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -37,7 +37,7 @@ PerformanceEventBuffer::PerformanceEventBuffer() { } -KResult PerformanceEventBuffer::append(int type, uintptr_t arg1, uintptr_t arg2) +KResult PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2) { if (count() >= capacity()) return KResult(-ENOBUFS); @@ -63,17 +63,17 @@ KResult PerformanceEventBuffer::append(int type, uintptr_t arg1, uintptr_t arg2) return KResult(-EINVAL); } - uintptr_t ebp; + FlatPtr ebp; asm volatile("movl %%ebp, %%eax" : "=a"(ebp)); - //copy_from_user(&ebp, (uintptr_t*)current->get_register_dump_from_stack().ebp); - Vector backtrace; + //copy_from_user(&ebp, (FlatPtr*)current->get_register_dump_from_stack().ebp); + Vector backtrace; { SmapDisabler disabler; backtrace = Thread::current->raw_backtrace(ebp); } - event.stack_size = min(sizeof(event.stack) / sizeof(uintptr_t), static_cast(backtrace.size())); - memcpy(event.stack, backtrace.data(), event.stack_size * sizeof(uintptr_t)); + event.stack_size = min(sizeof(event.stack) / sizeof(FlatPtr), static_cast(backtrace.size())); + memcpy(event.stack, backtrace.data(), event.stack_size * sizeof(FlatPtr)); #ifdef VERY_DEBUG for (size_t i = 0; i < event.stack_size; ++i) diff --git a/Kernel/PerformanceEventBuffer.h b/Kernel/PerformanceEventBuffer.h index 5e5f15ff4e7..f83d6f361be 100644 --- a/Kernel/PerformanceEventBuffer.h +++ b/Kernel/PerformanceEventBuffer.h @@ -34,13 +34,13 @@ namespace Kernel { struct [[gnu::packed]] MallocPerformanceEvent { size_t size; - uintptr_t ptr; + FlatPtr ptr; }; struct [[gnu::packed]] FreePerformanceEvent { size_t size; - uintptr_t ptr; + FlatPtr ptr; }; struct [[gnu::packed]] PerformanceEvent @@ -52,14 +52,14 @@ struct [[gnu::packed]] PerformanceEvent MallocPerformanceEvent malloc; FreePerformanceEvent free; } data; - uintptr_t stack[32]; + FlatPtr stack[32]; }; class PerformanceEventBuffer { public: PerformanceEventBuffer(); - KResult append(int type, uintptr_t arg1, uintptr_t arg2); + KResult append(int type, FlatPtr arg1, FlatPtr arg2); size_t capacity() const { return m_buffer.size() / sizeof(PerformanceEvent); } size_t count() const { return m_count; } diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 98e17eeca0d..eb156b07317 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -393,7 +393,7 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* user_params) if (size == 0) return (void*)-EINVAL; - if ((uintptr_t)addr & ~PAGE_MASK) + if ((FlatPtr)addr & ~PAGE_MASK) return (void*)-EINVAL; bool map_shared = flags & MAP_SHARED; @@ -1324,7 +1324,7 @@ Process* Process::create_user_process(Thread*& first_thread, const String& path, Process* Process::create_kernel_process(Thread*& first_thread, String&& name, void (*e)()) { auto* process = new Process(first_thread, move(name), (uid_t)0, (gid_t)0, (pid_t)0, Ring0); - first_thread->tss().eip = (uintptr_t)e; + first_thread->tss().eip = (FlatPtr)e; if (process->pid() != 0) { InterruptDisabler disabler; @@ -1474,7 +1474,7 @@ int Process::sys$sigreturn(RegisterState& registers) stack_ptr++; //pop edi, esi, ebp, esp, ebx, edx, ecx and eax - memcpy(®isters.edi, stack_ptr, 8 * sizeof(uintptr_t)); + memcpy(®isters.edi, stack_ptr, 8 * sizeof(FlatPtr)); stack_ptr += 8; registers.eip = *stack_ptr; @@ -3740,13 +3740,13 @@ int Process::sys$create_thread(void* (*entry)(void*), void* argument, const Sysc thread->set_joinable(is_thread_joinable); auto& tss = thread->tss(); - tss.eip = (uintptr_t)entry; + tss.eip = (FlatPtr)entry; tss.eflags = 0x0202; tss.cr3 = page_directory().cr3(); tss.esp = user_stack_address; // NOTE: The stack needs to be 16-byte aligned. - thread->push_value_on_stack((uintptr_t)argument); + thread->push_value_on_stack((FlatPtr)argument); thread->push_value_on_stack(0); thread->make_thread_specific_region({}); @@ -4531,7 +4531,7 @@ Thread& Process::any_thread() WaitQueue& Process::futex_queue(i32* userspace_address) { - auto& queue = m_futex_queues.ensure((uintptr_t)userspace_address); + auto& queue = m_futex_queues.ensure((FlatPtr)userspace_address); if (!queue) queue = make(); return *queue; @@ -4793,7 +4793,7 @@ int Process::sys$unveil(const Syscall::SC_unveil_params* user_params) return 0; } -int Process::sys$perf_event(int type, uintptr_t arg1, uintptr_t arg2) +int Process::sys$perf_event(int type, FlatPtr arg1, FlatPtr arg2) { if (!m_perf_event_buffer) m_perf_event_buffer = make(); diff --git a/Kernel/Process.h b/Kernel/Process.h index 3aa698cf8ec..b050c1cf28f 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -297,7 +297,7 @@ public: int sys$chroot(const char* path, size_t path_length, int mount_flags); int sys$pledge(const Syscall::SC_pledge_params*); int sys$unveil(const Syscall::SC_unveil_params*); - int sys$perf_event(int type, uintptr_t arg1, uintptr_t arg2); + int sys$perf_event(int type, FlatPtr arg1, FlatPtr arg2); template int get_sock_or_peer_name(const Params&); diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 10d880c331d..4379cad7460 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -625,10 +625,10 @@ void Thread::set_default_signal_dispositions() m_signal_action_data[SIGWINCH].handler_or_sigaction = VirtualAddress(SIG_IGN); } -void Thread::push_value_on_stack(uintptr_t value) +void Thread::push_value_on_stack(FlatPtr value) { m_tss.esp -= 4; - uintptr_t* stack_ptr = (uintptr_t*)m_tss.esp; + FlatPtr* stack_ptr = (FlatPtr*)m_tss.esp; copy_to_user(stack_ptr, &value); } @@ -681,9 +681,9 @@ u32 Thread::make_userspace_stack_for_main_thread(Vector arguments, Vecto }; // NOTE: The stack needs to be 16-byte aligned. - push_on_new_stack((uintptr_t)env); - push_on_new_stack((uintptr_t)argv); - push_on_new_stack((uintptr_t)argc); + push_on_new_stack((FlatPtr)env); + push_on_new_stack((FlatPtr)argv); + push_on_new_stack((FlatPtr)argc); push_on_new_stack(0); return new_esp; } @@ -797,20 +797,20 @@ String Thread::backtrace_impl() const auto elf_bundle = process.elf_bundle(); ProcessPagingScope paging_scope(process); - uintptr_t stack_ptr = start_frame; + FlatPtr stack_ptr = start_frame; for (;;) { if (!process.validate_read_from_kernel(VirtualAddress(stack_ptr), sizeof(void*) * 2)) break; - uintptr_t retaddr; + FlatPtr retaddr; - if (is_user_range(VirtualAddress(stack_ptr), sizeof(uintptr_t) * 2)) { - copy_from_user(&retaddr, &((uintptr_t*)stack_ptr)[1]); + if (is_user_range(VirtualAddress(stack_ptr), sizeof(FlatPtr) * 2)) { + copy_from_user(&retaddr, &((FlatPtr*)stack_ptr)[1]); recognized_symbols.append({ retaddr, ksymbolicate(retaddr) }); - copy_from_user(&stack_ptr, (uintptr_t*)stack_ptr); + copy_from_user(&stack_ptr, (FlatPtr*)stack_ptr); } else { - memcpy(&retaddr, &((uintptr_t*)stack_ptr)[1], sizeof(uintptr_t)); + memcpy(&retaddr, &((FlatPtr*)stack_ptr)[1], sizeof(FlatPtr)); recognized_symbols.append({ retaddr, ksymbolicate(retaddr) }); - memcpy(&stack_ptr, (uintptr_t*)stack_ptr, sizeof(uintptr_t)); + memcpy(&stack_ptr, (FlatPtr*)stack_ptr, sizeof(FlatPtr)); } } @@ -822,15 +822,15 @@ String Thread::backtrace_impl() const return builder.to_string(); } -Vector Thread::raw_backtrace(uintptr_t ebp) const +Vector Thread::raw_backtrace(FlatPtr ebp) const { InterruptDisabler disabler; auto& process = const_cast(this->process()); ProcessPagingScope paging_scope(process); - Vector backtrace; + Vector backtrace; backtrace.append(ebp); - for (uintptr_t* stack_ptr = (uintptr_t*)ebp; process.validate_read_from_kernel(VirtualAddress(stack_ptr), sizeof(uintptr_t) * 2) && MM.can_read_without_faulting(process, VirtualAddress(stack_ptr), sizeof(uintptr_t) * 2); stack_ptr = (uintptr_t*)*stack_ptr) { - uintptr_t retaddr = stack_ptr[1]; + for (FlatPtr* stack_ptr = (FlatPtr*)ebp; process.validate_read_from_kernel(VirtualAddress(stack_ptr), sizeof(FlatPtr) * 2) && MM.can_read_without_faulting(process, VirtualAddress(stack_ptr), sizeof(FlatPtr) * 2); stack_ptr = (FlatPtr*)*stack_ptr) { + FlatPtr retaddr = stack_ptr[1]; backtrace.append(retaddr); if (backtrace.size() == Profiling::max_stack_frame_count) break; diff --git a/Kernel/Thread.h b/Kernel/Thread.h index f59aeee95b0..1d0e9e0e50e 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -97,7 +97,7 @@ public: const Process& process() const { return m_process; } String backtrace(ProcessInspectionHandle&) const; - Vector raw_backtrace(uintptr_t ebp) const; + Vector raw_backtrace(FlatPtr ebp) const; const String& name() const { return m_name; } void set_name(StringView s) { m_name = s; } @@ -360,7 +360,7 @@ public: FPUState& fpu_state() { return *m_fpu_state; } void set_default_signal_dispositions(); - void push_value_on_stack(uintptr_t); + void push_value_on_stack(FlatPtr); u32 make_userspace_stack_for_main_thread(Vector arguments, Vector environment); diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 10cdbfca85c..fbfe47a6a95 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -41,9 +41,9 @@ //#define MM_DEBUG //#define PAGE_FAULT_DEBUG -extern uintptr_t start_of_kernel_text; -extern uintptr_t start_of_kernel_data; -extern uintptr_t end_of_kernel_bss; +extern FlatPtr start_of_kernel_text; +extern FlatPtr start_of_kernel_data; +extern FlatPtr end_of_kernel_bss; namespace Kernel { @@ -72,14 +72,14 @@ MemoryManager::~MemoryManager() void MemoryManager::protect_kernel_image() { // Disable writing to the kernel text and rodata segments. - for (size_t i = (uintptr_t)&start_of_kernel_text; i < (uintptr_t)&start_of_kernel_data; i += PAGE_SIZE) { + for (size_t i = (FlatPtr)&start_of_kernel_text; i < (FlatPtr)&start_of_kernel_data; i += PAGE_SIZE) { auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i)); pte.set_writable(false); } if (g_cpu_supports_nx) { // Disable execution of the kernel data and bss segments. - for (size_t i = (uintptr_t)&start_of_kernel_data; i < (uintptr_t)&end_of_kernel_bss; i += PAGE_SIZE) { + for (size_t i = (FlatPtr)&start_of_kernel_data; i < (FlatPtr)&end_of_kernel_bss; i += PAGE_SIZE) { auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i)); pte.set_execute_disabled(true); } @@ -104,7 +104,7 @@ void MemoryManager::setup_low_identity_mapping() if (g_cpu_supports_nx) pde_zero.set_execute_disabled(true); - for (uintptr_t offset = (1 * MB); offset < (2 * MB); offset += PAGE_SIZE) { + for (FlatPtr offset = (1 * MB); offset < (2 * MB); offset += PAGE_SIZE) { auto& page_table_page = m_low_page_table; auto& pte = quickmap_pt(page_table_page->paddr())[offset / PAGE_SIZE]; pte.set_physical_page_base(offset); @@ -132,7 +132,7 @@ void MemoryManager::parse_memory_map() if ((mmap->addr + mmap->len) > 0xffffffff) continue; - auto diff = (uintptr_t)mmap->addr % PAGE_SIZE; + auto diff = (FlatPtr)mmap->addr % PAGE_SIZE; if (diff != 0) { klog() << "MM: got an unaligned region base from the bootloader; correcting " << String::format("%p", mmap->addr) << " by " << diff << " bytes"; diff = PAGE_SIZE - diff; @@ -149,7 +149,7 @@ void MemoryManager::parse_memory_map() } #ifdef MM_DEBUG - klog() << "MM: considering memory at " << String::format("%p", (uintptr_t)mmap->addr) << " - " << String::format("%p", (uintptr_t)(mmap->addr + mmap->len)); + klog() << "MM: considering memory at " << String::format("%p", (FlatPtr)mmap->addr) << " - " << String::format("%p", (FlatPtr)(mmap->addr + mmap->len)); #endif for (size_t page_base = mmap->addr; page_base < (mmap->addr + mmap->len); page_base += PAGE_SIZE) { @@ -196,7 +196,7 @@ const PageTableEntry* MemoryManager::pte(const PageDirectory& page_directory, Vi if (!pde.is_present()) return nullptr; - return &quickmap_pt(PhysicalAddress((uintptr_t)pde.page_table_base()))[page_table_index]; + return &quickmap_pt(PhysicalAddress((FlatPtr)pde.page_table_base()))[page_table_index]; } PageTableEntry& MemoryManager::ensure_pte(PageDirectory& page_directory, VirtualAddress vaddr) @@ -224,7 +224,7 @@ PageTableEntry& MemoryManager::ensure_pte(PageDirectory& page_directory, Virtual page_directory.m_physical_pages.set(page_directory_index, move(page_table)); } - return quickmap_pt(PhysicalAddress((uintptr_t)pde.page_table_base()))[page_table_index]; + return quickmap_pt(PhysicalAddress((FlatPtr)pde.page_table_base()))[page_table_index]; } void MemoryManager::initialize() diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index aff510ce72a..67a4f96ffab 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -32,9 +32,9 @@ namespace Kernel { -static const uintptr_t userspace_range_base = 0x00800000; -static const uintptr_t userspace_range_ceiling = 0xbe000000; -static const uintptr_t kernelspace_range_base = 0xc0800000; +static const FlatPtr userspace_range_base = 0x00800000; +static const FlatPtr userspace_range_ceiling = 0xbe000000; +static const FlatPtr kernelspace_range_base = 0xc0800000; static HashMap& cr3_map() { @@ -60,9 +60,9 @@ PageDirectory::PageDirectory() m_range_allocator.initialize_with_range(VirtualAddress(0xc0800000), 0x3f000000); // Adopt the page tables already set up by boot.S - PhysicalAddress boot_pdpt_paddr(virtual_to_low_physical((uintptr_t)boot_pdpt)); - PhysicalAddress boot_pd0_paddr(virtual_to_low_physical((uintptr_t)boot_pd0)); - PhysicalAddress boot_pd3_paddr(virtual_to_low_physical((uintptr_t)boot_pd3)); + PhysicalAddress boot_pdpt_paddr(virtual_to_low_physical((FlatPtr)boot_pdpt)); + PhysicalAddress boot_pd0_paddr(virtual_to_low_physical((FlatPtr)boot_pd0)); + PhysicalAddress boot_pd3_paddr(virtual_to_low_physical((FlatPtr)boot_pd3)); klog() << "MM: boot_pdpt @ " << boot_pdpt_paddr; klog() << "MM: boot_pd0 @ " << boot_pd0_paddr; klog() << "MM: boot_pd3 @ " << boot_pd3_paddr; diff --git a/Kernel/VM/PhysicalRegion.cpp b/Kernel/VM/PhysicalRegion.cpp index 558d8a51c48..1a0880bdffa 100644 --- a/Kernel/VM/PhysicalRegion.cpp +++ b/Kernel/VM/PhysicalRegion.cpp @@ -105,9 +105,9 @@ void PhysicalRegion::return_page_at(PhysicalAddress addr) ptrdiff_t local_offset = addr.get() - m_lower.get(); ASSERT(local_offset >= 0); - ASSERT((uintptr_t)local_offset < (uintptr_t)(m_pages * PAGE_SIZE)); + ASSERT((FlatPtr)local_offset < (FlatPtr)(m_pages * PAGE_SIZE)); - auto page = (uintptr_t)local_offset / PAGE_SIZE; + auto page = (FlatPtr)local_offset / PAGE_SIZE; if (page < m_last) m_last = page; diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp index 6ceee3ce688..62f2350ef9b 100644 --- a/Kernel/VM/RangeAllocator.cpp +++ b/Kernel/VM/RangeAllocator.cpp @@ -112,8 +112,8 @@ Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment) if (available_range.size() < (effective_size + alignment)) continue; - uintptr_t initial_base = available_range.base().offset(offset_from_effective_base).get(); - uintptr_t aligned_base = round_up_to_power_of_two(initial_base, alignment); + FlatPtr initial_base = available_range.base().offset(offset_from_effective_base).get(); + FlatPtr aligned_base = round_up_to_power_of_two(initial_base, alignment); Range allocated_range(VirtualAddress(aligned_base), size); if (available_range == allocated_range) { diff --git a/Libraries/LibBareMetal/Memory/PhysicalAddress.h b/Libraries/LibBareMetal/Memory/PhysicalAddress.h index 02594b3389b..e982cece9b0 100644 --- a/Libraries/LibBareMetal/Memory/PhysicalAddress.h +++ b/Libraries/LibBareMetal/Memory/PhysicalAddress.h @@ -32,15 +32,15 @@ class PhysicalAddress { public: PhysicalAddress() {} - explicit PhysicalAddress(uintptr_t address) + explicit PhysicalAddress(FlatPtr address) : m_address(address) { } - PhysicalAddress offset(uintptr_t o) const { return PhysicalAddress(m_address + o); } - uintptr_t get() const { return m_address; } - void set(uintptr_t address) { m_address = address; } - void mask(uintptr_t m) { m_address &= m; } + PhysicalAddress offset(FlatPtr o) const { return PhysicalAddress(m_address + o); } + FlatPtr get() const { return m_address; } + void set(FlatPtr address) { m_address = address; } + void mask(FlatPtr m) { m_address &= m; } bool is_null() const { return m_address == 0; } @@ -58,7 +58,7 @@ public: bool operator<=(const PhysicalAddress& other) const { return m_address <= other.m_address; } private: - uintptr_t m_address { 0 }; + FlatPtr m_address { 0 }; }; inline const LogStream& operator<<(const LogStream& stream, PhysicalAddress value) diff --git a/Libraries/LibBareMetal/Memory/VirtualAddress.h b/Libraries/LibBareMetal/Memory/VirtualAddress.h index 92dfb6698de..2c82cb0d401 100644 --- a/Libraries/LibBareMetal/Memory/VirtualAddress.h +++ b/Libraries/LibBareMetal/Memory/VirtualAddress.h @@ -32,23 +32,23 @@ class VirtualAddress { public: VirtualAddress() {} - explicit VirtualAddress(uintptr_t address) + explicit VirtualAddress(FlatPtr address) : m_address(address) { } explicit VirtualAddress(const void* address) - : m_address((uintptr_t)address) + : m_address((FlatPtr)address) { } bool is_null() const { return m_address == 0; } bool is_page_aligned() const { return (m_address & 0xfff) == 0; } - VirtualAddress offset(uintptr_t o) const { return VirtualAddress(m_address + o); } - uintptr_t get() const { return m_address; } - void set(uintptr_t address) { m_address = address; } - void mask(uintptr_t m) { m_address &= m; } + VirtualAddress offset(FlatPtr o) const { return VirtualAddress(m_address + o); } + FlatPtr get() const { return m_address; } + void set(FlatPtr address) { m_address = address; } + void mask(FlatPtr m) { m_address &= m; } bool operator<=(const VirtualAddress& other) const { return m_address <= other.m_address; } bool operator>=(const VirtualAddress& other) const { return m_address >= other.m_address; } @@ -63,7 +63,7 @@ public: VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); } private: - uintptr_t m_address { 0 }; + FlatPtr m_address { 0 }; }; inline VirtualAddress operator-(const VirtualAddress& a, const VirtualAddress& b) diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp index 86f6e8bf7ac..0c1ddd388bb 100644 --- a/Libraries/LibC/malloc.cpp +++ b/Libraries/LibC/malloc.cpp @@ -294,7 +294,7 @@ static void free_impl(void* ptr) LOCKER(malloc_lock()); - void* block_base = (void*)((uintptr_t)ptr & block_mask); + void* block_base = (void*)((FlatPtr)ptr & block_mask); size_t magic = *(size_t*)block_base; if (magic == MAGIC_BIGALLOC_HEADER) { @@ -372,14 +372,14 @@ void* malloc(size_t size) { void* ptr = malloc_impl(size); if (s_profiling) - perf_event(PERF_EVENT_MALLOC, size, reinterpret_cast(ptr)); + perf_event(PERF_EVENT_MALLOC, size, reinterpret_cast(ptr)); return ptr; } void free(void* ptr) { if (s_profiling) - perf_event(PERF_EVENT_FREE, reinterpret_cast(ptr), 0); + perf_event(PERF_EVENT_FREE, reinterpret_cast(ptr), 0); free_impl(ptr); } @@ -396,7 +396,7 @@ size_t malloc_size(void* ptr) if (!ptr) return 0; LOCKER(malloc_lock()); - void* page_base = (void*)((uintptr_t)ptr & block_mask); + void* page_base = (void*)((FlatPtr)ptr & block_mask); auto* header = (const CommonHeader*)page_base; auto size = header->m_size; if (header->m_magic == MAGIC_BIGALLOC_HEADER) diff --git a/Libraries/LibC/serenity.cpp b/Libraries/LibC/serenity.cpp index a75ab557917..ce665489b86 100644 --- a/Libraries/LibC/serenity.cpp +++ b/Libraries/LibC/serenity.cpp @@ -79,7 +79,7 @@ int purge(int mode) __RETURN_WITH_ERRNO(rc, rc, -1); } -int perf_event(int type, uintptr_t arg1, uintptr_t arg2) +int perf_event(int type, uintptr_t arg1, FlatPtr arg2) { int rc = syscall(SC_perf_event, type, arg1, arg2); __RETURN_WITH_ERRNO(rc, rc, -1); diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index 74532d6b44b..c79f73e7a42 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -164,9 +164,9 @@ public: } if (type == "SetInspectedObject") { - auto address = request.get("address").to_number(); + auto address = request.get("address").to_number(); for (auto& object : Object::all_objects()) { - if ((uintptr_t)&object == address) { + if ((FlatPtr)&object == address) { if (m_inspected_object) m_inspected_object->decrement_inspector_count({}); m_inspected_object = object.make_weak_ptr(); @@ -178,9 +178,9 @@ public: } if (type == "SetProperty") { - auto address = request.get("address").to_number(); + auto address = request.get("address").to_number(); for (auto& object : Object::all_objects()) { - if ((uintptr_t)&object == address) { + if ((FlatPtr)&object == address) { bool success = object.set_property(request.get("name").to_string(), request.get("value")); JsonObject response; response.set("type", "SetProperty"); diff --git a/Libraries/LibCore/Object.cpp b/Libraries/LibCore/Object.cpp index c503a23d028..1321230317d 100644 --- a/Libraries/LibCore/Object.cpp +++ b/Libraries/LibCore/Object.cpp @@ -168,9 +168,9 @@ void Object::deferred_invoke(Function invokee) void Object::save_to(JsonObject& json) { json.set("class_name", class_name()); - json.set("address", (uintptr_t)this); + json.set("address", (FlatPtr)this); json.set("name", name()); - json.set("parent", (uintptr_t)parent()); + json.set("parent", (FlatPtr)parent()); } bool Object::set_property(const StringView& name, const JsonValue& value) diff --git a/Libraries/LibELF/ELFDynamicObject.h b/Libraries/LibELF/ELFDynamicObject.h index 80eb9db281b..8618d721d0e 100644 --- a/Libraries/LibELF/ELFDynamicObject.h +++ b/Libraries/LibELF/ELFDynamicObject.h @@ -228,32 +228,32 @@ private: unsigned m_symbol_count { 0 }; // Begin Section information collected from DT_* entries - uintptr_t m_init_offset { 0 }; - uintptr_t m_fini_offset { 0 }; + FlatPtr m_init_offset { 0 }; + FlatPtr m_fini_offset { 0 }; - uintptr_t m_init_array_offset { 0 }; + FlatPtr m_init_array_offset { 0 }; size_t m_init_array_size { 0 }; - uintptr_t m_fini_array_offset { 0 }; + FlatPtr m_fini_array_offset { 0 }; size_t m_fini_array_size { 0 }; - uintptr_t m_hash_table_offset { 0 }; + FlatPtr m_hash_table_offset { 0 }; - uintptr_t m_string_table_offset { 0 }; + FlatPtr m_string_table_offset { 0 }; size_t m_size_of_string_table { 0 }; - uintptr_t m_symbol_table_offset { 0 }; + FlatPtr m_symbol_table_offset { 0 }; size_t m_size_of_symbol_table_entry { 0 }; Elf32_Sword m_procedure_linkage_table_relocation_type { -1 }; - uintptr_t m_plt_relocation_offset_location { 0 }; // offset of PLT relocations, at end of relocations + FlatPtr m_plt_relocation_offset_location { 0 }; // offset of PLT relocations, at end of relocations size_t m_size_of_plt_relocation_entry_list { 0 }; - uintptr_t m_procedure_linkage_table_offset { 0 }; + FlatPtr m_procedure_linkage_table_offset { 0 }; // NOTE: We'll only ever either RELA or REL entries, not both (thank god) // NOTE: The x86 ABI will only ever genrerate REL entries. size_t m_number_of_relocations { 0 }; size_t m_size_of_relocation_entry { 0 }; size_t m_size_of_relocation_table { 0 }; - uintptr_t m_relocation_table_offset { 0 }; + FlatPtr m_relocation_table_offset { 0 }; // DT_FLAGS Elf32_Word m_dt_flags { 0 }; diff --git a/Libraries/LibGUI/CppSyntaxHighlighter.cpp b/Libraries/LibGUI/CppSyntaxHighlighter.cpp index acee7903aa9..3f1d5c43404 100644 --- a/Libraries/LibGUI/CppSyntaxHighlighter.cpp +++ b/Libraries/LibGUI/CppSyntaxHighlighter.cpp @@ -77,7 +77,7 @@ void CppSyntaxHighlighter::highlight_matching_token_pair() bool forward = direction == Direction::Forward; for (forward ? ++i : --i; forward ? (i < document.spans().size()) : (i >= 0); forward ? ++i : --i) { auto& span = document.spans().at(i); - auto span_token_type = (CppToken::Type)((uintptr_t)span.data); + auto span_token_type = (CppToken::Type)((FlatPtr)span.data); if (span_token_type == not_type) { ++nesting_level; } else if (span_token_type == type) { @@ -116,7 +116,7 @@ void CppSyntaxHighlighter::highlight_matching_token_pair() for (size_t i = 0; i < document.spans().size(); ++i) { auto& span = const_cast(document.spans().at(i)); - auto token_type = (CppToken::Type)((uintptr_t)span.data); + auto token_type = (CppToken::Type)((FlatPtr)span.data); for (auto& pair : pairs) { if (token_type == pair.open && span.range.start() == m_editor->cursor()) { diff --git a/Libraries/LibGUI/Layout.cpp b/Libraries/LibGUI/Layout.cpp index 38be0a87e17..71c37e9369b 100644 --- a/Libraries/LibGUI/Layout.cpp +++ b/Libraries/LibGUI/Layout.cpp @@ -138,7 +138,7 @@ void Layout::save_to(JsonObject& json) JsonObject entry_object; if (entry.type == Entry::Type::Widget) { entry_object.set("type", "Widget"); - entry_object.set("widget", (uintptr_t)entry.widget.ptr()); + entry_object.set("widget", (FlatPtr)entry.widget.ptr()); } else if (entry.type == Entry::Type::Spacer) { entry_object.set("type", "Spacer"); } else { diff --git a/Userland/syscall.cpp b/Userland/syscall.cpp index 0ccb7edd496..1c826c2a529 100644 --- a/Userland/syscall.cpp +++ b/Userland/syscall.cpp @@ -46,10 +46,10 @@ Syscall::Function syscall_table[] = { ENUMERATE_SYSCALLS }; -uintptr_t arg[SC_NARG]; +FlatPtr arg[SC_NARG]; char buf[BUFSIZ]; -uintptr_t parse(char* s); +FlatPtr parse(char* s); int main(int argc, char** argv) { @@ -104,13 +104,13 @@ int main(int argc, char** argv) return -1; } -uintptr_t parse(char* s) +FlatPtr parse(char* s) { char* t; - uintptr_t l; + FlatPtr l; if (strcmp(s, "buf") == 0) { - return (uintptr_t)buf; + return (FlatPtr)buf; } l = strtoul(s, &t, 0); @@ -118,5 +118,5 @@ uintptr_t parse(char* s) return l; } - return (uintptr_t)s; + return (FlatPtr)s; }