[libc-commits] [libc] [libc][NFC] Remove <sys/mman.h> from mmap.h and fix tests (PR #195240)

via libc-commits libc-commits at lists.llvm.org
Fri May 1 02:25:53 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Jeff Bailey (kaladron)

<details>
<summary>Changes</summary>

Removed the last direct <sys/mman.h> include from mmap.h, replacing it with hdr/types/size_t.h and hdr/types/off_t.h.

Added hdr/sys_mman_macros.h to test files that relied on transitive includes for PROT_READ, MAP_ANONYMOUS, and similar macros.

---
Full diff: https://github.com/llvm/llvm-project/pull/195240.diff


22 Files Affected:

- (modified) libc/src/sys/mman/mmap.h (+2-1) 
- (modified) libc/test/integration/src/pthread/CMakeLists.txt (+2) 
- (modified) libc/test/integration/src/pthread/pthread_create_test.cpp (+1) 
- (modified) libc/test/integration/src/pthread/pthread_rwlock_test.cpp (+1) 
- (modified) libc/test/integration/startup/linux/CMakeLists.txt (+1) 
- (modified) libc/test/integration/startup/linux/tls_test.cpp (+1) 
- (modified) libc/test/src/__support/threads/linux/CMakeLists.txt (+1) 
- (modified) libc/test/src/__support/threads/linux/raw_mutex_test.cpp (+1) 
- (modified) libc/test/src/strings/CMakeLists.txt (+1) 
- (modified) libc/test/src/strings/wide_read_memory_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/CMakeLists.txt (+11) 
- (modified) libc/test/src/sys/mman/linux/madvise_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/mincore_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/mlock_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/mmap_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/mprotect_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/mremap_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/msync_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/pkey_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/posix_madvise_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/remap_file_pages_test.cpp (+1) 
- (modified) libc/test/src/sys/mman/linux/shm_test.cpp (+1) 


``````````diff
diff --git a/libc/src/sys/mman/mmap.h b/libc/src/sys/mman/mmap.h
index b33be35d7b075..b6557b62d77e0 100644
--- a/libc/src/sys/mman/mmap.h
+++ b/libc/src/sys/mman/mmap.h
@@ -9,8 +9,9 @@
 #ifndef LLVM_LIBC_SRC_SYS_MMAN_MMAP_H
 #define LLVM_LIBC_SRC_SYS_MMAN_MMAP_H
 
+#include "hdr/types/off_t.h"
+#include "hdr/types/size_t.h"
 #include "src/__support/macros/config.h"
-#include <sys/mman.h> // For size_t and off_t
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/test/integration/src/pthread/CMakeLists.txt b/libc/test/integration/src/pthread/CMakeLists.txt
index 32ff223ffa986..98e5dbebbfcd1 100644
--- a/libc/test/integration/src/pthread/CMakeLists.txt
+++ b/libc/test/integration/src/pthread/CMakeLists.txt
@@ -50,6 +50,7 @@ add_integration_test(
   DEPENDS
     libc.hdr.time_macros
     libc.hdr.errno_macros
+    libc.hdr.sys_mman_macros
     libc.include.pthread
     libc.src.pthread.pthread_rwlock_destroy
     libc.src.pthread.pthread_rwlock_init
@@ -262,6 +263,7 @@ add_integration_test(
   SRCS
     pthread_create_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.pthread
     libc.src.errno.errno
     libc.src.pthread.pthread_create
diff --git a/libc/test/integration/src/pthread/pthread_create_test.cpp b/libc/test/integration/src/pthread/pthread_create_test.cpp
index 6fae8e747a204..a067a829e039b 100644
--- a/libc/test/integration/src/pthread/pthread_create_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_create_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/pthread/pthread_attr_destroy.h"
 #include "src/pthread/pthread_attr_getdetachstate.h"
 #include "src/pthread/pthread_attr_getguardsize.h"
diff --git a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
index 57d336d0704b1..1cc85caa89aa5 100644
--- a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/errno_macros.h"
+#include "hdr/sys_mman_macros.h"
 #include "hdr/time_macros.h"
 #include "src/__support/CPP/atomic.h"
 #include "src/__support/CPP/new.h"
diff --git a/libc/test/integration/startup/linux/CMakeLists.txt b/libc/test/integration/startup/linux/CMakeLists.txt
index 83baa8e1b2844..26ad9aa25623c 100644
--- a/libc/test/integration/startup/linux/CMakeLists.txt
+++ b/libc/test/integration/startup/linux/CMakeLists.txt
@@ -38,6 +38,7 @@ add_integration_test(
   SRCS
     tls_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.src.errno.errno
     libc.src.sys.mman.mmap
diff --git a/libc/test/integration/startup/linux/tls_test.cpp b/libc/test/integration/startup/linux/tls_test.cpp
index 7567f69f61d81..fac6c3ec5c24f 100644
--- a/libc/test/integration/startup/linux/tls_test.cpp
+++ b/libc/test/integration/startup/linux/tls_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/mmap.h"
 #include "test/IntegrationTest/test.h"
 
diff --git a/libc/test/src/__support/threads/linux/CMakeLists.txt b/libc/test/src/__support/threads/linux/CMakeLists.txt
index 855676b1ca05e..dd0cc5c81d176 100644
--- a/libc/test/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/test/src/__support/threads/linux/CMakeLists.txt
@@ -10,6 +10,7 @@ add_libc_test(
     libc.src.sys.mman.munmap
     libc.src.stdlib.exit
     libc.hdr.signal_macros
+    libc.hdr.sys_mman_macros
 )
 
 add_libc_test(
diff --git a/libc/test/src/__support/threads/linux/raw_mutex_test.cpp b/libc/test/src/__support/threads/linux/raw_mutex_test.cpp
index 6522ec75e619c..37755b2881391 100644
--- a/libc/test/src/__support/threads/linux/raw_mutex_test.cpp
+++ b/libc/test/src/__support/threads/linux/raw_mutex_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/signal_macros.h"
+#include "hdr/sys_mman_macros.h"
 #include "include/llvm-libc-macros/linux/time-macros.h"
 #include "src/__support/CPP/atomic.h"
 #include "src/__support/OSUtil/syscall.h"
diff --git a/libc/test/src/strings/CMakeLists.txt b/libc/test/src/strings/CMakeLists.txt
index 6e1befca16f37..4265211101a83 100644
--- a/libc/test/src/strings/CMakeLists.txt
+++ b/libc/test/src/strings/CMakeLists.txt
@@ -117,6 +117,7 @@ add_libc_test(
   SRCS
     wide_read_memory_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.src.string.string_utils
     libc.src.sys.mman.mmap
     libc.src.sys.mman.mprotect
diff --git a/libc/test/src/strings/wide_read_memory_test.cpp b/libc/test/src/strings/wide_read_memory_test.cpp
index 83a6294833b07..44b328d2c9c3f 100644
--- a/libc/test/src/strings/wide_read_memory_test.cpp
+++ b/libc/test/src/strings/wide_read_memory_test.cpp
@@ -21,6 +21,7 @@
 // unreadable, the middle usable normally. By placing test data at the edges
 // between the middle page and the others, we can test for bad accesses.
 
+#include "hdr/sys_mman_macros.h"
 #include "src/__support/CPP/array.h"
 #include "src/string/memory_utils/inline_memset.h"
 #include "src/string/string_utils.h"
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 8a290795e67f5..b73212d0c322f 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -7,6 +7,7 @@ add_libc_unittest(
   SRCS
     mmap_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.src.errno.errno
     libc.src.sys.mman.mmap
@@ -22,6 +23,7 @@ add_libc_unittest(
   SRCS
     mremap_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.src.errno.errno
     libc.src.sys.mman.mmap
@@ -39,6 +41,7 @@ if (NOT LLVM_USE_SANITIZER)
     SRCS
       mprotect_test.cpp
     DEPENDS
+      libc.hdr.sys_mman_macros
       libc.include.sys_mman
       libc.include.signal
       libc.src.errno.errno
@@ -57,6 +60,7 @@ add_libc_unittest(
   SRCS
   madvise_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.src.errno.errno
     libc.src.sys.mman.mmap
@@ -79,6 +83,7 @@ if (NOT LLVM_USE_SANITIZER)
     DEPENDS
       libc.hdr.errno_macros
       libc.hdr.signal_macros
+      libc.hdr.sys_mman_macros
       libc.hdr.types.size_t
       libc.src.sys.mman.mmap
       libc.src.sys.mman.munmap
@@ -99,6 +104,7 @@ add_libc_unittest(
   SRCS
   posix_madvise_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.src.errno.errno
     libc.src.sys.mman.mmap
@@ -115,6 +121,7 @@ add_libc_unittest(
   SRCS
     mincore_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.include.unistd
     libc.src.errno.errno
@@ -136,6 +143,7 @@ add_libc_unittest(
   SRCS
     mlock_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.include.unistd
     libc.src.errno.errno
@@ -162,6 +170,7 @@ add_libc_unittest(
   SRCS
     msync_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.include.unistd
     libc.src.errno.errno
@@ -183,6 +192,7 @@ add_libc_unittest(
   SRCS
     remap_file_pages_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.include.sys_stat
     libc.test.UnitTest.ErrnoCheckingTest
@@ -203,6 +213,7 @@ add_libc_unittest(
   SRCS
     shm_test.cpp
   DEPENDS
+    libc.hdr.sys_mman_macros
     libc.include.sys_mman
     libc.include.sys_syscall
     libc.src.errno.errno
diff --git a/libc/test/src/sys/mman/linux/madvise_test.cpp b/libc/test/src/sys/mman/linux/madvise_test.cpp
index b7c3f0571571c..5818696ce3840 100644
--- a/libc/test/src/sys/mman/linux/madvise_test.cpp
+++ b/libc/test/src/sys/mman/linux/madvise_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/madvise.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"
diff --git a/libc/test/src/sys/mman/linux/mincore_test.cpp b/libc/test/src/sys/mman/linux/mincore_test.cpp
index 1806bb1d671a2..65a184dc383ae 100644
--- a/libc/test/src/sys/mman/linux/mincore_test.cpp
+++ b/libc/test/src/sys/mman/linux/mincore_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/madvise.h"
 #include "src/sys/mman/mincore.h"
 #include "src/sys/mman/mlock.h"
diff --git a/libc/test/src/sys/mman/linux/mlock_test.cpp b/libc/test/src/sys/mman/linux/mlock_test.cpp
index 0056ccf7f0b3d..f8742e1b6749f 100644
--- a/libc/test/src/sys/mman/linux/mlock_test.cpp
+++ b/libc/test/src/sys/mman/linux/mlock_test.cpp
@@ -10,6 +10,7 @@
 // munlock, and munlockall should have separate test files which only need to
 // check our code paths (succeeds and errors).
 
+#include "hdr/sys_mman_macros.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/libc_errno.h"
 #include "src/sys/mman/madvise.h"
diff --git a/libc/test/src/sys/mman/linux/mmap_test.cpp b/libc/test/src/sys/mman/linux/mmap_test.cpp
index 1541576e3cbda..e5973a9f1888d 100644
--- a/libc/test/src/sys/mman/linux/mmap_test.cpp
+++ b/libc/test/src/sys/mman/linux/mmap_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"
 #include "test/UnitTest/ErrnoCheckingTest.h"
diff --git a/libc/test/src/sys/mman/linux/mprotect_test.cpp b/libc/test/src/sys/mman/linux/mprotect_test.cpp
index c1278a14fbfa7..07d0f7375f6ec 100644
--- a/libc/test/src/sys/mman/linux/mprotect_test.cpp
+++ b/libc/test/src/sys/mman/linux/mprotect_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/mprotect.h"
 #include "src/sys/mman/munmap.h"
diff --git a/libc/test/src/sys/mman/linux/mremap_test.cpp b/libc/test/src/sys/mman/linux/mremap_test.cpp
index 620292a2d0109..400719daf3af1 100644
--- a/libc/test/src/sys/mman/linux/mremap_test.cpp
+++ b/libc/test/src/sys/mman/linux/mremap_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/mremap.h"
 #include "src/sys/mman/munmap.h"
diff --git a/libc/test/src/sys/mman/linux/msync_test.cpp b/libc/test/src/sys/mman/linux/msync_test.cpp
index bf9640d39ebd6..7a9bab25be325 100644
--- a/libc/test/src/sys/mman/linux/msync_test.cpp
+++ b/libc/test/src/sys/mman/linux/msync_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/mlock.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/msync.h"
diff --git a/libc/test/src/sys/mman/linux/pkey_test.cpp b/libc/test/src/sys/mman/linux/pkey_test.cpp
index 9c6feae2d457b..73945df0d4177 100644
--- a/libc/test/src/sys/mman/linux/pkey_test.cpp
+++ b/libc/test/src/sys/mman/linux/pkey_test.cpp
@@ -8,6 +8,7 @@
 
 #include "hdr/errno_macros.h"
 #include "hdr/signal_macros.h"
+#include "hdr/sys_mman_macros.h"
 #include "hdr/types/size_t.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"
diff --git a/libc/test/src/sys/mman/linux/posix_madvise_test.cpp b/libc/test/src/sys/mman/linux/posix_madvise_test.cpp
index 7fe27182b02ce..59c580f61a5f9 100644
--- a/libc/test/src/sys/mman/linux/posix_madvise_test.cpp
+++ b/libc/test/src/sys/mman/linux/posix_madvise_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"
 #include "src/sys/mman/posix_madvise.h"
diff --git a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
index 08ffffe35ab2d..94e4c63286ad2 100644
--- a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
+++ b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_mman_macros.h"
 #include "src/fcntl/open.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"
diff --git a/libc/test/src/sys/mman/linux/shm_test.cpp b/libc/test/src/sys/mman/linux/shm_test.cpp
index 48bdf84c7270d..66875a535cfbb 100644
--- a/libc/test/src/sys/mman/linux/shm_test.cpp
+++ b/libc/test/src/sys/mman/linux/shm_test.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/fcntl_macros.h"
+#include "hdr/sys_mman_macros.h"
 #include "src/fcntl/fcntl.h"
 #include "src/sys/mman/mmap.h"
 #include "src/sys/mman/munmap.h"

``````````

</details>


https://github.com/llvm/llvm-project/pull/195240


More information about the libc-commits mailing list