Exemple #1
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "win_mmap");

	if (argc !=  2)
		UT_FATAL("usage: %s file", argv[0]);

	int fd = OPEN(argv[1], O_RDWR);
	int fd_ro = OPEN(argv[1], O_RDONLY);

	POSIX_FALLOCATE(fd, 0, FILE_SIZE);

	test_mmap_flags(fd);
	test_mmap_len(fd);
	test_mmap_hint(fd);
	test_mmap_fixed(fd);
	test_mmap_anon(fd);
	test_mmap_shared(fd);
	test_mmap_prot(fd, fd_ro);
	test_mmap_prot_anon();
	test_munmap(fd);
	test_msync(fd);
	test_mprotect(fd, fd_ro);
	test_mprotect_anon();

	CLOSE(fd_ro);
	CLOSE(fd);

	DONE(NULL);
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int err;
	int fd;
	void *p;

	test_init(argc, argv);

	struct sigaction sa = {
		.sa_sigaction = sig_handler,
		.sa_flags = SA_SIGINFO,
	};

	err = sigaction(SIGSEGV, &sa, NULL);
	if (err)
		FAIL("Can't install SIGSEGV handler: %s", strerror(errno));

	hpage_size = check_hugepagesize();

	fd = hugetlbfs_unlinked_fd();
	if (fd < 0)
		FAIL("hugetlbfs_unlinked_fd()");

	verbose_printf("instantiating page\n");

	p = mmap(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	if (p == MAP_FAILED)
		FAIL("mmap(): %s", strerror(errno));
	memset(p, 0, hpage_size);
	munmap(p, hpage_size);

	/* Basic protection change tests */
	test_mprotect(fd, "R->RW", hpage_size, PROT_READ,
		      hpage_size, PROT_READ|PROT_WRITE);
	test_mprotect(fd, "RW->R", hpage_size, PROT_READ|PROT_WRITE,
		      hpage_size, PROT_READ);

	/* Tests which require VMA splitting */
	test_mprotect(fd, "R->RW 1/2", 2*hpage_size, PROT_READ,
		      hpage_size, PROT_READ|PROT_WRITE);
	test_mprotect(fd, "RW->R 1/2", 2*hpage_size, PROT_READ|PROT_WRITE,
		      hpage_size, PROT_READ);

	/* PROT_NONE tests */
	test_mprotect(fd, "NONE->R", hpage_size, PROT_NONE,
		      hpage_size, PROT_READ);
	test_mprotect(fd, "NONE->RW", hpage_size, PROT_NONE,
		      hpage_size, PROT_READ|PROT_WRITE);

	PASS();
}