[libc-commits] [libc] a542c29 - [libc] Use a syscall wrapper for posix_madvise (#240073)

via libc-commits libc-commits at lists.llvm.org
Sun Nov 8 03:18:05 PST 2026


Author: Connector Switch
Date: 2026-11-08T19:17:55+08:00
New Revision: a542c29cf9bdc6fea066743acc61d448d1f930cc

URL: https://github.com/llvm/llvm-project/commit/a542c29cf9bdc6fea066743acc61d448d1f930cc
DIFF: https://github.com/llvm/llvm-project/commit/a542c29cf9bdc6fea066743acc61d448d1f930cc.diff

LOG: [libc] Use a syscall wrapper for posix_madvise (#240073)

This PR move posix_madvise behind the centralized syscall wrappers,
following libc/docs/dev/syscall_wrapper_refactor.md.

Added: 
    

Modified: 
    libc/src/sys/mman/linux/CMakeLists.txt
    libc/src/sys/mman/linux/posix_madvise.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index d8426921f85dac..c13d482e50600e 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -94,8 +94,9 @@ add_entrypoint_object(
   DEPENDS
     libc.hdr.sys_mman_macros
     libc.hdr.types.size_t
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.madvise
+    libc.src.__support.common
+    libc.src.__support.macros.config
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/sys/mman/linux/posix_madvise.cpp b/libc/src/sys/mman/linux/posix_madvise.cpp
index 18427e25911fd5..265ef8400f4a06 100644
--- a/libc/src/sys/mman/linux/posix_madvise.cpp
+++ b/libc/src/sys/mman/linux/posix_madvise.cpp
@@ -1,19 +1,22 @@
-//===---------- Linux implementation of the POSIX posix_madvise function --===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of posix_madvise.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/sys/mman/posix_madvise.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/madvise.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
-#include <sys/syscall.h> // For syscall numbers.
-
 #include "hdr/sys_mman_macros.h" // For POSIX_MADV_DONTNEED.
 
 namespace LIBC_NAMESPACE_DECL {
@@ -26,9 +29,8 @@ LLVM_LIBC_FUNCTION(int, posix_madvise, (void *addr, size_t size, int advice)) {
   if (advice == POSIX_MADV_DONTNEED) {
     return 0;
   }
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(
-      SYS_madvise, reinterpret_cast<long>(addr), size, advice);
-  return ret < 0 ? -ret : 0;
+  auto result = linux_syscalls::madvise(addr, size, advice);
+  return result ? 0 : result.error();
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 89c312fa4fe87b..c50e9193ac4248 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -19998,7 +19998,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_macros_config",
-        ":__support_osutil_syscall",
+        ":__support_osutil_linux_syscall_wrappers_madvise",
         ":hdr_sys_mman_macros",
         ":types_size_t",
     ],


        


More information about the libc-commits mailing list