1.1 --- a/libfsserver/include/fsserver/ipc.h Tue Mar 28 19:01:14 2023 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,36 +0,0 @@
1.4 -/*
1.5 - * Interprocess communication utilities.
1.6 - *
1.7 - * Copyright (C) 2021 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 -#pragma once
1.26 -
1.27 -#include <l4/sys/ipc.h>
1.28 -
1.29 -#include <mem/flexpage.h>
1.30 -
1.31 -
1.32 -
1.33 -long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset,
1.34 - offset_t max_offset, map_address_t hot_spot,
1.35 - map_flags_t flags, l4_snd_fpage_t *region);
1.36 -
1.37 -void ipc_unmap_flexpage(Flexpage *flexpage);
1.38 -
1.39 -// vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/libfsserver/lib/Makefile Tue Mar 28 19:01:14 2023 +0200
2.2 +++ b/libfsserver/lib/Makefile Wed Mar 29 00:32:20 2023 +0200
2.3 @@ -65,7 +65,6 @@
2.4 mapping/access_map.cc \
2.5 mapping/copied_page_mapper.cc \
2.6 mapping/generic_page_mapper.cc \
2.7 - mapping/ipc.cc \
2.8 mapping/masked_page_mapper.cc \
2.9 mapping/page_mapper.cc \
2.10 pages/page_queue.cc \
3.1 --- a/libfsserver/lib/generic/pager.cc Tue Mar 28 19:01:14 2023 +0200
3.2 +++ b/libfsserver/lib/generic/pager.cc Wed Mar 29 00:32:20 2023 +0200
3.3 @@ -1,7 +1,7 @@
3.4 /*
3.5 * Generic pager functionality.
3.6 *
3.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
3.8 + * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
3.9 *
3.10 * This program is free software; you can redistribute it and/or
3.11 * modify it under the terms of the GNU General Public License as
3.12 @@ -19,8 +19,9 @@
3.13 * Boston, MA 02110-1301, USA
3.14 */
3.15
3.16 +#include <mem/ipc.h>
3.17 +
3.18 #include "dataspace_server.h"
3.19 -#include "ipc.h"
3.20 #include "pager.h"
3.21
3.22 #include "copied_page_mapper.h"
4.1 --- a/libfsserver/lib/generic/simple_pager.cc Tue Mar 28 19:01:14 2023 +0200
4.2 +++ b/libfsserver/lib/generic/simple_pager.cc Wed Mar 29 00:32:20 2023 +0200
4.3 @@ -21,12 +21,12 @@
4.4
4.5 #include <l4/re/c/dataspace.h>
4.6
4.7 +#include <mem/ipc.h>
4.8 #include <mem/memory_incremental.h>
4.9
4.10 #include <string.h>
4.11
4.12 #include "dataspace_server.h"
4.13 -#include "ipc.h"
4.14 #include "simple_pager.h"
4.15
4.16
5.1 --- a/libfsserver/lib/mapping/ipc.cc Tue Mar 28 19:01:14 2023 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,73 +0,0 @@
5.4 -/*
5.5 - * Interprocess communication utilities.
5.6 - *
5.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
5.8 - *
5.9 - * This program is free software; you can redistribute it and/or
5.10 - * modify it under the terms of the GNU General Public License as
5.11 - * published by the Free Software Foundation; either version 2 of
5.12 - * the License, or (at your option) any later version.
5.13 - *
5.14 - * This program is distributed in the hope that it will be useful,
5.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.17 - * GNU General Public License for more details.
5.18 - *
5.19 - * You should have received a copy of the GNU General Public License
5.20 - * along with this program; if not, write to the Free Software
5.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
5.22 - * Boston, MA 02110-1301, USA
5.23 - */
5.24 -
5.25 -#include <l4/re/c/dataspace.h>
5.26 -#include <l4/re/consts.h>
5.27 -#include <l4/sys/task.h>
5.28 -
5.29 -#include <mem/send_flexpage.h>
5.30 -
5.31 -#include "ipc.h"
5.32 -
5.33 -
5.34 -
5.35 -/* Make an L4 representation of the given flexpage. */
5.36 -
5.37 -static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage)
5.38 -{
5.39 - unsigned char flags = send_flexpage->flags;
5.40 -
5.41 - if (!flags)
5.42 - flags = L4RE_DS_MAP_FLAG_RO;
5.43 -
5.44 - return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags);
5.45 -}
5.46 -
5.47 -/* Make a representation of a flexpage for the IPC system. */
5.48 -
5.49 -long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset,
5.50 - offset_t max_offset, map_address_t hot_spot,
5.51 - map_flags_t flags, l4_snd_fpage_t *region)
5.52 -{
5.53 - SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags,
5.54 - max_offset);
5.55 -
5.56 - /* NOTE: Consider l4_fpage_invalid() as the fpage here. */
5.57 -
5.58 - if (!send_flexpage.order)
5.59 - return -L4_ERANGE;
5.60 -
5.61 - region->fpage = ipc_get_fpage(&send_flexpage);
5.62 - region->snd_base = hot_spot;
5.63 -
5.64 - return L4_EOK;
5.65 -}
5.66 -
5.67 -/* Unmap the given flexpage. */
5.68 -
5.69 -void ipc_unmap_flexpage(Flexpage *flexpage)
5.70 -{
5.71 - SendFlexpage send_flexpage = flexpage->to_unmap();
5.72 -
5.73 - l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES);
5.74 -}
5.75 -
5.76 -// vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/libfsserver/lib/mapping/page_mapper.cc Tue Mar 28 19:01:14 2023 +0200
6.2 +++ b/libfsserver/lib/mapping/page_mapper.cc Wed Mar 29 00:32:20 2023 +0200
6.3 @@ -1,7 +1,7 @@
6.4 /*
6.5 * A page mapper providing memory pages to satisfy file accesses.
6.6 *
6.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
6.8 + * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
6.9 *
6.10 * This program is free software; you can redistribute it and/or
6.11 * modify it under the terms of the GNU General Public License as
6.12 @@ -19,7 +19,6 @@
6.13 * Boston, MA 02110-1301, USA
6.14 */
6.15
6.16 -#include "ipc.h"
6.17 #include "page_mapper.h"
6.18
6.19
6.20 @@ -165,23 +164,10 @@
6.21 _accessor->flush(flexpage);
6.22
6.23 /* Unmap the flexpage, requiring users of its memory to request another
6.24 - flexpage in future. */
6.25 -
6.26 - ipc_unmap_flexpage(flexpage);
6.27 - flexpage->invalidate();
6.28 -
6.29 - /* Unmap all derived flexpages, since these rely on the underlying file
6.30 - contents. */
6.31 + flexpage in future. This also unmaps all derived flexpages, since
6.32 + these rely on the underlying file contents. */
6.33
6.34 - DerivedFlexpages::iterator it;
6.35 -
6.36 - for (it = flexpage->derived.begin(); it != flexpage->derived.end(); it++)
6.37 - {
6.38 - ipc_unmap_flexpage(*it);
6.39 - (*it)->invalidate();
6.40 - }
6.41 -
6.42 - flexpage->disassociate();
6.43 + flexpage->invalidate();
6.44 }
6.45 }
6.46
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/libmem/include/mem/ipc.h Wed Mar 29 00:32:20 2023 +0200
7.3 @@ -0,0 +1,36 @@
7.4 +/*
7.5 + * Interprocess communication utilities.
7.6 + *
7.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
7.8 + *
7.9 + * This program is free software; you can redistribute it and/or
7.10 + * modify it under the terms of the GNU General Public License as
7.11 + * published by the Free Software Foundation; either version 2 of
7.12 + * the License, or (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License
7.20 + * along with this program; if not, write to the Free Software
7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 + * Boston, MA 02110-1301, USA
7.23 + */
7.24 +
7.25 +#pragma once
7.26 +
7.27 +#include <l4/sys/ipc.h>
7.28 +
7.29 +#include <mem/flexpage.h>
7.30 +
7.31 +
7.32 +
7.33 +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset,
7.34 + offset_t max_offset, map_address_t hot_spot,
7.35 + map_flags_t flags, l4_snd_fpage_t *region);
7.36 +
7.37 +void ipc_unmap_flexpage(Flexpage *flexpage);
7.38 +
7.39 +// vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/libmem/lib/src/Makefile Tue Mar 28 19:01:14 2023 +0200
8.2 +++ b/libmem/lib/src/Makefile Wed Mar 29 00:32:20 2023 +0200
8.3 @@ -5,7 +5,8 @@
8.4 PC_FILENAME = libmem
8.5
8.6 SRC_CC = \
8.7 - flexpage.cc memory_incremental.cc memory_preallocated.cc \
8.8 + flexpage.cc ipc.cc \
8.9 + memory_incremental.cc memory_preallocated.cc \
8.10 memory_utils.cc region.cc
8.11
8.12 REQUIRES_LIBS = l4re_c-util libstdc++ libsystypes libipc
9.1 --- a/libmem/lib/src/flexpage.cc Tue Mar 28 19:01:14 2023 +0200
9.2 +++ b/libmem/lib/src/flexpage.cc Wed Mar 29 00:32:20 2023 +0200
9.3 @@ -1,7 +1,7 @@
9.4 /*
9.5 * A flexpage abstraction.
9.6 *
9.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
9.8 + * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
9.9 *
9.10 * This program is free software; you can redistribute it and/or
9.11 * modify it under the terms of the GNU General Public License as
9.12 @@ -22,6 +22,7 @@
9.13 #include <algorithm>
9.14
9.15 #include "flexpage.h"
9.16 +#include "ipc.h"
9.17
9.18
9.19
9.20 @@ -99,11 +100,17 @@
9.21 _counter++;
9.22 }
9.23
9.24 -/* Invalidate the flexpage, meaning that it should not now be in use. */
9.25 +/* Unmap and invalidate the flexpage, meaning that it should not now be in
9.26 + use. */
9.27
9.28 void Flexpage::invalidate()
9.29 {
9.30 _counter = 0;
9.31 + ipc_unmap_flexpage(this);
9.32 +
9.33 + /* Unmap and invalidate all derived flexpages. */
9.34 +
9.35 + disassociate();
9.36 }
9.37
9.38 /* Return whether the flexpage is in use and is therefore valid. */
9.39 @@ -205,8 +212,15 @@
9.40 derived.push_back(flexpage);
9.41 }
9.42
9.43 +/* Invalidate and unmap all derived flexpages. */
9.44 +
9.45 void Flexpage::disassociate()
9.46 {
9.47 + DerivedFlexpages::iterator it;
9.48 +
9.49 + for (it = derived.begin(); it != derived.end(); it++)
9.50 + (*it)->invalidate();
9.51 +
9.52 derived.clear();
9.53 }
9.54
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/libmem/lib/src/ipc.cc Wed Mar 29 00:32:20 2023 +0200
10.3 @@ -0,0 +1,73 @@
10.4 +/*
10.5 + * Interprocess communication utilities.
10.6 + *
10.7 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
10.8 + *
10.9 + * This program is free software; you can redistribute it and/or
10.10 + * modify it under the terms of the GNU General Public License as
10.11 + * published by the Free Software Foundation; either version 2 of
10.12 + * the License, or (at your option) any later version.
10.13 + *
10.14 + * This program is distributed in the hope that it will be useful,
10.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.17 + * GNU General Public License for more details.
10.18 + *
10.19 + * You should have received a copy of the GNU General Public License
10.20 + * along with this program; if not, write to the Free Software
10.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
10.22 + * Boston, MA 02110-1301, USA
10.23 + */
10.24 +
10.25 +#include <l4/re/c/dataspace.h>
10.26 +#include <l4/re/consts.h>
10.27 +#include <l4/sys/task.h>
10.28 +
10.29 +#include <mem/send_flexpage.h>
10.30 +
10.31 +#include "ipc.h"
10.32 +
10.33 +
10.34 +
10.35 +/* Make an L4 representation of the given flexpage. */
10.36 +
10.37 +static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage)
10.38 +{
10.39 + unsigned char flags = send_flexpage->flags;
10.40 +
10.41 + if (!flags)
10.42 + flags = L4RE_DS_MAP_FLAG_RO;
10.43 +
10.44 + return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags);
10.45 +}
10.46 +
10.47 +/* Make a representation of a flexpage for the IPC system. */
10.48 +
10.49 +long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset,
10.50 + offset_t max_offset, map_address_t hot_spot,
10.51 + map_flags_t flags, l4_snd_fpage_t *region)
10.52 +{
10.53 + SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags,
10.54 + max_offset);
10.55 +
10.56 + /* NOTE: Consider l4_fpage_invalid() as the fpage here. */
10.57 +
10.58 + if (!send_flexpage.order)
10.59 + return -L4_ERANGE;
10.60 +
10.61 + region->fpage = ipc_get_fpage(&send_flexpage);
10.62 + region->snd_base = hot_spot;
10.63 +
10.64 + return L4_EOK;
10.65 +}
10.66 +
10.67 +/* Unmap the given flexpage. */
10.68 +
10.69 +void ipc_unmap_flexpage(Flexpage *flexpage)
10.70 +{
10.71 + SendFlexpage send_flexpage = flexpage->to_unmap();
10.72 +
10.73 + l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES);
10.74 +}
10.75 +
10.76 +// vim: tabstop=4 expandtab shiftwidth=4