18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * trace/beauty/cone.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "trace/beauty/beauty.h" 98c2ecf20Sopenharmony_ci#include <linux/kernel.h> 108c2ecf20Sopenharmony_ci#include <sys/types.h> 118c2ecf20Sopenharmony_ci#include <uapi/linux/sched.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic size_t clone__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci const char *prefix = "CLONE_"; 168c2ecf20Sopenharmony_ci int printed = 0; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define P_FLAG(n) \ 198c2ecf20Sopenharmony_ci if (flags & CLONE_##n) { \ 208c2ecf20Sopenharmony_ci printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ 218c2ecf20Sopenharmony_ci flags &= ~CLONE_##n; \ 228c2ecf20Sopenharmony_ci } 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci P_FLAG(VM); 258c2ecf20Sopenharmony_ci P_FLAG(FS); 268c2ecf20Sopenharmony_ci P_FLAG(FILES); 278c2ecf20Sopenharmony_ci P_FLAG(SIGHAND); 288c2ecf20Sopenharmony_ci P_FLAG(PIDFD); 298c2ecf20Sopenharmony_ci P_FLAG(PTRACE); 308c2ecf20Sopenharmony_ci P_FLAG(VFORK); 318c2ecf20Sopenharmony_ci P_FLAG(PARENT); 328c2ecf20Sopenharmony_ci P_FLAG(THREAD); 338c2ecf20Sopenharmony_ci P_FLAG(NEWNS); 348c2ecf20Sopenharmony_ci P_FLAG(SYSVSEM); 358c2ecf20Sopenharmony_ci P_FLAG(SETTLS); 368c2ecf20Sopenharmony_ci P_FLAG(PARENT_SETTID); 378c2ecf20Sopenharmony_ci P_FLAG(CHILD_CLEARTID); 388c2ecf20Sopenharmony_ci P_FLAG(DETACHED); 398c2ecf20Sopenharmony_ci P_FLAG(UNTRACED); 408c2ecf20Sopenharmony_ci P_FLAG(CHILD_SETTID); 418c2ecf20Sopenharmony_ci P_FLAG(NEWCGROUP); 428c2ecf20Sopenharmony_ci P_FLAG(NEWUTS); 438c2ecf20Sopenharmony_ci P_FLAG(NEWIPC); 448c2ecf20Sopenharmony_ci P_FLAG(NEWUSER); 458c2ecf20Sopenharmony_ci P_FLAG(NEWPID); 468c2ecf20Sopenharmony_ci P_FLAG(NEWNET); 478c2ecf20Sopenharmony_ci P_FLAG(IO); 488c2ecf20Sopenharmony_ci P_FLAG(CLEAR_SIGHAND); 498c2ecf20Sopenharmony_ci P_FLAG(INTO_CGROUP); 508c2ecf20Sopenharmony_ci#undef P_FLAG 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci if (flags) 538c2ecf20Sopenharmony_ci printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci return printed; 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cisize_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci unsigned long flags = arg->val; 618c2ecf20Sopenharmony_ci enum syscall_clone_args { 628c2ecf20Sopenharmony_ci SCC_FLAGS = (1 << 0), 638c2ecf20Sopenharmony_ci SCC_CHILD_STACK = (1 << 1), 648c2ecf20Sopenharmony_ci SCC_PARENT_TIDPTR = (1 << 2), 658c2ecf20Sopenharmony_ci SCC_CHILD_TIDPTR = (1 << 3), 668c2ecf20Sopenharmony_ci SCC_TLS = (1 << 4), 678c2ecf20Sopenharmony_ci }; 688c2ecf20Sopenharmony_ci if (!(flags & CLONE_PARENT_SETTID)) 698c2ecf20Sopenharmony_ci arg->mask |= SCC_PARENT_TIDPTR; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci if (!(flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID))) 728c2ecf20Sopenharmony_ci arg->mask |= SCC_CHILD_TIDPTR; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci if (!(flags & CLONE_SETTLS)) 758c2ecf20Sopenharmony_ci arg->mask |= SCC_TLS; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci return clone__scnprintf_flags(flags, bf, size, arg->show_string_prefix); 788c2ecf20Sopenharmony_ci} 79