xref: /llvm-project/libc/src/sys/mman/linux/mlock.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
124923214SSchrodinger ZHU Yifan //===---------- Linux implementation of the mlock function ----------------===//
224923214SSchrodinger ZHU Yifan //
324923214SSchrodinger ZHU Yifan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
424923214SSchrodinger ZHU Yifan // See https://llvm.org/LICENSE.txt for license information.
524923214SSchrodinger ZHU Yifan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
624923214SSchrodinger ZHU Yifan //
724923214SSchrodinger ZHU Yifan //===----------------------------------------------------------------------===//
824923214SSchrodinger ZHU Yifan 
924923214SSchrodinger ZHU Yifan #include "src/sys/mman/mlock.h"
1024923214SSchrodinger ZHU Yifan 
1124923214SSchrodinger ZHU Yifan #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1224923214SSchrodinger ZHU Yifan 
13*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1424923214SSchrodinger ZHU Yifan #include "src/errno/libc_errno.h"
1524923214SSchrodinger ZHU Yifan #include <sys/syscall.h> // For syscall numbers.
1624923214SSchrodinger ZHU Yifan 
17*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
1824923214SSchrodinger ZHU Yifan 
1924923214SSchrodinger ZHU Yifan LLVM_LIBC_FUNCTION(int, mlock, (const void *addr, size_t len)) {
2024923214SSchrodinger ZHU Yifan   long ret = syscall_impl(SYS_mlock, cpp::bit_cast<long>(addr), len);
2124923214SSchrodinger ZHU Yifan   if (ret < 0) {
2224923214SSchrodinger ZHU Yifan     libc_errno = static_cast<int>(-ret);
2324923214SSchrodinger ZHU Yifan     return -1;
2424923214SSchrodinger ZHU Yifan   }
2524923214SSchrodinger ZHU Yifan   return 0;
2624923214SSchrodinger ZHU Yifan }
27*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
28