[libc-commits] [libc] [libc] Add some checks to the mmap wrapper (PR #197694)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Thu May 14 08:00:36 PDT 2026
================
@@ -41,3 +42,40 @@ TEST_F(LlvmLibcMMapTest, Error_InvalidSize) {
EXPECT_THAT(LIBC_NAMESPACE::munmap(0, 0), Fails(EINVAL));
}
+
+TEST_F(LlvmLibcMMapTest, FileOffsets) {
+ int fd = LIBC_NAMESPACE::memfd_create("mmap_test", MFD_CLOEXEC);
+ ASSERT_NE(fd, -1);
+ ASSERT_ERRNO_SUCCESS();
+ LIBC_NAMESPACE::cpp::scope_exit close_fd(
+ [&]() { ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); });
+
+ // Check that we can map a file from offset zero. This succeeds even though
+ // the file is empty.
+ void *addr = LIBC_NAMESPACE::mmap(nullptr, 47, PROT_READ,
+ MAP_ANONYMOUS | MAP_PRIVATE, fd, 0);
----------------
kaladron wrote:
Is the MAP_ANONYMOUS needed here if it's backed by a zero-length file?
https://github.com/llvm/llvm-project/pull/197694
More information about the libc-commits
mailing list