1 /* Test the mlock2 function.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
20 #include <support/check.h>
21 #include <support/xunistd.h>
24 /* Allocate a page using mmap. */
28 return xmmap (NULL
, 1, PROT_READ
| PROT_WRITE
,
29 MAP_ANONYMOUS
| MAP_PRIVATE
, -1);
35 /* Current kernels have a small reserve of locked memory, so this
36 test does not need any privileges to run. */
38 void *page
= get_page ();
39 if (mlock (page
, 1) != 0)
40 FAIL_EXIT1 ("mlock: %m\n");
44 if (mlock2 (page
, 1, 0) != 0)
45 /* Should be implemented using mlock if necessary. */
46 FAIL_EXIT1 ("mlock2 (0): %m\n");
50 int ret
= mlock2 (page
, 1, MLOCK_ONFAULT
);
53 TEST_VERIFY (ret
== -1);
55 /* EINVAL means the system does not support the mlock2 system
57 FAIL_EXIT1 ("mlock2 (0): %m\n");
59 puts ("warning: mlock2 system call not supported");
66 #include <support/test-driver.c>