Decode the arguments passed to _umtx_op(). In particular, decode the

opcode.

MFC after:	1 week
Sponsored by:	Norse
This commit is contained in:
John Baldwin 2014-10-13 16:37:06 +00:00
parent 623b63e761
commit fdb5bf37fa
4 changed files with 103 additions and 2 deletions

View File

@ -57,6 +57,7 @@ extern int errno;
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysent.h>
#include <sys/umtx.h>
#include <sys/un.h>
#include <sys/queue.h>
#include <sys/wait.h>
@ -1268,6 +1269,26 @@ ktrsyscall(struct ktr_syscall *ktr, u_int flags)
ip++;
narg--;
break;
case SYS__umtx_op:
print_number(ip, narg, c);
putchar(',');
umtxopname(*ip);
switch (*ip) {
case UMTX_OP_CV_WAIT:
ip++;
narg--;
putchar(',');
umtxcvwaitflags(*ip);
break;
case UMTX_OP_RW_RDLOCK:
ip++;
narg--;
putchar(',');
umtxrwlockflags(*ip);
break;
}
ip++;
narg--;
}
}
while (narg > 0) {

View File

@ -185,6 +185,7 @@ cat <<_EOF_
#include <sys/ipc.h>
#include <sys/rtprio.h>
#include <sys/shm.h>
#include <sys/umtx.h>
#include <nfsserver/nfs.h>
#include <ufs/ufs/quota.h>
#include <sys/capsicum.h>
@ -489,6 +490,7 @@ auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+"
auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
auto_switch_type "umtxopname" "UMTX_OP_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/umtx.h"
auto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h"
auto_or_type "wait6optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
@ -677,6 +679,62 @@ cat <<_EOF_
}
}
/*
* AUTO - Special
*
* Just print 0 as 0.
*/
void
umtxcvwaitflags(intmax_t arg)
{
int or = 0;
if (arg == 0) {
printf("0");
return;
}
printf("%#jx<", (uintmax_t)arg);
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+CVWAIT_[A-Z_]+[[:space:]]+0x[0-9]+[[:space:]]*" \
$include_dir/sys/umtx.h | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
cat <<_EOF_
printf(">");
if (or == 0)
printf("<invalid>%jd", arg);
}
/*
* AUTO - Special
*
* Just print 0 as 0.
*/
void
umtxrwlockflags(intmax_t arg)
{
int or = 0;
if (arg == 0) {
printf("0");
return;
}
printf("%#jx<", (uintmax_t)arg);
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+URWLOCK_PREFER_READER[[:space:]]+0x[0-9]+[[:space:]]*" \
$include_dir/sys/umtx.h | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
cat <<_EOF_
printf(">");
if (or == 0)
printf("<invalid>%jd", arg);
}
_EOF_
egrep '#define[[:space:]]+CAP_[A-Z_]+[[:space:]]+CAPRIGHT\([0-9],[[:space:]]+0x[0-9]{16}ULL\)' \
$include_dir/sys/capsicum.h | \

View File

@ -5,6 +5,7 @@
* Hex -- values that should be printed in hex (addresses)
* Octal -- Same as above, but octal
* Int -- normal integer values (file descriptors, for example)
* LongHex -- long value that should be printed in hex
* Name -- pointer to a NULL-terminated string.
* BinString -- pointer to an array of chars, printed via strvisx().
* Ptr -- pointer to some unspecified structure. Just print as hex for now.
@ -34,13 +35,13 @@
* $FreeBSD$
*/
enum Argtype { None = 1, Hex, Octal, Int, Name, Ptr, Stat, Ioctl, Quad,
enum Argtype { None = 1, Hex, Octal, Int, LongHex, Name, Ptr, Stat, Ioctl, Quad,
Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval, Pollfd,
Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres,
Sigset, Sigprocmask, Kevent, Sockdomain, Socktype, Open,
Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2,
Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl,
LinuxSockArgs };
LinuxSockArgs, Umtxop };
#define ARG_MASK 0xff
#define OUT 0x100

View File

@ -279,6 +279,9 @@ static struct syscall syscalls[] = {
{ Waitoptions, 3 }, { Rusage | OUT, 4 }, { Ptr, 5 } } },
{ .name = "procctl", .ret_type = 1, .nargs = 4,
.args = { { Idtype, 0 }, { Int, 1 }, { Procctl, 2 }, { Ptr, 3 } } },
{ .name = "_umtx_op", .ret_type = 1, .nargs = 5,
.args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 },
{ Ptr, 4 } } },
{ .name = 0 },
};
@ -412,6 +415,18 @@ static struct xlat procctl_arg[] = {
X(PROC_SPROTECT) XEND
};
static struct xlat umtx_ops[] = {
X(UMTX_OP_RESERVED0) X(UMTX_OP_RESERVED1) X(UMTX_OP_WAIT)
X(UMTX_OP_WAKE) X(UMTX_OP_MUTEX_TRYLOCK) X(UMTX_OP_MUTEX_LOCK)
X(UMTX_OP_MUTEX_UNLOCK) X(UMTX_OP_SET_CEILING) X(UMTX_OP_CV_WAIT)
X(UMTX_OP_CV_SIGNAL) X(UMTX_OP_CV_BROADCAST) X(UMTX_OP_WAIT_UINT)
X(UMTX_OP_RW_RDLOCK) X(UMTX_OP_RW_WRLOCK) X(UMTX_OP_RW_UNLOCK)
X(UMTX_OP_WAIT_UINT_PRIVATE) X(UMTX_OP_WAKE_PRIVATE)
X(UMTX_OP_MUTEX_WAIT) X(UMTX_OP_MUTEX_WAKE) X(UMTX_OP_SEM_WAIT)
X(UMTX_OP_SEM_WAKE) X(UMTX_OP_NWAKE_PRIVATE) X(UMTX_OP_MUTEX_WAKE2)
XEND
};
#undef X
#undef XEND
@ -608,6 +623,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
case Int:
asprintf(&tmp, "%d", (int)args[sc->offset]);
break;
case LongHex:
asprintf(&tmp, "0x%lx", args[sc->offset]);
break;
case Name: {
/* NULL-terminated string. */
char *tmp2;
@ -1275,6 +1293,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
case Procctl:
tmp = strdup(xlookup(procctl_arg, args[sc->offset]));
break;
case Umtxop:
tmp = strdup(xlookup(umtx_ops, args[sc->offset]));
break;
default:
errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK);
}