cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

clone.c (1818B)


      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	P_FLAG(CLEAR_SIGHAND);
     49	P_FLAG(INTO_CGROUP);
     50#undef P_FLAG
     51
     52	if (flags)
     53		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
     54
     55	return printed;
     56}
     57
     58size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg)
     59{
     60	unsigned long flags = arg->val;
     61	enum syscall_clone_args {
     62		SCC_FLAGS	  = (1 << 0),
     63		SCC_CHILD_STACK	  = (1 << 1),
     64		SCC_PARENT_TIDPTR = (1 << 2),
     65		SCC_CHILD_TIDPTR  = (1 << 3),
     66		SCC_TLS		  = (1 << 4),
     67	};
     68	if (!(flags & CLONE_PARENT_SETTID))
     69		arg->mask |= SCC_PARENT_TIDPTR;
     70
     71	if (!(flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)))
     72		arg->mask |= SCC_CHILD_TIDPTR;
     73
     74	if (!(flags & CLONE_SETTLS))
     75		arg->mask |= SCC_TLS;
     76
     77	return clone__scnprintf_flags(flags, bf, size, arg->show_string_prefix);
     78}