1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#pragma once
14
15#include <autoconf.h>
16#include <stdlib.h>
17#include <sel4/types.h>
18#include <allocman/mspace/mspace.h>
19#include <allocman/mspace/k_r_malloc.h>
20#include <allocman/mspace/fixed_pool.h>
21#include <allocman/mspace/virtual_pool.h>
22
23/* This memory allocator supports have a fixed pool of memory, as well as a
24 * virtual pool that can be attached while running. */
25
26typedef struct mspace_dual_pool {
27    size_t fixed_pool_start;
28    size_t fixed_pool_end;
29    mspace_fixed_pool_t fixed_pool;
30    int have_virtual_pool;
31    mspace_virtual_pool_t virtual_pool;
32} mspace_dual_pool_t;
33
34void mspace_dual_pool_create(mspace_dual_pool_t *dual_pool, struct mspace_fixed_pool_config config);
35void mspace_dual_pool_attach_virtual(mspace_dual_pool_t *dual_pool, struct mspace_virtual_pool_config config);
36
37void *_mspace_dual_pool_alloc(struct allocman *alloc, void *_dual_pool, size_t bytes, int *error);
38void _mspace_dual_pool_free(struct allocman *alloc, void *_dual_pool, void *ptr, size_t bytes);
39
40static inline struct mspace_interface mspace_dual_pool_make_interface(mspace_dual_pool_t *dual_pool) {
41    return (struct mspace_interface){
42        .alloc = _mspace_dual_pool_alloc,
43        .free = _mspace_dual_pool_free,
44        .properties = ALLOCMAN_DEFAULT_PROPERTIES,
45        .mspace = dual_pool
46    };
47}
48
49