diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index b7fb79643..4c7ca72fd 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -259,6 +259,7 @@ TST_NOFILE := \ memfd02-hugetlb \ memfd03 \ memfd04 \ + memfd05 \ shmemfd \ shmemfd-priv \ time \ @@ -656,6 +657,7 @@ socket-tcp6-unconn: CFLAGS += -D ZDTM_IPV6 socket-tcp4v6-last-ack: CFLAGS += -D ZDTM_TCP_LAST_ACK -D ZDTM_IPV4V6 socket-tcp4v6-closing: CFLAGS += -D ZDTM_IPV4V6 memfd02-hugetlb: CFLAGS += -D ZDTM_HUGETLB +memfd05: CFLAGS += -D ZDTM_MEMFD05 sockets00-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET sockets01-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET diff --git a/test/zdtm/static/memfd04.c b/test/zdtm/static/memfd04.c index aae7864c1..215e949d1 100644 --- a/test/zdtm/static/memfd04.c +++ b/test/zdtm/static/memfd04.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -73,20 +74,46 @@ static const size_t script_len = sizeof(script) - 1; int main(int argc, char *argv[]) { +#ifdef MEMFD05 + char path[PATH_MAX]; + char *addr_p, *addr_s; + int rofd; +#endif int fd; test_init(argc, argv); fd = _memfd_create("somename", 0); if (fd < 0) { - fail("memfd_create()"); + pr_perror("memfd_create()"); + return 1; + } + if (ftruncate(fd, script_len) == -1) { + pr_perror("ftruncate"); return 1; } - if (write(fd, script, script_len) != script_len) { - fail("write(memfd)"); + pr_perror("write(memfd)"); return 1; } +#ifdef MEMFD05 + snprintf(path, PATH_MAX - 1, "/proc/self/fd/%d", fd); + rofd = open(path, O_RDONLY); + if (rofd < 0) { + pr_perror("unable to open read-only memfd"); + return 1; + } + addr_p = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, rofd, 0); + if (addr_p == MAP_FAILED) { + pr_perror("mmap"); + return 1; + } + addr_s = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); + if (addr_s == MAP_FAILED) { + pr_perror("mmap"); + return 1; + } +#endif if (!test_exec_fd(fd)) return 1; diff --git a/test/zdtm/static/memfd05.c b/test/zdtm/static/memfd05.c new file mode 120000 index 000000000..6caa9556f --- /dev/null +++ b/test/zdtm/static/memfd05.c @@ -0,0 +1 @@ +memfd04.c \ No newline at end of file diff --git a/test/zdtm/static/memfd05.desc b/test/zdtm/static/memfd05.desc new file mode 120000 index 000000000..1b4963572 --- /dev/null +++ b/test/zdtm/static/memfd05.desc @@ -0,0 +1 @@ +memfd04.desc \ No newline at end of file