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 <stdint.h> 18#include <sel4/types.h> 19#include <allocman/mspace/mspace.h> 20#include <allocman/mspace/k_r_malloc.h> 21 22/* Performs allocation from a fixed pool of memory */ 23 24struct mspace_fixed_pool_config { 25 void *pool; 26 size_t size; 27}; 28 29typedef struct mspace_fixed_pool { 30 uintptr_t pool_ptr; 31 size_t remaining; 32 mspace_k_r_malloc_t k_r_malloc; 33} mspace_fixed_pool_t; 34 35void mspace_fixed_pool_create(mspace_fixed_pool_t *fixed_pool, struct mspace_fixed_pool_config config); 36 37void *_mspace_fixed_pool_alloc(struct allocman *alloc, void *_fixed_pool, size_t bytes, int *error); 38void _mspace_fixed_pool_free(struct allocman *alloc, void *_fixed_pool, void *ptr, size_t bytes); 39 40static inline struct mspace_interface mspace_fixed_pool_make_interface(mspace_fixed_pool_t *fixed_pool) { 41 return (struct mspace_interface){ 42 .alloc = _mspace_fixed_pool_alloc, 43 .free = _mspace_fixed_pool_free, 44 .properties = ALLOCMAN_DEFAULT_PROPERTIES, 45 .mspace = fixed_pool 46 }; 47} 48 49