From 84eb264786914d9b9d62df6a6884fa828e408b54 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 6 Apr 2025 17:25:15 +0200 Subject: [PATCH] util/attempt.h: mark 'Attempt' types as nodiscard This catches bugs early on. E.g., when leaving an 'Allocation' unused, it gets immediately deallocated, which is most probably not intended. For regular 'Attempt' objects, this change encourages the proper propagation of errors, or at least the logging of unexpected conditions. Fixes #5513 --- repos/base-fiasco/src/core/platform.cc | 32 ++++++++---- .../src/core/spec/x86/platform_x86.cc | 7 ++- repos/base-foc/src/core/platform.cc | 33 ++++++++---- repos/base-foc/src/core/rpc_cap_factory.cc | 3 +- repos/base-foc/src/core/spec/x86/platform.cc | 3 +- .../base-foc/src/core/vm_session_component.cc | 4 +- repos/base-hw/src/bootstrap/platform.cc | 14 +++-- repos/base-hw/src/core/guest_memory.h | 3 +- repos/base-hw/src/core/platform.cc | 27 +++++++--- .../spec/x86_64/platform_support_common.cc | 3 +- repos/base-linux/src/core/platform.cc | 3 +- .../src/lib/base/attach_stack_area.cc | 5 +- .../src/lib/base/region_map_mmap.cc | 16 +++--- repos/base-nova/src/core/platform.cc | 52 +++++++++++-------- .../src/core/vm_session_component.cc | 4 +- repos/base-okl4/src/core/platform.cc | 22 ++++---- repos/base-pistachio/src/core/platform.cc | 34 ++++++++---- .../src/core/spec/x86/platform_x86.cc | 3 +- repos/base-sel4/src/core/platform.cc | 45 ++++++++++------ repos/base-sel4/src/core/spec/arm/platform.cc | 5 +- .../src/core/spec/x86/vm_session_component.cc | 4 +- .../src/core/spec/x86_64/platform.cc | 8 +-- repos/base/include/util/attempt.h | 12 ++--- repos/base/src/core/region_map_component.cc | 3 +- .../base/internal/attached_stack_area.h | 5 +- repos/base/src/lib/base/allocator_avl.cc | 3 +- repos/base/src/lib/base/heap.cc | 3 +- repos/base/src/lib/base/thread.cc | 5 +- repos/base/src/lib/ldso/include/file.h | 3 +- repos/base/src/lib/ldso/include/region_map.h | 3 +- repos/base/src/lib/ldso/main.cc | 3 +- repos/base/src/test/ds_ownership/main.cc | 3 +- repos/base/src/test/rm_nested/main.cc | 6 ++- repos/base/src/test/sub_rm/main.cc | 17 ++++-- repos/base/src/test/token/main.cc | 6 ++- .../dde_ipxe/src/lib/dde_ipxe/dde_support.cc | 2 +- repos/dde_linux/src/lib/lx_kit/memory.cc | 3 +- .../src/app/trace_recorder/pcapng/backend.cc | 2 +- repos/libports/src/lib/libc/libc_mem_alloc.cc | 3 +- repos/libports/src/lib/libdrm/ioctl_iris.cc | 3 +- repos/libports/src/lib/libdrm/ioctl_lima.cc | 3 +- repos/os/include/os/packet_stream.h | 8 +-- repos/os/src/app/trace_logger/main.cc | 4 +- repos/os/src/driver/acpi/memory.h | 10 ++-- repos/os/src/driver/platform/dma_allocator.cc | 6 ++- repos/os/src/server/cpu_balancer/trace.h | 8 +-- repos/os/src/server/vmm/config.h | 7 ++- .../pc/expanding_page_table_allocator.h | 4 +- repos/ports/src/virtualbox6/sup_gmm.cc | 3 +- 49 files changed, 300 insertions(+), 168 deletions(-) diff --git a/repos/base-fiasco/src/core/platform.cc b/repos/base-fiasco/src/core/platform.cc index 75434a71b4..0c36da34b4 100644 --- a/repos/base-fiasco/src/core/platform.cc +++ b/repos/base-fiasco/src/core/platform.cc @@ -192,6 +192,11 @@ struct Region { return (((base + size) > start) && (base < end)); } + + void print(Output &out) const + { + Genode::print(out, Hex_range(start, end - start)); + } }; @@ -204,7 +209,8 @@ static inline void add_region(Region r, Range_allocator &alloc) addr_t start = trunc_page(r.start); addr_t end = round_page(r.end); - alloc.add_range(start, end - start); + if (alloc.add_range(start, end - start).failed()) + warning("unable to add range to allocator: ", r); } @@ -217,7 +223,8 @@ static inline void remove_region(Region r, Range_allocator &alloc) addr_t start = trunc_page(r.start); addr_t end = round_page(r.end); - alloc.remove_range(start, end - start); + if (alloc.remove_range(start, end - start).failed()) + warning("unable to exclude range from allocator: ", r); } @@ -297,7 +304,8 @@ void Core::Platform::_setup_mem_alloc() void Core::Platform::_setup_irq_alloc() { - _irq_alloc.add_range(0, 0x10); + if (_irq_alloc.add_range(0, 0x10).failed()) + warning("unable to initialize IRQ allocator"); } @@ -371,15 +379,17 @@ void Core::Platform::_setup_basics() /* configure applicable address space but never use page0 */ _vm_size = _vm_start == 0 ? _vm_size - L4_PAGESIZE : _vm_size; _vm_start = _vm_start == 0 ? L4_PAGESIZE : _vm_start; - _region_alloc.add_range(_vm_start, _vm_size); + if (_region_alloc.add_range(_vm_start, _vm_size).failed()) + warning("unable to initialize core's virtual-memory allocator"); /* preserve stack area in core's virtual address space */ - _region_alloc.remove_range(stack_area_virtual_base(), - stack_area_virtual_size()); + if (_region_alloc.remove_range(stack_area_virtual_base(), + stack_area_virtual_size()).failed()) + warning("unable to mark stack-area as used virtual memory"); /* I/O memory could be the whole user address space */ - /* FIXME if the kernel helps to find out max address - use info here */ - _io_mem_alloc.add_range(0, ~0); + if (_io_mem_alloc.add_range(0, ~0).failed()) + warning("unable to initialize I/O-memory allocator"); /* remove KIP area from region and IO_MEM allocator */ remove_region(Region((addr_t)kip, (addr_t)kip + L4_PAGESIZE), _region_alloc); @@ -450,7 +460,11 @@ Core::Platform::Platform() addr_t const phys_addr = reinterpret_cast(phys.ptr); void * const core_local_ptr = phys.ptr; - region_alloc().remove_range((addr_t)core_local_ptr, size); + if (region_alloc().remove_range((addr_t)core_local_ptr, size).failed()) { + warning("unable to mark ROM-module range for '", + rom_name, "' as used virtual memory"); + return; + } memset(core_local_ptr, 0, size); content_fn(core_local_ptr, size); diff --git a/repos/base-fiasco/src/core/spec/x86/platform_x86.cc b/repos/base-fiasco/src/core/spec/x86/platform_x86.cc index b52e1d8699..14c633fa91 100644 --- a/repos/base-fiasco/src/core/spec/x86/platform_x86.cc +++ b/repos/base-fiasco/src/core/spec/x86/platform_x86.cc @@ -46,9 +46,8 @@ void Platform::_setup_io_port_alloc() && fp.iofp.f == 0xf /* got IO ports */ && fp.iofp.iosize == L4_WHOLE_IOADDRESS_SPACE && fp.iofp.iopage == 0)) /* got whole IO space */ + panic("Received no I/O ports from sigma0"); - panic("Received no I/O ports from sigma0"); - - /* setup allocator */ - _io_port_alloc.add_range(0, 0x10000); + if (_io_port_alloc.add_range(0, 0x10000).failed()) + warning("unable to initialize default I/O-port range"); } diff --git a/repos/base-foc/src/core/platform.cc b/repos/base-foc/src/core/platform.cc index 7b19c02d41..e1800022a4 100644 --- a/repos/base-foc/src/core/platform.cc +++ b/repos/base-foc/src/core/platform.cc @@ -188,6 +188,11 @@ struct Region { return (((base + size) > start) && (base < end)); } + + void print(Output &out) const + { + Genode::print(out, Hex_range(start, end - start)); + } }; @@ -200,7 +205,8 @@ static inline void add_region(Region r, Range_allocator &alloc) addr_t const start = trunc_page(r.start); addr_t const end = round_page(r.end); - alloc.add_range(start, end - start); + if (alloc.add_range(start, end - start).failed()) + warning("unable to add allocator region: ", r); } @@ -213,7 +219,8 @@ static inline void remove_region(Region r, Range_allocator &alloc) addr_t const start = trunc_page(r.start); addr_t const end = round_page(r.end); - alloc.remove_range(start, end - start); + if (alloc.remove_range(start, end - start).failed()) + warning("unable to exclude allocator region: ", r); } @@ -339,7 +346,8 @@ void Core::Platform::_setup_irq_alloc() if (l4_error(res)) panic("could not determine number of IRQs"); - _irq_alloc.add_range(0, info.nr_irqs); + if (_irq_alloc.add_range(0, info.nr_irqs).failed()) + warning("unable to initialize IRQ allocator"); } @@ -458,18 +466,22 @@ void Core::Platform::_setup_basics() _vm_start = VCPU_VIRT_EXT_END; } - _region_alloc.add_range(_vm_start, _vm_size); + if (_region_alloc.add_range(_vm_start, _vm_size).failed()) + warning("unable to initialize core's virtual memory"); /* preserve stack area in core's virtual address space */ - _region_alloc.remove_range(stack_area_virtual_base(), - stack_area_virtual_size()); + if (_region_alloc.remove_range(stack_area_virtual_base(), + stack_area_virtual_size()).failed()) + warning("unable to exclude stack area from core-local allocator"); /* preserve utcb- area in core's virtual address space */ - _region_alloc.remove_range((addr_t)l4_utcb(), L4_PAGESIZE * 16); + if (_region_alloc.remove_range((addr_t)l4_utcb(), L4_PAGESIZE * 16).failed()) + warning("unable to exclude UTCB area from core-local allocator"); /* I/O memory could be the whole user address space */ /* FIXME if the kernel helps to find out max address - use info here */ - _io_mem_alloc.add_range(0, ~0); + if (_io_mem_alloc.add_range(0, ~0).failed()) + warning("unable to initialize I/O-memory allocator"); /* remove KIP and MBI area from region and IO_MEM allocator */ remove_region(Region((addr_t)&kip, (addr_t)&kip + L4_PAGESIZE), _region_alloc); @@ -485,8 +497,9 @@ void Core::Platform::_setup_basics() add_region(Region(img_start, img_end), _core_address_ranges()); /* requested as I/O memory by the VESA driver and ACPI (rsdp search) */ - _io_mem_alloc.add_range (0, 0x2000); - ram_alloc() .remove_range(0, 0x2000); + if (_io_mem_alloc.add_range (0, 0x2000).failed() + || ram_alloc() .remove_range(0, 0x2000).failed()) + warning("unable to register RSDP as memory-mapped I/O range"); } diff --git a/repos/base-foc/src/core/rpc_cap_factory.cc b/repos/base-foc/src/core/rpc_cap_factory.cc index 1bc541a9f5..cdfd761043 100644 --- a/repos/base-foc/src/core/rpc_cap_factory.cc +++ b/repos/base-foc/src/core/rpc_cap_factory.cc @@ -190,7 +190,8 @@ Cap_id_allocator::Cap_id_allocator(Allocator &alloc) : _id_alloc(&alloc) { - _id_alloc.add_range(CAP_ID_OFFSET, unsigned(CAP_ID_RANGE) - unsigned(CAP_ID_OFFSET)); + (void)_id_alloc.add_range(CAP_ID_OFFSET, + unsigned(CAP_ID_RANGE) - unsigned(CAP_ID_OFFSET)); } diff --git a/repos/base-foc/src/core/spec/x86/platform.cc b/repos/base-foc/src/core/spec/x86/platform.cc index 935d8b571b..8ede17a451 100644 --- a/repos/base-foc/src/core/spec/x86/platform.cc +++ b/repos/base-foc/src/core/spec/x86/platform.cc @@ -45,7 +45,8 @@ void Platform::_setup_io_port_alloc() panic("Received no I/O ports from sigma0"); /* setup allocator */ - _io_port_alloc.add_range(0, 0x10000); + if (_io_port_alloc.add_range(0, 0x10000).failed()) + warning("unable to register default I/O-port range"); } diff --git a/repos/base-foc/src/core/vm_session_component.cc b/repos/base-foc/src/core/vm_session_component.cc index 46e1be3ef1..e6bdfd6867 100644 --- a/repos/base-foc/src/core/vm_session_component.cc +++ b/repos/base-foc/src/core/vm_session_component.cc @@ -113,8 +113,8 @@ Vm_session_component::Vm_session_component(Rpc_entrypoint &ep, } /* configure managed VM area */ - _map.add_range(0, 0UL - 0x1000); - _map.add_range(0UL - 0x1000, 0x1000); + (void)_map.add_range(0, 0UL - 0x1000); + (void)_map.add_range(0UL - 0x1000, 0x1000); caps.acknowledge(); } diff --git a/repos/base-hw/src/bootstrap/platform.cc b/repos/base-hw/src/bootstrap/platform.cc index 76f5019afa..d3d58ee450 100644 --- a/repos/base-hw/src/bootstrap/platform.cc +++ b/repos/base-hw/src/bootstrap/platform.cc @@ -45,12 +45,18 @@ void * Platform::Ram_allocator::alloc_aligned(size_t size, unsigned align) } -void Platform::Ram_allocator::add(Memory_region const & region) { - add_range(region.base, region.size); } +void Platform::Ram_allocator::add(Memory_region const & region) +{ + if (add_range(region.base, region.size).failed()) + Genode::warning("bootstrap failed to register RAM: ", region); +} -void Platform::Ram_allocator::remove(Memory_region const & region) { - remove_range(region.base, region.size); } +void Platform::Ram_allocator::remove(Memory_region const & region) +{ + if (remove_range(region.base, region.size).failed()) + Genode::warning("bootstrap unable to exclude RAM: ", region); +} /****************** diff --git a/repos/base-hw/src/core/guest_memory.h b/repos/base-hw/src/core/guest_memory.h index 8e4a416103..e824de612c 100644 --- a/repos/base-hw/src/core/guest_memory.h +++ b/repos/base-hw/src/core/guest_memory.h @@ -222,7 +222,8 @@ class Core::Guest_memory _sliced_heap(ram, region_map) { /* configure managed VM area */ - _map.add_range(0UL, ~0UL); + if (_map.add_range(0UL, ~0UL).failed()) + warning("unable to initialize guest-memory allocator"); } ~Guest_memory() diff --git a/repos/base-hw/src/core/platform.cc b/repos/base-hw/src/core/platform.cc index dcc2feec09..5474b1366a 100644 --- a/repos/base-hw/src/core/platform.cc +++ b/repos/base-hw/src/core/platform.cc @@ -75,9 +75,12 @@ addr_t Platform::core_main_thread_phys_utcb() void Platform::_init_io_mem_alloc() { /* add entire adress space minus the RAM memory regions */ - _io_mem_alloc.add_range(0, ~0x0UL); + if (_io_mem_alloc.add_range(0, ~0x0UL).failed()) + warning("unable to initialize I/O-memory allocator"); + _boot_info().ram_regions.for_each([this] (unsigned, Hw::Memory_region const &r) { - _io_mem_alloc.remove_range(r.base, r.size); }); + if (_io_mem_alloc.remove_range(r.base, r.size).failed()) + warning("unable to exclude I/O range from RAM: ", r); }); }; @@ -180,14 +183,21 @@ Platform::Platform() { struct Kernel_resource : Exception { }; - _core_mem_alloc.virt_alloc().add_range(Hw::Mm::core_heap().base, - Hw::Mm::core_heap().size); + if (_core_mem_alloc.virt_alloc().add_range(Hw::Mm::core_heap().base, + Hw::Mm::core_heap().size).failed()) + warning("unable to initialize core virtual-memory allocator"); + _core_virt_regions().for_each([this] (unsigned, Hw::Memory_region const & r) { - _core_mem_alloc.virt_alloc().remove_range(r.base, r.size); }); + if (_core_mem_alloc.virt_alloc().remove_range(r.base, r.size).failed()) + warning("unable to exclude core from core's virtual memory"); }); + _boot_info().elf_mappings.for_each([this] (unsigned, Hw::Mapping const & m) { - _core_mem_alloc.virt_alloc().remove_range(m.virt(), m.size()); }); + if (_core_mem_alloc.virt_alloc().remove_range(m.virt(), m.size()).failed()) + warning("unable to exclude ELF mapping from core's virtual memory"); }); + _boot_info().ram_regions.for_each([this] (unsigned, Hw::Memory_region const & region) { - _core_mem_alloc.phys_alloc().add_range(region.base, region.size); }); + if (_core_mem_alloc.phys_alloc().add_range(region.base, region.size).failed()) + warning("unable to register RAM region ", region); }); _init_io_port_alloc(); @@ -203,7 +213,8 @@ Platform::Platform() if (kernel_resource) { continue; } - _irq_alloc.add_range(i, 1); + if (_irq_alloc.add_range(i, 1).failed()) + warning("unable to register IRQ ", i); } _init_io_mem_alloc(); diff --git a/repos/base-hw/src/core/spec/x86_64/platform_support_common.cc b/repos/base-hw/src/core/spec/x86_64/platform_support_common.cc index 136459a4f9..8bdc941d3e 100644 --- a/repos/base-hw/src/core/spec/x86_64/platform_support_common.cc +++ b/repos/base-hw/src/core/spec/x86_64/platform_support_common.cc @@ -22,7 +22,8 @@ using namespace Core; void Platform::_init_io_port_alloc() { - _io_port_alloc.add_range(0, 0x10000); + if (_io_port_alloc.add_range(0, 0x10000).failed()) + warning("unable to register default I/O-port range"); } diff --git a/repos/base-linux/src/core/platform.cc b/repos/base-linux/src/core/platform.cc index 84b2055a7d..e99ab00548 100644 --- a/repos/base-linux/src/core/platform.cc +++ b/repos/base-linux/src/core/platform.cc @@ -111,7 +111,8 @@ Core::Platform::Platform() /* create resource directory under /tmp */ lx_mkdir(resource_path(), S_IRWXU); - _core_mem_alloc.add_range((addr_t)_core_mem, sizeof(_core_mem)); + if (_core_mem_alloc.add_range((addr_t)_core_mem, sizeof(_core_mem)).failed()) + warning("failed to initialize core memory allocator"); /* * Occupy the socket handle that will be used to propagate the parent diff --git a/repos/base-linux/src/lib/base/attach_stack_area.cc b/repos/base-linux/src/lib/base/attach_stack_area.cc index c8dd6ef6f9..96095000a3 100644 --- a/repos/base-linux/src/lib/base/attach_stack_area.cc +++ b/repos/base-linux/src/lib/base/attach_stack_area.cc @@ -23,14 +23,15 @@ using namespace Genode; void Platform::_attach_stack_area() { - pd._address_space.attach(pd._stack_area.dataspace(), Region_map::Attr { + if (pd._address_space.attach(pd._stack_area.dataspace(), Region_map::Attr { .size = stack_area_virtual_size(), .offset = { }, .use_at = true, .at = stack_area_virtual_base(), .executable = { }, .writeable = true - }); + }).failed()) + warning("unable to attach stack area to local address space"); env_stack_area_region_map = &pd._stack_area; env_stack_area_ram_allocator = &ram; diff --git a/repos/base-linux/src/lib/base/region_map_mmap.cc b/repos/base-linux/src/lib/base/region_map_mmap.cc index 80411fc1ef..e30a434559 100644 --- a/repos/base-linux/src/lib/base/region_map_mmap.cc +++ b/repos/base-linux/src/lib/base/region_map_mmap.cc @@ -260,9 +260,9 @@ Region_map_mmap::attach(Dataspace_capability ds, Attr const &attr) * argument as the region was reserved by a PROT_NONE mapping. */ if (_is_attached()) - _map_local(ds, region_size, attr.offset, - true, _base + attr.at, - attr.executable, true, attr.writeable); + if (_map_local(ds, region_size, attr.offset, true, _base + attr.at, + attr.executable, true, attr.writeable).failed()) + return Attach_error::REGION_CONFLICT; return Range { .start = attr.at, .num_bytes = region_size }; @@ -317,9 +317,10 @@ Region_map_mmap::attach(Dataspace_capability ds, Attr const &attr) * We have to enforce the mapping via the 'overmap' argument as * the region was reserved by a PROT_NONE mapping. */ - _map_local(region.dataspace(), region.size(), region.offset(), - true, rm->_base + region.start() + region.offset(), - attr.executable, true, attr.writeable); + if (_map_local(region.dataspace(), region.size(), region.offset(), + true, rm->_base + region.start() + region.offset(), + attr.executable, true, attr.writeable).failed()) + return Attach_error::REGION_CONFLICT; } return Range { .start = rm->_base, .num_bytes = region_size }; @@ -398,7 +399,8 @@ void Region_map_mmap::detach(addr_t at) */ if (_is_attached()) { lx_munmap((void *)(at + _base), region.size()); - _reserve_local(true, at + _base, region.size()); + if (_reserve_local(true, at + _base, region.size()).failed()) + warning(__PRETTY_FUNCTION__, ": _reserve_local unexpectedly failed"); } } else { diff --git a/repos/base-nova/src/core/platform.cc b/repos/base-nova/src/core/platform.cc index d6a1a9a32d..3612899175 100644 --- a/repos/base-nova/src/core/platform.cc +++ b/repos/base-nova/src/core/platform.cc @@ -405,7 +405,7 @@ Core::Platform::Platform() /* define core's virtual address space */ addr_t virt_beg = _vm_base; addr_t virt_end = _vm_size; - _core_mem_alloc.virt_alloc().add_range(virt_beg, virt_end - virt_beg); + (void)_core_mem_alloc.virt_alloc().add_range(virt_beg, virt_end - virt_beg); /* exclude core image from core's virtual address allocator */ addr_t const core_virt_beg = trunc_page((addr_t)&_prog_img_beg); @@ -414,29 +414,33 @@ Core::Platform::Platform() addr_t const binaries_end = round_page((addr_t)&_boot_modules_binaries_end); size_t const core_size = binaries_beg - core_virt_beg; - region_alloc().remove_range(core_virt_beg, core_size); + + auto exclude_from_core = [&] (addr_t start, size_t num_bytes) + { + if (region_alloc().remove_range(start, num_bytes).failed()) + warning("unable to exclude core-local range ", Hex_range(start, num_bytes)); + }; + + exclude_from_core(core_virt_beg, core_size); /* ROM modules are un-used by core - de-detach region */ addr_t const binaries_size = binaries_end - binaries_beg; unmap_local(*__main_thread_utcb, binaries_beg, binaries_size >> 12); /* preserve Bios Data Area (BDA) in core's virtual address space */ - region_alloc().remove_range(BDA_VIRT_ADDR, 0x1000); + exclude_from_core(BDA_VIRT_ADDR, 0x1000); /* preserve stack area in core's virtual address space */ - region_alloc().remove_range(stack_area_virtual_base(), - stack_area_virtual_size()); + exclude_from_core(stack_area_virtual_base(), stack_area_virtual_size()); /* exclude utcb of core pager thread + empty guard pages before and after */ - region_alloc().remove_range(CORE_PAGER_UTCB_ADDR - get_page_size(), - get_page_size() * 3); + exclude_from_core(CORE_PAGER_UTCB_ADDR - get_page_size(), get_page_size() * 3); /* exclude utcb of main thread and hip + empty guard pages before and after */ - region_alloc().remove_range((addr_t)__main_thread_utcb - get_page_size(), - get_page_size() * 4); + exclude_from_core((addr_t)__main_thread_utcb - get_page_size(), get_page_size() * 4); /* exclude HIP */ - region_alloc().remove_range(addr_t(&hip), _vm_base + _vm_size - addr_t(&hip)); + exclude_from_core(addr_t(&hip), _vm_base + _vm_size - addr_t(&hip)); /* sanity checks */ addr_t check [] = { @@ -458,7 +462,7 @@ Core::Platform::Platform() } /* initialize core's physical-memory and I/O memory allocator */ - _io_mem_alloc.add_range(0, ~0xfffUL); + (void)_io_mem_alloc.add_range(0, ~0xfffUL); Hip::Mem_desc *mem_desc = (Hip::Mem_desc *)mem_desc_base; Hip::Mem_desc *boot_fb = nullptr; @@ -495,10 +499,16 @@ Core::Platform::Platform() else size = trunc_page(mem_desc->addr + mem_desc->size) - base; - _io_mem_alloc.remove_range((addr_t)base, (size_t)size); - ram_alloc().add_range((addr_t)base, (size_t)size); + (void)_io_mem_alloc.remove_range((addr_t)base, (size_t)size); + (void)ram_alloc().add_range((addr_t)base, (size_t)size); } + auto exclude_from_ram = [&] (addr_t start, size_t num_bytes) + { + if (ram_alloc().remove_range(start, num_bytes).failed()) + warning("unable to exclude RAM range ", Hex_range(start, num_bytes)); + }; + addr_t hyp_log = 0; size_t hyp_log_size = 0; @@ -542,14 +552,14 @@ Core::Platform::Platform() /* make acpi regions as io_mem available to platform driver */ if (mem_desc->type == Hip::Mem_desc::ACPI_RECLAIM_MEMORY || mem_desc->type == Hip::Mem_desc::ACPI_NVS_MEMORY) - _io_mem_alloc.add_range((addr_t)base, (size_t)size); + (void)_io_mem_alloc.add_range((addr_t)base, (size_t)size); - ram_alloc().remove_range((addr_t)base, (size_t)size); + exclude_from_ram((addr_t)base, (size_t)size); } /* needed as I/O memory by the VESA driver */ - _io_mem_alloc.add_range(0, 0x1000); - ram_alloc().remove_range(0, 0x1000); + (void)_io_mem_alloc.add_range(0, 0x1000); + exclude_from_ram(0, 0x1000); /* exclude pages holding multi-boot command lines from core allocators */ mem_desc = (Hip::Mem_desc *)mem_desc_base; @@ -561,8 +571,8 @@ Core::Platform::Platform() curr_cmd_line_page = mem_desc->aux >> get_page_size_log2(); if (curr_cmd_line_page == prev_cmd_line_page) continue; - ram_alloc().remove_range(curr_cmd_line_page << get_page_size_log2(), - get_page_size() * 2); + exclude_from_ram(curr_cmd_line_page << get_page_size_log2(), + get_page_size() * 2); prev_cmd_line_page = curr_cmd_line_page; } @@ -804,10 +814,10 @@ Core::Platform::Platform() } /* I/O port allocator (only meaningful for x86) */ - _io_port_alloc.add_range(0, 0x10000); + (void)_io_port_alloc.add_range(0, 0x10000); /* IRQ allocator */ - _irq_alloc.add_range(0, hip.sel_gsi); + (void)_irq_alloc.add_range(0, hip.sel_gsi); _gsi_base_sel = (hip.mem_desc_offset - hip.cpu_desc_offset) / hip.cpu_desc_size; log(_rom_fs); diff --git a/repos/base-nova/src/core/vm_session_component.cc b/repos/base-nova/src/core/vm_session_component.cc index 9ca6467ffa..f7473a89a1 100644 --- a/repos/base-nova/src/core/vm_session_component.cc +++ b/repos/base-nova/src/core/vm_session_component.cc @@ -397,8 +397,8 @@ Vm_session_component::Vm_session_component(Rpc_entrypoint &ep, * Configure managed VM area. The two ranges work around the size * limitation to ULONG_MAX. */ - _map.add_range(0, 0UL - 0x1000); - _map.add_range(0UL - 0x1000, 0x1000); + (void)_map.add_range(0, 0UL - 0x1000); + (void)_map.add_range(0UL - 0x1000, 0x1000); } diff --git a/repos/base-okl4/src/core/platform.cc b/repos/base-okl4/src/core/platform.cc index 072b9999c6..61a30df437 100644 --- a/repos/base-okl4/src/core/platform.cc +++ b/repos/base-okl4/src/core/platform.cc @@ -56,8 +56,8 @@ int Core::Platform::bi_init_mem(Okl4::uintptr_t virt_base, Okl4::uintptr_t virt_ const Okl4::bi_user_data_t *data) { Platform &p = *(Platform *)data->user_data; - p._core_mem_alloc.phys_alloc().add_range(phys_base, phys_end - phys_base + 1); - p._core_mem_alloc.virt_alloc().add_range(virt_base, virt_end - virt_base + 1); + (void)p._core_mem_alloc.phys_alloc().add_range(phys_base, phys_end - phys_base + 1); + (void)p._core_mem_alloc.virt_alloc().add_range(virt_base, virt_end - virt_base + 1); return 0; } @@ -70,7 +70,7 @@ int Core::Platform::bi_add_virt_mem(Okl4::bi_name_t, Okl4::uintptr_t base, return 0; Platform &p = *(Platform *)data->user_data; - p._core_mem_alloc.virt_alloc().add_range(base, end - base + 1); + (void)p._core_mem_alloc.virt_alloc().add_range(base, end - base + 1); return 0; } @@ -80,7 +80,7 @@ int Core::Platform::bi_add_phys_mem(Okl4::bi_name_t pool, Okl4::uintptr_t base, { if (pool == 2) { Platform &p = *(Platform *)data->user_data; - p._core_mem_alloc.phys_alloc().add_range(base, end - base + 1); + (void)p._core_mem_alloc.phys_alloc().add_range(base, end - base + 1); } return 0; } @@ -149,19 +149,23 @@ Core::Platform::Platform() Okl4::bootinfo_parse((void *)boot_info_addr, &callbacks, this); /* initialize interrupt allocator */ - _irq_alloc.add_range(0, 0x10); + if (_irq_alloc.add_range(0, 0x10).failed()) + warning("unable to initialize IRQ allocator"); /* I/O memory could be the whole user address space */ - _io_mem_alloc.add_range(0, ~0); + if (_io_mem_alloc.add_range(0, ~0).failed()) + warning("unable to initialize I/O-memory allocator"); /* I/O port allocator (only meaningful for x86) */ - _io_port_alloc.add_range(0, 0x10000); + if (_io_port_alloc.add_range(0, 0x10000).failed()) + warning("unable to initialize I/O-port allocator"); _init_rom_modules(); /* preserve stack area in core's virtual address space */ - _core_mem_alloc.virt_alloc().remove_range(stack_area_virtual_base(), - stack_area_virtual_size()); + if (_core_mem_alloc.virt_alloc().remove_range(stack_area_virtual_base(), + stack_area_virtual_size()).failed()) + warning("unable to mark stack area as preserved virtual memory"); _vm_start = 0x1000; _vm_size = 0xc0000000 - _vm_start; diff --git a/repos/base-pistachio/src/core/platform.cc b/repos/base-pistachio/src/core/platform.cc index d79a948876..67d10c92ce 100644 --- a/repos/base-pistachio/src/core/platform.cc +++ b/repos/base-pistachio/src/core/platform.cc @@ -282,7 +282,8 @@ static inline void add_region(Region r, Range_allocator &alloc) addr_t start = trunc_page(r.start); addr_t end = round_page(r.end); - alloc.add_range(start, end - start); + if (alloc.add_range(start, end - start).failed()) + warning("failed to add range to allocator: ", r); } @@ -298,7 +299,8 @@ static inline void remove_region(Region r, Range_allocator &alloc) addr_t start = trunc_page(r.start); addr_t end = round_page(r.end); - alloc.remove_range(start, end - start); + if (alloc.remove_range(start, end - start).failed()) + warning("failed to exclude range from allocator: ", r); } @@ -451,7 +453,11 @@ void Core::Platform::_setup_mem_alloc() } -void Core::Platform::_setup_irq_alloc() { _irq_alloc.add_range(0, 0x10); } +void Core::Platform::_setup_irq_alloc() +{ + if (_irq_alloc.add_range(0, 0x10).failed()) + warning("unable to initialize IRQ allocator"); +} void Core::Platform::_setup_preemption() @@ -496,7 +502,8 @@ void Core::Platform::_setup_basics() Platform_pd::touch_utcb_space(); /* I/O memory could be the whole user address space */ - _io_mem_alloc.add_range(0, ~0); + if (_io_mem_alloc.add_range(0, ~0).failed()) + warning("unable to initialize I/O-memory allocator"); unsigned int kip_size = sizeof(L4_KernelInterfacePage_t); @@ -530,10 +537,15 @@ void Core::Platform::_setup_basics() } /* configure core's virtual memory, exclude KIP, stack area */ - _region_alloc.add_range(_vm_start, _vm_size); - _region_alloc.remove_range((addr_t)kip, kip_size); - _region_alloc.remove_range(stack_area_virtual_base(), - stack_area_virtual_size()); + if (_region_alloc.add_range(_vm_start, _vm_size).failed()) + warning("unable to initialize core's virtual-memory allocator"); + + if (_region_alloc.remove_range((addr_t)kip, kip_size).failed()) + warning("unable to mark KIP as preserved virtual memory"); + + if (_region_alloc.remove_range(stack_area_virtual_base(), + stack_area_virtual_size()).failed()) + warning("unable to mark stack area as preserved virtual memory"); /* remove KIP area from region and IO_MEM allocator */ remove_region(Region((addr_t)kip, (addr_t)kip + kip_size), _region_alloc); @@ -608,7 +620,11 @@ Core::Platform::Platform() addr_t const phys_addr = reinterpret_cast(phys.ptr); void * const core_local_ptr = phys.ptr; - region_alloc().remove_range((addr_t)core_local_ptr, size); + if (region_alloc().remove_range((addr_t)core_local_ptr, size).failed()) { + warning("unable to mark ROM-module range for '", + rom_name, "' as preserved virtual memory"); + return; + } memset(core_local_ptr, 0, size); content_fn(core_local_ptr, size); diff --git a/repos/base-pistachio/src/core/spec/x86/platform_x86.cc b/repos/base-pistachio/src/core/spec/x86/platform_x86.cc index d6ff5ef11d..020e98a7ca 100644 --- a/repos/base-pistachio/src/core/spec/x86/platform_x86.cc +++ b/repos/base-pistachio/src/core/spec/x86/platform_x86.cc @@ -26,5 +26,6 @@ void Platform::_setup_io_port_alloc() { /* setup allocator */ enum { IO_PORT_RANGE_SIZE = 0x10000 }; - _io_port_alloc.add_range(0, IO_PORT_RANGE_SIZE); + if (_io_port_alloc.add_range(0, IO_PORT_RANGE_SIZE).failed()) + warning("unable to initialize default I/O-port range"); } diff --git a/repos/base-sel4/src/core/platform.cc b/repos/base-sel4/src/core/platform.cc index d6449846eb..6c2ce7ec99 100644 --- a/repos/base-sel4/src/core/platform.cc +++ b/repos/base-sel4/src/core/platform.cc @@ -88,14 +88,16 @@ bool Mapped_mem_allocator::_unmap_local(addr_t virt_addr, addr_t phys_addr, size void Core::Platform::_init_unused_phys_alloc() { /* the lower physical ram is kept by the kernel and not usable to us */ - _unused_phys_alloc.add_range(0x100000, 0UL - 0x100000); + if (_unused_phys_alloc.add_range(0x100000, 0UL - 0x100000).failed()) + warning("unable to mark kernel-only memory as preserved"); } void Core::Platform::_init_allocators() { /* interrupt allocator */ - _irq_alloc.add_range(0, 256); + if (_irq_alloc.add_range(0, 256).failed()) + warning("unable to initialize IRQ allocator"); /* * XXX allocate intermediate CNodes for organizing the untyped pages here @@ -109,12 +111,17 @@ void Core::Platform::_init_allocators() addr_t const phys_addr = trunc_page(phys); size_t const phys_size = round_page(phys - phys_addr + size); - if (device_memory) - _io_mem_alloc.add_range(phys_addr, phys_size); - else - _core_mem_alloc.phys_alloc().add_range(phys_addr, phys_size); + Hex_range const range { phys_addr, phys_size }; - _unused_phys_alloc.remove_range(phys_addr, phys_size); + if (device_memory) { + if (_io_mem_alloc.add_range(phys_addr, phys_size).failed()) + warning("failed to register I/O range: ", range); + } else { + if (_core_mem_alloc.phys_alloc().add_range(phys_addr, phys_size).failed()) + warning("failed to register RAM range: ", range); + } + if (_unused_phys_alloc.remove_range(phys_addr, phys_size).failed()) + warning("failed to mark range as used: ", range); return true; /* range used by this functor */ }); @@ -125,7 +132,8 @@ void Core::Platform::_init_allocators() */ /* core's maximum virtual memory area */ - _unused_virt_alloc.add_range(_vm_base, _vm_size); + if (_unused_virt_alloc.add_range(_vm_base, _vm_size).failed()) + warning("unable to initialize core's virtual memory allocator"); /* remove core image from core's virtual address allocator */ addr_t const modules_start = reinterpret_cast(&_boot_modules_binaries_begin); @@ -133,23 +141,29 @@ void Core::Platform::_init_allocators() core_virt_end = round_page((addr_t)&_prog_img_end); addr_t const image_elf_size = core_virt_end - core_virt_beg; - _unused_virt_alloc.remove_range(core_virt_beg, image_elf_size); - _core_mem_alloc.virt_alloc().add_range(modules_start, core_virt_end - modules_start); + if (_unused_virt_alloc.remove_range(core_virt_beg, image_elf_size).failed()) + warning("unable to mark virtual range of core image as used"); + + if (_core_mem_alloc.virt_alloc() .add_range(modules_start, core_virt_end - modules_start).failed()) + warning("unable to register ROM-module range at core;s virtual memory"); /* remove initial IPC buffer from core's virtual address allocator */ seL4_BootInfo const &bi = sel4_boot_info(); addr_t const core_ipc_buffer = reinterpret_cast(bi.ipcBuffer); addr_t const core_ipc_bsize = 4096; - _unused_virt_alloc.remove_range(core_ipc_buffer, core_ipc_bsize); + if (_unused_virt_alloc.remove_range(core_ipc_buffer, core_ipc_bsize).failed()) + warning("unable to mark core's IPC buffer as preserved virtual memory"); /* remove sel4_boot_info page from core's virtual address allocator */ addr_t const boot_info_page = reinterpret_cast(&bi); addr_t const boot_info_size = 4096 + bi.extraLen; - _unused_virt_alloc.remove_range(boot_info_page, boot_info_size); + if (_unused_virt_alloc.remove_range(boot_info_page, boot_info_size).failed()) + warning("unable to mark seL4 boot-info page as preserved virtual memory"); /* preserve stack area in core's virtual address space */ - _unused_virt_alloc.remove_range(stack_area_virtual_base(), - stack_area_virtual_size()); + if (_unused_virt_alloc.remove_range(stack_area_virtual_base(), + stack_area_virtual_size()).failed()) + warning("unable to mark stack area as preserved virtual memory"); if (verbose_boot_info) { using Hex_range = Hex_range; @@ -590,7 +604,8 @@ Core::Platform::Platform() addr_t const virt_addr = (addr_t)virt.ptr; /* add to available virtual region of core */ - _core_mem_alloc.virt_alloc().add_range(virt_addr, virt_size); + if (_core_mem_alloc.virt_alloc().add_range(virt_addr, virt_size).failed()) + warning("unable to register virtual range for dynamic allocations"); /* back region by page tables */ _core_vm_space.unsynchronized_alloc_page_tables(virt_addr, virt_size); diff --git a/repos/base-sel4/src/core/spec/arm/platform.cc b/repos/base-sel4/src/core/spec/arm/platform.cc index a2caed4f52..de141b9e95 100644 --- a/repos/base-sel4/src/core/spec/arm/platform.cc +++ b/repos/base-sel4/src/core/spec/arm/platform.cc @@ -91,8 +91,9 @@ void Platform::_init_core_page_table_registry() if (device_memory) return false; - phys_alloc_16k().add_range(phys, size); - _unused_phys_alloc.remove_range(phys, size); + if (phys_alloc_16k() .add_range (phys, size).failed() + || _unused_phys_alloc.remove_range(phys, size).failed()) + warning("unable to register range as RAM: ", Hex_range(phys, size)); return true; }, diff --git a/repos/base-sel4/src/core/spec/x86/vm_session_component.cc b/repos/base-sel4/src/core/spec/x86/vm_session_component.cc index c80805824e..6f7d76ec7a 100644 --- a/repos/base-sel4/src/core/spec/x86/vm_session_component.cc +++ b/repos/base-sel4/src/core/spec/x86/vm_session_component.cc @@ -138,8 +138,8 @@ try } /* configure managed VM area */ - _map.add_range(0, 0UL - 0x1000); - _map.add_range(0UL - 0x1000, 0x1000); + (void)_map.add_range(0, 0UL - 0x1000); + (void)_map.add_range(0UL - 0x1000, 0x1000); caps.acknowledge(); ram.acknowledge(); diff --git a/repos/base-sel4/src/core/spec/x86_64/platform.cc b/repos/base-sel4/src/core/spec/x86_64/platform.cc index 1a2052b1d5..5cab6b65e8 100644 --- a/repos/base-sel4/src/core/spec/x86_64/platform.cc +++ b/repos/base-sel4/src/core/spec/x86_64/platform.cc @@ -87,8 +87,9 @@ void Platform::_init_core_page_table_registry() if (device_memory) return false; - phys_alloc_16k().add_range(phys, size); - _unused_phys_alloc.remove_range(phys, size); + if (phys_alloc_16k() .add_range (phys, size).failed() + || _unused_phys_alloc.remove_range(phys, size).failed()) + warning("unable to register range as RAM: ", Hex_range(phys, size)); return true; }, @@ -103,7 +104,8 @@ void Platform::_init_io_ports() enum { PORTS = 0x10000, PORT_FIRST = 0, PORT_LAST = PORTS - 1 }; /* I/O port allocator (only meaningful for x86) */ - _io_port_alloc.add_range(PORT_FIRST, PORTS); + if (_io_port_alloc.add_range(PORT_FIRST, PORTS).failed()) + warning("unable to register default I/O-port range"); /* create I/O port capability used by io_port_session_support.cc */ auto const root = _core_cnode.sel().value(); diff --git a/repos/base/include/util/attempt.h b/repos/base/include/util/attempt.h index 5f08a51ef2..789b1bdc92 100644 --- a/repos/base/include/util/attempt.h +++ b/repos/base/include/util/attempt.h @@ -17,8 +17,8 @@ #include namespace Genode { - template struct Attempt; - template struct Unique_attempt; + template struct [[nodiscard]] Attempt; + template struct [[nodiscard]] Unique_attempt; /** * Type used for results with no return value but error conditions @@ -86,8 +86,8 @@ class Genode::Attempt bool operator == (RESULT const &rhs) const { return ok() && (_result == rhs); } - bool ok() const { return _ok; } - bool failed() const { return !_ok; } + [[nodiscard]] bool ok() const { return _ok; } + [[nodiscard]] bool failed() const { return !_ok; } void print(Output &out) const { @@ -155,8 +155,8 @@ class Genode::Unique_attempt : Noncopyable bool operator == (ERROR const &rhs) const { return failed() && (_error == rhs); } - bool ok() const { return _result.constructed(); } - bool failed() const { return !_result.constructed(); } + [[nodiscard]] bool ok() const { return _result.constructed(); } + [[nodiscard]] bool failed() const { return !_result.constructed(); } void print(auto &out) const { diff --git a/repos/base/src/core/region_map_component.cc b/repos/base/src/core/region_map_component.cc index 1953663e4a..833d8380a3 100644 --- a/repos/base/src/core/region_map_component.cc +++ b/repos/base/src/core/region_map_component.cc @@ -538,7 +538,8 @@ Region_map_component::Region_map_component(Rpc_entrypoint &ep, _ds_cap(_type_deduction_helper(_ds_ep.manage(&_ds))) { /* configure managed VM area */ - _map.add_range(vm_start, align_addr(vm_size, get_page_size_log2())); + if (_map.add_range(vm_start, align_addr(vm_size, get_page_size_log2())).failed()) + warning("unable to initialize region-map allocator"); Capability cap = ep.manage(this); _ds.sub_rm(cap); diff --git a/repos/base/src/include/base/internal/attached_stack_area.h b/repos/base/src/include/base/internal/attached_stack_area.h index 5347485559..6befab5f41 100644 --- a/repos/base/src/include/base/internal/attached_stack_area.h +++ b/repos/base/src/include/base/internal/attached_stack_area.h @@ -35,14 +35,15 @@ struct Genode::Attached_stack_area : Expanding_region_map_client { Region_map_client local_rm(Pd_session_client(pd).address_space()); - local_rm.attach(Expanding_region_map_client::dataspace(), Region_map::Attr { + if (local_rm.attach(Expanding_region_map_client::dataspace(), Region_map::Attr { .size = stack_area_virtual_size(), .offset = { }, .use_at = true, .at = stack_area_virtual_base(), .executable = false, .writeable = true - }); + }).failed()) + warning("unable to attach stack area to local address space"); } }; diff --git a/repos/base/src/lib/base/allocator_avl.cc b/repos/base/src/lib/base/allocator_avl.cc index 5dd25548b0..655548cf1b 100644 --- a/repos/base/src/lib/base/allocator_avl.cc +++ b/repos/base/src/lib/base/allocator_avl.cc @@ -388,7 +388,8 @@ void Allocator_avl_base::free(void *addr) _destroy_block(*b); - add_range(new_addr, new_size); + add_range(new_addr, new_size).with_error([&] (Alloc_error e) { + error(__PRETTY_FUNCTION__, ": unable to release freed range: ", e); }); } diff --git a/repos/base/src/lib/base/heap.cc b/repos/base/src/lib/base/heap.cc index d42679b354..7a8ef35eca 100644 --- a/repos/base/src/lib/base/heap.cc +++ b/repos/base/src/lib/base/heap.cc @@ -328,7 +328,8 @@ Heap::Heap(Ram_allocator *ram_alloc, _chunk_size(MIN_CHUNK_SIZE) { if (static_addr) - _alloc->add_range((addr_t)static_addr, static_size); + if (_alloc->add_range((addr_t)static_addr, static_size).failed()) + warning("unable to add static range at heap-construction time"); } diff --git a/repos/base/src/lib/base/thread.cc b/repos/base/src/lib/base/thread.cc index 2d36d5229a..da75fc98ec 100644 --- a/repos/base/src/lib/base/thread.cc +++ b/repos/base/src/lib/base/thread.cc @@ -219,10 +219,7 @@ void Thread::free_secondary_stack(void* stack_addr) Thread::Stack_size_result Thread::stack_size(size_t const size) { return _stack.convert( - [&] (Stack *stack) { - stack->size(size); - return stack->top() - stack->base(); - }, + [&] (Stack *stack) { return stack->size(size); }, [&] (Stack_error e) { return e; }); } diff --git a/repos/base/src/lib/ldso/include/file.h b/repos/base/src/lib/ldso/include/file.h index 4949c268ff..66447189f2 100644 --- a/repos/base/src/lib/ldso/include/file.h +++ b/repos/base/src/lib/ldso/include/file.h @@ -130,7 +130,8 @@ struct Linker::Elf_file : File bool const binary = (start != 0); if (binary) { - Region_map::r()->alloc_region_at(size, start); + if (Region_map::r()->alloc_region_at(size, start).failed()) + warning("unable to allocate linker-area region for ", name);; reloc_base = 0; return; } diff --git a/repos/base/src/lib/ldso/include/region_map.h b/repos/base/src/lib/ldso/include/region_map.h index 8b95c479c5..67b74a2efd 100644 --- a/repos/base/src/lib/ldso/include/region_map.h +++ b/repos/base/src/lib/ldso/include/region_map.h @@ -62,7 +62,8 @@ class Linker::Region_map .writeable = true }).with_result( [&] (Genode::Region_map::Range) { - _range.add_range(base, Pd_session::LINKER_AREA_SIZE); + if (_range.add_range(base, Pd_session::LINKER_AREA_SIZE).failed()) + warning("failed to initialize linker-area range allocator"); if (Linker::verbose) log(" ", Hex(base), diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index 9b3c210041..ab588abac8 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -424,7 +424,8 @@ struct Linker::Binary : private Root_object, public Elf_object size_t const stack_size = ((size_t(*)())addr)(); /* expand stack according to the component's needs */ - Thread::myself()->stack_size(stack_size); + if (Thread::myself()->stack_size(stack_size).failed()) + warning("unable to set initial stack size to ", stack_size); } /* call 'Component::construct' function if present */ diff --git a/repos/base/src/test/ds_ownership/main.cc b/repos/base/src/test/ds_ownership/main.cc index db7d9cf45b..37704db18a 100644 --- a/repos/base/src/test/ds_ownership/main.cc +++ b/repos/base/src/test/ds_ownership/main.cc @@ -38,7 +38,8 @@ void Component::construct(Genode::Env &env) ram_2.free(ds); log("try to attach dataspace to see if it still exists"); - env.rm().attach(ds, { }); + if (env.rm().attach(ds, { }).failed()) + warning("dataspace unexpectedly vanished"); log("attach operation succeeded"); diff --git a/repos/base/src/test/rm_nested/main.cc b/repos/base/src/test/rm_nested/main.cc index 662fa3449c..28e79f5836 100644 --- a/repos/base/src/test/rm_nested/main.cc +++ b/repos/base/src/test/rm_nested/main.cc @@ -61,7 +61,11 @@ class Local_fault_handler : public Entrypoint _region_map.attach(ds, { .size = { }, .offset = { }, .use_at = true, .at = fault.addr & ~(PAGE_SIZE - 1), - .executable = { }, .writeable = true }); + .executable = { }, .writeable = true }) + .with_result( + [&] (Region_map::Range) { }, + [&] (Region_map::Attach_error) { warning("attach to sub rm failed"); } + ); log("returning from handle_fault"); } diff --git a/repos/base/src/test/sub_rm/main.cc b/repos/base/src/test/sub_rm/main.cc index 7cceaacdca..6aea6a6273 100644 --- a/repos/base/src/test/sub_rm/main.cc +++ b/repos/base/src/test/sub_rm/main.cc @@ -135,8 +135,11 @@ void Component::construct(Env &env) .use_at = true, .at = local_attach_addr, .executable = { }, .writeable = true }).convert( - [&] (Region_map::Range const range) { return (char *)range.start; }, - [&] (Region_map::Attach_error) { return nullptr; } + [&] (Env::Local_rm::Attachment &a) { + a.deallocate = false; + return (char *)a.ptr; + }, + [&] (Env::Local_rm::Error) { return nullptr; } ); log("validate pattern in sub rm"); @@ -225,7 +228,10 @@ void Component::construct(Env &env) .size = { }, .offset = 4096, .use_at = true, .at = DS_SUB_OFFSET_3, .executable = { }, .writeable = true - }); + }).with_result( + [&] (Region_map::Range) { }, + [&] (Region_map::Attach_error) { fail("RAM attachment with offset"); } + ); validate_pattern_at(test_pattern_2(), sub_rm_base + DS_SUB_OFFSET_3); /* @@ -238,7 +244,10 @@ void Component::construct(Env &env) .size = 2*4096, .offset = 4096, .use_at = true, .at = DS_SUB_OFFSET_4, .executable = { }, .writeable = true - }); + }).with_result( + [&] (Region_map::Range) { }, + [&] (Region_map::Attach_error) { fail("RAM attachment with offset and size"); } + ); validate_pattern_at(test_pattern_2(), sub_rm_base + DS_SUB_OFFSET_4); /* diff --git a/repos/base/src/test/token/main.cc b/repos/base/src/test/token/main.cc index 20ffd6fb1a..e138751c8a 100644 --- a/repos/base/src/test/token/main.cc +++ b/repos/base/src/test/token/main.cc @@ -38,10 +38,12 @@ static void test_out_of_bounds_access(Env &env) Attached_ram_dataspace buf_ds(env.ram(), env.rm(), BUF_SIZE); /* attach buffer at start of managed dataspace, leave 2nd page as guard */ - sub_rm.attach(buf_ds.cap(), { + if (sub_rm.attach(buf_ds.cap(), { .size = { }, .offset = { }, .use_at = true, .at = 0, - .executable = { }, .writeable = true }); + .executable = { }, .writeable = true + }).failed()) + warning("test_out_of_bounds_access: sub_rm.attach failed"); /* locally attach managed dataspace */ char * const buf_ptr = env.rm().attach(sub_rm.dataspace(), { diff --git a/repos/dde_ipxe/src/lib/dde_ipxe/dde_support.cc b/repos/dde_ipxe/src/lib/dde_ipxe/dde_support.cc index 0d1bbfb150..218eeacdec 100644 --- a/repos/dde_ipxe/src/lib/dde_ipxe/dde_support.cc +++ b/repos/dde_ipxe/src/lib/dde_ipxe/dde_support.cc @@ -303,7 +303,7 @@ struct Backing_store Backing_store (Genode::Allocator &alloc) : _avl(&alloc) { Range r = pci_drv().dma(); - _avl.add_range(r.start, r.size); + (void)_avl.add_range(r.start, r.size); } }; diff --git a/repos/dde_linux/src/lib/lx_kit/memory.cc b/repos/dde_linux/src/lib/lx_kit/memory.cc index c271b665f3..91437f3a6d 100644 --- a/repos/dde_linux/src/lib/lx_kit/memory.cc +++ b/repos/dde_linux/src/lib/lx_kit/memory.cc @@ -94,7 +94,8 @@ void * Lx_kit::Mem_allocator::alloc(size_t const size, size_t const align, */ Buffer & buffer = alloc_buffer(max(size + 1, min_buffer_size)); - _mem.add_range(buffer.virt_addr(), buffer.size() - 1); + if (_mem.add_range(buffer.virt_addr(), buffer.size() - 1).failed()) + warning("Lx_kit::Mem_allocator unable to extend virtual allocator"); /* re-try allocation */ void * const virt_addr = _mem.alloc_aligned(size, (unsigned)log2(align)).convert( diff --git a/repos/gems/src/app/trace_recorder/pcapng/backend.cc b/repos/gems/src/app/trace_recorder/pcapng/backend.cc index 9014ebed18..7478d347a9 100644 --- a/repos/gems/src/app/trace_recorder/pcapng/backend.cc +++ b/repos/gems/src/app/trace_recorder/pcapng/backend.cc @@ -39,7 +39,7 @@ void Writer::start_iteration(Directory &root, _interface_registry.clear(); _buffer.clear(); - _buffer.append(); + (void)_buffer.append(); /* header always fits in */ _empty_section = true; } catch (Append_file::Create_failed) { diff --git a/repos/libports/src/lib/libc/libc_mem_alloc.cc b/repos/libports/src/lib/libc/libc_mem_alloc.cc index 91b172a373..3e0e50c270 100644 --- a/repos/libports/src/lib/libc/libc_mem_alloc.cc +++ b/repos/libports/src/lib/libc/libc_mem_alloc.cc @@ -94,7 +94,8 @@ int Libc::Mem_alloc_impl::Dataspace_pool::expand(size_t size, Range_allocator *a } /* add new local address range to our local allocator */ - alloc->add_range(range.start, range.num_bytes); + if (alloc->add_range(range.start, range.num_bytes).failed()) + warning("libc is unable to extend range allocator of dataspace pool"); /* now that we have new backing store, allocate Dataspace structure */ return alloc->alloc_aligned(sizeof(Dataspace), 2).convert( diff --git a/repos/libports/src/lib/libdrm/ioctl_iris.cc b/repos/libports/src/lib/libdrm/ioctl_iris.cc index a61987e953..6125229d82 100644 --- a/repos/libports/src/lib/libdrm/ioctl_iris.cc +++ b/repos/libports/src/lib/libdrm/ioctl_iris.cc @@ -229,7 +229,8 @@ struct Gpu::Vram _cap(gpu.alloc_vram(_elem.id(), size)), _alloc(&md_alloc) { - _alloc.add_range(0, Genode::Dataspace_client(_cap).size()); + if (_alloc.add_range(0, Genode::Dataspace_client(_cap).size()).failed()) + Genode::warning("unable to initialize Gpu::Vram allocator"); } struct Allocation diff --git a/repos/libports/src/lib/libdrm/ioctl_lima.cc b/repos/libports/src/lib/libdrm/ioctl_lima.cc index b82dbe00c0..7549733cd9 100644 --- a/repos/libports/src/lib/libdrm/ioctl_lima.cc +++ b/repos/libports/src/lib/libdrm/ioctl_lima.cc @@ -303,7 +303,8 @@ class Lima::Call * The end of range correspondes to LIMA_VA_RESERVE_START * in Linux minus the page we omit at the start. */ - _alloc.add_range(0x1000, 0xfff00000ul - 0x1000); + if(_alloc.add_range(0x1000, 0xfff00000ul - 0x1000).failed()) + Genode::warning("unable to initialize Gpu::Vram allocator"); } Gpu::Virtual_address alloc(uint32_t size) diff --git a/repos/os/include/os/packet_stream.h b/repos/os/include/os/packet_stream.h index 6f705a162f..5544b247c3 100644 --- a/repos/os/include/os/packet_stream.h +++ b/repos/os/include/os/packet_stream.h @@ -648,14 +648,14 @@ class Genode::Packet_stream_source : private Packet_stream_base Ack_queue::CONSUMER)) { /* initialize packet allocator */ - _packet_alloc.add_range(_bulk_buffer_offset, - _bulk_buffer_size); + if (_packet_alloc.add_range(_bulk_buffer_offset, _bulk_buffer_size).failed()) + warning("unable to initialize packet-stream source allocator"); } ~Packet_stream_source() { - _packet_alloc.remove_range(_bulk_buffer_offset, - _bulk_buffer_size); + if (_packet_alloc.remove_range(_bulk_buffer_offset, _bulk_buffer_size).failed()) + warning("packet-stream source allocator in bad state at destruction time"); } using Packet_stream_base::packet_valid; diff --git a/repos/os/src/app/trace_logger/main.cc b/repos/os/src/app/trace_logger/main.cc index fa0ffa412e..46faf386b5 100644 --- a/repos/os/src/app/trace_logger/main.cc +++ b/repos/os/src/app/trace_logger/main.cc @@ -181,7 +181,9 @@ class Main { policy.id.with_result( [&] (Trace::Policy_id const policy_id) { - _trace.trace(id, policy_id, buffer_size); }, + if (_trace.trace(id, policy_id, buffer_size).failed()) + warning("failed to enable tracing with policy '", policy_name, "'"); + }, [&] (auto) { warning("skip tracing because of invalid policy '", policy_name, "'"); }); diff --git a/repos/os/src/driver/acpi/memory.h b/repos/os/src/driver/acpi/memory.h index 6064079bb2..39e10168a8 100644 --- a/repos/os/src/driver/acpi/memory.h +++ b/repos/os/src/driver/acpi/memory.h @@ -110,7 +110,8 @@ class Acpi::Memory Memory(Env &env, Allocator &heap) : _env(env), _heap(heap) { - _range.add_range(0, ~0UL); + if (_range.add_range(0, ~0UL).failed()) + warning("unable to initialize Memory::_range"); } addr_t map_region(addr_t const req_base, addr_t const req_size) @@ -182,20 +183,23 @@ class Acpi::Memory _range.construct_metadata((void *)loop_region.base(), _env, loop_region); + Io_mem &io_mem = *_range.metadata((void *)loop_region.base()); + /* * We attach the I/O memory dataspace into a virtual-memory window, * which starts at _io_region.base(). Therefore, the attachment * address is the offset of loop_region.base() from * _io_region.base(). */ - _acpi_window.attach(_range.metadata((void *)loop_region.base())->connection->dataspace(), { + if (_acpi_window.attach(io_mem.connection->dataspace(), { .size = loop_region.size(), .offset = { }, .use_at = true, .at = loop_region.base() - _io_region->base(), .executable = { }, .writeable = { } - }); + }).failed()) + warning("unable to attach io_mem to ACPI window: ", io_mem.region); return _acpi_ptr(req_base); } diff --git a/repos/os/src/driver/platform/dma_allocator.cc b/repos/os/src/driver/platform/dma_allocator.cc index 11efd0186a..81325ac559 100644 --- a/repos/os/src/driver/platform/dma_allocator.cc +++ b/repos/os/src/driver/platform/dma_allocator.cc @@ -121,7 +121,8 @@ Dma_allocator::Dma_allocator(Allocator & md_alloc, { /* 0x1000 - 4GB */ enum { DMA_SIZE = 0xffffe000 }; - _dma_alloc.add_range(0x1000, DMA_SIZE); + if (_dma_alloc.add_range(0x1000, DMA_SIZE).failed()) + warning("unable to add 0x1000 range to DMA allocator"); /* * Interrupt address range is special handled and in general not @@ -130,7 +131,8 @@ Dma_allocator::Dma_allocator(Allocator & md_alloc, * (March 2023, Revision 4.1) */ enum { IRQ_RANGE_BASE = 0xfee00000u, IRQ_RANGE_SIZE = 0x100000 }; - _dma_alloc.remove_range(IRQ_RANGE_BASE, IRQ_RANGE_SIZE); + if (_dma_alloc.remove_range(IRQ_RANGE_BASE, IRQ_RANGE_SIZE).failed()) + warning("unable to exclude IRQ range from DMA allocator"); } diff --git a/repos/os/src/server/cpu_balancer/trace.h b/repos/os/src/server/cpu_balancer/trace.h index 028a7a148b..938ae3c279 100644 --- a/repos/os/src/server/cpu_balancer/trace.h +++ b/repos/os/src/server/cpu_balancer/trace.h @@ -59,12 +59,8 @@ class Cpu::Trace _trace.destruct(); _trace.construct(_env, _ram_quota, _arg_quota); - /* - * Explicitly re-trigger import of subjects. Otherwise - * stored trace ids are not valid if used with subject_info(id) - * and we get exception thrown about unknown ids. - */ - _trace->_retry([&] { + /* explicitly re-trigger import of subjects */ + (void)_trace->_retry([&] { return _trace->call(); }); _subject_id_reread ++; diff --git a/repos/os/src/server/vmm/config.h b/repos/os/src/server/vmm/config.h index a59223f6c8..47d0e1dfe3 100644 --- a/repos/os/src/server/vmm/config.h +++ b/repos/os/src/server/vmm/config.h @@ -120,8 +120,11 @@ class Vmm::Config public: - Config(Heap & heap) : _heap(heap) { - _mmio_alloc.add_range(VIRTIO_MMIO_START, VIRTIO_MMIO_SIZE); } + Config(Heap & heap) : _heap(heap) + { + if (_mmio_alloc.add_range(VIRTIO_MMIO_START, VIRTIO_MMIO_SIZE).failed()) + warning("failed to add virtio MMIO range"); + } bool initrd() const { return _initrd_name.valid(); } diff --git a/repos/pc/src/driver/platform/pc/expanding_page_table_allocator.h b/repos/pc/src/driver/platform/pc/expanding_page_table_allocator.h index 1732af7cd4..ae387f5159 100644 --- a/repos/pc/src/driver/platform/pc/expanding_page_table_allocator.h +++ b/repos/pc/src/driver/platform/pc/expanding_page_table_allocator.h @@ -75,11 +75,11 @@ class Driver::Expanding_page_table_allocator _virt_addr((addr_t)_dataspace.local_addr()), _phys_addr(pd.dma_addr(_dataspace.cap())) { - _range_alloc.add_range(_phys_addr, size); + (void)_range_alloc.add_range(_phys_addr, size); } ~Element() { - _range_alloc.remove_range(_phys_addr, _dataspace.size()); } + (void)_range_alloc.remove_range(_phys_addr, _dataspace.size()); } bool matches(addr_t pa) { diff --git a/repos/ports/src/virtualbox6/sup_gmm.cc b/repos/ports/src/virtualbox6/sup_gmm.cc index 15b73efe2b..633accc249 100644 --- a/repos/ports/src/virtualbox6/sup_gmm.cc +++ b/repos/ports/src/virtualbox6/sup_gmm.cc @@ -61,7 +61,8 @@ void Sup::Gmm::_add_one_slice() _slices[_slice_index(Offset{attach_base})] = ds; - _alloc.add_range(attach_base, slice_size); + if (_alloc.add_range(attach_base, slice_size).failed()) + warning("unable to to add Gmm slice to range allocator"); /* update allocation size */ _size_pages = { (attach_base + slice_size) >> PAGE_SHIFT };