12c28215423293e443469a07ae7011135d058b671Garrett Cooper/*
20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002, Intel Corporation. All rights reserved.
30dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license.  For the full content
42c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this
50dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree.
60dc076565f772bb1953209fb69ea150b494aaa40robbiew *
7e9410dfd93b8e415ecbe3f7e09a085462b27836eGarrett Cooper * The munmap() function shall fail if:
82c28215423293e443469a07ae7011135d058b671Garrett Cooper * [EINVAL] Addresses in the range [addr,addr+len)
90dc076565f772bb1953209fb69ea150b494aaa40robbiew * are outside the valid range for the
100dc076565f772bb1953209fb69ea150b494aaa40robbiew * address space of a process.
110dc076565f772bb1953209fb69ea150b494aaa40robbiew *
120dc076565f772bb1953209fb69ea150b494aaa40robbiew */
130dc076565f772bb1953209fb69ea150b494aaa40robbiew
140dc076565f772bb1953209fb69ea150b494aaa40robbiew#define _XOPEN_SOURCE 600
150dc076565f772bb1953209fb69ea150b494aaa40robbiew
160dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <pthread.h>
170dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h>
180dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdlib.h>
190dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <unistd.h>
200dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sys/mman.h>
210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sys/types.h>
220dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sys/stat.h>
230dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sys/wait.h>
240dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <fcntl.h>
250dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <string.h>
260dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <errno.h>
270dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h"
282c28215423293e443469a07ae7011135d058b671Garrett Cooper
290dc076565f772bb1953209fb69ea150b494aaa40robbiew#define TNAME "munmap/8-1.c"
300dc076565f772bb1953209fb69ea150b494aaa40robbiew
314ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void)
320dc076565f772bb1953209fb69ea150b494aaa40robbiew{
33354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	int rc;
34354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	void *pa;
352c28215423293e443469a07ae7011135d058b671Garrett Cooper
36354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	/* -1 should be an invalid address */
37354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	pa = (void *)-1;
38354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	rc = munmap(pa, 1);
39354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (rc == -1 && errno == EINVAL) {
40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		printf("Got EINVAL\n");
41354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		printf("Test PASSED\n");
42354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		exit(PTS_PASS);
43354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	} else {
44354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		printf("Test FAILED: Expect EINVAL but get: %s\n",
45354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		       strerror(errno));
46354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		return PTS_FAIL;
47354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	}
48ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
49