2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-09-16 10:19:44 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-02-01 10:36:25 +01:00
|
|
|
#define SLAB_ALLOC_SCRUB_BYTE 0xab
|
|
|
|
#define SLAB_DEALLOC_SCRUB_BYTE 0xbc
|
|
|
|
|
2019-09-16 10:19:44 +02:00
|
|
|
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)>);
|
|
|
|
|
2021-05-11 03:51:31 -07:00
|
|
|
#define MAKE_SLAB_ALLOCATED(type) \
|
|
|
|
public: \
|
|
|
|
[[nodiscard]] void* operator new(size_t) noexcept { return slab_alloc(sizeof(type)); } \
|
|
|
|
void operator delete(void* ptr) noexcept { slab_dealloc(ptr, sizeof(type)); } \
|
|
|
|
\
|
2019-09-16 10:19:44 +02:00
|
|
|
private:
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|