Home | History | Annotate | Download | only in munmap
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * This file is licensed under the GPL license.  For the full content
      4  * of this license, see the COPYING file at the top level of this
      5  * source tree.
      6  *
      7  * If there are no
      8  * mappings in the specified address range, then munmap() has no effect.
      9  *
     10  */
     11 
     12 #define _XOPEN_SOURCE 600
     13 
     14 #include <pthread.h>
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 #include <unistd.h>
     18 #include <sys/mman.h>
     19 #include <sys/types.h>
     20 #include <sys/stat.h>
     21 #include <sys/wait.h>
     22 #include <fcntl.h>
     23 #include <string.h>
     24 #include <errno.h>
     25 #include "posixtest.h"
     26 
     27 #define TNAME "munmap/2-1.c"
     28 
     29 int main(void)
     30 {
     31 	int rc;
     32 
     33 	int page_size;
     34 	void *buffer = NULL, *new_addr = NULL;
     35 
     36 	page_size = sysconf(_SC_PAGE_SIZE);
     37 	buffer = malloc(page_size * 2);
     38 	if (buffer == NULL) {
     39 		printf("Error at malloc\n");
     40 		exit(PTS_UNRESOLVED);
     41 	}
     42 
     43 	/* Make new_addr is a multiple of page_size, while
     44 	 * [new_addr, new_addr + page_size] is a valid memory range
     45 	 */
     46 	new_addr = buffer + (page_size - (unsigned long)buffer % page_size);
     47 
     48 	rc = munmap(new_addr, page_size);
     49 	if (rc == -1) {
     50 		printf("Test FAILED " TNAME " Error at munmap(): %s\n",
     51 		       strerror(errno));
     52 		free(buffer);
     53 		exit(PTS_FAIL);
     54 	}
     55 
     56 	free(buffer);
     57 	printf("Test PASSED\n");
     58 	return PTS_PASS;
     59 }
     60