diff --git a/AK/Vector.h b/AK/Vector.h index a4e66a3fd8e..0d529fd2b64 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -758,12 +758,12 @@ public: { MUST(try_grow_capacity(needed_capacity)); } -#endif void ensure_capacity(size_t needed_capacity) { MUST(try_ensure_capacity(needed_capacity)); } +#endif void shrink(size_t new_size, bool keep_capacity = false) { diff --git a/Kernel/Arch/x86_64/Interrupts/APIC.cpp b/Kernel/Arch/x86_64/Interrupts/APIC.cpp index 7508d2ad731..be84a4e8bd1 100644 --- a/Kernel/Arch/x86_64/Interrupts/APIC.cpp +++ b/Kernel/Arch/x86_64/Interrupts/APIC.cpp @@ -339,7 +339,7 @@ UNMAP_AFTER_INIT void APIC::setup_ap_boot_environment() memcpy(apic_startup_region_ptr, reinterpret_cast(apic_ap_start), apic_ap_start_size); // Allocate enough stacks for all APs - m_ap_temporary_boot_stacks.ensure_capacity(aps_to_enable); + m_ap_temporary_boot_stacks.try_ensure_capacity(aps_to_enable).release_value_but_fixme_should_propagate_errors(); for (u32 i = 0; i < aps_to_enable; i++) { auto stack_region_or_error = MM.allocate_kernel_region(Thread::default_kernel_stack_size, {}, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow); if (stack_region_or_error.is_error()) { diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp index b57539847e9..d42bfe51a8f 100644 --- a/Kernel/Bus/USB/UHCI/UHCIController.cpp +++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp @@ -343,7 +343,7 @@ ErrorOr UHCIController::initialize_device(USB::Device& device) // Fetch the configuration descriptors from the device auto& configurations = device.configurations({}); - configurations.ensure_capacity(dev_descriptor.num_configurations); + TRY(configurations.try_ensure_capacity(dev_descriptor.num_configurations)); for (u8 configuration = 0u; configuration < dev_descriptor.num_configurations; configuration++) { USBConfigurationDescriptor configuration_descriptor; transfer_length = TRY(device.control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor)); diff --git a/Kernel/Bus/USB/USBConfiguration.h b/Kernel/Bus/USB/USBConfiguration.h index 214ab91179d..954a1cea671 100644 --- a/Kernel/Bus/USB/USBConfiguration.h +++ b/Kernel/Bus/USB/USBConfiguration.h @@ -25,7 +25,7 @@ public: , m_descriptor(descriptor) , m_descriptor_index(descriptor_index) { - m_interfaces.ensure_capacity(descriptor.number_of_interfaces); + m_interfaces.try_ensure_capacity(descriptor.number_of_interfaces).release_value_but_fixme_should_propagate_errors(); } private: diff --git a/Kernel/Bus/USB/USBDevice.cpp b/Kernel/Bus/USB/USBDevice.cpp index de537f81fa6..22206559fd0 100644 --- a/Kernel/Bus/USB/USBDevice.cpp +++ b/Kernel/Bus/USB/USBDevice.cpp @@ -74,8 +74,7 @@ Device::Device(Device const& device) , m_controller(device.controller()) , m_hub(device.hub()) { - // FIXME: This can definitely OOM - m_configurations.ensure_capacity(device.configurations().size()); + m_configurations.try_ensure_capacity(device.configurations().size()).release_value_but_fixme_should_propagate_errors(); for (auto const& configuration : device.configurations()) { m_configurations.unchecked_append(configuration.copy()); m_configurations.last().set_device({}, *this); diff --git a/Kernel/Bus/USB/xHCI/xHCIController.cpp b/Kernel/Bus/USB/xHCI/xHCIController.cpp index 92957280a4a..5b77d31d7c2 100644 --- a/Kernel/Bus/USB/xHCI/xHCIController.cpp +++ b/Kernel/Bus/USB/xHCI/xHCIController.cpp @@ -715,7 +715,7 @@ ErrorOr xHCIController::initialize_device(USB::Device& device) // Fetch the configuration descriptors from the device auto& configurations = device.configurations({}); - configurations.ensure_capacity(dev_descriptor.num_configurations); + TRY(configurations.try_ensure_capacity(dev_descriptor.num_configurations)); for (u8 configuration = 0u; configuration < dev_descriptor.num_configurations; configuration++) { USBConfigurationDescriptor configuration_descriptor; transfer_length = TRY(device.control_transfer(USB_REQUEST_TRANSFER_DIRECTION_DEVICE_TO_HOST, USB_REQUEST_GET_DESCRIPTOR, (DESCRIPTOR_TYPE_CONFIGURATION << 8u) | configuration, 0, sizeof(USBConfigurationDescriptor), &configuration_descriptor)); diff --git a/Kernel/Devices/TTY/PTYMultiplexer.cpp b/Kernel/Devices/TTY/PTYMultiplexer.cpp index 492b3d3d660..b1266e13a3f 100644 --- a/Kernel/Devices/TTY/PTYMultiplexer.cpp +++ b/Kernel/Devices/TTY/PTYMultiplexer.cpp @@ -26,7 +26,7 @@ UNMAP_AFTER_INIT PTYMultiplexer::PTYMultiplexer() : CharacterDevice(MajorAllocation::CharacterDeviceFamily::Console, 2) { m_freelist.with([&](auto& freelist) { - freelist.ensure_capacity(max_pty_pairs); + freelist.try_ensure_capacity(max_pty_pairs).release_value_but_fixme_should_propagate_errors(); for (int i = max_pty_pairs; i > 0; --i) freelist.unchecked_append(i - 1); }); diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index c1c44e05ab5..18063c86da0 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -256,7 +256,7 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() { // Register used memory regions that we know of. m_global_data.with([this](auto& global_data) { - global_data.used_memory_ranges.ensure_capacity(4); + global_data.used_memory_ranges.try_ensure_capacity(4).release_value_but_fixme_should_propagate_errors(); #if ARCH(X86_64) // NOTE: We don't touch the first 1 MiB of RAM on x86-64 even if it's usable as indicated // by a certain memory map. There are 2 reasons for this: @@ -640,7 +640,7 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map_fdt(MemoryManager::GlobalD VERIFY(state.address_cells); VERIFY(state.size_cells); - state.reg.ensure_capacity(data.size() / ((state.address_cells + state.size_cells) * sizeof(u32))); + state.reg.try_ensure_capacity(data.size() / ((state.address_cells + state.size_cells) * sizeof(u32))).release_value_but_fixme_should_propagate_errors(); FixedMemoryStream reg_stream { data }; diff --git a/Kernel/Memory/PhysicalRegion.cpp b/Kernel/Memory/PhysicalRegion.cpp index cb5fc93f89a..3c3f22903f9 100644 --- a/Kernel/Memory/PhysicalRegion.cpp +++ b/Kernel/Memory/PhysicalRegion.cpp @@ -96,10 +96,10 @@ Vector> PhysicalRegion::take_contiguous_free_page return {}; Vector> physical_pages; - physical_pages.ensure_capacity(count); + physical_pages.try_ensure_capacity(count).release_value_but_fixme_should_propagate_errors(); for (size_t i = 0; i < count; ++i) - physical_pages.try_append(PhysicalRAMPage::create(page_base.value().offset(i * PAGE_SIZE))).release_value_but_fixme_should_propagate_errors(); + physical_pages.unchecked_append(PhysicalRAMPage::create(page_base.value().offset(i * PAGE_SIZE))); return physical_pages; } diff --git a/Kernel/Tasks/Thread.h b/Kernel/Tasks/Thread.h index 4b091c01290..4bf9bd92c3c 100644 --- a/Kernel/Tasks/Thread.h +++ b/Kernel/Tasks/Thread.h @@ -394,7 +394,7 @@ public: VERIFY(move_count > 0); Vector taken_blockers; - taken_blockers.ensure_capacity(move_count); + taken_blockers.try_ensure_capacity(move_count).release_value_but_fixme_should_propagate_errors(); for (size_t i = 0; i < move_count; i++) taken_blockers.unchecked_append(m_blockers.take(i)); m_blockers.remove(0, move_count); @@ -409,7 +409,7 @@ public: m_blockers = move(blockers_to_append); return; } - m_blockers.ensure_capacity(m_blockers.size() + blockers_to_append.size()); + m_blockers.try_ensure_capacity(m_blockers.size() + blockers_to_append.size()).release_value_but_fixme_should_propagate_errors(); for (size_t i = 0; i < blockers_to_append.size(); i++) m_blockers.unchecked_append(blockers_to_append.take(i)); blockers_to_append.clear();