alpha: enhance decoding of getxpid, getxuid, and getxgid syscalls

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.
This commit is contained in:
Дмитрий Левин 2016-01-09 00:06:06 +00:00
parent b61b2d820f
commit 2720a61832
10 changed files with 157 additions and 15 deletions

View File

@ -64,6 +64,7 @@ strace_SOURCES = \
access.c \
affinity.c \
aio.c \
alpha.c \
bjm.c \
block.c \
bpf.c \

1
NEWS
View File

@ -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.

63
alpha.c Normal file
View File

@ -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 */

View File

@ -46,11 +46,11 @@
[ 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 */

1
tests/.gitignore vendored
View File

@ -30,6 +30,7 @@ ftruncate64
getdents
getdents64
getrandom
getxxid
inet-accept-connect-send-recv
inet-cmsg
ioctl

View 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 \

61
tests/getxxid.c Normal file
View File

@ -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

13
tests/getxxid.test Executable file
View File

@ -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

View 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") {

View File

@ -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"
case "$STRACE_ARCH" in
alpha) getuid=getxuid ;;
*) getuid=getuid ;;
esac
syscalls="$syscalls,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s"
syscalls="$getuid$s,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s"
run_strace -e trace="$syscalls" $args
AWK=gawk