Linux: Remove generic Implies
[glibc.git] / sysdeps / unix / sysv / linux / tst-mlock2.c
blob415056485cf87c246f0c183dd136b264e9b45153
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/>. */
18 #include <errno.h>
19 #include <stdio.h>
20 #include <support/check.h>
21 #include <support/xunistd.h>
22 #include <sys/mman.h>
24 /* Allocate a page using mmap. */
25 static void *
26 get_page (void)
28 return xmmap (NULL, 1, PROT_READ | PROT_WRITE,
29 MAP_ANONYMOUS | MAP_PRIVATE, -1);
32 static int
33 do_test (void)
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");
41 xmunmap (page, 1);
43 page = get_page ();
44 if (mlock2 (page, 1, 0) != 0)
45 /* Should be implemented using mlock if necessary. */
46 FAIL_EXIT1 ("mlock2 (0): %m\n");
47 xmunmap (page, 1);
49 page = get_page ();
50 int ret = mlock2 (page, 1, MLOCK_ONFAULT);
51 if (ret != 0)
53 TEST_VERIFY (ret == -1);
54 if (errno != EINVAL)
55 /* EINVAL means the system does not support the mlock2 system
56 call. */
57 FAIL_EXIT1 ("mlock2 (0): %m\n");
58 else
59 puts ("warning: mlock2 system call not supported");
61 xmunmap (page, 1);
63 return 0;
66 #include <support/test-driver.c>