[libc-commits] [libc] [libc] Add some checks to the mmap wrapper (PR #197694)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Thu May 14 08:08:55 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);
----------------
labath wrote:
No, in fact, it goes against what I was trying to achieve. :(
The checks don't really care about whether they are mapping a file or not, but I wanted to make the test case realistic.
I'm going to blame AI autocomplete on that one :P
https://github.com/llvm/llvm-project/pull/197694
More information about the libc-commits
mailing list