[PATCH v5] Implement decoding of ustat syscall

Dmitry V. Levin ldv at altlinux.org
Wed Jan 11 23:31:06 UTC 2017


On Wed, Jan 11, 2017 at 11:52:21PM +0800, JingPiao Chen wrote:
[...]
> +#include "tests.h"
> +#include <asm/unistd.h>
> +
> +#ifdef __NR_ustat
> +
> +# include <stdio.h>
> +# include <sys/stat.h>
> +# include <sys/sysmacros.h>
> +# include <unistd.h>
> +# include <ustat.h>
> +
> +int
> +main(void)
> +{
> +	kernel_ulong_t magic = (kernel_ulong_t) 0xfacefeedffffffff;
> +	unsigned int dev = (unsigned int) magic;
> +	struct ustat *ust = tail_alloc(sizeof(*ust));
> +	struct stat st;
> +
> +	long rc = syscall(__NR_ustat, magic, 0);
> +	printf("ustat(makedev(%u, %u), NULL) = %s\n",
> +	       major(dev), minor(dev), sprintrc(rc));
> +
> +	rc = syscall(__NR_ustat, magic, ust);
> +	printf("ustat(makedev(%u, %u), %p) = %s\n",
> +	       major(dev), minor(dev), ust, sprintrc(rc));
> +
> +	if (stat("/", &st) == -1)
> +		perror_msg_and_fail("stat");

My personal preference is to use "." instead of "/", but I do not insist.

> +	dev = (unsigned int) st.st_dev;
> +	rc = syscall(__NR_ustat, dev, ust);
> +	if (rc == -1)
> +		printf("ustat(makedev(%u, %u), %p) = %s\n",
> +		       major(dev), minor(dev), ust, sprintrc(rc));
> +	else
> +		printf("ustat(makedev(%u, %u), {f_tfree=%llu, f_tinode=%llu}) = %s\n",

This line is slightly longer than 80 symbols, please wrap it.

> +		       major(dev), minor(dev), (unsigned long long) ust->f_tfree,
> +		       (unsigned long long) ust->f_tinode, sprintrc(rc));

As you probably remember, f_tfree and f_tinode fields are signed but
kernel treats them as unsigned, so they can easily contain "negative" values
and your sign extending casts would result to wrong values.

Just use zero_extend_signed_to_ull instead.

> +
> +	puts("+++ exited with 0 +++");
> +	return 0;
> +}
> +
> +#else
> +
> +SKIP_MAIN_UNDEFINED("__NR_ustat")
> +
> +#endif
> diff --git a/tests/ustat.test b/tests/ustat.test
> new file mode 100755
> index 0000000..ff49e3c
> --- /dev/null
> +++ b/tests/ustat.test
> @@ -0,0 +1,6 @@
> +#!/bin/sh
> +
> +# Check ustat syscall decoding.
> +
> +. "${srcdir=.}/init.sh"
> +run_strace_match_diff -a26

I think you can safely increase this to 36.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170112/f936df7f/attachment.bin>


More information about the Strace-devel mailing list