]> sourceware.org Git - glibc.git/commitdiff
Implement the mlock2 function
authorFlorian Weimer <fweimer@redhat.com>
Mon, 27 Nov 2017 16:14:29 +0000 (17:14 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 27 Nov 2017 16:14:29 +0000 (17:14 +0100)
Fallback using mlock is provided if the flags argument is zero.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
37 files changed:
ChangeLog
NEWS
manual/memory.texi
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/aarch64/libc.abilist
sysdeps/unix/sysv/linux/alpha/libc.abilist
sysdeps/unix/sysv/linux/arm/libc.abilist
sysdeps/unix/sysv/linux/bits/mman-shared.h
sysdeps/unix/sysv/linux/hppa/libc.abilist
sysdeps/unix/sysv/linux/i386/libc.abilist
sysdeps/unix/sysv/linux/ia64/libc.abilist
sysdeps/unix/sysv/linux/kernel-features.h
sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
sysdeps/unix/sysv/linux/microblaze/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
sysdeps/unix/sysv/linux/mlock2.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/nios2/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
sysdeps/unix/sysv/linux/sh/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist
sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist
sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist
sysdeps/unix/sysv/linux/tst-mlock2.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist

index 389e39ea39a5388bf19e5f22335d065f389c604a..b7779c6b595f26f3aa9e1d37c004fbfbc4b2c920 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2017-11-27  Florian Weimer  <fweimer@redhat.com>
+
+       * sysdeps/unix/sysv/linux/mlock2.c: New file.
+       * sysdeps/unix/sysv/linux/tst-mlock2.c: Likewise.
+       * sysdeps/unix/sysv/linux/Makefile (routines): Add mlock2.
+       (tests): Add tst-mlock2.
+       * sysdeps/unix/sysv/linux/Versions (GLIBC_2.27): Export mlock2.
+       * sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_MLOCK2)
+       [__LINUX_KERNEL_VERSION >= 4.4]: Define.
+       * sysdeps/unix/sysv/linux/libc**.abilist: Update.
+       * manual/memory.texi (Page Lock Functions): Move @end deftypefun
+       for mlock.  Document mlock2.
+
 2017-11-27  Joseph Myers  <joseph@codesourcery.com>
 
        * sysdeps/ia64/Makeconfig (float64x-alias-fcts): New variable.
diff --git a/NEWS b/NEWS
index 33c62abf2f87bd58c5cbcb2f79dc38242755722f..f3fdf9aec56db0de9200d9b38ab2ad07f3eb5164 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,7 +41,7 @@ Major new features:
   18661-3:2015.  These are corresponding interfaces to those supported for
   _Float128.
 
-* glibc now implements the memfd_create function on Linux.
+* glibc now implements the memfd_create and mlock2 functions on Linux.
 
 Deprecated and removed features, and other changes affecting compatibility:
 
index 3f5dd9026061102abdf73c362ce225aef61c9d30..1b431bf5dae642ecd044f438dc3e7c5f43a938f1 100644 (file)
@@ -3337,6 +3337,36 @@ The calling process is not superuser.
 The kernel does not provide @code{mlock} capability.
 
 @end table
+@end deftypefun
+
+@deftypefun int mlock2 (const void *@var{addr}, size_t @var{len}, unsigned int @var{flags})
+@standards{Linux, sys/mman.h}
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+
+This function is similar to @code{mlock}.  If @var{flags} is zero, a
+call to @code{mlock2} behaves exactly as the equivalent call to @code{mlock}.
+
+The @var{flags} argument must be a combination of zero or more of the
+following flags:
+
+@vtable @code
+@item MLOCK_ONFAULT
+@standards{Linux, sys/mman.h}
+Only those pages in the specified address range which are already in
+memory are locked immediately.  Additional pages in the range are
+automatically locked in case of a page fault and allocation of memory.
+@end vtable
+
+Like @code{mlock}, @code{mlock2} returns zero on success and @code{-1}
+on failure, setting @code{errno} accordingly.  Additional @code{errno}
+values defined for @code{mlock2} are:
+
+@table @code
+@item EINVAL
+The specified (non-zero) @var{flags} argument is not supported by this
+system.
+@end table
+@end deftypefun
 
 You can lock @emph{all} a process' memory with @code{mlockall}.  You
 unlock memory with @code{munlock} or @code{munlockall}.
@@ -3346,8 +3376,6 @@ To avoid all page faults in a C program, you have to use
 from the C code, e.g. the stack and automatic variables, and you
 wouldn't know what address to tell @code{mlock}.
 
-@end deftypefun
-
 @deftypefun int munlock (const void *@var{addr}, size_t @var{len})
 @standards{POSIX.1b, sys/mman.h}
 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
index 58ce07b5262e87e881b608225ce09dba1f82dbd7..478f7e3d4d68148e9bddfd6b1387f2ce41869ce7 100644 (file)
@@ -18,7 +18,7 @@ sysdep_routines += clone umount umount2 readahead \
                   setfsuid setfsgid epoll_pwait signalfd \
                   eventfd eventfd_read eventfd_write prlimit \
                   personality epoll_wait tee vmsplice splice \
-                  open_by_handle_at
+                  open_by_handle_at mlock2
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables
@@ -44,7 +44,7 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
 
 tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
         tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
-        test-errno-linux tst-memfd_create
+        test-errno-linux tst-memfd_create tst-mlock2
 
 # Generate the list of SYS_* macros for the system calls (__NR_*
 # macros).  The file syscall-names.list contains all possible system
index 6f2fe516d7830d5687c6d3f6a9572e8f69ecc0d9..e799b62285b1db2c461d4908c596ec54fb5856ae 100644 (file)
@@ -168,6 +168,7 @@ libc {
   }
   GLIBC_2.27 {
     memfd_create;
+    mlock2;
   }
   GLIBC_PRIVATE {
     # functions used in other libraries
index af60b4f577a919df8fff90212a3bd201fdcc1f47..3448d62cee3b86301fa7e07e295da5a711569031 100644 (file)
@@ -2107,6 +2107,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index 98c6a17ae19b6685968a23881bfcfb84cc1a798d..d064f5445ed6542819b2c3971c6776acd1d5be52 100644 (file)
@@ -2018,6 +2018,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index 8a8af3e3e43c4bdb38699bd4662eeb25b626e3d7..a5ce7964d03e6eeb42674310ddfab77010000a3e 100644 (file)
@@ -108,6 +108,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.4 GLIBC_2.4 A
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
index 5bbcbbc14aede4d380a231cc60bd0f7fe74781b4..bee99c23841e44f31983bc3c1493d3fb9802b3e7 100644 (file)
 #  define MFD_HUGETLB 4U
 # endif
 
+/* Flags for mlock2.  */
+# ifndef MLOCK_ONFAULT
+#  define MLOCK_ONFAULT 1U
+# endif
+
 __BEGIN_DECLS
 
 /* Create a new memory file descriptor.  NAME is a name for debugging.
    FLAGS is a combination of the MFD_* constants.  */
 int memfd_create (const char *__name, unsigned int __flags) __THROW;
 
+/* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
+   memory.  FLAGS is a combination of the MLOCK_* flags above.  */
+int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW;
+
 __END_DECLS
 
 #endif /* __USE_GNU */
index 5b81a6cd7d8cb5a207dda64a5bdd7e912d0877a3..69ddf15361c05a25ebd78af6db342a7113823775 100644 (file)
@@ -1872,6 +1872,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index 1526778ec2ab698d26e9fb6a572e71bf54303cc2..a140edd4a39795e7d3c4506eb138666b4c41e991 100644 (file)
@@ -2037,6 +2037,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof64x F
 GLIBC_2.27 strtof64x_l F
index 132200f2bd539c2b97a1ea4d74adfef2003f1d86..178c0a45ecef85de9196d1da054c8198404b8310 100644 (file)
@@ -1901,6 +1901,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof64x F
 GLIBC_2.27 strtof64x_l F
index 2e1fe6597a11d76eb5ba564cdb189bedfa3210cc..59b613377f27c24674a0822f90a20626d465e09e 100644 (file)
 #if __LINUX_KERNEL_VERSION >= 0x031300
 # define __ASSUME_EXECVEAT     1
 #endif
+
+#if __LINUX_KERNEL_VERSION >= 0x040400
+# define __ASSUME_MLOCK2 1
+#endif
index d9c97779e48de7315918cded5643c13800d6c1f6..01d10d907cd9214341a8d197413f986fd29eee90 100644 (file)
@@ -109,6 +109,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.4 GLIBC_2.4 A
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
index 4acbf7eeed95fc518d86c61f8ac34b3c6e82704a..3ad08c20bfbe1004cb3c5ac491fc255ce2cbadf6 100644 (file)
@@ -1986,6 +1986,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index 93f02f08ceaa85a67260576b632bd468dbb1b2e7..6bd7be19290c818410600e85a458eb7c624ec252 100644 (file)
@@ -2107,3 +2107,4 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
index 795e85de7083b48a984a22b0bde4440d51356dca..9b1e890eda73d94af551c22522ab6a42afff5ac0 100644 (file)
@@ -1961,6 +1961,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index dc714057b75e011b0d571dcc545643c1a6c1bcc3..3eb5b66f8b9f06500665ff6eac13005bd87b33fc 100644 (file)
@@ -1959,6 +1959,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index 6ec940ee99c793349d6724ef16080d11e56462cf..543a725114b5cdc34cf781558fa3f8acdf2030e7 100644 (file)
@@ -1957,6 +1957,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index 71062b0eed17fa672730a640730cf34668edc747..a9198a3936ea31c1ab0565392045a9f597724ebf 100644 (file)
@@ -1952,6 +1952,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
diff --git a/sysdeps/unix/sysv/linux/mlock2.c b/sysdeps/unix/sysv/linux/mlock2.c
new file mode 100644 (file)
index 0000000..1686ab9
--- /dev/null
@@ -0,0 +1,40 @@
+/* Wrapper for the mlock2 system call with fallback to mlock.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/mman.h>
+#include <errno.h>
+#include <sysdep.h>
+
+int
+mlock2 (const void *addr, size_t length, unsigned int flags)
+{
+#ifdef __ASSUME_MLOCK2
+  return INLINE_SYSCALL_CALL (mlock2, addr, length, flags);
+#else
+  if (flags == 0)
+    return INLINE_SYSCALL_CALL (mlock, addr, length);
+# ifdef __NR_mlock2
+  int ret = INLINE_SYSCALL_CALL (mlock2, addr, length, flags);
+  if (ret == 0 || errno != ENOSYS)
+    return ret;
+# endif /* __NR_mlock2 */
+  /* Treat the missing system call as an invalid (non-zero) flag
+     argument.  */
+  __set_errno (EINVAL);
+  return -1;
+#endif /* __ASSUME_MLOCK2 */
+}
index 3e0bcb2a5ccd3f64be13bcf4b85fed1719640b0a..afacf1ff2db08e557a29a478c5f763b37c2bd4d6 100644 (file)
@@ -2148,3 +2148,4 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
index 375c69d9d1b201905bb4ece98b6002f4b36e3205..48af097b6afb3dae472069a9e3afcb3344b9c5ed 100644 (file)
@@ -1990,6 +1990,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index a88172a9069611d1a7db858e16e11e0b49a80504..e30535dac93ef04d8a50179215fcaf6b6a9859e2 100644 (file)
@@ -1995,6 +1995,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index a00f9042f816d6dddddaad1f511ebc641a29395e..f52270089029c5374499942273435c3402bff3e5 100644 (file)
@@ -2202,6 +2202,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof64x F
 GLIBC_2.27 strtof64x_l F
index 838f395d78e91401b194896efb551b210b6b2ed2..d3092afd25e67f4348837412086c51980b1bdc17 100644 (file)
@@ -109,6 +109,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 _Exit F
 GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
index b7dbfaa23ea1d0cda2c63fc0a96fe3820c900848..752176108edf523d5f69411fe6a00e51ae92b231 100644 (file)
@@ -1990,6 +1990,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index 1175cd7d13f73804882446c877aba040462a881b..b6d4c73635fe02952c395798031183f21555b447 100644 (file)
@@ -1891,6 +1891,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index bc1aae275eb64c7daba0d46496a18f7ad135925c..1ee21fe8e8c2454b28cdce04774fa1d405bd5009 100644 (file)
@@ -1876,6 +1876,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.3 GLIBC_2.3 A
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
index 899d5ff604d0529fad9b9e6446554887e15ebbd1..e652191c608a90a0af9f6a028fe9f11c86c66cfc 100644 (file)
@@ -1983,6 +1983,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index fbe0e51f629cc6b09c6d47e7e0d72caa9e02a6cc..37cf8713a5d738d28f3656ceb7f823a60f30ebd6 100644 (file)
@@ -1920,6 +1920,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof128 F
index e9eb4ff7bdeb42ff6402da8efd7378080d05f1e2..57427eb3eeee354ea9704e1b3c6f7a569b5fca9f 100644 (file)
@@ -2114,3 +2114,4 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
index 8f08e909cd033f447557cc1bbd111d04c23a2cc7..321f65c6007a5c839df3caee249de791ef0532e3 100644 (file)
@@ -2114,3 +2114,4 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
index e9eb4ff7bdeb42ff6402da8efd7378080d05f1e2..57427eb3eeee354ea9704e1b3c6f7a569b5fca9f 100644 (file)
@@ -2114,3 +2114,4 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
diff --git a/sysdeps/unix/sysv/linux/tst-mlock2.c b/sysdeps/unix/sysv/linux/tst-mlock2.c
new file mode 100644 (file)
index 0000000..53c435a
--- /dev/null
@@ -0,0 +1,66 @@
+/* Test the mlock2 function.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdio.h>
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/mman.h>
+
+/* Allocate a page using mmap.  */
+static void *
+get_page (void)
+{
+  return xmmap (NULL, 1, PROT_READ | PROT_WRITE,
+                MAP_ANONYMOUS | MAP_PRIVATE, -1);
+}
+
+static int
+do_test (void)
+{
+  /* Current kernels have a small reserve of locked memory, so this
+     test does not need any privileges to run.  */
+
+  void *page = get_page ();
+  if (mlock (page, 1) != 0)
+    FAIL_EXIT1 ("mlock: %m\n");
+  xmunmap (page, 1);
+
+  page = get_page ();
+  if (mlock2 (page, 1, 0) != 0)
+    /* Should be implemented using mlock if necessary.  */
+    FAIL_EXIT1 ("mlock2 (0): %m\n");
+  xmunmap (page, 1);
+
+  page = get_page ();
+  int ret = mlock2 (page, 1, MLOCK_ONFAULT);
+  if (ret != 0)
+    {
+      TEST_VERIFY (ret == -1);
+      if (errno != EINVAL)
+        /* EINVAL means the system does not support the mlock2 system
+           call.  */
+        FAIL_EXIT1 ("mlock2 (0): %m\n");
+      else
+        puts ("warning: mlock2 system call not supported");
+    }
+  xmunmap (page, 1);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index 9c4b53b4168714d4609d6e99270b40ca93c4d712..f26c8b99d543c9dfc7ffce15df39c07e5ec1eca1 100644 (file)
@@ -1878,6 +1878,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof64x F
 GLIBC_2.27 strtof64x_l F
index 7a179a5ff6544ff36a27dbd4bc39c6709bfa72eb..2a6057154b433d8f702e2125a315359045303366 100644 (file)
@@ -2121,6 +2121,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
+GLIBC_2.27 mlock2 F
 GLIBC_2.27 strfromf64x F
 GLIBC_2.27 strtof64x F
 GLIBC_2.27 strtof64x_l F
This page took 0.127794 seconds and 5 git commands to generate.