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