* [LTP] [PATCH v5 0/6] Added memfd_create() testsuite
@ 2017-03-23 18:15 Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 1/6] Added syscall numbers for memfd_create Jakub Racek
` (5 more replies)
0 siblings, 6 replies; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
memfd_create() is a syscall that creates an anonymous file. This syscall was
originally introduced in "File Sealing & memfd_create()" patchset by
David Herrmann <dh.herrmann@gmail.com>.
My patchset is a partial port of memfd_create() testsuite to LTP, with lapi
extended as necessary. Code that runs _dup, _mmap and _open tests in
multi-threaded environment was not ported yet.
V2: fixed LTP style problems, added syscall numbers for each arch
V3: fixed more style problems, moved fallocate.h to include/lapi
V4:
* fixed more style problems
V5:
* (really) fixed broken syscall availability detection
* fixed more style problems
* fixed checking write() return value
* memfd_create_common is now a library
Jakub Racek (6):
Added syscall numbers for memfd_create
Added memfd_create() lapi flags
Added fcntl() lapi flags
move fallocate.h to lapi
syscalls: added memfd_create dir and memfd_create/memfd_create01.c
syscalls/memfd_create02.c: added new test
include/lapi/fallocate.h | 66 +++
include/lapi/fcntl.h | 25 ++
include/lapi/memfd.h | 27 ++
runtest/syscalls | 3 +
testcases/kernel/include/aarch64.in | 1 +
testcases/kernel/include/arm.in | 1 +
testcases/kernel/include/hppa.in | 1 +
testcases/kernel/include/i386.in | 1 +
testcases/kernel/include/ia64.in | 1 +
testcases/kernel/include/powerpc.in | 1 +
testcases/kernel/include/powerpc64.in | 1 +
testcases/kernel/include/s390.in | 1 +
testcases/kernel/include/s390x.in | 1 +
testcases/kernel/include/sh.in | 1 +
testcases/kernel/include/sparc.in | 1 +
testcases/kernel/include/sparc64.in | 1 +
testcases/kernel/include/x86_64.in | 1 +
testcases/kernel/syscalls/.gitignore | 2 +
testcases/kernel/syscalls/fallocate/fallocate.h | 70 ----
testcases/kernel/syscalls/fallocate/fallocate01.c | 2 +-
testcases/kernel/syscalls/fallocate/fallocate02.c | 2 +-
testcases/kernel/syscalls/fallocate/fallocate03.c | 2 +-
testcases/kernel/syscalls/fallocate/fallocate04.c | 2 +-
testcases/kernel/syscalls/memfd_create/Makefile | 23 ++
.../kernel/syscalls/memfd_create/memfd_create01.c | 270 +++++++++++++
.../kernel/syscalls/memfd_create/memfd_create02.c | 94 +++++
.../syscalls/memfd_create/memfd_create_common.c | 446 +++++++++++++++++++++
.../syscalls/memfd_create/memfd_create_common.h | 152 +++++++
28 files changed, 1125 insertions(+), 74 deletions(-)
create mode 100644 include/lapi/fallocate.h
create mode 100644 include/lapi/memfd.h
delete mode 100644 testcases/kernel/syscalls/fallocate/fallocate.h
create mode 100644 testcases/kernel/syscalls/memfd_create/Makefile
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create01.c
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create02.c
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.c
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.h
--
1.8.3.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 1/6] Added syscall numbers for memfd_create
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
@ 2017-03-23 18:15 ` Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 2/6] Added memfd_create() lapi flags Jakub Racek
` (4 subsequent siblings)
5 siblings, 0 replies; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Jakub Racek <jracek@redhat.com>
---
testcases/kernel/include/aarch64.in | 1 +
testcases/kernel/include/arm.in | 1 +
testcases/kernel/include/hppa.in | 1 +
testcases/kernel/include/i386.in | 1 +
testcases/kernel/include/ia64.in | 1 +
testcases/kernel/include/powerpc.in | 1 +
testcases/kernel/include/powerpc64.in | 1 +
testcases/kernel/include/s390.in | 1 +
testcases/kernel/include/s390x.in | 1 +
testcases/kernel/include/sh.in | 1 +
testcases/kernel/include/sparc.in | 1 +
testcases/kernel/include/sparc64.in | 1 +
testcases/kernel/include/x86_64.in | 1 +
13 files changed, 13 insertions(+)
diff --git a/testcases/kernel/include/aarch64.in b/testcases/kernel/include/aarch64.in
index cb3fe06..b81c068 100644
--- a/testcases/kernel/include/aarch64.in
+++ b/testcases/kernel/include/aarch64.in
@@ -255,3 +255,4 @@ setns 268
sendmmsg 269
kcmp 272
getrandom 278
+memfd_create 279
diff --git a/testcases/kernel/include/arm.in b/testcases/kernel/include/arm.in
index cee9718..0a5dde1 100644
--- a/testcases/kernel/include/arm.in
+++ b/testcases/kernel/include/arm.in
@@ -338,3 +338,4 @@ sched_setattr (__NR_SYSCALL_BASE+380)
sched_getattr (__NR_SYSCALL_BASE+381)
renameat2 (__NR_SYSCALL_BASE+382)
getrandom (__NR_SYSCALL_BASE+384)
+memfd_create (__NR_SYSCALL_BASE+385)
diff --git a/testcases/kernel/include/hppa.in b/testcases/kernel/include/hppa.in
index b784a2b..3946155 100644
--- a/testcases/kernel/include/hppa.in
+++ b/testcases/kernel/include/hppa.in
@@ -15,3 +15,4 @@ faccessat (__NR_openat + 12)
splice 291
tee 293
vmsplice 294
+memfd_create 340
diff --git a/testcases/kernel/include/i386.in b/testcases/kernel/include/i386.in
index 1f1cade..42c5e3f 100644
--- a/testcases/kernel/include/i386.in
+++ b/testcases/kernel/include/i386.in
@@ -338,3 +338,4 @@ sched_setattr 351
sched_getattr 352
renameat2 354
getrandom 355
+memfd_create 356
diff --git a/testcases/kernel/include/ia64.in b/testcases/kernel/include/ia64.in
index 846141f..dad25f4 100644
--- a/testcases/kernel/include/ia64.in
+++ b/testcases/kernel/include/ia64.in
@@ -294,3 +294,4 @@ fanotify_mark 1324
prlimit64 1325
renameat2 1338
getrandom 1339
+memfd_create 1340
diff --git a/testcases/kernel/include/powerpc.in b/testcases/kernel/include/powerpc.in
index 5ca42a6..10a6e5d 100644
--- a/testcases/kernel/include/powerpc.in
+++ b/testcases/kernel/include/powerpc.in
@@ -345,3 +345,4 @@ sched_setattr 355
sched_getattr 356
renameat2 357
getrandom 359
+memfd_create 360
diff --git a/testcases/kernel/include/powerpc64.in b/testcases/kernel/include/powerpc64.in
index 5ca42a6..10a6e5d 100644
--- a/testcases/kernel/include/powerpc64.in
+++ b/testcases/kernel/include/powerpc64.in
@@ -345,3 +345,4 @@ sched_setattr 355
sched_getattr 356
renameat2 357
getrandom 359
+memfd_create 360
diff --git a/testcases/kernel/include/s390.in b/testcases/kernel/include/s390.in
index afe94f5..770db7f 100644
--- a/testcases/kernel/include/s390.in
+++ b/testcases/kernel/include/s390.in
@@ -329,3 +329,4 @@ sched_setattr 345
sched_getattr 346
renameat2 347
getrandom 349
+memfd_create 350
diff --git a/testcases/kernel/include/s390x.in b/testcases/kernel/include/s390x.in
index afe94f5..770db7f 100644
--- a/testcases/kernel/include/s390x.in
+++ b/testcases/kernel/include/s390x.in
@@ -329,3 +329,4 @@ sched_setattr 345
sched_getattr 346
renameat2 347
getrandom 349
+memfd_create 350
diff --git a/testcases/kernel/include/sh.in b/testcases/kernel/include/sh.in
index 3cb7e21..0345f8d 100644
--- a/testcases/kernel/include/sh.in
+++ b/testcases/kernel/include/sh.in
@@ -362,3 +362,4 @@ fanotify_init 367
fanotify_mark 368
prlimit64 369
kcmp 378
+memfd_create 385
diff --git a/testcases/kernel/include/sparc.in b/testcases/kernel/include/sparc.in
index f266777..b84c844 100644
--- a/testcases/kernel/include/sparc.in
+++ b/testcases/kernel/include/sparc.in
@@ -334,3 +334,4 @@ prlimit64 331
kcmp 341
renameat2 345
getrandom 347
+memfd_create 348
diff --git a/testcases/kernel/include/sparc64.in b/testcases/kernel/include/sparc64.in
index cb91828..7e0be30 100644
--- a/testcases/kernel/include/sparc64.in
+++ b/testcases/kernel/include/sparc64.in
@@ -310,3 +310,4 @@ prlimit64 331
kcmp 341
renameat2 345
getrandom 347
+memfd_create 348
diff --git a/testcases/kernel/include/x86_64.in b/testcases/kernel/include/x86_64.in
index f54abf4..dec7742 100644
--- a/testcases/kernel/include/x86_64.in
+++ b/testcases/kernel/include/x86_64.in
@@ -305,3 +305,4 @@ sched_setattr 314
sched_getattr 315
renameat2 316
getrandom 318
+memfd_create 319
--
1.8.3.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 2/6] Added memfd_create() lapi flags
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 1/6] Added syscall numbers for memfd_create Jakub Racek
@ 2017-03-23 18:15 ` Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 3/6] Added fcntl() " Jakub Racek
` (3 subsequent siblings)
5 siblings, 0 replies; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Jakub Racek <jracek@redhat.com>
---
include/lapi/memfd.h | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 include/lapi/memfd.h
diff --git a/include/lapi/memfd.h b/include/lapi/memfd.h
new file mode 100644
index 0000000..18ed40f
--- /dev/null
+++ b/include/lapi/memfd.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef LAPI_MEMFD_H
+#define LAPI_MEMFD_H
+
+/* flags for memfd_create(2) (unsigned int) */
+#ifndef MFD_CLOEXEC
+# define MFD_CLOEXEC 0x0001U
+#endif
+#ifndef MFD_ALLOW_SEALING
+# define MFD_ALLOW_SEALING 0x0002U
+#endif
+
+#endif
--
1.8.3.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 3/6] Added fcntl() lapi flags
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 1/6] Added syscall numbers for memfd_create Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 2/6] Added memfd_create() lapi flags Jakub Racek
@ 2017-03-23 18:15 ` Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 4/6] move fallocate.h to lapi Jakub Racek
` (2 subsequent siblings)
5 siblings, 0 replies; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Jakub Racek <jracek@redhat.com>
---
include/lapi/fcntl.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index 38e41ec..849439d 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -50,6 +50,31 @@
# define F_GETPIPE_SZ 1032
#endif
+/*
+ * Set/Get seals
+ */
+#ifndef F_ADD_SEALS
+# define F_ADD_SEALS (1033)
+#endif
+
+#ifndef F_GET_SEALS
+# define F_GET_SEALS (1034)
+#endif
+
+#ifndef F_SEAL_SEAL
+# define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
+#endif
+
+#ifndef F_SEAL_SHRINK
+# define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
+#endif
+#ifndef F_SEAL_GROW
+# define F_SEAL_GROW 0x0004 /* prevent file from growing */
+#endif
+#ifndef F_SEAL_WRITE
+# define F_SEAL_WRITE 0x0008 /* prevent writes */
+#endif
+
#ifndef F_OWNER_PGRP
# define F_OWNER_PGRP 2
#endif
--
1.8.3.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 4/6] move fallocate.h to lapi
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
` (2 preceding siblings ...)
2017-03-23 18:15 ` [LTP] [PATCH v5 3/6] Added fcntl() " Jakub Racek
@ 2017-03-23 18:15 ` Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 6/6] syscalls/memfd_create02.c: added new test Jakub Racek
5 siblings, 0 replies; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Jakub Racek <jracek@redhat.com>
---
include/lapi/fallocate.h | 66 +++++++++++++++++++++
testcases/kernel/syscalls/fallocate/fallocate.h | 70 -----------------------
testcases/kernel/syscalls/fallocate/fallocate01.c | 2 +-
testcases/kernel/syscalls/fallocate/fallocate02.c | 2 +-
testcases/kernel/syscalls/fallocate/fallocate03.c | 2 +-
testcases/kernel/syscalls/fallocate/fallocate04.c | 2 +-
6 files changed, 70 insertions(+), 74 deletions(-)
create mode 100644 include/lapi/fallocate.h
delete mode 100644 testcases/kernel/syscalls/fallocate/fallocate.h
diff --git a/include/lapi/fallocate.h b/include/lapi/fallocate.h
new file mode 100644
index 0000000..79d0b7b
--- /dev/null
+++ b/include/lapi/fallocate.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (c) 2014 Fujitsu Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ */
+
+#ifndef FALLOCATE_H
+#define FALLOCATE_H
+
+#include <sys/types.h>
+#include <endian.h>
+#include "config.h"
+#include "lapi/abisize.h"
+#include "linux_syscall_numbers.h"
+
+#ifndef SEEK_HOLE
+# define SEEK_HOLE 4
+#endif
+
+#ifndef FALLOC_FL_KEEP_SIZE
+# define FALLOC_FL_KEEP_SIZE 0x01
+#endif
+
+#ifndef FALLOC_FL_PUNCH_HOLE
+# define FALLOC_FL_PUNCH_HOLE 0x02
+#endif
+
+#ifndef FALLOC_FL_COLLAPSE_RANGE
+# define FALLOC_FL_COLLAPSE_RANGE 0x08
+#endif
+
+#ifndef FALLOC_FL_ZERO_RANGE
+# define FALLOC_FL_ZERO_RANGE 0x10
+#endif
+
+#ifndef FALLOC_FL_INSERT_RANGE
+# define FALLOC_FL_INSERT_RANGE 0x20
+#endif
+
+#if !defined(HAVE_FALLOCATE)
+static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+ /* Deal with 32bit ABIs that have 64bit syscalls. */
+# if LTP_USE_64_ABI
+ return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
+# else
+ return (long)ltp_syscall(__NR_fallocate, fd, mode,
+ __LONG_LONG_PAIR((off_t) (offset >> 32),
+ (off_t) offset),
+ __LONG_LONG_PAIR((off_t) (len >> 32),
+ (off_t) len));
+# endif
+}
+#endif
+
+#endif /* FALLOCATE_H */
diff --git a/testcases/kernel/syscalls/fallocate/fallocate.h b/testcases/kernel/syscalls/fallocate/fallocate.h
deleted file mode 100644
index 5119988..0000000
--- a/testcases/kernel/syscalls/fallocate/fallocate.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2007
- * Copyright (c) 2014 Fujitsu Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- */
-
-#ifndef FALLOCATE_H
-#define FALLOCATE_H
-
-#include <sys/types.h>
-#include <endian.h>
-#include "config.h"
-#include "lapi/abisize.h"
-#include "linux_syscall_numbers.h"
-
-#ifndef SEEK_HOLE
-#define SEEK_HOLE 4
-#endif
-
-#ifndef FALLOC_FL_KEEP_SIZE
-#define FALLOC_FL_KEEP_SIZE 0x01
-#endif
-
-#ifndef FALLOC_FL_PUNCH_HOLE
-#define FALLOC_FL_PUNCH_HOLE 0x02
-#endif
-
-#ifndef FALLOC_FL_COLLAPSE_RANGE
-#define FALLOC_FL_COLLAPSE_RANGE 0x08
-#endif
-
-#ifndef FALLOC_FL_ZERO_RANGE
-#define FALLOC_FL_ZERO_RANGE 0x10
-#endif
-
-#ifndef FALLOC_FL_INSERT_RANGE
-#define FALLOC_FL_INSERT_RANGE 0x20
-#endif
-
-#if !defined(HAVE_FALLOCATE)
-static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
-{
- /* Deal with 32bit ABIs that have 64bit syscalls. */
-# if LTP_USE_64_ABI
- return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
-# else
- return (long)ltp_syscall(__NR_fallocate, fd, mode,
- __LONG_LONG_PAIR((off_t) (offset >> 32),
- (off_t) offset),
- __LONG_LONG_PAIR((off_t) (len >> 32),
- (off_t) len));
-# endif
-}
-#endif
-
-#endif /* FALLOCATE_H */
diff --git a/testcases/kernel/syscalls/fallocate/fallocate01.c b/testcases/kernel/syscalls/fallocate/fallocate01.c
index c99e799..89ce996 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate01.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate01.c
@@ -100,7 +100,7 @@
#include <sys/utsname.h>
#include "test.h"
-#include "fallocate.h"
+#include "lapi/fallocate.h"
#include "lapi/fcntl.h"
#define BLOCKS_WRITTEN 12
diff --git a/testcases/kernel/syscalls/fallocate/fallocate02.c b/testcases/kernel/syscalls/fallocate/fallocate02.c
index ba37796..bee0863 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate02.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate02.c
@@ -39,7 +39,7 @@
#include "test.h"
#include "safe_macros.h"
-#include "fallocate.h"
+#include "lapi/fallocate.h"
#define BLOCKS_WRITTEN 12
#ifdef TEST_DEFAULT
diff --git a/testcases/kernel/syscalls/fallocate/fallocate03.c b/testcases/kernel/syscalls/fallocate/fallocate03.c
index 092d2bb..d73d07d 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate03.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate03.c
@@ -96,7 +96,7 @@
#include <sys/utsname.h>
#include "test.h"
-#include "fallocate.h"
+#include "lapi/fallocate.h"
#define BLOCKS_WRITTEN 12
#define HOLE_SIZE_IN_BLOCKS 12
diff --git a/testcases/kernel/syscalls/fallocate/fallocate04.c b/testcases/kernel/syscalls/fallocate/fallocate04.c
index f204188..a672916 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate04.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate04.c
@@ -32,7 +32,7 @@
#include "test.h"
#include "safe_macros.h"
-#include "fallocate.h"
+#include "lapi/fallocate.h"
char *TCID = "fallocate04";
int TST_TOTAL = 5;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
` (3 preceding siblings ...)
2017-03-23 18:15 ` [LTP] [PATCH v5 4/6] move fallocate.h to lapi Jakub Racek
@ 2017-03-23 18:15 ` Jakub Racek
2017-03-24 15:26 ` Cyril Hrubis
2017-03-23 18:15 ` [LTP] [PATCH v5 6/6] syscalls/memfd_create02.c: added new test Jakub Racek
5 siblings, 1 reply; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Jakub Racek <jracek@redhat.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/.gitignore | 1 +
testcases/kernel/syscalls/memfd_create/Makefile | 23 ++
.../kernel/syscalls/memfd_create/memfd_create01.c | 270 +++++++++++++
.../syscalls/memfd_create/memfd_create_common.c | 446 +++++++++++++++++++++
.../syscalls/memfd_create/memfd_create_common.h | 152 +++++++
6 files changed, 894 insertions(+)
create mode 100644 testcases/kernel/syscalls/memfd_create/Makefile
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create01.c
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.c
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.h
diff --git a/runtest/syscalls b/runtest/syscalls
index 84930ca..2da5b48 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1450,3 +1450,5 @@ futex_wake03 futex_wake03
futex_wake04 futex_wake04
futex_wait_bitset01 futex_wait_bitset01
futex_wait_bitset02 futex_wait_bitset02
+
+memfd_create01 memfd_create01
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 5838c1c..905badc 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1118,3 +1118,4 @@
/fanotify/fanotify06
/perf_event_open/perf_event_open01
/perf_event_open/perf_event_open02
+/memfd_create/memfd_create01
diff --git a/testcases/kernel/syscalls/memfd_create/Makefile b/testcases/kernel/syscalls/memfd_create/Makefile
new file mode 100644
index 0000000..f23b873
--- /dev/null
+++ b/testcases/kernel/syscalls/memfd_create/Makefile
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2017 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+FILTER_OUT_MAKE_TARGETS := memfd_create_common
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+$(MAKE_TARGETS): %: %.o memfd_create_common.o
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create01.c b/testcases/kernel/syscalls/memfd_create/memfd_create01.c
new file mode 100644
index 0000000..c181fe6
--- /dev/null
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create01.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/*
+ * Based on Linux/tools/testing/selftests/memfd/memfd_test.c
+ * by David Herrmann <dh.herrmann@gmail.com>
+ *
+ * 24/02/2017 Port to LTP <jracek@redhat.com>
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "memfd_create_common.h"
+
+/*
+ * Do few basic sealing tests to see whether setting/retrieving seals works.
+ */
+static void test_basic(int fd)
+{
+ /* add basic seals */
+ CHECK_MFD_HAS_SEALS(fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
+
+ /* add them again */
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
+
+ /* add more seals and seal against sealing */
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_GROW | F_SEAL_SEAL);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SHRINK | F_SEAL_GROW |
+ F_SEAL_WRITE | F_SEAL_SEAL);
+
+ /* verify that sealing no longer works */
+ CHECK_MFD_FAIL_ADD_SEALS(fd, F_SEAL_GROW);
+ CHECK_MFD_FAIL_ADD_SEALS(fd, 0);
+}
+
+/*
+ * Verify that no sealing is possible when memfd is created without
+ * MFD_ALLOW_SEALING flag.
+ */
+static void test_no_sealing_without_flag(int fd)
+{
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SEAL);
+ CHECK_MFD_FAIL_ADD_SEALS(fd,
+ F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SEAL);
+}
+
+/*
+ * Test SEAL_WRITE
+ * Test whether SEAL_WRITE actually prevents modifications.
+ */
+static void test_seal_write(int fd)
+{
+ CHECK_MFD_HAS_SEALS(fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE);
+
+ CHECK_MFD_READABLE(fd);
+ CHECK_MFD_NON_WRITEABLE(fd);
+ CHECK_MFD_SHRINKABLE(fd);
+ CHECK_MFD_GROWABLE(fd);
+ CHECK_NON_GROWABLE_BY_WRITE(fd);
+}
+
+/*
+ * Test SEAL_SHRINK
+ * Test whether SEAL_SHRINK actually prevents shrinking
+ */
+static void test_seal_shrink(int fd)
+{
+ CHECK_MFD_HAS_SEALS(fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SHRINK);
+
+ CHECK_MFD_READABLE(fd);
+ CHECK_MFD_WRITEABLE(fd);
+ CHECK_MFD_NON_SHRINKABLE(fd);
+ CHECK_MFD_GROWABLE(fd);
+ CHECK_MFD_GROWABLE_BY_WRITE(fd);
+}
+
+/*
+ * Test SEAL_GROW
+ * Test whether SEAL_GROW actually prevents growing
+ */
+static void test_seal_grow(int fd)
+{
+ CHECK_MFD_HAS_SEALS(fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_GROW);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_GROW);
+
+ CHECK_MFD_READABLE(fd);
+ CHECK_MFD_WRITEABLE(fd);
+ CHECK_MFD_SHRINKABLE(fd);
+ CHECK_MFD_NON_GROWABLE(fd);
+ CHECK_NON_GROWABLE_BY_WRITE(fd);
+}
+
+/*
+ * Test SEAL_SHRINK | SEAL_GROW
+ * Test whether SEAL_SHRINK | SEAL_GROW actually prevents resizing
+ */
+static void test_seal_resize(int fd)
+{
+ CHECK_MFD_HAS_SEALS(fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_SHRINK | F_SEAL_GROW);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SHRINK | F_SEAL_GROW);
+
+ CHECK_MFD_READABLE(fd);
+ CHECK_MFD_WRITEABLE(fd);
+ CHECK_MFD_NON_SHRINKABLE(fd);
+ CHECK_MFD_NON_GROWABLE(fd);
+ CHECK_NON_GROWABLE_BY_WRITE(fd);
+}
+
+/*
+ * Test sharing via dup()
+ * Test that seals are shared between dupped FDs and they're all equal.
+ */
+static void test_share_dup(int fd)
+{
+ int fd2;
+
+ CHECK_MFD_HAS_SEALS(fd, 0);
+
+ fd2 = SAFE_DUP(fd);
+ CHECK_MFD_HAS_SEALS(fd2, 0);
+
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd2, F_SEAL_WRITE);
+
+ CHECK_MFD_ADD_SEALS(fd2, F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd2, F_SEAL_WRITE | F_SEAL_SHRINK);
+
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_SEAL);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL);
+ CHECK_MFD_HAS_SEALS(fd2, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL);
+
+ CHECK_MFD_FAIL_ADD_SEALS(fd, F_SEAL_GROW);
+ CHECK_MFD_FAIL_ADD_SEALS(fd2, F_SEAL_GROW);
+ CHECK_MFD_FAIL_ADD_SEALS(fd, F_SEAL_SEAL);
+ CHECK_MFD_FAIL_ADD_SEALS(fd2, F_SEAL_SEAL);
+
+ SAFE_CLOSE(fd2);
+
+ CHECK_MFD_FAIL_ADD_SEALS(fd, F_SEAL_GROW);
+}
+
+/*
+ * Test sealing with active mmap()s
+ * Modifying seals is only allowed if no other mmap() refs exist.
+ */
+static void test_share_mmap(int fd)
+{
+ void *p;
+
+ CHECK_MFD_HAS_SEALS(fd, 0);
+
+ /* shared/writable ref prevents sealing WRITE, but allows others */
+ p = SAFE_MMAP(NULL, MFD_DEF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
+ fd, 0);
+
+ CHECK_MFD_FAIL_ADD_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_SHRINK);
+ SAFE_MUNMAP(p, MFD_DEF_SIZE);
+
+ /* readable ref allows sealing */
+ p = SAFE_MMAP(NULL, MFD_DEF_SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
+ SAFE_MUNMAP(p, MFD_DEF_SIZE);
+}
+
+/*
+ * Test sealing with open(/proc/self/fd/%d)
+ * Via /proc we can get access to a separate file-context for the same memfd.
+ * This is *not* like dup(), but like a real separate open(). Make sure the
+ * semantics are as expected and we correctly check for RDONLY / WRONLY / RDWR.
+ */
+static void test_share_open(int fd)
+{
+ int fd2;
+
+ CHECK_MFD_HAS_SEALS(fd, 0);
+
+ fd2 = CHECK_MFD_OPEN(fd, O_RDWR, 0);
+ CHECK_MFD_ADD_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE);
+ CHECK_MFD_HAS_SEALS(fd2, F_SEAL_WRITE);
+
+ CHECK_MFD_ADD_SEALS(fd2, F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd2, F_SEAL_WRITE | F_SEAL_SHRINK);
+
+ SAFE_CLOSE(fd);
+ fd = CHECK_MFD_OPEN(fd2, O_RDONLY, 0);
+
+ CHECK_MFD_FAIL_ADD_SEALS(fd, F_SEAL_SEAL);
+ CHECK_MFD_HAS_SEALS(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
+ CHECK_MFD_HAS_SEALS(fd2, F_SEAL_WRITE | F_SEAL_SHRINK);
+
+ SAFE_CLOSE(fd2);
+}
+
+
+static const struct tcase {
+ int flags;
+ void (*func)(int fd);
+ const char *desc;
+} tcases[] = {
+ {MFD_ALLOW_SEALING, &test_basic, "Basic tests + set/get seals"},
+ {0, &test_no_sealing_without_flag, "Disabled sealing"},
+
+ {MFD_ALLOW_SEALING, &test_seal_write, "Write seal"},
+ {MFD_ALLOW_SEALING, &test_seal_shrink, "Shrink seal"},
+ {MFD_ALLOW_SEALING, &test_seal_grow, "Grow seal"},
+ {MFD_ALLOW_SEALING, &test_seal_resize, "Resize seal"},
+
+ {MFD_ALLOW_SEALING, &test_share_dup, "Seals shared for dup"},
+ {MFD_ALLOW_SEALING, &test_share_mmap, "Seals shared for mmap"},
+ {MFD_ALLOW_SEALING, &test_share_open, "Seals shared for open"},
+};
+
+static void verify_memfd_create(unsigned int n)
+{
+ int fd;
+ const struct tcase *tc;
+
+ tc = &tcases[n];
+
+ tst_res(TINFO, "%s", tc->desc);
+
+ fd = CHECK_MFD_NEW(TCID, MFD_DEF_SIZE, tc->flags);
+
+ tc->func(fd);
+
+ SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+ ASSERT_HAVE_MEMFD_CREATE();
+}
+
+static struct tst_test test = {
+ .tid = "memfd_create01",
+ .test = verify_memfd_create,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+};
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
new file mode 100644
index 0000000..0c7143b
--- /dev/null
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
@@ -0,0 +1,446 @@
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+ #define _GNU_SOURCE
+
+ #include <sys/types.h>
+ #include <sys/syscall.h>
+ #include <sys/uio.h>
+ #include <lapi/fallocate.h>
+ #include <lapi/fcntl.h>
+ #include <lapi/memfd.h>
+ #include <errno.h>
+ #include <string.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+
+ #define TST_NO_DEFAULT_MAIN
+ #include <tst_test.h>
+
+#include "linux_syscall_numbers.h"
+
+#include "memfd_create_common.h"
+
+int sys_memfd_create(const char *name, unsigned int flags)
+{
+ return tst_syscall(__NR_memfd_create, name, flags);
+}
+
+int check_fallocate(const char *filename, const int lineno, int fd,
+ int mode, off_t offset, off_t len)
+{
+ int r;
+
+ r = fallocate(fd, mode, offset, len);
+ if (r < 0) {
+ tst_brk_(filename, lineno, TFAIL | TERRNO,
+ "fallocate(%d, %d, %ld, %ld) failed", fd, mode,
+ offset, len);
+ }
+
+ tst_res_(filename, lineno, TPASS,
+ "fallocate(%d, %d, %ld, %ld) succeeded", fd, mode,
+ offset, len);
+
+ return r;
+}
+
+int check_fallocate_fail(const char *filename, const int lineno, int fd,
+ int mode, off_t offset, off_t len)
+{
+ int r;
+
+ r = fallocate(fd, mode, offset, len);
+ if (r >= 0) {
+ tst_res_(filename, lineno, TFAIL,
+ "fallocate(%d, %d, %ld, %ld) succeeded unexpectedly",
+ fd, mode, offset, len);
+
+ return r;
+ }
+
+ tst_res_(filename, lineno, TPASS | TERRNO,
+ "fallocate(%d, %d, %ld, %ld) failed as expected", fd,
+ mode, offset, len);
+
+ return r;
+}
+
+void check_ftruncate(const char *filename, const int lineno, int fd,
+ off_t length)
+{
+ safe_ftruncate(filename, lineno, fd, length);
+
+ tst_res_(filename, lineno, TPASS, "ftruncate(%d, %ld) succeeded", fd,
+ length);
+}
+
+void check_ftruncate_fail(const char *filename, const int lineno,
+ int fd, off_t length)
+{
+ if (ftruncate(fd, length) >= 0) {
+ tst_res_(filename, lineno, TFAIL,
+ "ftruncate(%d, %ld) succeeded unexpectedly",
+ fd, length);
+
+ return;
+ }
+
+ tst_res_(filename, lineno, TPASS | TERRNO,
+ "ftruncate(%d, %ld) failed as expected", fd, length);
+}
+
+void assert_have_memfd_create(const char *filename, const int lineno)
+{
+ TEST(sys_memfd_create("dummy_call", 0));
+ if (TEST_RETURN < 0) {
+ if (TEST_ERRNO == EINVAL) {
+ tst_brk_(filename, lineno, TCONF | TTERRNO,
+ "memfd_create() not implemented");
+ }
+
+ tst_brk_(filename, lineno, TBROK | TTERRNO,
+ "memfd_create() failed");
+ }
+
+ SAFE_CLOSE(TEST_RETURN);
+}
+
+int check_mfd_new(const char *filename, const int lineno,
+ const char *name, loff_t sz, int flags)
+{
+ int fd;
+
+ fd = sys_memfd_create(name, flags);
+ if (fd < 0) {
+ tst_brk_(filename, lineno, TBROK | TERRNO,
+ "memfd_create(%s, %d) failed", name, flags);
+ }
+
+ tst_res_(filename, lineno, TPASS, "memfd_create(%s, %d) succeeded",
+ name, flags);
+
+ check_ftruncate(filename, lineno, fd, sz);
+
+ return fd;
+}
+
+void check_mfd_fail_new(const char *filename, const int lineno,
+ const char *name, int flags)
+{
+ int fd;
+
+ fd = sys_memfd_create(name, flags);
+ if (fd >= 0) {
+ safe_close(filename, lineno, NULL, fd);
+ tst_brk(TFAIL, "memfd_create(%s, %d) succeeded unexpectedly",
+ name, flags);
+ }
+
+ tst_res_(filename, lineno, TPASS | TERRNO,
+ "memfd_create(%s, %d) failed as expected", name, flags);
+}
+
+void *check_mmap(const char *file, const int lineno, void *addr, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *p;
+
+ p = safe_mmap(file, lineno, addr, length, prot, flags, fd, offset);
+
+ tst_res_(file, lineno, TPASS,
+ "mmap(%p, %zu, %i, %i, %i, %zi) succeeded", addr,
+ length, prot, flags, fd, offset);
+
+ return p;
+}
+
+void check_mmap_fail(const char *file, const int lineno, void *addr,
+ size_t length, int prot, int flags, int fd, off_t offset)
+{
+ if (mmap(addr, length, prot, flags, fd, offset) != MAP_FAILED) {
+ tst_res_(file, lineno, TFAIL,
+ "mmap(%p, %zu, %i, %i, %i, %zi) succeeded unexpectedly",
+ addr, length, prot, flags, fd, offset);
+
+ return;
+ }
+
+ tst_res_(file, lineno, TPASS | TERRNO,
+ "mmap(%p, %zu, %i, %i, %i, %zi) failed as expected",
+ addr, length, prot, flags, fd, offset);
+}
+
+void check_munmap(const char *file, const int lineno, void *p, size_t length)
+{
+ safe_munmap(file, lineno, NULL, p, length);
+
+ tst_res_(file, lineno, TPASS, "munmap(%p, %ld) succeeded", p, length);
+}
+
+void check_mprotect(const char *file, const int lineno, void *addr,
+ size_t length, int prot)
+{
+ if (mprotect(addr, length, prot) < 0) {
+ tst_brk_(file, lineno, TFAIL | TERRNO,
+ "mprotect(%p, %ld, %d) failed", addr, length, prot);
+ }
+
+ tst_res_(file, lineno, TPASS, "mprotect(%p, %ld, %d) succeeded", addr,
+ length, prot);
+}
+
+void check_mfd_fail_add_seals(const char *filename, const int lineno,
+ int fd, int seals)
+{
+ if (fcntl(fd, F_ADD_SEALS, seals) >= 0) {
+ tst_brk_(filename, lineno, TFAIL,
+ "fcntl(%d, F_ADD_SEALS) succeeded unexpectedly", fd);
+ }
+
+ tst_res_(filename, lineno, TPASS | TERRNO,
+ "fcntl(%d, F_ADD_SEALS, %d) failed as expected", (fd),
+ (seals));
+}
+
+void check_mfd_size(const char *filename, const int lineno, int fd,
+ size_t size)
+{
+ struct stat st;
+
+ safe_fstat(filename, lineno, fd, &st);
+
+ if (st.st_size != (long)size) {
+ tst_brk_(filename, lineno, TFAIL,
+ "fstat(%d, &st): unexpected file size", fd);
+ }
+
+ tst_res_(filename, lineno, TPASS,
+ "fstat(%d, &st): file size is correct", fd);
+}
+
+int check_mfd_open(const char *filename, const int lineno, int fd,
+ int flags, mode_t mode)
+{
+ int r;
+ char buf[512];
+
+ sprintf(buf, "/proc/self/fd/%d", fd);
+
+ r = safe_open(filename, lineno, NULL, buf, flags, mode);
+
+ tst_res_(filename, lineno, TPASS, "open(%s, %d, %d) succeeded", buf,
+ flags, mode);
+
+ return r;
+}
+
+void check_mfd_fail_open(const char *filename, const int lineno, int fd,
+ int flags, mode_t mode)
+{
+ char buf[512];
+
+ sprintf(buf, "/proc/self/fd/%d", fd);
+
+ fd = open(buf, flags, mode);
+ if (fd > 0) {
+ safe_close(filename, lineno, NULL, fd);
+ tst_res_(filename, lineno, TFAIL,
+ "open(%s, %d, %d) succeeded unexpectedly", buf,
+ flags, mode);
+ } else {
+ tst_res_(filename, lineno, TPASS | TERRNO,
+ "open(%s, %d, %d) failed as expected", buf,
+ flags, mode);
+ }
+}
+
+void check_mfd_readable(const char *filename, const int lineno, int fd)
+{
+ char buf[16];
+ void *p;
+
+ safe_read(filename, lineno, NULL, 1, fd, buf, sizeof(buf));
+ tst_res_(filename, lineno, TPASS, "read(%d, %s, %ld) succeeded", fd,
+ buf, sizeof(buf));
+
+ /* verify PROT_READ *is* allowed */
+ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE, PROT_READ,
+ MAP_PRIVATE, fd, 0);
+
+ check_munmap(filename, lineno, p, MFD_DEF_SIZE);
+
+ /* verify MAP_PRIVATE is *always* allowed (even writable) */
+ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+
+ check_munmap(filename, lineno, p, MFD_DEF_SIZE);
+}
+
+void check_mfd_writeable(const char *filename, const int lineno, int fd)
+{
+ void *p;
+
+ /* verify write() succeeds */
+ safe_write(filename, lineno, NULL, 1, fd, "\0\0\0\0", 4);
+ tst_res_(filename, lineno, TPASS, "write(%d, %p, %d) succeeded", fd,
+ "\0\0\0\0", 4);
+
+ /* verify PROT_READ | PROT_WRITE is allowed */
+ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ *(char *)p = 0;
+ check_munmap(filename, lineno, p, MFD_DEF_SIZE);
+
+ /* verify PROT_WRITE is allowed */
+ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
+ PROT_WRITE, MAP_SHARED, fd, 0);
+
+ *(char *)p = 0;
+ check_munmap(filename, lineno, p, MFD_DEF_SIZE);
+
+ /* verify PROT_READ with MAP_SHARED is allowed and a following
+ * mprotect(PROT_WRITE) allows writing
+ */
+ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
+ PROT_READ, MAP_SHARED, fd, 0);
+
+ check_mprotect(filename, lineno, p, MFD_DEF_SIZE,
+ PROT_READ | PROT_WRITE);
+
+ *(char *)p = 0;
+ check_munmap(filename, lineno, p, MFD_DEF_SIZE);
+
+ /* verify PUNCH_HOLE works */
+ check_fallocate(filename, lineno, fd,
+ FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0,
+ MFD_DEF_SIZE);
+}
+
+void check_mfd_non_writeable(const char *filename, const int lineno,
+ int fd)
+{
+ void *p;
+
+ /* verify write() fails */
+ TEST(write(fd, "data", 4));
+ if (TEST_RETURN < 0) {
+ if (TEST_ERRNO != EPERM) {
+ tst_brk_(filename, lineno, TFAIL | TTERRNO,
+ "write() didn't fail as expected");
+ }
+ } else {
+ tst_brk_(filename, lineno, TFAIL,
+ "write() succeeded unexpectedly");
+ }
+ tst_res_(filename, lineno, TPASS | TTERRNO, "write failed as expected");
+
+ /* verify PROT_READ | PROT_WRITE is not allowed */
+ check_mmap_fail(filename, lineno, NULL, MFD_DEF_SIZE,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ /* verify PROT_WRITE is not allowed */
+ check_mmap_fail(filename, lineno, NULL, MFD_DEF_SIZE,
+ PROT_WRITE, MAP_SHARED, fd, 0);
+
+ /* Verify PROT_READ with MAP_SHARED with a following mprotect is not
+ * allowed. Note that for r/w the kernel already prevents the mmap.
+ */
+ p = mmap(NULL, MFD_DEF_SIZE, PROT_READ, MAP_SHARED, fd, 0);
+ if (p != MAP_FAILED) {
+ if (mprotect(p, MFD_DEF_SIZE, PROT_READ | PROT_WRITE) >= 0) {
+ tst_brk_(filename, lineno, TFAIL | TERRNO,
+ "mmap()+mprotect() succeeded unexpectedly");
+ }
+ }
+
+ /* verify PUNCH_HOLE fails */
+ check_fallocate_fail(filename, lineno, fd,
+ FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0,
+ MFD_DEF_SIZE);
+}
+
+void check_mfd_shrinkable(const char *filename, const int lineno, int fd)
+{
+ int fd2;
+
+ check_ftruncate(filename, lineno, fd, MFD_DEF_SIZE / 2);
+ check_mfd_size(filename, lineno, fd, MFD_DEF_SIZE / 2);
+
+ fd2 = check_mfd_open(filename, lineno, fd,
+ O_RDWR | O_CREAT | O_TRUNC, 0600);
+ safe_close(filename, lineno, NULL, fd2);
+
+ check_mfd_size(filename, lineno, fd, 0);
+}
+
+void check_mfd_non_shrinkable(const char *filename, const int lineno, int fd)
+{
+ check_ftruncate_fail(filename, lineno, fd, MFD_DEF_SIZE / 2);
+ check_mfd_fail_open(filename, lineno, fd,
+ O_RDWR | O_CREAT | O_TRUNC, 0600);
+}
+
+void check_mfd_growable(const char *filename, const int lineno, int fd)
+{
+ check_ftruncate(filename, lineno, fd, MFD_DEF_SIZE * 2);
+ check_mfd_size(filename, lineno, fd, MFD_DEF_SIZE * 2);
+
+ check_fallocate(filename, lineno, fd, 0, 0, MFD_DEF_SIZE * 4);
+ check_mfd_size(filename, lineno, fd, MFD_DEF_SIZE * 4);
+}
+
+void check_mfd_non_growable(const char *filename, const int lineno, int fd)
+{
+ check_ftruncate_fail(filename, lineno, fd, MFD_DEF_SIZE * 2);
+ check_fallocate_fail(filename, lineno, fd, 0, 0, MFD_DEF_SIZE * 4);
+}
+
+void check_mfd_growable_by_write(const char *filename, const int lineno, int fd)
+{
+ char buf[MFD_DEF_SIZE * 8];
+
+ if (pwrite(fd, buf, sizeof(buf), 0) != sizeof(buf)) {
+ tst_res_(filename, lineno, TFAIL | TERRNO,
+ "pwrite(%d, %s, %ld, %d) failed",
+ fd, buf, sizeof(buf), 0);
+
+ return;
+ }
+
+ tst_res_(filename, lineno, TPASS, "pwrite(%d, %s, %ld, %d) succeeded",
+ fd, buf, sizeof(buf), 0);
+
+ check_mfd_size(filename, lineno, fd, MFD_DEF_SIZE * 8);
+}
+
+void check_mfd_non_growable_by_write(const char *filename, const int lineno,
+ int fd)
+{
+ char buf[MFD_DEF_SIZE * 8];
+
+ if (pwrite(fd, buf, sizeof(buf), 0) == sizeof(buf)) {
+ tst_res_(filename, lineno, TFAIL,
+ "pwrite(%d, %s, %ld, %d) didn't fail as expected",
+ fd, buf, sizeof(buf), 0);
+
+ return;
+ }
+
+ tst_res_(filename, lineno, TPASS, "pwrite(%d, %s, %ld, %d) succeeded",
+ fd, buf, sizeof(buf), 0);
+}
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.h b/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
new file mode 100644
index 0000000..2705375
--- /dev/null
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef MEMFD_TEST_COMMON
+#define MEMFD_TEST_COMMON
+
+#include <sys/types.h>
+#include <lapi/fcntl.h>
+#include <lapi/memfd.h>
+
+#define MFD_DEF_SIZE 8192
+
+#define ASSERT_HAVE_MEMFD_CREATE() \
+ assert_have_memfd_create(__FILE__, __LINE__)
+
+#define CHECK_MFD_NEW(name, sz, flags) \
+ check_mfd_new(__FILE__, __LINE__, (name), (sz), (flags))
+
+#define CHECK_MFD_FAIL_NEW(name, flags) \
+ check_mfd_fail_new(__FILE__, __LINE__, (name), (flags))
+
+#define CHECK_MMAP(addr, length, prot, flags, fd, offset) \
+ check_mmap(__FILE__, __LINE__, (addr), (length), (prot), \
+ (flags), (fd), (offset))
+
+#define CHECK_MMAP_FAIL(addr, length, prot, flags, fd, offset) \
+ check_mmap_fail(__FILE__, __LINE__, (addr), (length), (prot), \
+ (flags), (fd), (offset))
+
+#define CHECK_MUNMAP(p, length) \
+ check_munmap(__FILE__, __LINE__, (p), (length))
+
+#define CHECK_MFD_HAS_SEALS(fd, seals) \
+ do { \
+ if (SAFE_FCNTL((fd), F_GET_SEALS) != (seals)) { \
+ tst_brk(TFAIL, "fd %d doesn't have expected seals", \
+ (fd)); \
+ } \
+ tst_res(TPASS, "fd %d has expected seals", (fd)); \
+ } while (0)
+
+#define CHECK_MFD_ADD_SEALS(fd, seals) \
+ ({int r = SAFE_FCNTL((fd), F_ADD_SEALS, (seals)); \
+ tst_res(TPASS, "fcntl(%d, F_ADD_SEALS, %d) succeeded", \
+ (fd), (seals)); r; })
+
+#define CHECK_MFD_FAIL_ADD_SEALS(fd, seals) \
+ check_mfd_fail_add_seals(__FILE__, __LINE__, (fd), (seals))
+
+#define CHECK_MFD_SIZE(fd, size) \
+ check_mfd_size(__FILE__, __LINE__, (fd), (size))
+
+#define CHECK_MFD_OPEN(fd, flags, mode) \
+ check_mfd_open(__FILE__, __LINE__, (fd), (flags), (mode))
+
+#define CHECK_MFD_FAIL_OPEN(fd, flags, mode) \
+ check_mfd_fail_open(__FILE__, __LINE__, (fd), (flags), (mode))
+
+#define CHECK_MFD_READABLE(fd) \
+ check_mfd_readable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_WRITEABLE(fd) \
+ check_mfd_writeable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_NON_WRITEABLE(fd) \
+ check_mfd_non_writeable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_SHRINKABLE(fd) \
+ check_mfd_shrinkable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_NON_SHRINKABLE(fd) \
+ check_mfd_non_shrinkable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_GROWABLE(fd) \
+ check_mfd_growable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_NON_GROWABLE(fd) \
+ check_mfd_non_growable(__FILE__, __LINE__, (fd))
+
+#define CHECK_MFD_GROWABLE_BY_WRITE(fd) \
+ check_mfd_growable_by_write(__FILE__, __LINE__, (fd))
+
+#define CHECK_NON_GROWABLE_BY_WRITE(fd) \
+ check_mfd_non_growable_by_write(__FILE__, __LINE__, (fd))
+
+void assert_have_memfd_create(const char *filename, const int lineno);
+int sys_memfd_create(const char *name, unsigned int flags);
+
+int check_fallocate(const char *filename, const int lineno, int fd,
+ int mode, off_t offset, off_t len);
+int check_fallocate_fail(const char *filename, const int lineno, int fd,
+ int mode, off_t offset, off_t len);
+void check_ftruncate(const char *filename, const int lineno, int fd,
+ off_t length);
+void check_ftruncate_fail(const char *filename, const int lineno, int fd,
+ off_t length);
+
+int check_mfd_new(const char *filename, const int lineno,
+ const char *name, loff_t sz, int flags);
+void check_mfd_fail_new(const char *filename, const int lineno,
+ const char *name, int flags);
+
+void *check_mmap(const char *file, const int lineno, void *addr, size_t length,
+ int prot, int flags, int fd, off_t offset);
+void check_mmap_fail(const char *file, const int lineno, void *addr,
+ size_t length, int prot, int flags, int fd, off_t offset);
+
+void check_munmap(const char *file, const int lineno, void *p, size_t length);
+
+void check_mprotect(const char *file, const int lineno, void *addr,
+ size_t length, int prot);
+
+void check_mfd_fail_add_seals(const char *filename, const int lineno, int fd,
+ int seals);
+
+void check_mfd_size(const char *filename, const int lineno, int fd,
+ size_t size);
+
+int check_mfd_open(const char *filename, const int lineno, int fd,
+ int flags, mode_t mode);
+void check_mfd_fail_open(const char *filename, const int lineno, int fd,
+ int flags, mode_t mode);
+
+void check_mfd_readable(const char *filename, const int lineno, int fd);
+
+void check_mfd_writeable(const char *filename, const int lineno, int fd);
+void check_mfd_non_writeable(const char *filename, const int lineno, int fd);
+
+void check_mfd_shrinkable(const char *filename, const int lineno, int fd);
+void check_mfd_non_shrinkable(const char *filename, const int lineno, int fd);
+
+void check_mfd_growable(const char *filename, const int lineno, int fd);
+void check_mfd_non_growable(const char *filename, const int lineno, int fd);
+
+void check_mfd_growable_by_write(const char *filename, const int lineno,
+ int fd);
+void check_mfd_non_growable_by_write(const char *filename, const int lineno,
+ int fd);
+
+#endif
--
1.8.3.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 6/6] syscalls/memfd_create02.c: added new test
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
` (4 preceding siblings ...)
2017-03-23 18:15 ` [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c Jakub Racek
@ 2017-03-23 18:15 ` Jakub Racek
5 siblings, 0 replies; 17+ messages in thread
From: Jakub Racek @ 2017-03-23 18:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Jakub Racek <jracek@redhat.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/.gitignore | 1 +
.../kernel/syscalls/memfd_create/memfd_create02.c | 94 ++++++++++++++++++++++
3 files changed, 96 insertions(+)
create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 2da5b48..1be9710 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1452,3 +1452,4 @@ futex_wait_bitset01 futex_wait_bitset01
futex_wait_bitset02 futex_wait_bitset02
memfd_create01 memfd_create01
+memfd_create02 memfd_create02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 905badc..9f07273 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1119,3 +1119,4 @@
/perf_event_open/perf_event_open01
/perf_event_open/perf_event_open02
/memfd_create/memfd_create01
+/memfd_create/memfd_create02
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create02.c b/testcases/kernel/syscalls/memfd_create/memfd_create02.c
new file mode 100644
index 0000000..1c56156
--- /dev/null
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create02.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+ /*
+ * Based on Linux/tools/testing/selftests/memfd/memfd_test.c
+ * by David Herrmann <dh.herrmann@gmail.com>
+ *
+ * 24/02/2017 Port to LTP <jracek@redhat.com>
+ */
+
+#define _GNU_SOURCE
+
+#include <errno.h>
+
+#include <tst_test.h>
+
+#include "memfd_create_common.h"
+
+static char buf[2048];
+static char term_buf[2048];
+
+static const struct tcase {
+ char *descr;
+ char *memfd_name;
+ int flags;
+ int memfd_create_exp_err;
+} tcases[] = {
+ /*
+ * Test memfd_create() syscall
+ * Verify syscall-argument validation, including name checks,
+ * flag validation and more.
+ */
+ {"invalid name fail 1", NULL, 0, EFAULT },
+ {"invalid name fail 2", buf, 0, EINVAL },
+ {"invalid name fail 3", term_buf, 0, EINVAL },
+
+ {"invalid flags fail 1", "test", -500, EINVAL },
+ {"invalid flags fail 2", "test", 0x0100, EINVAL },
+ {"invalid flags fail 3", "test", ~MFD_CLOEXEC, EINVAL },
+ {"invalid flags fail 4", "test", ~MFD_ALLOW_SEALING, EINVAL },
+ {"invalid flags fail 5", "test", ~0, EINVAL },
+ {"invalid flags fail 6", "test", 0x80000000U, EINVAL },
+
+ {"valid flags 1 pass", "test", MFD_CLOEXEC, 0 },
+ {"valid flags 2 pass", "test", MFD_ALLOW_SEALING, 0 },
+ {"valid flags 3 pass", "test", MFD_CLOEXEC | MFD_ALLOW_SEALING, 0 },
+ {"valid flags 4 pass", "test", 0, 0 },
+ {"valid flags 5 pass", "", 0, 0 },
+};
+
+static void setup(void)
+{
+ ASSERT_HAVE_MEMFD_CREATE();
+
+ memset(buf, 0xff, sizeof(buf));
+
+ memset(term_buf, 0xff, sizeof(term_buf));
+ term_buf[sizeof(term_buf) - 1] = 0;
+}
+
+static void verify_memfd_create_errno(unsigned int n)
+{
+ const struct tcase *tc;
+
+ tc = &tcases[n];
+
+ TEST(sys_memfd_create(tc->memfd_name, tc->flags));
+ if (TEST_ERRNO != tc->memfd_create_exp_err)
+ tst_brk(TFAIL, "test '%s'", tc->descr);
+ else
+ tst_res(TPASS, "test '%s'", tc->descr);
+
+ if (TEST_RETURN > 0)
+ SAFE_CLOSE(TEST_RETURN);
+}
+
+static struct tst_test test = {
+ .tid = "memfd_create02",
+ .test = verify_memfd_create_errno,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+};
--
1.8.3.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c
2017-03-23 18:15 ` [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c Jakub Racek
@ 2017-03-24 15:26 ` Cyril Hrubis
2017-03-24 15:42 ` Jakub =?unknown-8bit?q?Ra=C4=8Dek?=
2017-03-29 8:42 ` Jan Stancek
0 siblings, 2 replies; 17+ messages in thread
From: Cyril Hrubis @ 2017-03-24 15:26 UTC (permalink / raw)
To: ltp
Hi!
Patchset pushed with cosmetic chnages to this patch (see diff below),
thanks.
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create01.c b/testcases/kernel/syscalls/memfd_create/memfd_create01.c
index c181fe6..04a5f4f 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create01.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create01.c
@@ -75,7 +75,7 @@ static void test_seal_write(int fd)
CHECK_MFD_NON_WRITEABLE(fd);
CHECK_MFD_SHRINKABLE(fd);
CHECK_MFD_GROWABLE(fd);
- CHECK_NON_GROWABLE_BY_WRITE(fd);
+ CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
}
*** Added MFD here just for consistency
/*
@@ -109,7 +109,7 @@ static void test_seal_grow(int fd)
CHECK_MFD_WRITEABLE(fd);
CHECK_MFD_SHRINKABLE(fd);
CHECK_MFD_NON_GROWABLE(fd);
- CHECK_NON_GROWABLE_BY_WRITE(fd);
+ CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
}
/*
@@ -126,7 +126,7 @@ static void test_seal_resize(int fd)
CHECK_MFD_WRITEABLE(fd);
CHECK_MFD_NON_SHRINKABLE(fd);
CHECK_MFD_NON_GROWABLE(fd);
- CHECK_NON_GROWABLE_BY_WRITE(fd);
+ CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
}
/*
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
index 0c7143b..dfc75a8 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
@@ -13,22 +13,22 @@
*
*/
- #define _GNU_SOURCE
-
- #include <sys/types.h>
- #include <sys/syscall.h>
- #include <sys/uio.h>
- #include <lapi/fallocate.h>
- #include <lapi/fcntl.h>
- #include <lapi/memfd.h>
- #include <errno.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
-
- #define TST_NO_DEFAULT_MAIN
- #include <tst_test.h>
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/uio.h>
+#include <lapi/fallocate.h>
+#include <lapi/fcntl.h>
+#include <lapi/memfd.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include <tst_test.h>
*** Removed spaces before #
#include "linux_syscall_numbers.h"
@@ -146,7 +146,8 @@ void check_mfd_fail_new(const char *filename, const int lineno,
fd = sys_memfd_create(name, flags);
if (fd >= 0) {
safe_close(filename, lineno, NULL, fd);
- tst_brk(TFAIL, "memfd_create(%s, %d) succeeded unexpectedly",
+ tst_brk_(filename, lineno, TFAIL,
+ "memfd_create(%s, %d) succeeded unexpectedly",
name, flags);
}
*** Added forgotten filename and lineno to the message
@@ -172,6 +173,7 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,
size_t length, int prot, int flags, int fd, off_t offset)
{
if (mmap(addr, length, prot, flags, fd, offset) != MAP_FAILED) {
+ safe_munmap(file, lineno, NULL, addr, length);
tst_res_(file, lineno, TFAIL,
"mmap(%p, %zu, %i, %i, %i, %zi) succeeded unexpectedly",
addr, length, prot, flags, fd, offset);
@@ -191,6 +193,19 @@ void check_munmap(const char *file, const int lineno, void *p, size_t length)
tst_res_(file, lineno, TPASS, "munmap(%p, %ld) succeeded", p, length);
}
*** Added forgotten munmap
+void check_mfd_has_seals(const char *file, const int lineno, int fd, int seals)
+{
+ int ret = SAFE_FCNTL((fd), F_GET_SEALS);
+ if (ret != seals) {
+ tst_brk_(file, lineno, TFAIL,
+ "fd %d doesn't have expected seals (%d expected %d)",
+ fd, ret, seals);
+ }
+
+ tst_res_(file, lineno, TPASS,
+ "fd %d has expected seals (%d)", fd, seals);
+}
*** Changed this macro for a function and make it print the values of seals
void check_mprotect(const char *file, const int lineno, void *addr,
size_t length, int prot)
{
@@ -297,7 +312,7 @@ void check_mfd_writeable(const char *filename, const int lineno, int fd)
/* verify write() succeeds */
safe_write(filename, lineno, NULL, 1, fd, "\0\0\0\0", 4);
tst_res_(filename, lineno, TPASS, "write(%d, %s, %d) succeeded", fd,
- "\0\0\0\0", 4);
+ "\\0\\0\\0\\0", 4);
** Changed this to print literal '\0\0\0\0' instead of random pointer
/* verify PROT_READ | PROT_WRITE is allowed */
p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.h b/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
index 2705375..6329ac3 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
@@ -43,13 +43,7 @@
check_munmap(__FILE__, __LINE__, (p), (length))
#define CHECK_MFD_HAS_SEALS(fd, seals) \
- do { \
- if (SAFE_FCNTL((fd), F_GET_SEALS) != (seals)) { \
- tst_brk(TFAIL, "fd %d doesn't have expected seals", \
- (fd)); \
- } \
- tst_res(TPASS, "fd %d has expected seals", (fd)); \
- } while (0)
+ check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals));
#define CHECK_MFD_ADD_SEALS(fd, seals) \
({int r = SAFE_FCNTL((fd), F_ADD_SEALS, (seals)); \
@@ -92,7 +86,7 @@
#define CHECK_MFD_GROWABLE_BY_WRITE(fd) \
check_mfd_growable_by_write(__FILE__, __LINE__, (fd))
-#define CHECK_NON_GROWABLE_BY_WRITE(fd) \
+#define CHECK_MFD_NON_GROWABLE_BY_WRITE(fd) \
check_mfd_non_growable_by_write(__FILE__, __LINE__, (fd))
void assert_have_memfd_create(const char *filename, const int lineno);
@@ -119,6 +113,8 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,
void check_munmap(const char *file, const int lineno, void *p, size_t length);
+void check_mfd_has_seals(const char *file, const int lineno, int fd, int seals);
+
void check_mprotect(const char *file, const int lineno, void *addr,
size_t length, int prot);
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c
2017-03-24 15:26 ` Cyril Hrubis
@ 2017-03-24 15:42 ` Jakub =?unknown-8bit?q?Ra=C4=8Dek?=
2017-03-29 8:42 ` Jan Stancek
1 sibling, 0 replies; 17+ messages in thread
From: Jakub =?unknown-8bit?q?Ra=C4=8Dek?= @ 2017-03-24 15:42 UTC (permalink / raw)
To: ltp
Hi,
thank you for the reviews. I learned a lot from that.
I'm also glad it finally made it through.
Best regards,
Jakub Racek
On 03/24/2017 04:26 PM, Cyril Hrubis wrote:
> Hi!
> Patchset pushed with cosmetic chnages to this patch (see diff below),
> thanks.
>
> diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create01.c b/testcases/kernel/syscalls/memfd_create/memfd_create01.c
> index c181fe6..04a5f4f 100644
> --- a/testcases/kernel/syscalls/memfd_create/memfd_create01.c
> +++ b/testcases/kernel/syscalls/memfd_create/memfd_create01.c
> @@ -75,7 +75,7 @@ static void test_seal_write(int fd)
> CHECK_MFD_NON_WRITEABLE(fd);
> CHECK_MFD_SHRINKABLE(fd);
> CHECK_MFD_GROWABLE(fd);
> - CHECK_NON_GROWABLE_BY_WRITE(fd);
> + CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
> }
>
> *** Added MFD here just for consistency
>
> /*
> @@ -109,7 +109,7 @@ static void test_seal_grow(int fd)
> CHECK_MFD_WRITEABLE(fd);
> CHECK_MFD_SHRINKABLE(fd);
> CHECK_MFD_NON_GROWABLE(fd);
> - CHECK_NON_GROWABLE_BY_WRITE(fd);
> + CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
> }
>
> /*
> @@ -126,7 +126,7 @@ static void test_seal_resize(int fd)
> CHECK_MFD_WRITEABLE(fd);
> CHECK_MFD_NON_SHRINKABLE(fd);
> CHECK_MFD_NON_GROWABLE(fd);
> - CHECK_NON_GROWABLE_BY_WRITE(fd);
> + CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
> }
>
> /*
> diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
> index 0c7143b..dfc75a8 100644
> --- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
> +++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
> @@ -13,22 +13,22 @@
> *
> */
>
> - #define _GNU_SOURCE
> -
> - #include <sys/types.h>
> - #include <sys/syscall.h>
> - #include <sys/uio.h>
> - #include <lapi/fallocate.h>
> - #include <lapi/fcntl.h>
> - #include <lapi/memfd.h>
> - #include <errno.h>
> - #include <string.h>
> - #include <stdio.h>
> - #include <stdlib.h>
> - #include <unistd.h>
> -
> - #define TST_NO_DEFAULT_MAIN
> - #include <tst_test.h>
> +#define _GNU_SOURCE
> +
> +#include <sys/types.h>
> +#include <sys/syscall.h>
> +#include <sys/uio.h>
> +#include <lapi/fallocate.h>
> +#include <lapi/fcntl.h>
> +#include <lapi/memfd.h>
> +#include <errno.h>
> +#include <string.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include <tst_test.h>
>
> *** Removed spaces before #
>
> #include "linux_syscall_numbers.h"
>
> @@ -146,7 +146,8 @@ void check_mfd_fail_new(const char *filename, const int lineno,
> fd = sys_memfd_create(name, flags);
> if (fd >= 0) {
> safe_close(filename, lineno, NULL, fd);
> - tst_brk(TFAIL, "memfd_create(%s, %d) succeeded unexpectedly",
> + tst_brk_(filename, lineno, TFAIL,
> + "memfd_create(%s, %d) succeeded unexpectedly",
> name, flags);
> }
>
> *** Added forgotten filename and lineno to the message
>
> @@ -172,6 +173,7 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,
> size_t length, int prot, int flags, int fd, off_t offset)
> {
> if (mmap(addr, length, prot, flags, fd, offset) != MAP_FAILED) {
> + safe_munmap(file, lineno, NULL, addr, length);
> tst_res_(file, lineno, TFAIL,
> "mmap(%p, %zu, %i, %i, %i, %zi) succeeded unexpectedly",
> addr, length, prot, flags, fd, offset);
> @@ -191,6 +193,19 @@ void check_munmap(const char *file, const int lineno, void *p, size_t length)
> tst_res_(file, lineno, TPASS, "munmap(%p, %ld) succeeded", p, length);
> }
>
> *** Added forgotten munmap
>
> +void check_mfd_has_seals(const char *file, const int lineno, int fd, int seals)
> +{
> + int ret = SAFE_FCNTL((fd), F_GET_SEALS);
> + if (ret != seals) {
> + tst_brk_(file, lineno, TFAIL,
> + "fd %d doesn't have expected seals (%d expected %d)",
> + fd, ret, seals);
> + }
> +
> + tst_res_(file, lineno, TPASS,
> + "fd %d has expected seals (%d)", fd, seals);
> +}
>
> *** Changed this macro for a function and make it print the values of seals
>
> void check_mprotect(const char *file, const int lineno, void *addr,
> size_t length, int prot)
> {
> @@ -297,7 +312,7 @@ void check_mfd_writeable(const char *filename, const int lineno, int fd)
> /* verify write() succeeds */
> safe_write(filename, lineno, NULL, 1, fd, "\0\0\0\0", 4);
> tst_res_(filename, lineno, TPASS, "write(%d, %s, %d) succeeded", fd,
> - "\0\0\0\0", 4);
> + "\\0\\0\\0\\0", 4);
>
> ** Changed this to print literal '\0\0\0\0' instead of random pointer
>
> /* verify PROT_READ | PROT_WRITE is allowed */
> p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
> diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.h b/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
> index 2705375..6329ac3 100644
> --- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
> +++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.h
> @@ -43,13 +43,7 @@
> check_munmap(__FILE__, __LINE__, (p), (length))
>
> #define CHECK_MFD_HAS_SEALS(fd, seals) \
> - do { \
> - if (SAFE_FCNTL((fd), F_GET_SEALS) != (seals)) { \
> - tst_brk(TFAIL, "fd %d doesn't have expected seals", \
> - (fd)); \
> - } \
> - tst_res(TPASS, "fd %d has expected seals", (fd)); \
> - } while (0)
> + check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals));
>
> #define CHECK_MFD_ADD_SEALS(fd, seals) \
> ({int r = SAFE_FCNTL((fd), F_ADD_SEALS, (seals)); \
> @@ -92,7 +86,7 @@
> #define CHECK_MFD_GROWABLE_BY_WRITE(fd) \
> check_mfd_growable_by_write(__FILE__, __LINE__, (fd))
>
> -#define CHECK_NON_GROWABLE_BY_WRITE(fd) \
> +#define CHECK_MFD_NON_GROWABLE_BY_WRITE(fd) \
> check_mfd_non_growable_by_write(__FILE__, __LINE__, (fd))
>
> void assert_have_memfd_create(const char *filename, const int lineno);
> @@ -119,6 +113,8 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,
>
> void check_munmap(const char *file, const int lineno, void *p, size_t length);
>
> +void check_mfd_has_seals(const char *file, const int lineno, int fd, int seals);
> +
> void check_mprotect(const char *file, const int lineno, void *addr,
> size_t length, int prot);
>
>
--
Regards,
Jakub
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c
2017-03-24 15:26 ` Cyril Hrubis
2017-03-24 15:42 ` Jakub =?unknown-8bit?q?Ra=C4=8Dek?=
@ 2017-03-29 8:42 ` Jan Stancek
2017-03-29 9:18 ` Cyril Hrubis
1 sibling, 1 reply; 17+ messages in thread
From: Jan Stancek @ 2017-03-29 8:42 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Hi!
> Patchset pushed with cosmetic chnages to this patch (see diff below),
> thanks.
Hi,
build on distro that doesn't define HAVE_FALLOCATE is now failing
for me:
# git describe
20170116-207-g16f4d56
# ./configure && make
...
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create01.o memfd_create01.c
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create_common.o memfd_create_common.c
In file included from memfd_create_common.c:21:
../../../../include/lapi/fallocate.h: In function ‘fallocate’:
../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ‘syscall’
../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ‘tst_brkm’
../../../../include/lapi/fallocate.h:55: error: ‘TCONF’ undeclared (first use in this function)
../../../../include/lapi/fallocate.h:55: error: (Each undeclared identifier is reported only once
../../../../include/lapi/fallocate.h:55: error: for each function it appears in.)
In file included from memfd_create_common.c:28:
/usr/include/unistd.h: At top level:
/usr/include/unistd.h:1011: error: conflicting types for ‘syscall’
../../../../include/lapi/fallocate.h:55: error: previous implicit declaration of ‘syscall’ was here
make[4]: *** [memfd_create_common.o] Error 1
make[4]: Leaving directory `/root/ltp/testcases/kernel/syscalls/memfd_create'
make[3]: *** [all] Error 2
make[3]: Leaving directory `/root/ltp/testcases/kernel/syscalls'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/ltp/testcases/kernel'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2
Regards,
Jan
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c
2017-03-29 8:42 ` Jan Stancek
@ 2017-03-29 9:18 ` Cyril Hrubis
2017-03-29 9:32 ` [LTP] [PATCH] syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined Guangwen Feng
0 siblings, 1 reply; 17+ messages in thread
From: Cyril Hrubis @ 2017-03-29 9:18 UTC (permalink / raw)
To: ltp
Hi!
> build on distro that doesn't define HAVE_FALLOCATE is now failing
> for me:
>
> # git describe
> 20170116-207-g16f4d56
>
> # ./configure && make
> ...
> gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create01.o memfd_create01.c
> gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create_common.o memfd_create_common.c
> In file included from memfd_create_common.c:21:
> ../../../../include/lapi/fallocate.h: In function ???fallocate???:
> ../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ???syscall???
> ../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ???tst_brkm???
> ../../../../include/lapi/fallocate.h:55: error: ???TCONF??? undeclared (first use in this function)
> ../../../../include/lapi/fallocate.h:55: error: (Each undeclared identifier is reported only once
> ../../../../include/lapi/fallocate.h:55: error: for each function it appears in.)
> In file included from memfd_create_common.c:28:
> /usr/include/unistd.h: At top level:
> /usr/include/unistd.h:1011: error: conflicting types for ???syscall???
> ../../../../include/lapi/fallocate.h:55: error: previous implicit declaration of ???syscall??? was here
> make[4]: *** [memfd_create_common.o] Error 1
> make[4]: Leaving directory `/root/ltp/testcases/kernel/syscalls/memfd_create'
> make[3]: *** [all] Error 2
> make[3]: Leaving directory `/root/ltp/testcases/kernel/syscalls'
> make[2]: *** [all] Error 2
> make[2]: Leaving directory `/root/ltp/testcases/kernel'
> make[1]: *** [all] Error 2
> make[1]: Leaving directory `/root/ltp/testcases'
> make: *** [testcases-all] Error 2
Ah, right looks like we have the old API/new API mixed again. Sorry I
should have caught that during the review.
Now easy fix would be switching on newlib/oldlib and
tst_syscall()/ltp_syscall(). Bit better one would be to rewrite the
fallocate tests to newlib and switch to tst_sycall() in the fallocate.h
header.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH] syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined
2017-03-29 9:18 ` Cyril Hrubis
@ 2017-03-29 9:32 ` Guangwen Feng
2017-03-30 9:35 ` Cyril Hrubis
0 siblings, 1 reply; 17+ messages in thread
From: Guangwen Feng @ 2017-03-29 9:32 UTC (permalink / raw)
To: ltp
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
include/lapi/fallocate.h | 12 ++++++++++++
testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 4 ++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/lapi/fallocate.h b/include/lapi/fallocate.h
index 79d0b7b..20ba40c 100644
--- a/include/lapi/fallocate.h
+++ b/include/lapi/fallocate.h
@@ -52,13 +52,25 @@ static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
{
/* Deal with 32bit ABIs that have 64bit syscalls. */
# if LTP_USE_64_ABI
+#ifdef __TEST_H__
return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
+#else
+ return tst_syscall(__NR_fallocate, fd, mode, offset, len);
+#endif /* __TEST_H__ */
# else
+#ifdef __TEST_H__
return (long)ltp_syscall(__NR_fallocate, fd, mode,
__LONG_LONG_PAIR((off_t) (offset >> 32),
(off_t) offset),
__LONG_LONG_PAIR((off_t) (len >> 32),
(off_t) len));
+#else
+ return (long)tst_syscall(__NR_fallocate, fd, mode,
+ __LONG_LONG_PAIR((off_t) (offset >> 32),
+ (off_t) offset),
+ __LONG_LONG_PAIR((off_t) (len >> 32),
+ (off_t) len));
+#endif /* __TEST_H__ */
# endif
}
#endif
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
index 8612db7..ddf9f05 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
@@ -18,7 +18,6 @@
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/uio.h>
-#include <lapi/fallocate.h>
#include <lapi/fcntl.h>
#include <lapi/memfd.h>
#include <errno.h>
@@ -28,7 +27,8 @@
#include <unistd.h>
#define TST_NO_DEFAULT_MAIN
-#include <tst_test.h>
+#include "tst_test.h"
+#include "lapi/fallocate.h"
#include "linux_syscall_numbers.h"
--
1.8.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH] syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined
2017-03-29 9:32 ` [LTP] [PATCH] syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined Guangwen Feng
@ 2017-03-30 9:35 ` Cyril Hrubis
2017-03-30 9:49 ` Guangwen Feng
0 siblings, 1 reply; 17+ messages in thread
From: Cyril Hrubis @ 2017-03-30 9:35 UTC (permalink / raw)
To: ltp
Hi!
> /* Deal with 32bit ABIs that have 64bit syscalls. */
> # if LTP_USE_64_ABI
> +#ifdef __TEST_H__
> return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
> +#else
> + return tst_syscall(__NR_fallocate, fd, mode, offset, len);
> +#endif /* __TEST_H__ */
> # else
> +#ifdef __TEST_H__
> return (long)ltp_syscall(__NR_fallocate, fd, mode,
> __LONG_LONG_PAIR((off_t) (offset >> 32),
> (off_t) offset),
> __LONG_LONG_PAIR((off_t) (len >> 32),
> (off_t) len));
> +#else
> + return (long)tst_syscall(__NR_fallocate, fd, mode,
> + __LONG_LONG_PAIR((off_t) (offset >> 32),
> + (off_t) offset),
> + __LONG_LONG_PAIR((off_t) (len >> 32),
> + (off_t) len));
> +#endif /* __TEST_H__ */
We can spare a bit of the duplication by definign the function name:
...
#ifdef __TEST_H__
# define TST_SYSCALL_WRAPPER ltp_syscall
#else
# define TST_SYSCALL_WRAPPER tst_syscall
#endif
...
return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode,
__LONG_LONG_PAIR((off_t) (offset >> 32),
(off_t) offset),
__LONG_LONG_PAIR((off_t) (len >> 32),
(off_t) len));
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH] syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined
2017-03-30 9:35 ` Cyril Hrubis
@ 2017-03-30 9:49 ` Guangwen Feng
2017-03-30 10:48 ` [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure " Guangwen Feng
0 siblings, 1 reply; 17+ messages in thread
From: Guangwen Feng @ 2017-03-30 9:49 UTC (permalink / raw)
To: ltp
Hi!
On 03/30/2017 05:35 PM, Cyril Hrubis wrote:
> Hi!
>> /* Deal with 32bit ABIs that have 64bit syscalls. */
>> # if LTP_USE_64_ABI
>> +#ifdef __TEST_H__
>> return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
>> +#else
>> + return tst_syscall(__NR_fallocate, fd, mode, offset, len);
>> +#endif /* __TEST_H__ */
>> # else
>> +#ifdef __TEST_H__
>> return (long)ltp_syscall(__NR_fallocate, fd, mode,
>> __LONG_LONG_PAIR((off_t) (offset >> 32),
>> (off_t) offset),
>> __LONG_LONG_PAIR((off_t) (len >> 32),
>> (off_t) len));
>> +#else
>> + return (long)tst_syscall(__NR_fallocate, fd, mode,
>> + __LONG_LONG_PAIR((off_t) (offset >> 32),
>> + (off_t) offset),
>> + __LONG_LONG_PAIR((off_t) (len >> 32),
>> + (off_t) len));
>> +#endif /* __TEST_H__ */
>
> We can spare a bit of the duplication by definign the function name:
>
> ...
>
> #ifdef __TEST_H__
> # define TST_SYSCALL_WRAPPER ltp_syscall
> #else
> # define TST_SYSCALL_WRAPPER tst_syscall
> #endif
>
> ...
> return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode,
> __LONG_LONG_PAIR((off_t) (offset >> 32),
> (off_t) offset),
> __LONG_LONG_PAIR((off_t) (len >> 32),
> (off_t) len));
>
Oh, right, thanks a lot...
I will send a V2 soon.
Best Regards,
Guangwen Feng
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure when HAVE_FALLOCATE not defined
2017-03-30 9:49 ` Guangwen Feng
@ 2017-03-30 10:48 ` Guangwen Feng
2017-03-30 13:34 ` Jan Stancek
2017-03-30 14:04 ` Cyril Hrubis
0 siblings, 2 replies; 17+ messages in thread
From: Guangwen Feng @ 2017-03-30 10:48 UTC (permalink / raw)
To: ltp
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
include/lapi/fallocate.h | 11 +++++++++--
testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 4 ++--
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/lapi/fallocate.h b/include/lapi/fallocate.h
index 79d0b7b..aa32ff3 100644
--- a/include/lapi/fallocate.h
+++ b/include/lapi/fallocate.h
@@ -48,13 +48,20 @@
#endif
#if !defined(HAVE_FALLOCATE)
+
+#ifdef __TEST_H__
+# define TST_SYSCALL_WRAPPER ltp_syscall
+#else
+# define TST_SYSCALL_WRAPPER tst_syscall
+#endif /* __TEST_H__ */
+
static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
{
/* Deal with 32bit ABIs that have 64bit syscalls. */
# if LTP_USE_64_ABI
- return ltp_syscall(__NR_fallocate, fd, mode, offset, len);
+ return TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, offset, len);
# else
- return (long)ltp_syscall(__NR_fallocate, fd, mode,
+ return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode,
__LONG_LONG_PAIR((off_t) (offset >> 32),
(off_t) offset),
__LONG_LONG_PAIR((off_t) (len >> 32),
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
index 8612db7..ddf9f05 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
@@ -18,7 +18,6 @@
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/uio.h>
-#include <lapi/fallocate.h>
#include <lapi/fcntl.h>
#include <lapi/memfd.h>
#include <errno.h>
@@ -28,7 +27,8 @@
#include <unistd.h>
#define TST_NO_DEFAULT_MAIN
-#include <tst_test.h>
+#include "tst_test.h"
+#include "lapi/fallocate.h"
#include "linux_syscall_numbers.h"
--
1.8.4.2
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure when HAVE_FALLOCATE not defined
2017-03-30 10:48 ` [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure " Guangwen Feng
@ 2017-03-30 13:34 ` Jan Stancek
2017-03-30 14:04 ` Cyril Hrubis
1 sibling, 0 replies; 17+ messages in thread
From: Jan Stancek @ 2017-03-30 13:34 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
> ---
> include/lapi/fallocate.h | 11
> +++++++++--
> testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 4 ++--
> 2 files changed, 11 insertions(+), 4 deletions(-)
ACK, it builds now OK for me.
Regards,
Jan
^ permalink raw reply [flat|nested] 17+ messages in thread
* [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure when HAVE_FALLOCATE not defined
2017-03-30 10:48 ` [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure " Guangwen Feng
2017-03-30 13:34 ` Jan Stancek
@ 2017-03-30 14:04 ` Cyril Hrubis
1 sibling, 0 replies; 17+ messages in thread
From: Cyril Hrubis @ 2017-03-30 14:04 UTC (permalink / raw)
To: ltp
Hi!
Pushed with cosmetic changes and ack from Jan, thanks.
> diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
> index 8612db7..ddf9f05 100644
> --- a/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
> +++ b/testcases/kernel/syscalls/memfd_create/memfd_create_common.c
> @@ -18,7 +18,6 @@
> #include <sys/types.h>
> #include <sys/syscall.h>
> #include <sys/uio.h>
> -#include <lapi/fallocate.h>
> #include <lapi/fcntl.h>
> #include <lapi/memfd.h>
> #include <errno.h>
> @@ -28,7 +27,8 @@
> #include <unistd.h>
>
> #define TST_NO_DEFAULT_MAIN
> -#include <tst_test.h>
> +#include "tst_test.h"
> +#include "lapi/fallocate.h"
I've moved the rest of the lapi headers down here so they stay grouped
toghether.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2017-03-30 14:04 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-23 18:15 [LTP] [PATCH v5 0/6] Added memfd_create() testsuite Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 1/6] Added syscall numbers for memfd_create Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 2/6] Added memfd_create() lapi flags Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 3/6] Added fcntl() " Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 4/6] move fallocate.h to lapi Jakub Racek
2017-03-23 18:15 ` [LTP] [PATCH v5 5/6] syscalls: added memfd_create dir and memfd_create/memfd_create01.c Jakub Racek
2017-03-24 15:26 ` Cyril Hrubis
2017-03-24 15:42 ` Jakub =?unknown-8bit?q?Ra=C4=8Dek?=
2017-03-29 8:42 ` Jan Stancek
2017-03-29 9:18 ` Cyril Hrubis
2017-03-29 9:32 ` [LTP] [PATCH] syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined Guangwen Feng
2017-03-30 9:35 ` Cyril Hrubis
2017-03-30 9:49 ` Guangwen Feng
2017-03-30 10:48 ` [LTP] [PATCH v2] syscalls/memfd_create: Fix build failure " Guangwen Feng
2017-03-30 13:34 ` Jan Stancek
2017-03-30 14:04 ` Cyril Hrubis
2017-03-23 18:15 ` [LTP] [PATCH v5 6/6] syscalls/memfd_create02.c: added new test Jakub Racek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox