• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License version 2.
4  *
5  *  This program is distributed in the hope that it will be useful,
6  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
7  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8  *  GNU General Public License for more details.
9  *
10  * Test that the munlockall() function always return a value of zero if it is
11  * supported by the implementation.
12  */
13 
14 #include <unistd.h>
15 #include <sys/mman.h>
16 #include <stdio.h>
17 #include <errno.h>
18 #include "posixtest.h"
19 
20 #if !defined(_POSIX_MEMLOCK) || _POSIX_MEMLOCK == -1
21 
main(void)22 int main(void)
23 {
24 	printf("Does not support ML (Memory Lock).\n");
25 	return PTS_UNSUPPORTED;
26 }
27 
28 #else
29 
30 #if _POSIX_MEMLOCK != 0
main(void)31 int main(void)
32 {
33 	int result;
34 
35 	result = munlockall();
36 
37 	if (result == 0) {
38 		printf("Test PASSED\n");
39 		return PTS_PASS;
40 	} else if (errno == EPERM) {
41 		printf
42 		    ("You don't have permission to unlock your address space.\nTry to rerun this test as root.\n");
43 		return PTS_UNRESOLVED;
44 	} else {
45 		printf("munlockall() returns %i instead of zero.\n", result);
46 		return PTS_FAIL;
47 	}
48 
49 }
50 
51 #else
52 
main(void)53 int main(void)
54 {
55 	int result;
56 	long memlock;
57 
58 	memlock = sysconf(_SC_MEMLOCK);
59 	if (errno) {
60 		perror("An errno occurs when calling sysconf().\n");
61 		return PTS_UNRESOLVED;
62 	}
63 
64 	result = munlockall();
65 
66 	if ((result == 0 && memlock > 0) || (result == -1 && memlock <= 0)) {
67 		printf("Test PASSED\n");
68 		return PTS_PASS;
69 	} else if (errno == EPERM) {
70 		printf
71 		    ("You don't have permission to unlock your address space.\nTry to rerun this test as root.\n");
72 		return PTS_UNRESOLVED;
73 	} else {
74 		printf("munlockall() returns %i instead of zero.\n", result);
75 		return PTS_FAIL;
76 	}
77 
78 }
79 
80 #endif
81 
82 #endif
83