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 mlock() 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 26int main() { 27 int result; 28 long page_size; 29 void *page_ptr; 30 31 page_size = sysconf(_SC_PAGESIZE); 32 if(errno) { 33 perror("An error occurs when calling sysconf()"); 34 return PTS_UNRESOLVED; 35 } 36 37 page_ptr = (void*)( LONG_MAX - (LONG_MAX % page_size) ); 38 result = mlock(page_ptr, BUFSIZE); 39 40 if(result == -1 && errno == ENOMEM) { 41 printf("Test PASSED\n"); 42 return PTS_PASS; 43 } else if(errno == EPERM) { 44 printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); 45 return PTS_UNRESOLVED; 46 } else { 47 perror("Unexpected error"); 48 return PTS_UNRESOLVED; 49 } 50 51} 52