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 munlock() function sets errno = ENOMEM if some or all of the 11 * address range specified by the addr and len arguments does not correspond to 12 * valid mapped pages in the address space of the process. 13 * 14 * Assume that the value LONG_MAX is an invalid pointer. 15 */ 16 17 #include <sys/mman.h> 18 #include <stdio.h> 19 #include <unistd.h> 20 #include <errno.h> 21 #include <limits.h> 22 #include "posixtest.h" 23 24 #define BUFSIZE 8 25 main(void)26int main(void) 27 { 28 int result; 29 long page_size; 30 void *page_ptr; 31 32 page_size = sysconf(_SC_PAGESIZE); 33 if (errno) { 34 perror("An error occurs when calling sysconf()"); 35 return PTS_UNRESOLVED; 36 } 37 38 page_ptr = (void *)(LONG_MAX - (LONG_MAX % page_size)); 39 result = munlock(page_ptr, BUFSIZE); 40 41 if (result == -1 && errno == ENOMEM) { 42 printf("Test PASSED\n"); 43 return PTS_PASS; 44 } else { 45 perror("Unexpected error"); 46 return PTS_UNRESOLVED; 47 } 48 49 } 50