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
29int main()
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  {
40  	printf("Error at malloc\n");
41    exit(PTS_UNRESOLVED);
42  }
43
44  /* Make new_addr is a multiple of page_size, while
45   * [new_addr, new_addr + page_size] is a valid memory range
46   */
47  new_addr = buffer + (page_size - (unsigned long)buffer % page_size);
48
49  rc = munmap(new_addr, page_size);
50  if (rc == -1)
51  {
52  	printf ("Test FAILED " TNAME " Error at munmap(): %s\n",
53             strerror(errno));
54  	free(buffer);
55  	exit(PTS_FAIL);
56  }
57
58  free(buffer);
59  printf ("Test PASSED\n");
60  return PTS_PASS;
61}
62