1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libmem/lib/src/ipc.cc Wed Mar 29 00:32:20 2023 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +/*
1.5 + * Interprocess communication utilities.
1.6 + *
1.7 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <l4/re/c/dataspace.h>
1.26 +#include <l4/re/consts.h>
1.27 +#include <l4/sys/task.h>
1.28 +
1.29 +#include <mem/send_flexpage.h>
1.30 +
1.31 +#include "ipc.h"
1.32 +
1.33 +
1.34 +
1.35 +/* Make an L4 representation of the given flexpage. */
1.36 +
1.37 +static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage)
1.38 +{
1.39 + unsigned char flags = send_flexpage->flags;
1.40 +
1.41 + if (!flags)
1.42 + flags = L4RE_DS_MAP_FLAG_RO;
1.43 +
1.44 + return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags);
1.45 +}
1.46 +
1.47 +/* Make a representation of a flexpage for the IPC system. */
1.48 +
1.49 +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset,
1.50 + offset_t max_offset, map_address_t hot_spot,
1.51 + map_flags_t flags, l4_snd_fpage_t *region)
1.52 +{
1.53 + SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags,
1.54 + max_offset);
1.55 +
1.56 + /* NOTE: Consider l4_fpage_invalid() as the fpage here. */
1.57 +
1.58 + if (!send_flexpage.order)
1.59 + return -L4_ERANGE;
1.60 +
1.61 + region->fpage = ipc_get_fpage(&send_flexpage);
1.62 + region->snd_base = hot_spot;
1.63 +
1.64 + return L4_EOK;
1.65 +}
1.66 +
1.67 +/* Unmap the given flexpage. */
1.68 +
1.69 +void ipc_unmap_flexpage(Flexpage *flexpage)
1.70 +{
1.71 + SendFlexpage send_flexpage = flexpage->to_unmap();
1.72 +
1.73 + l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES);
1.74 +}
1.75 +
1.76 +// vim: tabstop=4 expandtab shiftwidth=4