nlattr: introduce decode_nla_xval helper

* nlattr.c (decode_nla_xval): New function.
* nlattr.h: Include "xlat.h".
(struct decode_nla_xlat_opts): New type.
(DECL_NLA(xval)): New declaration.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
This commit is contained in:
Eugene Syromyatnikov 2018-05-07 08:40:02 +02:00 committed by Dmitry V. Levin
parent 4646db8e4d
commit 01f39a8001
2 changed files with 35 additions and 0 deletions

View File

@ -243,6 +243,30 @@ decode_nla_ifindex(struct tcb *const tcp,
return true;
}
bool
decode_nla_xval(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts * const opts = opaque_data;
union {
uint64_t val;
uint8_t bytes[sizeof(uint64_t)];
} data;
const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
data.val = 0;
if (len > sizeof(data))
return false;
else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
printxval_dispatch_ex(opts->xlat, opts->xlat_size, data.val,
opts->dflt, opts->xt, opts->style);
return true;
}
bool
decode_nla_be16(struct tcb *const tcp,
const kernel_ulong_t addr,

View File

@ -30,6 +30,16 @@
#ifndef STRACE_NLATTR_H
#define STRACE_NLATTR_H
#include "xlat.h"
struct decode_nla_xlat_opts {
const struct xlat *xlat;
size_t xlat_size; /* is not needed for XT_NORMAL */
const char *dflt;
enum xlat_type xt;
enum xlat_style style;
};
typedef bool (*nla_decoder_t)(struct tcb *, kernel_ulong_t addr,
unsigned int len, const void *opaque_data);
extern void
@ -58,6 +68,7 @@ DECL_NLA(s32);
DECL_NLA(s64);
DECL_NLA(be16);
DECL_NLA(be64);
DECL_NLA(xval);
DECL_NLA(str);
DECL_NLA(strn);
DECL_NLA(fd);