File: grow_map02.c

package info (click to toggle)
criu 4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,584 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (60 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <signal.h>
#include <sys/wait.h>

#include "zdtmtst.h"

const char *test_doc = "Check that a few grow-down VMA-s are restored correctly";
const char *test_author = "Andrew Vagin <avagin@openvz.org>";

int main(int argc, char **argv)
{
	char *start_addr, *grow_down;
	test_init(argc, argv);

	start_addr = mmap(NULL, PAGE_SIZE * 10, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
	if (start_addr == MAP_FAILED) {
		pr_perror("Can't mal a new region");
		return 1;
	}
	munmap(start_addr, PAGE_SIZE * 10);

	grow_down = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE * 3, PROT_READ | PROT_WRITE,
			 MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0);
	if (grow_down == MAP_FAILED) {
		pr_perror("Can't mal a new region");
		return 1;
	}

	grow_down[0 * PAGE_SIZE] = 'x';
	grow_down[1 * PAGE_SIZE] = 'y';
	grow_down[2 * PAGE_SIZE] = 'z';

	/*
	 * Split the grow-down vma on three parts.
	 * Only the irst one will have a guard page
	 */
	if (mprotect(grow_down + PAGE_SIZE, PAGE_SIZE, PROT_READ)) {
		pr_perror("Can't change set protection on a region of memory");
		return 1;
	}

	test_daemon();
	test_waitsig();

	test_msg("%c %c %c\n", grow_down[0 * PAGE_SIZE], grow_down[1 * PAGE_SIZE], grow_down[2 * PAGE_SIZE]);

	if (grow_down[0 * PAGE_SIZE] != 'x')
		return 1;
	if (grow_down[1 * PAGE_SIZE] != 'y')
		return 1;
	if (grow_down[2 * PAGE_SIZE] != 'z')
		return 1;

	pass();

	return 0;
}