I would like to implement the parser for statx. Here is my current
attempt (no tests yet).
I've spotted the tests/statx.sh script. Unfortunately, due to that
tests/init.sh expects the caller name to end with ".test", it just
endlessly runs itself. What is it supposed to do?
Also, how do I get syscall numbers for all the platforms?

On 03/07/2017 01:10 AM, Dmitry V. Levin wrote:
Hi Victor, > > On Sun, Mar 05, 2017 at 06:31:31PM +0300, Victor Krapivensky
wrote: >> Hi everybody! My name is Victor Krapivensky and I am a first-year >> student at MIPT. >> >> I want to implement Lua-scriptable advanced syscall tampering for >> strace. >> >> I am quite fluent in C, have an interest in system programming and >> debugging, and have good understanding of how Lua C API works. >> >> I have previously contributed to i3 and mpv (see GitHub pull >> requests by author), and am currently developing my own project, >> luastatus [1]. >> >> [1] https://github.com/shdown/luastatus > > Thanks for showing interest in strace GSoC projects. > > As you have probably noticed in our ideas page at > https://sourceforge.net/p/strace/wiki/GoogleSummerOfCode2017/ it is > required that students who want to apply to the strace project for > the GSoC 2017 complete a relatively small code-related "microproject" > as part of their application. > > You can refer to our guidelines and suggestions for microprojects at > https://sourceforge.net/p/strace/wiki/Microprojects/ > > Please do not hesitate to ask questions as soon as you've got them.
>From 3dcb53903227d0d955ee62bcd6a19e2556c9e73d Mon Sep 17 00:00:00 2001
From: Victor Krapivensky <krapivenskiy...@phystech.edu>
Date: Thu, 9 Mar 2017 20:26:14 +0300
Subject: [PATCH v1] Add support for statx syscall

---
 Makefile.am               |   1 +
 linux/32/syscallent.h     |   1 +
 linux/x32/syscallent.h    |   3 +-
 linux/x86_64/syscallent.h |   1 +
 statx.c                   | 148 ++++++++++++++++++++++++++++++++++++++++++++++
 xlat/at_flags.in          |   2 +
 xlat/statx_attrs.in       |   6 ++
 xlat/statx_mask.in        |  12 ++++
 8 files changed, 173 insertions(+), 1 deletion(-)
 create mode 100644 statx.c
 create mode 100644 xlat/statx_attrs.in
 create mode 100644 xlat/statx_mask.in

diff --git a/Makefile.am b/Makefile.am
index 7e837b3..e350fd2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -232,6 +232,7 @@ strace_SOURCES =	\
 	stat64.c	\
 	statfs.c	\
 	statfs.h	\
+	statx.c		\
 	strace.c	\
 	swapon.c	\
 	syscall.c	\
diff --git a/linux/32/syscallent.h b/linux/32/syscallent.h
index a8f9510..3d79d2c 100644
--- a/linux/32/syscallent.h
+++ b/linux/32/syscallent.h
@@ -281,6 +281,7 @@
 [288] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [289] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [290] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
+[383] = { 5,	TD|TF,	SEN(statx),				"statx"			},
 
 #undef sys_ARCH_mmap
 #undef ARCH_WANT_SYNC_FILE_RANGE2
diff --git a/linux/x32/syscallent.h b/linux/x32/syscallent.h
index 2699bc0..c7d44c1 100644
--- a/linux/x32/syscallent.h
+++ b/linux/x32/syscallent.h
@@ -330,7 +330,8 @@
 [329] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [330] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [331] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
-[332 ... 511] = { },
+[332] = { 5,	TD|TF,	SEN(statx),				"statx"	},
+[333 ... 511] = { },
 /*
  * x32-specific system call numbers start at 512 to avoid cache impact
  * for native 64-bit operation.
diff --git a/linux/x86_64/syscallent.h b/linux/x86_64/syscallent.h
index a1a268e..de3a88a 100644
--- a/linux/x86_64/syscallent.h
+++ b/linux/x86_64/syscallent.h
@@ -330,3 +330,4 @@
 [329] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [330] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [331] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
+[332] = { 5,	TD|TF,	SEN(statx),			"statx"		},
diff --git a/statx.c b/statx.c
new file mode 100644
index 0000000..ff4e0bd
--- /dev/null
+++ b/statx.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2017 Victor Krapivensky <krapivenskiy...@phystech.edu>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+
+#include <sys/stat.h>
+
+#include "xlat/statx_mask.h"
+#include "xlat/statx_attrs.h"
+
+struct statx_timestamp {
+	int64_t sec;
+	int32_t nsec;
+	int32_t reserved;
+};
+
+struct statx {
+	uint32_t stx_mask; /* What results were written [uncond] */
+	uint32_t stx_blksize; /* Preferred general I/O size [uncond] */
+	uint64_t stx_attributes; /* Flags conveying information about the file
+	                            [uncond] */
+
+	uint32_t stx_nlink; /* Number of hard links */
+	uint32_t stx_uid; /* User ID of owner */
+	uint32_t stx_gid; /* Group ID of owner */
+	uint16_t stx_mode; /* File mode */
+	uint16_t intpa_tre0[1];
+
+	uint64_t stx_ino; /* Inode number */
+	uint64_t stx_size; /* File size */
+	uint64_t stx_blocks; /* Number of 512-byte blocks allocated */
+	uint64_t intpa_tre1[1];
+
+	struct statx_timestamp stx_atime; /* Last access time */
+	struct statx_timestamp stx_btime; /* File creation time */
+	struct statx_timestamp stx_ctime; /* Last attribute change time */
+	struct statx_timestamp stx_mtime; /* Last data modification time */
+
+	uint32_t stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
+	uint32_t stx_rdev_minor;
+	uint32_t stx_dev_major; /* ID of device containing file [uncond] */
+	uint32_t stx_dev_minor;
+
+	uint64_t intpa_tre2[16]; /* Spare space for future expansion */
+};
+
+SYS_FUNC(statx)
+{
+	if (entering(tcp)) {
+		print_dirfd(tcp, tcp->u_arg[0]);
+		printpath(tcp, tcp->u_arg[1]);
+		tprints(", ");
+		printflags(at_flags, tcp->u_arg[2], "AT_???");
+		tprints(", ");
+		printflags(statx_mask, tcp->u_arg[3], "STATX_???");
+		tprints(", ");
+	} else {
+#define PRINT_FIELD(field) \
+	tprintf(", %s=%llu", #field, (unsigned long long) stx.field)
+
+#define PRINT_FIELD_IF_SET(bit, field) \
+	if (stx.stx_mask & bit) PRINT_FIELD(field)
+
+#define ABS(x) ((x) < 0 ? -(x) : (x))
+
+#define PRINT_FIELD_TIME(field)						\
+	do {								\
+		tprints(", " #field "=");				\
+		tprints(sprinttime(stx.field.sec));			\
+		tprintf(".%09lld", (long long) ABS(stx.field.nsec));	\
+	} while (0)
+
+#define PRINT_FIELD_TIME_IF_SET(bit, field_prefix) \
+	if (stx.stx_mask & bit) PRINT_FIELD_TIME(field_prefix)
+
+		struct statx stx;
+		if (umove_or_printaddr(tcp, tcp->u_arg[4], &stx)) {
+			return 0;
+		}
+		tprints("{stx_mask=");
+		printflags(statx_mask, stx.stx_mask, "STATX_???");
+		if (!abbrev(tcp)) {
+			PRINT_FIELD(stx_blksize);
+		}
+		tprints(", stx_attributes=");
+		printflags(statx_attrs, stx.stx_attributes, "STATX_ATTR_???");
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_IF_SET(STATX_NLINK, stx_nlink);
+			PRINT_FIELD_IF_SET(STATX_UID, stx_uid);
+			PRINT_FIELD_IF_SET(STATX_GID, stx_gid);
+		}
+		if (stx.stx_mask & (STATX_MODE | STATX_TYPE)) {
+			tprints(", stx_mode=");
+			print_symbolic_mode_t(stx.stx_mode);
+		}
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_IF_SET(STATX_INO, stx_ino);
+		}
+		PRINT_FIELD_IF_SET(STATX_SIZE, stx_size);
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_IF_SET(STATX_BLOCKS, stx_blocks);
+			PRINT_FIELD_TIME_IF_SET(STATX_ATIME, stx_atime);
+			PRINT_FIELD_TIME_IF_SET(STATX_BTIME, stx_btime);
+			PRINT_FIELD_TIME_IF_SET(STATX_CTIME, stx_ctime);
+			PRINT_FIELD_TIME_IF_SET(STATX_MTIME, stx_mtime);
+		}
+		if (stx.stx_mask & STATX_TYPE) {
+			switch (stx.stx_mask & S_IFMT) {
+			case S_IFCHR: case S_IFBLK:
+				PRINT_FIELD(stx_rdev_major);
+				PRINT_FIELD(stx_rdev_minor);
+				break;
+			}
+		}
+		if (!abbrev(tcp)) {
+			PRINT_FIELD(stx_dev_major);
+			PRINT_FIELD(stx_dev_minor);
+		} else {
+			tprints(", ...");
+		}
+		tprints("}");
+	}
+	return 0;
+}
diff --git a/xlat/at_flags.in b/xlat/at_flags.in
index 77a8de9..9f0f264 100644
--- a/xlat/at_flags.in
+++ b/xlat/at_flags.in
@@ -3,3 +3,5 @@ AT_REMOVEDIR		0x200
 AT_SYMLINK_FOLLOW	0x400
 AT_NO_AUTOMOUNT		0x800
 AT_EMPTY_PATH		0x1000
+AT_STATX_FORCE_SYNC	0x2000
+AT_STATX_DONT_SYNC	0x4000
diff --git a/xlat/statx_attrs.in b/xlat/statx_attrs.in
new file mode 100644
index 0000000..f6e4078
--- /dev/null
+++ b/xlat/statx_attrs.in
@@ -0,0 +1,6 @@
+STATX_ATTR_COMPRESSED	0x00000004
+STATX_ATTR_IMMUTABLE	0x00000010
+STATX_ATTR_APPEND	0x00000020
+STATX_ATTR_NODUMP	0x00000040
+STATX_ATTR_ENCRYPTED	0x00000800
+STATX_ATTR_AUTOMOUNT	0x00001000
diff --git a/xlat/statx_mask.in b/xlat/statx_mask.in
new file mode 100644
index 0000000..0986bce
--- /dev/null
+++ b/xlat/statx_mask.in
@@ -0,0 +1,12 @@
+STATX_TYPE	0x00000001U
+STATX_MODE	0x00000002U
+STATX_NLINK	0x00000004U
+STATX_UID	0x00000008U
+STATX_GID	0x00000010U
+STATX_ATIME	0x00000020U
+STATX_MTIME	0x00000040U
+STATX_CTIME	0x00000080U
+STATX_INO	0x00000100U
+STATX_SIZE	0x00000200U
+STATX_BLOCKS	0x00000400U
+STATX_BTIME	0x00000800U
-- 
2.10.2

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to