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 13 static size_t clone__scnprintf_flags(unsigned long flags, char *bf, size_t size) 14 { 15 int printed = 0; 16 17 #define P_FLAG(n) \ 18 if (flags & CLONE_##n) { \ 19 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 20 flags &= ~CLONE_##n; \ 21 } 22 23 P_FLAG(VM); 24 P_FLAG(FS); 25 P_FLAG(FILES); 26 P_FLAG(SIGHAND); 27 P_FLAG(PTRACE); 28 P_FLAG(VFORK); 29 P_FLAG(PARENT); 30 P_FLAG(THREAD); 31 P_FLAG(NEWNS); 32 P_FLAG(SYSVSEM); 33 P_FLAG(SETTLS); 34 P_FLAG(PARENT_SETTID); 35 P_FLAG(CHILD_CLEARTID); 36 P_FLAG(DETACHED); 37 P_FLAG(UNTRACED); 38 P_FLAG(CHILD_SETTID); 39 P_FLAG(NEWCGROUP); 40 P_FLAG(NEWUTS); 41 P_FLAG(NEWIPC); 42 P_FLAG(NEWUSER); 43 P_FLAG(NEWPID); 44 P_FLAG(NEWNET); 45 P_FLAG(IO); 46 #undef P_FLAG 47 48 if (flags) 49 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 50 51 return printed; 52 } 53 54 size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg) 55 { 56 unsigned long flags = arg->val; 57 enum syscall_clone_args { 58 SCC_FLAGS = (1 << 0), 59 SCC_CHILD_STACK = (1 << 1), 60 SCC_PARENT_TIDPTR = (1 << 2), 61 SCC_CHILD_TIDPTR = (1 << 3), 62 SCC_TLS = (1 << 4), 63 }; 64 if (!(flags & CLONE_PARENT_SETTID)) 65 arg->mask |= SCC_PARENT_TIDPTR; 66 67 if (!(flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID))) 68 arg->mask |= SCC_CHILD_TIDPTR; 69 70 if (!(flags & CLONE_SETTLS)) 71 arg->mask |= SCC_TLS; 72 73 return clone__scnprintf_flags(flags, bf, size); 74 } 75