[libc-commits] [libc] [libc] implement mlock/mlock2/munlock/mlockall/munlockall (PR #79645)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Jan 30 08:31:38 PST 2024
================
@@ -0,0 +1,174 @@
+//===-- Unittests for mlock -----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/errno/libc_errno.h"
+#include "src/sys/mman/madvise.h"
+#include "src/sys/mman/mincore.h"
+#include "src/sys/mman/mlock.h"
+#include "src/sys/mman/mlock2.h"
+#include "src/sys/mman/mlockall.h"
+#include "src/sys/mman/mmap.h"
+#include "src/sys/mman/munlock.h"
+#include "src/sys/mman/munlockall.h"
+#include "src/sys/mman/munmap.h"
+#include "src/sys/resource/getrlimit.h"
+#include "src/unistd/sysconf.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/LibcTest.h"
+#include "test/UnitTest/Test.h"
+
+#include <asm-generic/errno-base.h>
+#include <asm-generic/mman.h>
+#include <linux/capability.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+
+struct PageHolder {
+ size_t size;
+ void *addr;
+
+ PageHolder()
+ : size(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE)),
+ addr(LIBC_NAMESPACE::mmap(nullptr, size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)) {}
+ ~PageHolder() {
+ if (addr != MAP_FAILED)
+ LIBC_NAMESPACE::munmap(addr, size);
+ }
+
+ char &operator[](size_t i) { return reinterpret_cast<char *>(addr)[i]; }
+
+ bool is_valid() { return addr != MAP_FAILED; }
+};
+
+static bool get_capacity(unsigned int cap) {
+ struct __user_cap_header_struct header;
+ header.pid = 0;
+ header.version = _LINUX_CAPABILITY_VERSION_3;
+ struct __user_cap_data_struct data[_LINUX_CAPABILITY_U32S_3];
----------------
nickdesaulniers wrote:
no struct
https://github.com/llvm/llvm-project/pull/79645
More information about the libc-commits
mailing list