1865695bbc89088b9526ea9045410e5afb70a985cplars/* 2865695bbc89088b9526ea9045410e5afb70a985cplars * 3865695bbc89088b9526ea9045410e5afb70a985cplars * Copyright (c) International Business Machines Corp., 2001 4865695bbc89088b9526ea9045410e5afb70a985cplars * 5865695bbc89088b9526ea9045410e5afb70a985cplars * This program is free software; you can redistribute it and/or modify 6865695bbc89088b9526ea9045410e5afb70a985cplars * it under the terms of the GNU General Public License as published by 7865695bbc89088b9526ea9045410e5afb70a985cplars * the Free Software Foundation; either version 2 of the License, or 8865695bbc89088b9526ea9045410e5afb70a985cplars * (at your option) any later version. 9865695bbc89088b9526ea9045410e5afb70a985cplars * 10865695bbc89088b9526ea9045410e5afb70a985cplars * This program is distributed in the hope that it will be useful, 11865695bbc89088b9526ea9045410e5afb70a985cplars * but WITHOUT ANY WARRANTY; without even the implied warranty of 12865695bbc89088b9526ea9045410e5afb70a985cplars * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13865695bbc89088b9526ea9045410e5afb70a985cplars * the GNU General Public License for more details. 14865695bbc89088b9526ea9045410e5afb70a985cplars * 15865695bbc89088b9526ea9045410e5afb70a985cplars * You should have received a copy of the GNU General Public License 16865695bbc89088b9526ea9045410e5afb70a985cplars * along with this program; if not, write to the Free Software 174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18865695bbc89088b9526ea9045410e5afb70a985cplars */ 19865695bbc89088b9526ea9045410e5afb70a985cplars 20865695bbc89088b9526ea9045410e5afb70a985cplars/* 21865695bbc89088b9526ea9045410e5afb70a985cplars * Test Name: munmap02 22865695bbc89088b9526ea9045410e5afb70a985cplars * 23865695bbc89088b9526ea9045410e5afb70a985cplars * Test Description: 24865695bbc89088b9526ea9045410e5afb70a985cplars * Verify that, munmap call will succeed to unmap a mapped file or 25865695bbc89088b9526ea9045410e5afb70a985cplars * anonymous shared memory region from the calling process's address space 26865695bbc89088b9526ea9045410e5afb70a985cplars * if the region specified by the address and the length is part or all of 27865695bbc89088b9526ea9045410e5afb70a985cplars * the mapped region. 28865695bbc89088b9526ea9045410e5afb70a985cplars * 29865695bbc89088b9526ea9045410e5afb70a985cplars * Expected Result: 30865695bbc89088b9526ea9045410e5afb70a985cplars * munmap call should succeed to unmap a part or all of mapped region of a 31865695bbc89088b9526ea9045410e5afb70a985cplars * file or anonymous shared memory from the process's address space and it 324bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * returns with a value 0, 33865695bbc89088b9526ea9045410e5afb70a985cplars * further reference to the unmapped region should result in a segmentation 34865695bbc89088b9526ea9045410e5afb70a985cplars * fault (SIGSEGV). 35865695bbc89088b9526ea9045410e5afb70a985cplars * 36865695bbc89088b9526ea9045410e5afb70a985cplars * Algorithm: 37865695bbc89088b9526ea9045410e5afb70a985cplars * Setup: 38865695bbc89088b9526ea9045410e5afb70a985cplars * Setup signal handling. 39865695bbc89088b9526ea9045410e5afb70a985cplars * Create temporary directory. 40865695bbc89088b9526ea9045410e5afb70a985cplars * Pause for SIGUSR1 if option specified. 41865695bbc89088b9526ea9045410e5afb70a985cplars * 42865695bbc89088b9526ea9045410e5afb70a985cplars * Test: 43865695bbc89088b9526ea9045410e5afb70a985cplars * Loop if the proper options are given. 44865695bbc89088b9526ea9045410e5afb70a985cplars * Execute system call 45865695bbc89088b9526ea9045410e5afb70a985cplars * Check return code, if system call failed (return=-1) 46865695bbc89088b9526ea9045410e5afb70a985cplars * Log the errno and Issue a FAIL message. 47865695bbc89088b9526ea9045410e5afb70a985cplars * Otherwise, 48bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak * Verify the Functionality of system call 49865695bbc89088b9526ea9045410e5afb70a985cplars * if successful, 50865695bbc89088b9526ea9045410e5afb70a985cplars * Issue Functionality-Pass message. 51865695bbc89088b9526ea9045410e5afb70a985cplars * Otherwise, 52865695bbc89088b9526ea9045410e5afb70a985cplars * Issue Functionality-Fail message. 53865695bbc89088b9526ea9045410e5afb70a985cplars * Cleanup: 54865695bbc89088b9526ea9045410e5afb70a985cplars * Print errno log and/or timing stats if options given 55865695bbc89088b9526ea9045410e5afb70a985cplars * Delete the temporary directory created. 56865695bbc89088b9526ea9045410e5afb70a985cplars * 57865695bbc89088b9526ea9045410e5afb70a985cplars * Usage: <for command-line> 58865695bbc89088b9526ea9045410e5afb70a985cplars * munmap01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] 59865695bbc89088b9526ea9045410e5afb70a985cplars * where, -c n : Run n copies concurrently. 60865695bbc89088b9526ea9045410e5afb70a985cplars * -f : Turn off functionality Testing. 61865695bbc89088b9526ea9045410e5afb70a985cplars * -i n : Execute test n times. 62865695bbc89088b9526ea9045410e5afb70a985cplars * -I x : Execute test for x seconds. 63865695bbc89088b9526ea9045410e5afb70a985cplars * -P x : Pause for x seconds between iterations. 64865695bbc89088b9526ea9045410e5afb70a985cplars * -t : Turn on syscall timing. 65865695bbc89088b9526ea9045410e5afb70a985cplars * 66865695bbc89088b9526ea9045410e5afb70a985cplars * HISTORY 67865695bbc89088b9526ea9045410e5afb70a985cplars * 07/2001 Ported by Wayne Boyer 68865695bbc89088b9526ea9045410e5afb70a985cplars * 69865695bbc89088b9526ea9045410e5afb70a985cplars * RESTRICTIONS: 70865695bbc89088b9526ea9045410e5afb70a985cplars * None. 71865695bbc89088b9526ea9045410e5afb70a985cplars */ 72865695bbc89088b9526ea9045410e5afb70a985cplars#include <errno.h> 73865695bbc89088b9526ea9045410e5afb70a985cplars#include <unistd.h> 74865695bbc89088b9526ea9045410e5afb70a985cplars#include <fcntl.h> 75865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/stat.h> 76865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/mman.h> 77865695bbc89088b9526ea9045410e5afb70a985cplars 78865695bbc89088b9526ea9045410e5afb70a985cplars#include "test.h" 79865695bbc89088b9526ea9045410e5afb70a985cplars 80865695bbc89088b9526ea9045410e5afb70a985cplars#define TEMPFILE "mmapfile" 81865695bbc89088b9526ea9045410e5afb70a985cplars 82fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716Cyril Hrubischar *TCID = "munmap02"; 83fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716Cyril Hrubisint TST_TOTAL = 1; 84865695bbc89088b9526ea9045410e5afb70a985cplars 859d048f81cb2c60d2f019ea3677f12928f8629cf1Zeng Linggangstatic size_t page_sz; 86865695bbc89088b9526ea9045410e5afb70a985cplarschar *addr; /* addr of memory mapped region */ 87865695bbc89088b9526ea9045410e5afb70a985cplarsint fildes; /* file descriptor for tempfile */ 88865695bbc89088b9526ea9045410e5afb70a985cplarsunsigned int map_len; /* length of the region to be mapped */ 89865695bbc89088b9526ea9045410e5afb70a985cplars 90865695bbc89088b9526ea9045410e5afb70a985cplarsvoid setup(); /* Main setup function of test */ 91865695bbc89088b9526ea9045410e5afb70a985cplarsvoid cleanup(); /* cleanup function for the test */ 92865695bbc89088b9526ea9045410e5afb70a985cplarsvoid sig_handler(); /* signal catching function */ 93865695bbc89088b9526ea9045410e5afb70a985cplars 94e68561c77204321438fe275bb4425f73f90b9a8arobbiew#ifndef UCLINUX 95e68561c77204321438fe275bb4425f73f90b9a8arobbiew 9656207cec7732e09c216c751c0b5f88a242bacae6subrata_modakint main(int ac, char **av) 97865695bbc89088b9526ea9045410e5afb70a985cplars{ 9889af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis int lc; 99bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 100d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(ac, av, NULL, NULL); 101865695bbc89088b9526ea9045410e5afb70a985cplars 102865695bbc89088b9526ea9045410e5afb70a985cplars for (lc = 0; TEST_LOOPING(lc); lc++) { 103865695bbc89088b9526ea9045410e5afb70a985cplars 104d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 105865695bbc89088b9526ea9045410e5afb70a985cplars 106865695bbc89088b9526ea9045410e5afb70a985cplars setup(); 107865695bbc89088b9526ea9045410e5afb70a985cplars 1084bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak /* 109865695bbc89088b9526ea9045410e5afb70a985cplars * Call munmap to unmap the part of the mapped region of the 110865695bbc89088b9526ea9045410e5afb70a985cplars * temporary file from the address and length that is part of 111865695bbc89088b9526ea9045410e5afb70a985cplars * the mapped region. 112865695bbc89088b9526ea9045410e5afb70a985cplars */ 113865695bbc89088b9526ea9045410e5afb70a985cplars TEST(munmap(addr, map_len)); 114865695bbc89088b9526ea9045410e5afb70a985cplars 115865695bbc89088b9526ea9045410e5afb70a985cplars /* Check for the return value of munmap() */ 116865695bbc89088b9526ea9045410e5afb70a985cplars if (TEST_RETURN == -1) { 117865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TFAIL, "munmap() fails, errno=%d : %s", 118865695bbc89088b9526ea9045410e5afb70a985cplars TEST_ERRNO, strerror(TEST_ERRNO)); 119865695bbc89088b9526ea9045410e5afb70a985cplars continue; 120865695bbc89088b9526ea9045410e5afb70a985cplars } 121865695bbc89088b9526ea9045410e5afb70a985cplars /* 122e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis * Check whether further reference is possible 123e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis * to the unmapped memory region by writing 124e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis * to the first byte of region with 125e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis * some arbitrary number. 126865695bbc89088b9526ea9045410e5afb70a985cplars */ 127e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis *addr = 50; 128865695bbc89088b9526ea9045410e5afb70a985cplars 129e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* This message is printed if no SIGSEGV */ 130e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TFAIL, "process succeeds to refer unmapped " 131e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis "memory region"); 132865695bbc89088b9526ea9045410e5afb70a985cplars cleanup(); 133865695bbc89088b9526ea9045410e5afb70a985cplars 1342c28215423293e443469a07ae7011135d058b671Garrett Cooper } 135ad8b91f328fab376f5f52ff73babcdd941e58217Garrett Cooper tst_exit(); 1362c28215423293e443469a07ae7011135d058b671Garrett Cooper} 137865695bbc89088b9526ea9045410e5afb70a985cplars 138e68561c77204321438fe275bb4425f73f90b9a8arobbiew#else 139e68561c77204321438fe275bb4425f73f90b9a8arobbiew 140c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingerint main(void) 141e68561c77204321438fe275bb4425f73f90b9a8arobbiew{ 142e68561c77204321438fe275bb4425f73f90b9a8arobbiew tst_resm(TINFO, "munmap02 test is not available on uClinux"); 1432c28215423293e443469a07ae7011135d058b671Garrett Cooper tst_exit(); 144e68561c77204321438fe275bb4425f73f90b9a8arobbiew} 145e68561c77204321438fe275bb4425f73f90b9a8arobbiew 146e68561c77204321438fe275bb4425f73f90b9a8arobbiew#endif /* ifndef UCLINUX */ 147e68561c77204321438fe275bb4425f73f90b9a8arobbiew 148865695bbc89088b9526ea9045410e5afb70a985cplars/* 149865695bbc89088b9526ea9045410e5afb70a985cplars * setup() - performs all ONE TIME setup for this test. 150865695bbc89088b9526ea9045410e5afb70a985cplars * Setup signal handler to catch SIGSEGV. 151865695bbc89088b9526ea9045410e5afb70a985cplars * Get system page size, create a temporary file for reading/writing, 152865695bbc89088b9526ea9045410e5afb70a985cplars * write one byte data into it, map the open file for the specified 153865695bbc89088b9526ea9045410e5afb70a985cplars * map length. 154865695bbc89088b9526ea9045410e5afb70a985cplars */ 155c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid setup(void) 156865695bbc89088b9526ea9045410e5afb70a985cplars{ 157865695bbc89088b9526ea9045410e5afb70a985cplars 158865695bbc89088b9526ea9045410e5afb70a985cplars tst_sig(NOFORK, DEF_HANDLER, cleanup); 159865695bbc89088b9526ea9045410e5afb70a985cplars 160865695bbc89088b9526ea9045410e5afb70a985cplars /* call signal function to trap the signal generated */ 161865695bbc89088b9526ea9045410e5afb70a985cplars if (signal(SIGSEGV, sig_handler) == SIG_ERR) { 162865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "signal fails to catch signal"); 163865695bbc89088b9526ea9045410e5afb70a985cplars } 164865695bbc89088b9526ea9045410e5afb70a985cplars 165865695bbc89088b9526ea9045410e5afb70a985cplars TEST_PAUSE; 166865695bbc89088b9526ea9045410e5afb70a985cplars 167865695bbc89088b9526ea9045410e5afb70a985cplars /* Get the system page size */ 1689d048f81cb2c60d2f019ea3677f12928f8629cf1Zeng Linggang page_sz = getpagesize(); 169865695bbc89088b9526ea9045410e5afb70a985cplars 170865695bbc89088b9526ea9045410e5afb70a985cplars /* 171865695bbc89088b9526ea9045410e5afb70a985cplars * Get the length of the open file to be mapped into process 172865695bbc89088b9526ea9045410e5afb70a985cplars * address space. 173865695bbc89088b9526ea9045410e5afb70a985cplars */ 174865695bbc89088b9526ea9045410e5afb70a985cplars map_len = 3 * page_sz; 175865695bbc89088b9526ea9045410e5afb70a985cplars 176865695bbc89088b9526ea9045410e5afb70a985cplars tst_tmpdir(); 177865695bbc89088b9526ea9045410e5afb70a985cplars 178865695bbc89088b9526ea9045410e5afb70a985cplars /* Creat a temporary file used for mapping */ 179865695bbc89088b9526ea9045410e5afb70a985cplars if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) { 180865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "open() on %s Failed, errno=%d : %s", 181865695bbc89088b9526ea9045410e5afb70a985cplars TEMPFILE, errno, strerror(errno)); 182865695bbc89088b9526ea9045410e5afb70a985cplars } 183865695bbc89088b9526ea9045410e5afb70a985cplars 184865695bbc89088b9526ea9045410e5afb70a985cplars /* 185865695bbc89088b9526ea9045410e5afb70a985cplars * move the file pointer to maplength position from the beginning 186865695bbc89088b9526ea9045410e5afb70a985cplars * of the file. 187865695bbc89088b9526ea9045410e5afb70a985cplars */ 188865695bbc89088b9526ea9045410e5afb70a985cplars if (lseek(fildes, map_len, SEEK_SET) == -1) { 189865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "lseek() fails on %s, errno=%d : %s", 190865695bbc89088b9526ea9045410e5afb70a985cplars TEMPFILE, errno, strerror(errno)); 191865695bbc89088b9526ea9045410e5afb70a985cplars } 192865695bbc89088b9526ea9045410e5afb70a985cplars 193865695bbc89088b9526ea9045410e5afb70a985cplars /* Write one byte into temporary file */ 194865695bbc89088b9526ea9045410e5afb70a985cplars if (write(fildes, "a", 1) != 1) { 195865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "write() on %s Failed, errno=%d : %s", 196865695bbc89088b9526ea9045410e5afb70a985cplars TEMPFILE, errno, strerror(errno)); 197865695bbc89088b9526ea9045410e5afb70a985cplars } 198bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 199865695bbc89088b9526ea9045410e5afb70a985cplars /* 200865695bbc89088b9526ea9045410e5afb70a985cplars * map the open file 'TEMPFILE' from its beginning up to the maplength 201865695bbc89088b9526ea9045410e5afb70a985cplars * into the calling process's address space at the system choosen 202865695bbc89088b9526ea9045410e5afb70a985cplars * with read/write permissions to the the mapped region. 203865695bbc89088b9526ea9045410e5afb70a985cplars */ 204034306d15fec7cc6c9b4e9d5e6f17b51eb17c02crobbiew#ifdef UCLINUX 205034306d15fec7cc6c9b4e9d5e6f17b51eb17c02crobbiew /* mmap() doesn't support MAP_SHARED on uClinux */ 206034306d15fec7cc6c9b4e9d5e6f17b51eb17c02crobbiew addr = mmap(0, map_len, PROT_READ | PROT_WRITE, 207034306d15fec7cc6c9b4e9d5e6f17b51eb17c02crobbiew MAP_FILE | MAP_PRIVATE, fildes, 0); 208034306d15fec7cc6c9b4e9d5e6f17b51eb17c02crobbiew#else 209865695bbc89088b9526ea9045410e5afb70a985cplars addr = mmap(0, map_len, PROT_READ | PROT_WRITE, 210865695bbc89088b9526ea9045410e5afb70a985cplars MAP_FILE | MAP_SHARED, fildes, 0); 211034306d15fec7cc6c9b4e9d5e6f17b51eb17c02crobbiew#endif 212865695bbc89088b9526ea9045410e5afb70a985cplars 213865695bbc89088b9526ea9045410e5afb70a985cplars /* check for the return value of mmap system call */ 214865695bbc89088b9526ea9045410e5afb70a985cplars if (addr == (char *)MAP_FAILED) { 215865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "mmap() Failed on %s, errno=%d : %s", 216865695bbc89088b9526ea9045410e5afb70a985cplars TEMPFILE, errno, strerror(errno)); 217865695bbc89088b9526ea9045410e5afb70a985cplars } 218865695bbc89088b9526ea9045410e5afb70a985cplars 219865695bbc89088b9526ea9045410e5afb70a985cplars /* 220865695bbc89088b9526ea9045410e5afb70a985cplars * increment the start address of the region at which the file is 221865695bbc89088b9526ea9045410e5afb70a985cplars * mapped to a maplength of 3 times the system page size by the value 222865695bbc89088b9526ea9045410e5afb70a985cplars * of system page size and decrement the maplength value by the value 223865695bbc89088b9526ea9045410e5afb70a985cplars * of system page size. 224865695bbc89088b9526ea9045410e5afb70a985cplars */ 225865695bbc89088b9526ea9045410e5afb70a985cplars addr = (char *)((long)addr + page_sz); 226865695bbc89088b9526ea9045410e5afb70a985cplars map_len = map_len - page_sz; 227865695bbc89088b9526ea9045410e5afb70a985cplars} 228865695bbc89088b9526ea9045410e5afb70a985cplars 229865695bbc89088b9526ea9045410e5afb70a985cplars/* 230865695bbc89088b9526ea9045410e5afb70a985cplars * void 231865695bbc89088b9526ea9045410e5afb70a985cplars * sig_handler() - signal catching function. 232865695bbc89088b9526ea9045410e5afb70a985cplars * This function is used to trap the signal generated when tried to read or 233865695bbc89088b9526ea9045410e5afb70a985cplars * write to the memory mapped region which is already detached from the 234865695bbc89088b9526ea9045410e5afb70a985cplars * calling process address space. 235865695bbc89088b9526ea9045410e5afb70a985cplars * this function is invoked when SIGSEGV generated and it calls test 236865695bbc89088b9526ea9045410e5afb70a985cplars * cleanup function and exit the program. 237865695bbc89088b9526ea9045410e5afb70a985cplars */ 238c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid sig_handler(void) 239865695bbc89088b9526ea9045410e5afb70a985cplars{ 240865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TPASS, "Functionality of munmap() successful"); 241865695bbc89088b9526ea9045410e5afb70a985cplars 242865695bbc89088b9526ea9045410e5afb70a985cplars /* Invoke test cleanup function and exit */ 243865695bbc89088b9526ea9045410e5afb70a985cplars cleanup(); 244865695bbc89088b9526ea9045410e5afb70a985cplars 245865695bbc89088b9526ea9045410e5afb70a985cplars tst_exit(); 246865695bbc89088b9526ea9045410e5afb70a985cplars} 247865695bbc89088b9526ea9045410e5afb70a985cplars 248865695bbc89088b9526ea9045410e5afb70a985cplars/* 249865695bbc89088b9526ea9045410e5afb70a985cplars * cleanup() - performs all ONE TIME cleanup for this test at 250865695bbc89088b9526ea9045410e5afb70a985cplars * completion or premature exit. 251865695bbc89088b9526ea9045410e5afb70a985cplars * Unmap the portion of the region of the file left unmapped. 252865695bbc89088b9526ea9045410e5afb70a985cplars * Close the temporary file. 253865695bbc89088b9526ea9045410e5afb70a985cplars * Remove the temporary directory. 254865695bbc89088b9526ea9045410e5afb70a985cplars */ 255c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid cleanup(void) 256865695bbc89088b9526ea9045410e5afb70a985cplars{ 257865695bbc89088b9526ea9045410e5afb70a985cplars 258865695bbc89088b9526ea9045410e5afb70a985cplars /* 259865695bbc89088b9526ea9045410e5afb70a985cplars * get the start address and length of the portion of 260865695bbc89088b9526ea9045410e5afb70a985cplars * the mapped region of the file. 261865695bbc89088b9526ea9045410e5afb70a985cplars */ 262865695bbc89088b9526ea9045410e5afb70a985cplars addr = (char *)((long)addr - page_sz); 263865695bbc89088b9526ea9045410e5afb70a985cplars map_len = map_len - page_sz; 264865695bbc89088b9526ea9045410e5afb70a985cplars 265865695bbc89088b9526ea9045410e5afb70a985cplars /* unmap the portion of the region of the file left unmapped */ 266865695bbc89088b9526ea9045410e5afb70a985cplars if (munmap(addr, map_len) < 0) { 267865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, NULL, 268865695bbc89088b9526ea9045410e5afb70a985cplars "munmap() fails to unmap portion of mapped region"); 269865695bbc89088b9526ea9045410e5afb70a985cplars } 270865695bbc89088b9526ea9045410e5afb70a985cplars 271865695bbc89088b9526ea9045410e5afb70a985cplars /* Close the temporary file */ 272865695bbc89088b9526ea9045410e5afb70a985cplars if (close(fildes) < 0) { 273865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, NULL, "close() on %s Failed, errno=%d : %s", 274865695bbc89088b9526ea9045410e5afb70a985cplars TEMPFILE, errno, strerror(errno)); 275865695bbc89088b9526ea9045410e5afb70a985cplars } 276865695bbc89088b9526ea9045410e5afb70a985cplars 277865695bbc89088b9526ea9045410e5afb70a985cplars tst_rmdir(); 278ad8b91f328fab376f5f52ff73babcdd941e58217Garrett Cooper} 279