]> granicus.if.org Git - strace/commitdiff
alpha: enhance decoding of getxpid, getxuid, and getxgid syscalls
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 9 Jan 2016 00:06:06 +0000 (00:06 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 9 Jan 2016 00:09:04 +0000 (00:09 +0000)
Print the second return value of getxpid, getxuid, and getxgid syscalls
that return a pair of values using the same mechanism as pipe syscall.

* alpha.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* linux/alpha/syscallent.h [20]: Change SEN(getpid) to SEN(getxpid).
[24]: Change SEN(getuid) to SEN(getxuid).
[47]: Change SEN(getgid) to SEN(getxgid).
* NEWS: Mention this enhancement.
* tests/uid.awk: Update for getxgid output change.
* tests/uid.test: Cleanup.
* tests/getxxid.c: New file.
* tests/getxxid.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add getxxid.
(TESTS): Add getxxid.test.
* tests/.gitignore: Add getxxid.

Makefile.am
NEWS
alpha.c [new file with mode: 0644]
linux/alpha/syscallent.h
tests/.gitignore
tests/Makefile.am
tests/getxxid.c [new file with mode: 0644]
tests/getxxid.test [new file with mode: 0755]
tests/uid.awk
tests/uid.test

index d43608d904ae6ddd4e7f77f05b673fbf2ec74576..b107235f39f18e46ce2fb0aaeea4d99cc6a45a00 100644 (file)
@@ -64,6 +64,7 @@ strace_SOURCES =      \
        access.c        \
        affinity.c      \
        aio.c           \
+       alpha.c         \
        bjm.c           \
        block.c         \
        bpf.c           \
diff --git a/NEWS b/NEWS
index 731b4d47820331e97ec2d55a003917bad8c5267e..eefd0662fc146780fdf5fad9c56f6a0a609359b4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Noteworthy changes in release ?.?? (????-??-??)
 * Improvements
   * Enhanced decoding of personality, sched_getaffinity,
     and sched_setaffinity syscalls.
+  * Enhanced decoding of getxpid, getxuid, and getxgid syscalls on alpha.
 
 * Bug fixes
   * Fixed build on arc, metag, nios2, or1k, and tile architectures.
diff --git a/alpha.c b/alpha.c
new file mode 100644 (file)
index 0000000..e343b7e
--- /dev/null
+++ b/alpha.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * 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"
+
+#ifdef ALPHA
+
+static int
+decode_getxxid(struct tcb *tcp, const char *what)
+{
+       if (entering(tcp))
+               return 0;
+
+       long rval = getrval2(tcp);
+       if (rval == -1)
+               return 0;
+       static const char const fmt[] = "%s %ld";
+       static char outstr[sizeof(fmt) + 3 * sizeof(rval)];
+       snprintf(outstr, sizeof(outstr), fmt, what, rval);
+       tcp->auxstr = outstr;
+       return RVAL_STR;
+}
+
+SYS_FUNC(getxpid)
+{
+       return decode_getxxid(tcp, "ppid");
+}
+
+SYS_FUNC(getxuid)
+{
+       return decode_getxxid(tcp, "euid");
+}
+
+SYS_FUNC(getxgid)
+{
+       return decode_getxxid(tcp, "egid");
+}
+
+#endif /* ALPHA */
index 026c1cf7e2ca16954e162e8b0c5ce53f95900427..c622e618d763105ac8eb82094024390cff78ea3d 100644 (file)
 [ 17] = { 1,   TM|SI,          SEN(brk),                       "brk"                   },
 [ 18] = { 5,   0,              SEN(printargs),                 "osf_getfsstat"         }, /*not implemented */
 [ 19] = { 3,   TD,             SEN(lseek),                     "lseek"                 },
-[ 20] = { 0,   NF,             SEN(getpid),                    "getxpid"               },
+[ 20] = { 0,   NF,             SEN(getxpid),                   "getxpid"               },
 [ 21] = { 4,   0,              SEN(printargs),                 "osf_mount"             },
 [ 22] = { 2,   TF,             SEN(umount2),                   "umount"                },
 [ 23] = { 1,   0,              SEN(setuid),                    "setuid"                },
-[ 24] = { 0,   NF,             SEN(getuid),                    "getxuid"               },
+[ 24] = { 0,   NF,             SEN(getxuid),                   "getxuid"               },
 [ 25] = { 5,   0,              SEN(printargs),                 "exec_with_loader"      }, /*not implemented */
 [ 26] = { 4,   0,              SEN(ptrace),                    "ptrace"                },
 [ 27] = { 5,   0,              SEN(printargs),                 "osf_nrecvmsg"          }, /*not implemented */
@@ -73,7 +73,7 @@
 [ 44] = { 5,   0,              SEN(printargs),                 "osf_profil"            }, /*not implemented */
 [ 45] = { 3,   TD|TF,          SEN(open),                      "open"                  },
 [ 46] = { 5,   0,              SEN(printargs),                 "osf_old_sigaction"     }, /*not implemented */
-[ 47] = { 1,   NF,             SEN(getgid),                    "getxgid"               },
+[ 47] = { 1,   NF,             SEN(getxgid),                   "getxgid"               },
 [ 48] = { 2,   TS,             SEN(sigprocmask),               "osf_sigprocmask"       },
 [ 49] = { 5,   0,              SEN(printargs),                 "osf_getlogin"          }, /*not implemented */
 [ 50] = { 5,   0,              SEN(printargs),                 "osf_setlogin"          }, /*not implemented */
index cfe1e9fbbac05dc5aa82223473a88325d0c55724..6188bddd632f4683a44b45ec9c469203401b1c63 100644 (file)
@@ -30,6 +30,7 @@ ftruncate64
 getdents
 getdents64
 getrandom
+getxxid
 inet-accept-connect-send-recv
 inet-cmsg
 ioctl
index 33f76cbcc08f6c0701f96a4cd3b2ae8e5bf0f2ce..ab46af16024b0c5a9784ff15cb80371c03963cd8 100644 (file)
@@ -76,6 +76,7 @@ check_PROGRAMS = \
        getdents \
        getdents64 \
        getrandom \
+       getxxid \
        inet-accept-connect-send-recv \
        inet-cmsg \
        ioctl \
@@ -213,6 +214,7 @@ TESTS = \
        getdents.test \
        getdents64.test \
        getrandom.test \
+       getxxid.test \
        inet-cmsg.test \
        ioctl.test \
        ip_mreq.test \
diff --git a/tests/getxxid.c b/tests/getxxid.c
new file mode 100644 (file)
index 0000000..1f2076c
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * 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 "tests.h"
+#include <sys/syscall.h>
+
+#if defined __NR_getxpid && defined __NR_getxuid && defined __NR_getxgid
+
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+       long id;
+       pid_t ppid;
+
+       id = syscall(__NR_getxpid);
+       ppid = getppid();
+       printf("getxpid() = %ld (ppid %ld)\n", id, (long) ppid);
+       printf("getxpid() = %ld (ppid %ld)\n", id, (long) ppid);
+
+       id = syscall(__NR_getxuid);
+       printf("getxuid() = %ld (euid %ld)\n", id, id);
+
+       id = syscall(__NR_getxgid);
+       printf("getxgid() = %ld (egid %ld)\n", id, id);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_getxpid && __NR_getxuid && __NR_getxgid")
+
+#endif
diff --git a/tests/getxxid.test b/tests/getxxid.test
new file mode 100755 (executable)
index 0000000..d6a206a
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# Check getxpid, getxuid, and getxgid syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -a10 -egetxpid,getxuid,getxgid $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
+
+exit 0
index a56c5be8993dbe96427386bbc268aaef6e1dabd4..a5fdf1aaba62db95d50e325c250c7292c7c67f49 100644 (file)
@@ -27,7 +27,9 @@
 
 BEGIN {
   r_uint = "(0|[1-9][0-9]*)"
-  regexp = "^getx?uid" suffix "\\(\\)[[:space:]]+= " r_uint "$"
+  r_getuid = "getuid" suffix "\\(\\)[[:space:]]+= " r_uint
+  r_getxuid = "getxuid" suffix "\\(\\)[[:space:]]+= " r_uint " \\(euid " r_uint "\\)"
+  regexp = "^(" r_getuid "|" r_getxuid ")$"
   expected = "getuid"
   fail = 0
 }
@@ -40,7 +42,10 @@ regexp == "" {
 {
   if (match($0, regexp, a)) {
     if (expected == "getuid") {
-      uid = a[1]
+      if ("" != a[2])
+        uid = a[2]
+      else
+        uid = a[3]
       expected = "setuid"
       regexp = "^setuid" suffix "\\(" uid "\\)[[:space:]]+= 0$"
     } else if (expected == "setuid") {
index e214272d4670da5db4b9bec7889e5b3859ba1fee..9c5a97f8fbd225b790767185314b5d8236b948a3 100755 (executable)
@@ -9,17 +9,12 @@ w="${uid_t_size-}"
 
 run_prog ./uid$s$w
 
-syscalls=
-for n in "getuid$s" "getxuid$s"; do
-       if $STRACE -e "$n" -h > /dev/null; then
-               syscalls="$n"
-               break
-       fi
-done
-test -n "$syscalls" ||
-        fail_ "neither getuid$s nor getxuid$s is supported on this architecture"
-
-syscalls="$syscalls,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s"
+case "$STRACE_ARCH" in
+       alpha) getuid=getxuid ;;
+       *) getuid=getuid ;;
+esac
+
+syscalls="$getuid$s,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s"
 run_strace -e trace="$syscalls" $args
 
 AWK=gawk