xref: /aosp_15_r20/external/llvm-libc/src/sys/mman/linux/remap_file_pages.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===------- Linux implementation of the remap_file_pages function --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/sys/mman/remap_file_pages.h"
10 
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/errno/libc_errno.h"
15 #include <sys/syscall.h> // For syscall numbers.
16 
17 namespace LIBC_NAMESPACE_DECL {
18 
19 LLVM_LIBC_FUNCTION(int, remap_file_pages,
20                    (void *addr, size_t size, int prot, size_t pgoff,
21                     int flags)) {
22 #ifdef SYS_remap_file_pages
23   int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_remap_file_pages,
24                                               reinterpret_cast<long>(addr),
25                                               size, prot, pgoff, flags);
26 #else
27 #error "remap_file_pages syscall is not available."
28 #endif
29 
30   // A negative return value indicates an error with the magnitude of the
31   // value being the error code.
32   if (ret < 0) {
33     libc_errno = -ret;
34     return -1;
35   }
36 
37   return 0;
38 }
39 
40 } // namespace LIBC_NAMESPACE_DECL
41