[PATCH v2] Implement decoding of ustat syscall
Dmitry V. Levin
ldv at altlinux.org
Fri Jan 6 15:31:11 UTC 2017
On Fri, Jan 06, 2017 at 10:27:05PM +0800, JingPiao Chen wrote:
[...]
> +#include "defs.h"
> +#include DEF_MPERS_TYPE(struct_ustat)
> +#include <ustat.h>
> +typedef struct ustat struct_ustat;
> +#include MPERS_DEFS
This is correct.
> +
> +SYS_FUNC(ustat)
> +{
> + struct_ustat ust;
> +
> + if (entering(tcp))
> + print_dev_t(tcp->u_arg[0]);
This is not quite correct, because, as you can see
$ git grep sys_ustat include/linux/
include/linux/compat.h:asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
include/linux/syscalls.h:asmlinkage long sys_ustat(unsigned dev, struct ustat __user *ubuf);
the type of 1st argument is unsigned int.
An explicit cast to (unsigned int) is needed.
> + else {
> + tprints(", ");
> + if (!umove_or_printaddr(tcp, tcp->u_arg[1], &ust))
> + tprintf("{f_tfree=%llu, f_tinode=%llu}",
> + zero_extend_signed_to_ull(ust.f_tfree),
> + zero_extend_signed_to_ull(ust.f_tinode));
Please indent properly.
[...]
> +#include "tests.h"
> +#include <asm/unistd.h>
> +
> +#ifdef __NR_ustat
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <ustat.h>
> +
> +int
> +main(void)
> +{
> + struct ustat ust;
Use tail_alloc to allocate memory for the object at the end of mapped
segment.
> +
> + long rc = syscall(__NR_ustat, -1, 0);
What is -1 here? Is it int or long? Is it going to be sign-extended
or not? Please be specific when invoking syscall().
I suggest replacing -1 with a magic of type kernel_ulong_t, e.g.
kernel_ulong_t magic = (kernel_ulong_t) 0xfacefeedffffffff;
> + printf("ustat(makedev(%u, %u), NULL) = %s\n", major((unsigned int) -1),
> + minor((unsigned int) -1), sprintrc(rc));
There is a shorter way to write this, e.g. -1U.
> + rc = syscall(__NR_ustat, -1, &ust);
> + printf("ustat(makedev(%u, %u), %p) = %s\n", major((unsigned int) -1),
> + minor((unsigned int) -1), &ust, sprintrc(rc));
Please test the case when ustat succeeds. For example, find out a real
device number and feed it to ustat. If this device number doesn't
overflow unsigned int, the syscall is likely to succeed.
--
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/20170106/9dbd989a/attachment.bin>
More information about the Strace-devel
mailing list