1 /* 2 * Data space allocation utility functions. 3 * 4 * Copyright (C) 2018, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/re/c/mem_alloc.h> 23 24 #include <ipc/mem_ipc.h> 25 26 #include "dataspace.h" 27 28 29 30 /* Allocate and map a region containing data, using the given mem_size to 31 indicate the required region size, along with a pointer to be set to the 32 allocated region. Return a capability which may be invalid if allocation or 33 mapping failed. 34 */ 35 36 l4re_ds_t allocate_data(l4_size_t mem_size, void **allocated) 37 { 38 l4re_ds_t mem; 39 40 /* Allocate memory for the data and map it to a virtual address. */ 41 42 if (ipc_new_dataspace(mem_size, L4RE_MA_CONTINUOUS, 0, &mem)) 43 return L4_INVALID_CAP; 44 45 if (ipc_attach_dataspace_align(mem, mem_size, 46 L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RW, 47 0, allocated)) 48 return L4_INVALID_CAP; 49 50 return mem; 51 }