Commit 13371c6a authored by Jamie Liu's avatar Jamie Liu Committed by Pavel Emelyanov

zdtm: add maps_file_prot

Tests for the bugs fixed by "criu: fix filemap open permissions".
Signed-off-by: 's avatarJamie Liu <jamieliu@google.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent efe594f8
......@@ -12,6 +12,7 @@ static/maps00
static/maps01
static/maps02
static/maps04
static/maps_file_prot
static/mprotect00
static/mtime_mmap
static/sleeping00
......
......@@ -140,6 +140,7 @@ TST_FILE = \
file_locks00 \
file_locks01 \
netns-nf \
maps_file_prot \
TST_DIR = \
cwd00 \
......
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Test mappings of same file with different prot";
const char *test_author = "Jamie Liu <jamieliu@google.com>";
char *filename;
TEST_OPTION(filename, string, "file name", 1);
#define die(fmt, arg...) do { err(fmt, ## arg); return 1; } while (0)
int main(int argc, char ** argv)
{
void *ro_map, *rw_map;
int fd;
test_init(argc, argv);
fd = open(filename, O_RDWR | O_CREAT, 0644);
if (fd < 0)
die("open failed");
if (ftruncate(fd, 2 * PAGE_SIZE))
die("ftruncate failed");
ro_map = mmap(NULL, 2 * PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
if (ro_map == MAP_FAILED)
die("mmap failed");
rw_map = ro_map + PAGE_SIZE;
if (mprotect(rw_map, PAGE_SIZE, PROT_READ | PROT_WRITE))
die("mprotect failed");
close(fd);
test_daemon();
test_waitsig();
/* Check that rw_map is still writeable */
*(volatile char *)rw_map = 1;
if (mprotect(ro_map, PAGE_SIZE, PROT_READ | PROT_WRITE)) {
fail("mprotect after restore failed");
return 1;
}
pass();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment