[libc-commits] [libc] [libc] implement mlock/mlock2/munlock/mlockall/munlockall (PR #79645)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Fri Jan 26 13:08:44 PST 2024


https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/79645

>From e3a09dfaca3d013f816c46b4cb1bdd23783c55b8 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Fri, 26 Jan 2024 15:41:28 -0500
Subject: [PATCH 1/2] [libc] implement mlock/mlock2/munlock/mlockall/munlockall

---
 libc/spec/linux.td |  9 +++++++++
 libc/spec/posix.td | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/libc/spec/linux.td b/libc/spec/linux.td
index eab0a987b920cd9..0cb8b7f8bf5251b 100644
--- a/libc/spec/linux.td
+++ b/libc/spec/linux.td
@@ -89,6 +89,15 @@ def Linux : StandardSpec<"Linux"> {
               ArgSpec<UnsignedCharPtr>,
             ]
         >,
+        FunctionSpec<
+          "mlock2",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<VoidPtr>,
+            ArgSpec<SizeTType>,
+            ArgSpec<UnsignedIntType>,
+          ]
+        >,
       ]  // Functions
   >;
 
diff --git a/libc/spec/posix.td b/libc/spec/posix.td
index 7e1cf892135acf9..40a663afd2595ca 100644
--- a/libc/spec/posix.td
+++ b/libc/spec/posix.td
@@ -289,6 +289,26 @@ def POSIX : StandardSpec<"POSIX"> {
              ArgSpec<SizeTType>,
              ArgSpec<IntType>]
         >,
+        FunctionSpec<
+          "mlock",
+          RetValSpec<IntType>,
+          [ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
+        >,
+        FunctionSpec<
+          "munlock",
+          RetValSpec<IntType>,
+          [ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
+        >,
+        FunctionSpec<
+          "mlockall",
+          RetValSpec<IntType>,
+          [ArgSpec<IntType>]
+        >,
+        FunctionSpec<
+          "munlockall",
+          RetValSpec<IntType>,
+          [ArgSpec<VoidType>]
+        >,
       ]
   >;
 

>From 8167dbc2cd28771a55cba13f48132f16ca6cc074 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Fri, 26 Jan 2024 15:59:34 -0500
Subject: [PATCH 2/2] add mlock related flags

---
 libc/include/llvm-libc-macros/linux/sys-mman-macros.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/include/llvm-libc-macros/linux/sys-mman-macros.h b/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
index 1925c3c7cd3da09..33d2bc3850ee3db 100644
--- a/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
+++ b/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
@@ -85,4 +85,6 @@
 #define POSIX_MADV_WILLNEED MADV_WILLNEED
 #define POSIX_MADV_DONTNEED MADV_DONTNEED
 
+// Flags for mlock2.
+#define MLOCK_ONFAULT 0x01
 #endif // __LLVM_LIBC_MACROS_LINUX_SYS_MMAN_MACROS_H



More information about the libc-commits mailing list