Coverage Report

Created: 2026-09-14 07:15

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
30.6M
#    define kcalloc calloc
20
4.28G
#    define kmalloc malloc
21
3.87G
#    define kmalloc_good_size malloc_good_size
22
23
inline void kfree_sized(void* ptr, size_t)
24
4.32G
{
25
4.32G
    free(ptr);
26
4.32G
}
27
#endif
28
29
#ifndef AK_OS_SERENITY
30
#    include <AK/Types.h>
31
32
#    ifndef AK_OS_MACOS
33
extern "C" {
34
3.87G
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
3.84G
{
45
3.84G
    auto size = a * b;
46
3.84G
    VERIFY(!size.has_overflow());
47
3.84G
    return kmalloc(size.value());
48
3.84G
}
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
}