1/* 2 * Copyright (c) International Business Machines Corp., 2004 3 * Written by Robbie Williamson 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20/* 21 * Test Description: Test that a normal page cannot be mapped into a high 22 * memory region. 23 */ 24 25#include <sys/types.h> 26#include <sys/mman.h> 27#include <sys/mount.h> 28#include <sys/stat.h> 29#include <errno.h> 30#include <fcntl.h> 31#include <signal.h> 32#include <stdint.h> 33#include <stdio.h> 34#include <stdlib.h> 35#include <string.h> 36#include <unistd.h> 37#include "test.h" 38#include "safe_macros.h" 39#include "lapi/abisize.h" 40 41char *TCID = "mmap15"; 42int TST_TOTAL = 1; 43 44#ifdef __ia64__ 45# define HIGH_ADDR (void *)(0xa000000000000000UL) 46#else 47# define HIGH_ADDR (void *)(-page_size) 48#endif 49 50static long page_size; 51 52static void setup(void); 53static void cleanup(void); 54 55int main(int ac, char **av) 56{ 57 int lc, fd; 58 void *addr; 59 60#ifdef TST_ABI32 61 tst_brkm(TCONF, NULL, "This test is only for 64bit"); 62#endif 63 64 tst_parse_opts(ac, av, NULL, NULL); 65 66 setup(); 67 68 for (lc = 0; TEST_LOOPING(lc); lc++) { 69 tst_count = 0; 70 71 fd = SAFE_OPEN(cleanup, "testfile", O_RDWR | O_CREAT, 0666); 72 73 /* Attempt to mmap into highmem addr, should get ENOMEM */ 74 addr = mmap(HIGH_ADDR, page_size, PROT_READ, 75 MAP_SHARED | MAP_FIXED, fd, 0); 76 if (addr != MAP_FAILED) { 77 tst_resm(TFAIL, "mmap into high region " 78 "succeeded unexpectedly"); 79 munmap(addr, page_size); 80 close(fd); 81 continue; 82 } 83 84 if (errno != ENOMEM && errno != EINVAL) { 85 tst_resm(TFAIL | TERRNO, "mmap into high region " 86 "failed unexpectedly"); 87 } else { 88 tst_resm(TPASS | TERRNO, "mmap into high region " 89 "failed as expected"); 90 } 91 92 SAFE_CLOSE(cleanup, fd); 93 } 94 95 cleanup(); 96 tst_exit(); 97} 98 99static void setup(void) 100{ 101 tst_require_root(); 102 103 tst_tmpdir(); 104 105 page_size = getpagesize(); 106 107 TEST_PAUSE; 108} 109 110static void cleanup(void) 111{ 112 tst_rmdir(); 113} 114