LibCore: Allow zero-size AnonymousBuffer creation

Previously, `AnonymousBuffer::create_with_size(0)` returned an error
because POSIX `mmap` rejects a zero length with `EINVAL`, and Windows
`CreateFileMapping` rejects a zero maximum size for an anonymous
mapping. This caused a crash when using `--headless=text` with zero
size pages like `about:blank`.
This commit is contained in:
Tim Ledbetter
2026-04-22 10:34:21 +01:00
committed by Tim Flynn
parent 1b5f85da1e
commit 884a0140aa
Notes: github-actions[bot] 2026-04-22 13:09:52 +00:00
4 changed files with 37 additions and 10 deletions

View File

@@ -42,6 +42,20 @@ TEST_CASE(read_and_write_contents)
EXPECT_EQ(read_back, payload);
}
TEST_CASE(create_with_zero_size)
{
auto buffer = MUST(Core::AnonymousBuffer::create_with_size(0));
EXPECT(buffer.is_valid());
EXPECT_EQ(buffer.size(), 0u);
EXPECT(buffer.bytes().is_empty());
auto fd = MUST(Core::System::dup(buffer.fd()));
auto mirror = MUST(Core::AnonymousBuffer::create_from_anon_fd(fd, 0));
EXPECT(mirror.is_valid());
EXPECT_EQ(mirror.size(), 0u);
EXPECT(mirror.bytes().is_empty());
}
TEST_CASE(reconstruct_from_anon_fd_shares_memory)
{
auto original = MUST(Core::AnonymousBuffer::create_with_size(128));