summaryrefslogtreecommitdiff
path: root/tests/fsopen.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2019-06-26 08:00:39 +0000
committerDmitry V. Levin <ldv@altlinux.org>2019-06-29 17:38:25 +0000
commit7ab2b642f8f5795afe90ac857fdc64192ec15b87 (patch)
treedeb59b0f3f1bb52ad54ba9df60ae8bdedf290801 /tests/fsopen.c
parent363c347676edc07826f6320e55950e253fa33554 (diff)
downloadstrace-7ab2b642f8f5795afe90ac857fdc64192ec15b87.tar.gz
Implement decoding of fsopen syscall
... introduced by Linux kernel commits v5.2-rc1~141^2~5, v5.2-rc1~20^2~1, and v5.2-rc1~20^2. * fsopen.c: New file. * Makefile.am (strace_SOURCES): Add it. * pathtrace.c (pathtrace_match_set): Add SEN_fsopen. * xlat/fsopen_flags.in: New file. * linux/syscallent-common.h [BASE_NR + 430]: Wire up fsopen. * NEWS: Mention this change. * tests/fsopen.c: New file. * tests/gen_tests.in (fsopen): New entry. * tests/pure_executables.list: Add fsopen. * tests/.gitignore: Likewise.
Diffstat (limited to 'tests/fsopen.c')
-rw-r--r--tests/fsopen.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/fsopen.c b/tests/fsopen.c
new file mode 100644
index 000000000..2b0baf741
--- /dev/null
+++ b/tests/fsopen.c
@@ -0,0 +1,68 @@
+/*
+ * Check decoding of fsopen syscall.
+ *
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <asm/unistd.h>
+#include "scno.h"
+
+#ifdef __NR_fsopen
+
+# include <stdio.h>
+# include <stdint.h>
+# include <unistd.h>
+
+static const char *errstr;
+
+static long
+k_fsopen(const void *name, const unsigned int flags)
+{
+ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
+ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
+ const kernel_ulong_t arg1 = (uintptr_t) name;
+ const kernel_ulong_t arg2 = fill | flags;
+ const long rc = syscall(__NR_fsopen, arg1, arg2, bad, bad, bad, bad);
+ errstr = sprintrc(rc);
+ return rc;
+}
+
+int
+main(void)
+{
+ char *const name1 = tail_alloc(DEFAULT_STRLEN + 2);
+ char *const name = name1 + 1;
+ const void *const efault = name + DEFAULT_STRLEN + 1;
+ const char *const empty = efault - 1;
+ fill_memory_ex(name1, DEFAULT_STRLEN + 1, '0', 10);
+ name1[DEFAULT_STRLEN + 1] = '\0';
+
+ k_fsopen(name, 0);
+ printf("fsopen(\"%s\", 0) = %s\n", name, errstr);
+
+ k_fsopen(name1, 1);
+ printf("fsopen(\"%.*s\"..., FSOPEN_CLOEXEC) = %s\n",
+ DEFAULT_STRLEN, name1, errstr);
+
+ k_fsopen(0, 2);
+ printf("fsopen(NULL, 0x2 /* FSOPEN_??? */) = %s\n", errstr);
+
+ k_fsopen(efault, 0xfffffffe);
+ printf("fsopen(%p, 0xfffffffe /* FSOPEN_??? */) = %s\n", efault, errstr);
+
+ k_fsopen(empty, -1);
+ printf("fsopen(\"\", FSOPEN_CLOEXEC|0xfffffffe) = %s\n", errstr);
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_fsopen")
+
+#endif