linux/tools/perf/trace/beauty/clone.c
<<
>>
Prefs
   1// SPDX-License-Identifier: LGPL-2.1
   2/*
   3 * trace/beauty/cone.c
   4 *
   5 *  Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
   6 */
   7
   8#include "trace/beauty/beauty.h"
   9#include <linux/kernel.h>
  10#include <sys/types.h>
  11#include <uapi/linux/sched.h>
  12
  13static size_t clone__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
  14{
  15        const char *prefix = "CLONE_";
  16        int printed = 0;
  17
  18#define P_FLAG(n) \
  19        if (flags & CLONE_##n) { \
  20                printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
  21                flags &= ~CLONE_##n; \
  22        }
  23
  24        P_FLAG(VM);
  25        P_FLAG(FS);
  26        P_FLAG(FILES);
  27        P_FLAG(SIGHAND);
  28        P_FLAG(PIDFD);
  29        P_FLAG(PTRACE);
  30        P_FLAG(VFORK);
  31        P_FLAG(PARENT);
  32        P_FLAG(THREAD);
  33        P_FLAG(NEWNS);
  34        P_FLAG(SYSVSEM);
  35        P_FLAG(SETTLS);
  36        P_FLAG(PARENT_SETTID);
  37        P_FLAG(CHILD_CLEARTID);
  38        P_FLAG(DETACHED);
  39        P_FLAG(UNTRACED);
  40        P_FLAG(CHILD_SETTID);
  41        P_FLAG(NEWCGROUP);
  42        P_FLAG(NEWUTS);
  43        P_FLAG(NEWIPC);
  44        P_FLAG(NEWUSER);
  45        P_FLAG(NEWPID);
  46        P_FLAG(NEWNET);
  47        P_FLAG(IO);
  48#undef P_FLAG
  49
  50        if (flags)
  51                printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
  52
  53        return printed;
  54}
  55
  56size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg)
  57{
  58        unsigned long flags = arg->val;
  59        enum syscall_clone_args {
  60                SCC_FLAGS         = (1 << 0),
  61                SCC_CHILD_STACK   = (1 << 1),
  62                SCC_PARENT_TIDPTR = (1 << 2),
  63                SCC_CHILD_TIDPTR  = (1 << 3),
  64                SCC_TLS           = (1 << 4),
  65        };
  66        if (!(flags & CLONE_PARENT_SETTID))
  67                arg->mask |= SCC_PARENT_TIDPTR;
  68
  69        if (!(flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)))
  70                arg->mask |= SCC_CHILD_TIDPTR;
  71
  72        if (!(flags & CLONE_SETTLS))
  73                arg->mask |= SCC_TLS;
  74
  75        return clone__scnprintf_flags(flags, bf, size, arg->show_string_prefix);
  76}
  77