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/* Implements a null memory manager. This is useful if you are using allocators
16   that do not perform any dynamic book keeping */
17
18#include <autoconf.h>
19#include <sel4/types.h>
20#include <allocman/mspace/mspace.h>
21#include <allocman/util.h>
22#include <stdlib.h>
23
24static inline void *_mspace_null_alloc(struct allocman *alloc, void *unused, size_t bytes, int *error)
25{
26    SET_ERROR(error, 1);
27    return NULL;
28}
29
30static inline void _mspace_null_free(struct allocman *alloc, void *unused, void *ptr, size_t bytes)
31{
32    /* While this is clearly a bug, we have no nice WARN_ON or other macro for flagging this, so just ignore */
33}
34
35static const struct mspace_interface mspace_null_interface = {
36    .alloc = _mspace_null_alloc,
37    .free = _mspace_null_free,
38    .properties = ALLOCMAN_DEFAULT_PROPERTIES,
39    .mspace = NULL
40};
41
42