Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal: PageList.reset has to zero arena memory to avoid reuse #2878

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/terminal/PageList.zig
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,25 @@ pub fn reset(self: *PageList) void {
.retain_with_limit = page_count * NodePool.item_size,
});

// Our page pool relies on mmap to zero our page memory. Since we're
// retaining a certain amount of memory, it won't use mmap and won't
// be zeroed. This block zeroes out all the memory in the pool arena.
{
// Note: we only have to do this for the page pool because the
// nodes are always fully overwritten on each allocation.
const page_arena = &self.pool.pages.arena;
var it = page_arena.state.buffer_list.first;
while (it) |node| : (it = node.next) {
// The fully allocated buffer
const alloc_buf = @as([*]u8, @ptrCast(node))[0..node.data];

// The buffer minus our header
const BufNode = @TypeOf(page_arena.state.buffer_list).Node;
const data_buf = alloc_buf[@sizeOf(BufNode)..];
@memset(data_buf, 0);
}
}

// Initialize our pages. This should not be able to fail since
// we retained the capacity for the minimum number of pages we need.
self.pages, self.page_size = initPages(
Expand Down