diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-11-29 03:01:24 -0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-30 11:16:35 +0100 |
commit | 74ee491b842e1f1a4df75f81e980957ff194c5b0 (patch) | |
tree | dbc9414585f48368ff2e31112d38b7d82cd7bbd0 /Kernel/Heap | |
parent | a0e59099fcbd4f22f081928f6f47849ee7b7842d (diff) | |
download | serenity-74ee491b842e1f1a4df75f81e980957ff194c5b0.zip |
Kernel: Handle string format errors in SlabAllocator stats :^)
Switch to KString::formatted and fix API so we can propagate errors.
Diffstat (limited to 'Kernel/Heap')
-rw-r--r-- | Kernel/Heap/SlabAllocator.cpp | 24 | ||||
-rw-r--r-- | Kernel/Heap/SlabAllocator.h | 2 |
2 files changed, 15 insertions, 11 deletions
diff --git a/Kernel/Heap/SlabAllocator.cpp b/Kernel/Heap/SlabAllocator.cpp index 179cdcc0b8..ed9e83449b 100644 --- a/Kernel/Heap/SlabAllocator.cpp +++ b/Kernel/Heap/SlabAllocator.cpp @@ -116,13 +116,14 @@ static_assert(sizeof(Memory::Region) <= s_slab_allocator_128.slab_size()); #endif template<typename Callback> -void for_each_allocator(Callback callback) +ErrorOr<void> for_each_allocator(Callback callback) { - callback(s_slab_allocator_16); - callback(s_slab_allocator_32); - callback(s_slab_allocator_64); - callback(s_slab_allocator_128); - callback(s_slab_allocator_256); + TRY(callback(s_slab_allocator_16)); + TRY(callback(s_slab_allocator_32)); + TRY(callback(s_slab_allocator_64)); + TRY(callback(s_slab_allocator_128)); + TRY(callback(s_slab_allocator_256)); + return {}; } UNMAP_AFTER_INIT void slab_alloc_init() @@ -164,13 +165,16 @@ void slab_dealloc(void* ptr, size_t slab_size) VERIFY_NOT_REACHED(); } -void slab_alloc_stats(Function<void(size_t slab_size, size_t allocated, size_t free)> callback) +ErrorOr<void> slab_alloc_stats(Function<ErrorOr<void>(size_t slab_size, size_t allocated, size_t free)> callback) { - for_each_allocator([&](auto& allocator) { + TRY(for_each_allocator([&](auto& allocator) -> ErrorOr<void> { auto num_allocated = allocator.num_allocated(); auto num_free = allocator.slab_count() - num_allocated; - callback(allocator.slab_size(), num_allocated, num_free); - }); + TRY(callback(allocator.slab_size(), num_allocated, num_free)); + return {}; + })); + + return {}; } } diff --git a/Kernel/Heap/SlabAllocator.h b/Kernel/Heap/SlabAllocator.h index 5650d428c1..81d0612fb4 100644 --- a/Kernel/Heap/SlabAllocator.h +++ b/Kernel/Heap/SlabAllocator.h @@ -17,7 +17,7 @@ namespace Kernel { void* slab_alloc(size_t slab_size); void slab_dealloc(void*, size_t slab_size); void slab_alloc_init(); -void slab_alloc_stats(Function<void(size_t slab_size, size_t allocated, size_t free)>); +ErrorOr<void> slab_alloc_stats(Function<ErrorOr<void>(size_t slab_size, size_t allocated, size_t free)>); #define MAKE_SLAB_ALLOCATED(type) \ public: \ |