From 98b7f7172177a01efad3fdd3b8997bd1d81bb9d8 Mon Sep 17 00:00:00 2001 From: Shankara Pailoor Date: Fri, 11 Jan 2019 20:59:00 -0800 Subject: [PATCH] Honor xlat styles when decoding ioprio_get and ioprio_set * ioprio.c (SYS_FUNC(ioprio_get), SYS_FUNC(ioprio_set)): Add xlat_style support. * tests/ioprio-Xabbrev.c: New file. * tests/ioprio-Xraw.c: Likewise. * tests/ioprio-Xverbose.c: Likewise. * tests/ioprio.c: Handle XLAT_RAW, XLAT_ABBREV, and XLAT_VERBOSE macros. * tests/gen_tests.in (ioprio-Xabbrev, ioprio-Xraw, ioprio-Xverbose): New tests. * tests/pure_executables.list: Add ioprio-Xabbrev, ioprio-Xraw, and ioprio-Xverbose. * tests/.gitignore: Likewise. Co-Authored-by: Dmitry V. Levin --- ioprio.c | 15 ++++++-- tests/.gitignore | 3 ++ tests/gen_tests.in | 3 ++ tests/ioprio-Xabbrev.c | 1 + tests/ioprio-Xraw.c | 2 + tests/ioprio-Xverbose.c | 2 + tests/ioprio.c | 74 ++++++++++++++++++++++++++++--------- tests/pure_executables.list | 3 ++ 8 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 tests/ioprio-Xabbrev.c create mode 100644 tests/ioprio-Xraw.c create mode 100644 tests/ioprio-Xverbose.c diff --git a/ioprio.c b/ioprio.c index 2d7c4f6a..5a5c469a 100644 --- a/ioprio.c +++ b/ioprio.c @@ -45,8 +45,10 @@ SYS_FUNC(ioprio_get) } else { if (syserror(tcp)) return 0; - - tcp->auxstr = sprint_ioprio(tcp->u_rval); + if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW) + tcp->auxstr = NULL; + else + tcp->auxstr = sprint_ioprio(tcp->u_rval); return RVAL_STR; } } @@ -58,7 +60,14 @@ SYS_FUNC(ioprio_set) /* int who */ tprintf(", %d, ", (int) tcp->u_arg[1]); /* int ioprio */ - tprints(sprint_ioprio(tcp->u_arg[2])); + if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV) + tprintf("%d", (int) tcp->u_arg[2]); + + if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW) + return RVAL_DECODED; + + (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE + ? tprints_comment : tprints)(sprint_ioprio(tcp->u_arg[2])); return RVAL_DECODED; } diff --git a/tests/.gitignore b/tests/.gitignore index aecdf432..781e50a2 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -176,6 +176,9 @@ ioctl_v4l2 ioperm iopl ioprio +ioprio-Xabbrev +ioprio-Xraw +ioprio-Xverbose ip_mreq ipc ipc_msg diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 3b35a67b..128f4ca8 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -147,6 +147,9 @@ ioctl_v4l2 +ioctl.test ioperm -a27 iopl -a8 ioprio -a18 -e trace=ioprio_get,ioprio_set +ioprio-Xabbrev -a18 -e trace=ioprio_get,ioprio_set -Xabbrev +ioprio-Xraw -a18 -e trace=ioprio_get,ioprio_set -Xraw +ioprio-Xverbose -a18 -e trace=ioprio_get,ioprio_set -Xverbose ip_mreq -e trace=setsockopt ipc -a19 ipc_msg +ipc.sh -a26 diff --git a/tests/ioprio-Xabbrev.c b/tests/ioprio-Xabbrev.c new file mode 100644 index 00000000..01a07f48 --- /dev/null +++ b/tests/ioprio-Xabbrev.c @@ -0,0 +1 @@ +#include "ioprio.c" diff --git a/tests/ioprio-Xraw.c b/tests/ioprio-Xraw.c new file mode 100644 index 00000000..6a815069 --- /dev/null +++ b/tests/ioprio-Xraw.c @@ -0,0 +1,2 @@ +#define XLAT_RAW 1 +#include "ioprio.c" diff --git a/tests/ioprio-Xverbose.c b/tests/ioprio-Xverbose.c new file mode 100644 index 00000000..3c12bb6c --- /dev/null +++ b/tests/ioprio-Xverbose.c @@ -0,0 +1,2 @@ +#define XLAT_VERBOSE 1 +#include "ioprio.c" diff --git a/tests/ioprio.c b/tests/ioprio.c index 5c52b3db..6c54ad65 100644 --- a/tests/ioprio.c +++ b/tests/ioprio.c @@ -27,14 +27,6 @@ enum { # include "xlat.h" # include "xlat/ioprio_class.h" -void -print_ioprio(unsigned long val) -{ - printf(" (IOPRIO_PRIO_VALUE("); - printxval(ioprio_class, val >> 13, "IOPRIO_CLASS_???"); - printf(", %d))", (int) (val & 0x1fff)); -} - int main(void) { @@ -44,32 +36,78 @@ main(void) (kernel_ulong_t) 0xbadc0dedda7a1057ULL; static const kernel_ulong_t bogus_ioprio = (kernel_ulong_t) 0xdec0ded1facefeedULL; +# if !XLAT_RAW static const char * const bogus_ioprio_str = "IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)"; +# endif long rc; + const char *errstr; rc = syscall(__NR_ioprio_get, bogus_which, bogus_who); + errstr = sprintrc(rc); +# if XLAT_RAW + printf("ioprio_get(%#x, %d) = %s\n", + (int) bogus_which, (int) bogus_who, errstr); +# else /* XLAT_ABBREV || XLAT_VERBOSE */ printf("ioprio_get(%#x /* IOPRIO_WHO_??? */, %d) = %s\n", - (int) bogus_which, (int) bogus_who, sprintrc(rc)); + (int) bogus_which, (int) bogus_who, errstr); +# endif rc = syscall(__NR_ioprio_get, 1, 0); - printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", sprintrc(rc)); - - if (rc >= -1) - print_ioprio(rc); - + errstr = sprintrc(rc); +# if XLAT_RAW + printf("ioprio_get(0x1, 0) = %s\n", errstr); +# elif XLAT_VERBOSE + printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s", errstr); + if (rc >= 0) { + printf(" (IOPRIO_PRIO_VALUE(%u /* ", (unsigned int) rc >> 13); + printxval(ioprio_class, (unsigned int) rc >> 13, + "IOPRIO_CLASS_???"); + printf(" */, %u))", (unsigned int) rc & 0x1fff); + } + puts(""); +# else /* XLAT_ABBREV */ + printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", errstr); + if (rc >= 0) { + printf(" (IOPRIO_PRIO_VALUE("); + printxval(ioprio_class, (unsigned int) rc >> 13, + "IOPRIO_CLASS_???"); + printf(", %u))", (unsigned int) rc & 0x1fff); + } puts(""); +# endif rc = syscall(__NR_ioprio_set, 2, 0, 8191); - printf("ioprio_set(IOPRIO_WHO_PGRP, 0, " - "IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n", - sprintrc(rc)); + errstr = sprintrc(rc); +# if XLAT_RAW + printf("ioprio_set(%#x, 0, 8191) = %s\n", 2, errstr); +# elif XLAT_VERBOSE + printf("ioprio_set(%#x /* IOPRIO_WHO_PGRP */, 0, 8191" + " /* IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 8191) */)" + " = %s\n", + 2, errstr); +# else /* XLAT_ABBREV */ + printf("ioprio_set(IOPRIO_WHO_PGRP, 0" + ", IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n", + errstr); +# endif rc = syscall(__NR_ioprio_set, bogus_which, bogus_who, bogus_ioprio); + errstr = sprintrc(rc); +# if XLAT_RAW + printf("ioprio_set(%#x, %d, %d) = %s\n", + (int) bogus_which, (int) bogus_who, (int) bogus_ioprio, + errstr); +# elif XLAT_VERBOSE + printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %d /* %s */) = %s\n", + (int) bogus_which, (int) bogus_who, (int) bogus_ioprio, + bogus_ioprio_str, errstr); +# else /* XLAT_ABBREV */ printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %s) = %s\n", (int) bogus_which, (int) bogus_who, bogus_ioprio_str, - sprintrc(rc)); + errstr); +# endif puts("+++ exited with 0 +++"); diff --git a/tests/pure_executables.list b/tests/pure_executables.list index af99bda6..edb0be93 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -144,6 +144,9 @@ ioctl_v4l2 ioperm iopl ioprio +ioprio-Xabbrev +ioprio-Xraw +ioprio-Xverbose ip_mreq ipc ipc_msg -- 2.40.0