]> granicus.if.org Git - strace/commitdiff
nlattr: introduce decode_nla_flags
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 7 May 2018 06:40:02 +0000 (08:40 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 6 Jun 2018 15:10:37 +0000 (15:10 +0000)
Similar to decode_nla_xval.

* nlattr.c (decode_nla_flags): New function.
* nlattr.h: (DECL_NLA(flags)): New declaration.

nlattr.c
nlattr.h

index f65d9cf6a6288f245aefff97f6512cd322b2d552..835cf25e5f07f7687d1c9cfa46a1f370caf56f73 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -295,6 +295,32 @@ decode_nla_ip_proto(struct tcb *const tcp,
        return decode_nla_xval(tcp, addr, len, &opts);
 }
 
+bool
+decode_nla_flags(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 flags;
+               uint8_t  bytes[sizeof(uint64_t)];
+       } data = { .flags = 0 };
+       const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
+
+       if (opts->xt == XT_INDEXED)
+               error_func_msg("indexed xlats are currently incompatible with "
+                              "printflags");
+
+       if (len > sizeof(data))
+               return false;
+       else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
+               printflags_ex(data.flags, opts->dflt, opts->style, opts->xlat,
+                             NULL);
+
+       return true;
+}
+
 bool
 decode_nla_be16(struct tcb *const tcp,
                const kernel_ulong_t addr,
index 765aba82389f81aa92287dc7f36e874501b7d4c1..fc7a67d9261c2b239c0a54a704b2f35ce4759de7 100644 (file)
--- a/nlattr.h
+++ b/nlattr.h
@@ -75,6 +75,7 @@ DECL_NLA(s64);
 DECL_NLA(be16);
 DECL_NLA(be64);
 DECL_NLA(xval);
+DECL_NLA(flags);
 DECL_NLA(str);
 DECL_NLA(strn);
 DECL_NLA(fd);