Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/AK/kmalloc.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
3
 * Copyright (c) 2021, Daniel Bertalan <dani@danielbertalan.dev>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#pragma once
9
10
#include <AK/Checked.h>
11
#include <AK/Platform.h>
12
13
#if defined(KERNEL)
14
#    include <Kernel/Heap/kmalloc.h>
15
#else
16
#    include <new>
17
#    include <stdlib.h>
18
19
22.6M
#    define kcalloc calloc
20
3.28G
#    define kmalloc malloc
21
2.96G
#    define kmalloc_good_size malloc_good_size
22
23
inline void kfree_sized(void* ptr, size_t)
24
3.31G
{
25
3.31G
    free(ptr);
26
3.31G
}
27
#endif
28
29
#ifndef AK_OS_SERENITY
30
#    include <AK/Types.h>
31
32
#    ifndef AK_OS_MACOS
33
extern "C" {
34
2.96G
inline size_t malloc_good_size(size_t size) { return size; }
35
}
36
#    else
37
#        include <malloc/malloc.h>
38
#    endif
39
#endif
40
41
using std::nothrow;
42
43
inline void* kmalloc_array(AK::Checked<size_t> a, AK::Checked<size_t> b)
44
2.93G
{
45
2.93G
    auto size = a * b;
46
2.93G
    VERIFY(!size.has_overflow());
47
2.93G
    return kmalloc(size.value());
48
2.93G
}
49
50
inline void* kmalloc_array(AK::Checked<size_t> a, AK::Checked<size_t> b, AK::Checked<size_t> c)
51
0
{
52
0
    auto size = a * b * c;
53
0
    VERIFY(!size.has_overflow());
54
0
    return kmalloc(size.value());
55
0
}