Skip to content

[libc] Use a syscall wrapper for posix_madvise - #240073

Open
c8ef wants to merge 1 commit into
mainfrom
users/c8ef/posix_madvise
Open

c8ef wants to merge 1 commit into
mainfrom
users/c8ef/posix_madvise

Conversation

@c8ef

@c8ef c8ef commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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

This PR move posix_madvise behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
@c8ef
c8ef requested review from a team, kaladron and labath as code owners November 8, 2026 00:20
@llvmorg-github-actions llvmorg-github-actions Bot added libc bazel "Peripheral" support tier build system: utils/bazel labels Nov 8, 2026
@c8ef
c8ef added this pull request to stack #240075 November 8, 2026 00:20
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

Changes

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


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

3 Files Affected:

  • (modified) libc/src/sys/mman/linux/CMakeLists.txt (+3-2)
  • (modified) libc/src/sys/mman/linux/posix_madvise.cpp (+9-7)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+1-1)
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",
     ],

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant