• 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 mlock return a value of zero upon successful completion.
11  *
12  */
13 #include <sys/mman.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <errno.h>
17 #include "posixtest.h"
18 
19 #define BUFSIZE 8
20 
main(void)21 int main(void)
22 {
23 	int result;
24 	void *ptr;
25 
26 	ptr = malloc(BUFSIZE);
27 	if (ptr == NULL) {
28 		printf("Can not allocate memory.\n");
29 		return PTS_UNRESOLVED;
30 	}
31 
32 	result = mlock(ptr, BUFSIZE);
33 	if (result == 0 && errno == 0) {
34 		printf("Test PASSED\n");
35 		return PTS_PASS;
36 	} else if (errno == 0) {
37 		printf("mlock did not return a value of zero\n");
38 		return PTS_FAIL;
39 	} else if (errno == EPERM) {
40 		printf
41 		    ("You don't have permission to lock your address space.\nTry to rerun this test as root.\n");
42 		return PTS_UNRESOLVED;
43 	}
44 
45 	perror("Unexpected error");
46 	return PTS_UNRESOLVED;
47 }
48