# HG changeset patch # User Paul Boddie # Date 1680042740 -7200 # Node ID b3eab5c454521596e02dddeec0f28833cb775aba # Parent 9bf4d6f92b33021517e349fcf5dea3158a9dd04a Moved flexpage-related IPC functions into libmem, also incorporating the invalidation of derived flexpages into the flexpage abstraction. diff -r 9bf4d6f92b33 -r b3eab5c45452 libfsserver/include/fsserver/ipc.h --- a/libfsserver/include/fsserver/ipc.h Tue Mar 28 19:01:14 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Interprocess communication utilities. - * - * Copyright (C) 2021 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#pragma once - -#include - -#include - - - -long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, - offset_t max_offset, map_address_t hot_spot, - map_flags_t flags, l4_snd_fpage_t *region); - -void ipc_unmap_flexpage(Flexpage *flexpage); - -// vim: tabstop=4 expandtab shiftwidth=4 diff -r 9bf4d6f92b33 -r b3eab5c45452 libfsserver/lib/Makefile --- a/libfsserver/lib/Makefile Tue Mar 28 19:01:14 2023 +0200 +++ b/libfsserver/lib/Makefile Wed Mar 29 00:32:20 2023 +0200 @@ -65,7 +65,6 @@ mapping/access_map.cc \ mapping/copied_page_mapper.cc \ mapping/generic_page_mapper.cc \ - mapping/ipc.cc \ mapping/masked_page_mapper.cc \ mapping/page_mapper.cc \ pages/page_queue.cc \ diff -r 9bf4d6f92b33 -r b3eab5c45452 libfsserver/lib/generic/pager.cc --- a/libfsserver/lib/generic/pager.cc Tue Mar 28 19:01:14 2023 +0200 +++ b/libfsserver/lib/generic/pager.cc Wed Mar 29 00:32:20 2023 +0200 @@ -1,7 +1,7 @@ /* * Generic pager functionality. * - * Copyright (C) 2021, 2022 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -19,8 +19,9 @@ * Boston, MA 02110-1301, USA */ +#include + #include "dataspace_server.h" -#include "ipc.h" #include "pager.h" #include "copied_page_mapper.h" diff -r 9bf4d6f92b33 -r b3eab5c45452 libfsserver/lib/generic/simple_pager.cc --- a/libfsserver/lib/generic/simple_pager.cc Tue Mar 28 19:01:14 2023 +0200 +++ b/libfsserver/lib/generic/simple_pager.cc Wed Mar 29 00:32:20 2023 +0200 @@ -21,12 +21,12 @@ #include +#include #include #include #include "dataspace_server.h" -#include "ipc.h" #include "simple_pager.h" diff -r 9bf4d6f92b33 -r b3eab5c45452 libfsserver/lib/mapping/ipc.cc --- a/libfsserver/lib/mapping/ipc.cc Tue Mar 28 19:01:14 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Interprocess communication utilities. - * - * Copyright (C) 2021, 2022 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#include -#include -#include - -#include - -#include "ipc.h" - - - -/* Make an L4 representation of the given flexpage. */ - -static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage) -{ - unsigned char flags = send_flexpage->flags; - - if (!flags) - flags = L4RE_DS_MAP_FLAG_RO; - - return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags); -} - -/* Make a representation of a flexpage for the IPC system. */ - -long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, - offset_t max_offset, map_address_t hot_spot, - map_flags_t flags, l4_snd_fpage_t *region) -{ - SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags, - max_offset); - - /* NOTE: Consider l4_fpage_invalid() as the fpage here. */ - - if (!send_flexpage.order) - return -L4_ERANGE; - - region->fpage = ipc_get_fpage(&send_flexpage); - region->snd_base = hot_spot; - - return L4_EOK; -} - -/* Unmap the given flexpage. */ - -void ipc_unmap_flexpage(Flexpage *flexpage) -{ - SendFlexpage send_flexpage = flexpage->to_unmap(); - - l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES); -} - -// vim: tabstop=4 expandtab shiftwidth=4 diff -r 9bf4d6f92b33 -r b3eab5c45452 libfsserver/lib/mapping/page_mapper.cc --- a/libfsserver/lib/mapping/page_mapper.cc Tue Mar 28 19:01:14 2023 +0200 +++ b/libfsserver/lib/mapping/page_mapper.cc Wed Mar 29 00:32:20 2023 +0200 @@ -1,7 +1,7 @@ /* * A page mapper providing memory pages to satisfy file accesses. * - * Copyright (C) 2021, 2022 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -19,7 +19,6 @@ * Boston, MA 02110-1301, USA */ -#include "ipc.h" #include "page_mapper.h" @@ -165,23 +164,10 @@ _accessor->flush(flexpage); /* Unmap the flexpage, requiring users of its memory to request another - flexpage in future. */ - - ipc_unmap_flexpage(flexpage); - flexpage->invalidate(); - - /* Unmap all derived flexpages, since these rely on the underlying file - contents. */ + flexpage in future. This also unmaps all derived flexpages, since + these rely on the underlying file contents. */ - DerivedFlexpages::iterator it; - - for (it = flexpage->derived.begin(); it != flexpage->derived.end(); it++) - { - ipc_unmap_flexpage(*it); - (*it)->invalidate(); - } - - flexpage->disassociate(); + flexpage->invalidate(); } } diff -r 9bf4d6f92b33 -r b3eab5c45452 libmem/include/mem/ipc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmem/include/mem/ipc.h Wed Mar 29 00:32:20 2023 +0200 @@ -0,0 +1,36 @@ +/* + * Interprocess communication utilities. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + +#include + + + +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, + offset_t max_offset, map_address_t hot_spot, + map_flags_t flags, l4_snd_fpage_t *region); + +void ipc_unmap_flexpage(Flexpage *flexpage); + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 9bf4d6f92b33 -r b3eab5c45452 libmem/lib/src/Makefile --- a/libmem/lib/src/Makefile Tue Mar 28 19:01:14 2023 +0200 +++ b/libmem/lib/src/Makefile Wed Mar 29 00:32:20 2023 +0200 @@ -5,7 +5,8 @@ PC_FILENAME = libmem SRC_CC = \ - flexpage.cc memory_incremental.cc memory_preallocated.cc \ + flexpage.cc ipc.cc \ + memory_incremental.cc memory_preallocated.cc \ memory_utils.cc region.cc REQUIRES_LIBS = l4re_c-util libstdc++ libsystypes libipc diff -r 9bf4d6f92b33 -r b3eab5c45452 libmem/lib/src/flexpage.cc --- a/libmem/lib/src/flexpage.cc Tue Mar 28 19:01:14 2023 +0200 +++ b/libmem/lib/src/flexpage.cc Wed Mar 29 00:32:20 2023 +0200 @@ -1,7 +1,7 @@ /* * A flexpage abstraction. * - * Copyright (C) 2021, 2022 Paul Boddie + * Copyright (C) 2021, 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -22,6 +22,7 @@ #include #include "flexpage.h" +#include "ipc.h" @@ -99,11 +100,17 @@ _counter++; } -/* Invalidate the flexpage, meaning that it should not now be in use. */ +/* Unmap and invalidate the flexpage, meaning that it should not now be in + use. */ void Flexpage::invalidate() { _counter = 0; + ipc_unmap_flexpage(this); + + /* Unmap and invalidate all derived flexpages. */ + + disassociate(); } /* Return whether the flexpage is in use and is therefore valid. */ @@ -205,8 +212,15 @@ derived.push_back(flexpage); } +/* Invalidate and unmap all derived flexpages. */ + void Flexpage::disassociate() { + DerivedFlexpages::iterator it; + + for (it = derived.begin(); it != derived.end(); it++) + (*it)->invalidate(); + derived.clear(); } diff -r 9bf4d6f92b33 -r b3eab5c45452 libmem/lib/src/ipc.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmem/lib/src/ipc.cc Wed Mar 29 00:32:20 2023 +0200 @@ -0,0 +1,73 @@ +/* + * Interprocess communication utilities. + * + * Copyright (C) 2021, 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include +#include +#include + +#include + +#include "ipc.h" + + + +/* Make an L4 representation of the given flexpage. */ + +static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage) +{ + unsigned char flags = send_flexpage->flags; + + if (!flags) + flags = L4RE_DS_MAP_FLAG_RO; + + return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags); +} + +/* Make a representation of a flexpage for the IPC system. */ + +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, + offset_t max_offset, map_address_t hot_spot, + map_flags_t flags, l4_snd_fpage_t *region) +{ + SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags, + max_offset); + + /* NOTE: Consider l4_fpage_invalid() as the fpage here. */ + + if (!send_flexpage.order) + return -L4_ERANGE; + + region->fpage = ipc_get_fpage(&send_flexpage); + region->snd_base = hot_spot; + + return L4_EOK; +} + +/* Unmap the given flexpage. */ + +void ipc_unmap_flexpage(Flexpage *flexpage) +{ + SendFlexpage send_flexpage = flexpage->to_unmap(); + + l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES); +} + +// vim: tabstop=4 expandtab shiftwidth=4