paul@324 | 1 | /* |
paul@324 | 2 | * Capability mapping between tasks. |
paul@324 | 3 | * |
paul@324 | 4 | * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> |
paul@324 | 5 | * |
paul@324 | 6 | * This program is free software; you can redistribute it and/or |
paul@324 | 7 | * modify it under the terms of the GNU General Public License as |
paul@324 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@324 | 9 | * the License, or (at your option) any later version. |
paul@324 | 10 | * |
paul@324 | 11 | * This program is distributed in the hope that it will be useful, |
paul@324 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@324 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@324 | 14 | * GNU General Public License for more details. |
paul@324 | 15 | * |
paul@324 | 16 | * You should have received a copy of the GNU General Public License |
paul@324 | 17 | * along with this program; if not, write to the Free Software |
paul@324 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@324 | 19 | * Boston, MA 02110-1301, USA |
paul@324 | 20 | */ |
paul@324 | 21 | |
paul@324 | 22 | #include <l4/re/consts.h> |
paul@324 | 23 | #include <l4/sys/err.h> |
paul@324 | 24 | #include <l4/sys/ipc.h> |
paul@324 | 25 | #include <l4/sys/task.h> |
paul@324 | 26 | |
paul@324 | 27 | #include "map.h" |
paul@324 | 28 | |
paul@324 | 29 | |
paul@324 | 30 | |
paul@324 | 31 | /* Map a capability to another task. */ |
paul@324 | 32 | |
paul@324 | 33 | long ipc_map_capability(l4_cap_idx_t task, struct ipc_mapped_cap mapped_cap) |
paul@324 | 34 | { |
paul@324 | 35 | return l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP, |
paul@324 | 36 | l4_obj_fpage(mapped_cap.cap, 0, mapped_cap.rights), |
paul@376 | 37 | l4_map_obj_control(mapped_cap.mapped_cap, L4_MAP_ITEM_MAP) | |
paul@376 | 38 | mapped_cap.obj_rights)); |
paul@324 | 39 | } |
paul@324 | 40 | |
paul@324 | 41 | /* Map several capabilities to another task. */ |
paul@324 | 42 | |
paul@365 | 43 | long ipc_map_capabilities(l4_cap_idx_t task, struct ipc_mapped_cap mapped_caps[], |
paul@365 | 44 | unsigned int *count) |
paul@324 | 45 | { |
paul@324 | 46 | long err = L4_EOK; |
paul@365 | 47 | unsigned int i; |
paul@324 | 48 | |
paul@365 | 49 | for (i = 0; l4_is_valid_cap(mapped_caps[i].cap) && !err; i++) |
paul@324 | 50 | err = ipc_map_capability(task, mapped_caps[i]); |
paul@324 | 51 | |
paul@365 | 52 | if (count != NULL) |
paul@370 | 53 | *count = i; |
paul@365 | 54 | |
paul@324 | 55 | return err; |
paul@324 | 56 | } |
paul@324 | 57 | |
paul@324 | 58 | // vim: tabstop=2 expandtab shiftwidth=2 |