[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 12:59:48 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 ab9735c8a4911a220ccebd8175bc1fb0ca643b68 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 | 6 ++++++
 1 file changed, 6 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..fe5b58cb0854bbe 100644
--- a/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
+++ b/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
@@ -9,6 +9,9 @@
 #ifndef __LLVM_LIBC_MACROS_LINUX_SYS_MMAN_MACROS_H
 #define __LLVM_LIBC_MACROS_LINUX_SYS_MMAN_MACROS_H
 
+#if __has_include(<linux/mman.h>)
+#include <linux/mman.h>
+#else
 // Memory protection flags. (mmap, munmap, mprotect)
 #define PROT_NONE 0x0
 #define PROT_READ 0x1
@@ -85,4 +88,7 @@
 #define POSIX_MADV_WILLNEED MADV_WILLNEED
 #define POSIX_MADV_DONTNEED MADV_DONTNEED
 
+// Flags for mlock2.
+#define MLOCK_ONFAULT 0x01
+#endif // __has_include(<linux/mman.h>)
 #endif // __LLVM_LIBC_MACROS_LINUX_SYS_MMAN_MACROS_H



More information about the libc-commits mailing list