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 <stdint.h> 17#include <sel4/types.h> 18#include <allocman/mspace/mspace.h> 19#include <allocman/mspace/k_r_malloc.h> 20#include <vspace/vspace.h> 21 22/* Performs allocation from a virtual pool of memory. It takes both a vspace 23 * manager as well as a virtual range because we need to construct sbrk semantics 24 * which requires a contiguous virtual address range. But we will use the vspace 25 * manager to ensure we do not accidentally clobber somebody else. This memory manager 26 * must *not* be used as a backing memory manager for somethign that is given to 27 * the vspace library as the resulting circular dependency is unresolvable 28 */ 29 30struct mspace_vspace_pool_config { 31 uintptr_t vstart; 32 reservation_t reservation; 33 vspace_t vspace; 34}; 35 36typedef struct mspace_vspace_pool { 37 uintptr_t pool_ptr; 38 uintptr_t pool_top; 39 /* reservation inside the vspace_t */ 40 reservation_t reservation; 41 vspace_t vspace; 42 mspace_k_r_malloc_t k_r_malloc; 43 struct allocman *morecore_alloc; 44} mspace_vspace_pool_t; 45 46void mspace_vspace_pool_create(mspace_vspace_pool_t *vspace_pool, struct mspace_vspace_pool_config config); 47 48void *_mspace_vspace_pool_alloc(struct allocman *alloc, void *_vspace_pool, size_t bytes, int *error); 49void _mspace_vspace_pool_free(struct allocman *alloc, void *_vspace_pool, void *ptr, size_t bytes); 50 51static inline struct mspace_interface mspace_vspace_pool_make_interface(mspace_vspace_pool_t *vspace_pool) { 52 return (struct mspace_interface){ 53 .alloc = _mspace_vspace_pool_alloc, 54 .free = _mspace_vspace_pool_free, 55 .properties = ALLOCMAN_DEFAULT_PROPERTIES, 56 .mspace = vspace_pool 57 }; 58} 59 60