xref: /openbmc/linux/tools/perf/trace/beauty/clone.c (revision 2359ccdd)
1 /*
2  * trace/beauty/cone.c
3  *
4  *  Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5  *
6  * Released under the GPL v2. (and only v2, not any later version)
7  */
8 
9 #include "trace/beauty/beauty.h"
10 #include <linux/kernel.h>
11 #include <sys/types.h>
12 #include <uapi/linux/sched.h>
13 
14 static size_t clone__scnprintf_flags(unsigned long flags, char *bf, size_t size)
15 {
16 	int printed = 0;
17 
18 #define	P_FLAG(n) \
19 	if (flags & CLONE_##n) { \
20 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #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(PTRACE);
29 	P_FLAG(VFORK);
30 	P_FLAG(PARENT);
31 	P_FLAG(THREAD);
32 	P_FLAG(NEWNS);
33 	P_FLAG(SYSVSEM);
34 	P_FLAG(SETTLS);
35 	P_FLAG(PARENT_SETTID);
36 	P_FLAG(CHILD_CLEARTID);
37 	P_FLAG(DETACHED);
38 	P_FLAG(UNTRACED);
39 	P_FLAG(CHILD_SETTID);
40 	P_FLAG(NEWCGROUP);
41 	P_FLAG(NEWUTS);
42 	P_FLAG(NEWIPC);
43 	P_FLAG(NEWUSER);
44 	P_FLAG(NEWPID);
45 	P_FLAG(NEWNET);
46 	P_FLAG(IO);
47 #undef P_FLAG
48 
49 	if (flags)
50 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
51 
52 	return printed;
53 }
54 
55 size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg)
56 {
57 	unsigned long flags = arg->val;
58 	enum syscall_clone_args {
59 		SCC_FLAGS	  = (1 << 0),
60 		SCC_CHILD_STACK	  = (1 << 1),
61 		SCC_PARENT_TIDPTR = (1 << 2),
62 		SCC_CHILD_TIDPTR  = (1 << 3),
63 		SCC_TLS		  = (1 << 4),
64 	};
65 	if (!(flags & CLONE_PARENT_SETTID))
66 		arg->mask |= SCC_PARENT_TIDPTR;
67 
68 	if (!(flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)))
69 		arg->mask |= SCC_CHILD_TIDPTR;
70 
71 	if (!(flags & CLONE_SETTLS))
72 		arg->mask |= SCC_TLS;
73 
74 	return clone__scnprintf_flags(flags, bf, size);
75 }
76