This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit fe16a50150e23f2d9d38652caf124d2cb86f600a
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 09:09:01 2026 -0600
backlog_view: bound entries by the bytes a page is mapped to
A page maps as far as its cells go, no longer a whole page, so an entry
whose offset and width pass the cells held by the mapping read past it.
Bound them by what was mapped: the size of the memfd mapped by a
client, or the size the store reports for a page it keeps, which the
view reads again each time the store says the head grew.
---
src/bin/backlog_store.c | 14 +++++++
src/bin/backlog_store.h | 4 ++
src/bin/backlog_view.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++--
src/bin/backlog_view.h | 3 ++
src/bin/termtymux.c | 1 +
src/bin/tytest.c | 3 ++
src/bin/unit_tests.h | 2 +
7 files changed, 122 insertions(+), 4 deletions(-)
diff --git a/src/bin/backlog_store.c b/src/bin/backlog_store.c
index 6e2de4f9..b387a23e 100644
--- a/src/bin/backlog_store.c
+++ b/src/bin/backlog_store.c
@@ -1345,6 +1345,20 @@ backlog_store_page_get(BacklogStore *bs, uint32_t page_id)
return page->export_map;
}
+size_t
+backlog_store_page_map_size(BacklogStore *bs, uint32_t page_id)
+{
+ BacklogStorePage *page;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(bs, 0);
+ page = _page_find(bs, page_id);
+ if (!page)
+ return 0;
+ if (page->state != PAGE_COMPRESSED)
+ return page->map_size;
+ return page->export_map ? page->export_size : 0;
+}
+
Eina_Bool
backlog_store_page_exists(BacklogStore *bs, uint32_t page_id)
{
diff --git a/src/bin/backlog_store.h b/src/bin/backlog_store.h
index 718d37c6..c7b6e445 100644
--- a/src/bin/backlog_store.h
+++ b/src/bin/backlog_store.h
@@ -178,6 +178,10 @@ Eina_Bool backlog_store_page_fd_async(BacklogStore *bs, uint32_t page_id,
const TermSrvBacklogPage *backlog_store_page_get(BacklogStore *bs,
uint32_t page_id);
+/* The bytes that backlog_store_page_get() maps for page_id, 0 for an unknown
+ * page or one that is not rebuilt. */
+size_t backlog_store_page_map_size(BacklogStore *bs, uint32_t page_id);
+
/* Whether page_id is held, whatever state it is in. */
Eina_Bool backlog_store_page_exists(BacklogStore *bs, uint32_t page_id);
diff --git a/src/bin/backlog_view.c b/src/bin/backlog_view.c
index 0db9a54b..103ffc51 100644
--- a/src/bin/backlog_view.c
+++ b/src/bin/backlog_view.c
@@ -18,9 +18,6 @@
# define MAP_NORESERVE 0
#endif
-#define PAGE_CELLS_MAX \
- ((size_t)TERMSRV_BACKLOG_PAGE_SEAL_CELLS + TERMSRV_BACKLOG_ENTRY_MAX_CELLS)
-
static Termcell *_blank_cells = NULL;
/* What the entries of the pages that are not mapped point at: one
@@ -78,6 +75,15 @@ _page_entry_w_get(const BacklogViewPage *page)
page->entries_per_page);
}
+/* How many cells the mapping of page holds after its header. */
+static size_t
+_page_cells_mapped(const BacklogViewPage *page)
+{
+ if (page->mapped_size <= page->header_size)
+ return 0;
+ return (page->mapped_size - page->header_size) / sizeof(Termcell);
+}
+
/* The cells and width of entry k of page. An entry that would not fit in
* the page is read as empty. Returns NULL if there are no cells to point
* at. */
@@ -101,7 +107,7 @@ _page_entry_get(const BacklogViewPage *page, uint32_t k, uint32_t *w)
*w = atomic_load_explicit(&_page_entry_w_get(page)[k],
memory_order_acquire);
if ((*w > TERMSRV_BACKLOG_ENTRY_MAX_CELLS) ||
- ((size_t)off + *w > PAGE_CELLS_MAX))
+ ((size_t)off + *w > _page_cells_mapped(page)))
{
off = 0;
*w = 0;
@@ -846,6 +852,9 @@ backlog_view_page_set(BacklogView *view, uint32_t page_id,
}
page->mapped = mapped;
page->map_size = size;
+ page->mapped_size = size;
+ if (!size && view->store)
+ page->mapped_size = backlog_store_page_map_size(view->store, page_id);
page->header_size = header_size;
page->entries_per_page = entries_per_page;
page->generation = atomic_load_explicit(&mapped->generation,
@@ -1042,6 +1051,7 @@ _local_page_moved(void *data, uint32_t page_id)
return;
}
page->mapped = mapped;
+ page->mapped_size = backlog_store_page_map_size(view->store, page_id);
_page_entries_repoint(view, page);
view->changed = EINA_TRUE;
}
@@ -1329,6 +1339,7 @@ _test_page_attach(BacklogViewPage *page, TermSrvBacklogPage *mapped)
{
page->mapped = mapped;
page->map_size = termsrv_backlog_page_size(mapped->header_size);
+ page->mapped_size = page->map_size;
page->header_size = mapped->header_size;
page->entries_per_page = mapped->entries_per_page;
}
@@ -1561,6 +1572,86 @@ tytest_backlog_view_map_short(void)
return 0;
}
+/* Test: an entry that lies beyond the bytes the page is mapped to, as a
+ * header written by another process may, reads as empty instead of past the
+ * mapping. The pages after it are protected, so a read there faults. */
+int
+tytest_backlog_view_entry_beyond_mapping(void)
+{
+ const uint32_t w[] = { 1, 1 };
+ Termpty *ty = _test_pty_new(10, 2, 32);
+ Test_Source src;
+ BacklogView *view = _test_view_new(ty, &src);
+ TermSrvBacklogPage *mapped = _test_page_new(0, 2, w, 'a');
+ BacklogViewPage *page;
+ uint32_t cells_mapped;
+ int err;
+
+ _pages_range_set(view, 0, 1);
+ page = &view->pages[0];
+ _test_page_attach(page, mapped);
+ page->mapped_size = mapped->header_size + 4096;
+ err = mprotect((char *)mapped + page->mapped_size,
+ page->map_size - page->mapped_size, PROT_NONE);
+ assert(!err);
+ cells_mapped = 4096 / sizeof(Termcell);
+ termsrv_backlog_entry_off(mapped)[1] = cells_mapped;
+
+ assert(backlog_view_sync(view));
+ assert(termpty_backlog_length(ty) == 2);
+ assert(BACKLOG_ROW_GET(ty, 2)->cells[0].codepoint == 'a');
+ assert(BACKLOG_ROW_GET(ty, 1)->w == 0);
+
+ _test_view_free(view, ty);
+ return 0;
+}
+
+/* Test: the head of a local view grows as an entry outgrows its mapping, in
+ * place or moving: the view learns the new size, and reads the entry that
+ * lies past the old one. */
+int
+tytest_backlog_view_local_grow(void)
+{
+ enum { BIG = 100000 };
+ Termcell small[10];
+ Termcell *big = calloc(BIG, sizeof(Termcell));
+ Termpty *ty = _test_pty_new(10, 2, 32);
+ BacklogStore *bs = backlog_store_new("view-grow", BACKLOG_STORE_ANON, 2000);
+ BacklogView *view;
+ BacklogViewPage *page;
+ Termcell *cells;
+ size_t old_size;
+ uint32_t w;
+
+ assert(big && bs);
+ memset(small, 0, sizeof(small));
+ big[BIG - 1].codepoint = 'x';
+ assert(backlog_store_append(bs, small, 10, BACKLOG_STORE_NEW, EINA_FALSE,
+ NULL));
+ view = backlog_view_local_new(ty, bs);
+ assert(view);
+ _pages_range_set(view, 0, 1);
+ _local_page_map(view, 0);
+ page = &view->pages[0];
+ assert(page->mapped);
+ old_size = backlog_store_page_map_size(bs, 0);
+ assert(page->mapped_size == old_size);
+
+ assert(backlog_store_append(bs, big, BIG, BACKLOG_STORE_NEW, EINA_FALSE,
+ NULL));
+ assert(backlog_store_page_map_size(bs, 0) > old_size);
+ assert(page->mapped_size == backlog_store_page_map_size(bs, 0));
+ assert(page->mapped == backlog_store_page_get(bs, 0));
+ assert((BIG + 10) * sizeof(Termcell) > old_size - page->header_size);
+ cells = _page_entry_get(page, 1, &w);
+ assert(w == BIG && cells[BIG - 1].codepoint == 'x');
+
+ _test_view_free(view, ty);
+ backlog_store_free(bs);
+ free(big);
+ return 0;
+}
+
/* Test: a map reply that does not echo the range asked for, or one that
* keeps echoing the same start, does not make the view ask again and again:
* only an echo that advances does. */
diff --git a/src/bin/backlog_view.h b/src/bin/backlog_view.h
index 49976e5d..69fa1747 100644
--- a/src/bin/backlog_view.h
+++ b/src/bin/backlog_view.h
@@ -28,6 +28,9 @@ typedef struct
const TermSrvBacklogPage *mapped; /* or NULL */
size_t map_size; /* to unmap it with, 0 if the
* source keeps the mapping */
+ size_t mapped_size; /* bytes the mapping holds:
+ * map_size, or what the store
+ * mapped if it keeps it */
uint32_t header_size; /* of the mapping, checked */
uint32_t entries_per_page; /* when it was handed over:
* not the header's */
diff --git a/src/bin/termtymux.c b/src/bin/termtymux.c
index 04464e3a..9dd26bab 100644
--- a/src/bin/termtymux.c
+++ b/src/bin/termtymux.c
@@ -1572,6 +1572,7 @@ _tt_page_attach(BacklogViewPage *page, TermSrvBacklogPage *mapped)
{
page->mapped = mapped;
page->map_size = termsrv_backlog_page_size(mapped->header_size);
+ page->mapped_size = page->map_size;
page->header_size = mapped->header_size;
page->entries_per_page = mapped->entries_per_page;
}
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index cdadc1e1..86694a10 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -190,6 +190,9 @@ static struct {
{ "backlog_view_ring_full", tytest_backlog_view_ring_full},
{ "backlog_view_map_again", tytest_backlog_view_map_again},
{ "backlog_view_map_empty", tytest_backlog_view_map_empty},
+ { "backlog_view_local_grow", tytest_backlog_view_local_grow},
+ { "backlog_view_entry_beyond_mapping",
+ tytest_backlog_view_entry_beyond_mapping},
{ "backlog_view_map_short", tytest_backlog_view_map_short},
{ "backlog_view_map_echo", tytest_backlog_view_map_echo},
{ "backlog_view_pending_evicted", tytest_backlog_view_pending_evicted},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index f40acda1..fcd22ca4 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -145,6 +145,8 @@ int tytest_backlog_view_sync(void);
int tytest_backlog_view_ring_full(void);
int tytest_backlog_view_map_again(void);
int tytest_backlog_view_map_empty(void);
+int tytest_backlog_view_entry_beyond_mapping(void);
+int tytest_backlog_view_local_grow(void);
int tytest_backlog_view_map_short(void);
int tytest_backlog_view_map_echo(void);
int tytest_backlog_view_pending_evicted(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.