2 * Copyright (c) 1999-2000 Wichert Akkerman <wichert@cistron.nl>
3 * Copyright (c) 2002-2005 Roland McGrath <roland@redhat.com>
4 * Copyright (c) 2008 Jan Kratochvil <jan.kratochvil@redhat.com>
5 * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com>
6 * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
7 * Copyright (c) 2014-2018 The strace developers.
10 * SPDX-License-Identifier: LGPL-2.1-or-later
15 #include <asm/unistd.h>
18 # define CSIGNAL 0x000000ff
21 #include "xlat/clone_flags.h"
22 #include "xlat/setns_types.h"
23 #include "xlat/unshare_flags.h"
28 # define ARG_STACKSIZE (tcp->scno == __NR_clone2 ? 2 : -1)
29 # define ARG_PTID (tcp->scno == __NR_clone2 ? 3 : 2)
30 # define ARG_CTID (tcp->scno == __NR_clone2 ? 4 : 3)
31 # define ARG_TLS (tcp->scno == __NR_clone2 ? 5 : 4)
32 #elif defined S390 || defined S390X
38 #elif defined X86_64 || defined X32
39 /* x86 personality processes have the last two arguments flipped. */
43 # define ARG_CTID ((current_personality != 1) ? 3 : 4)
44 # define ARG_TLS ((current_personality != 1) ? 4 : 3)
45 #elif defined ALPHA || defined TILE || defined OR1K || defined RISCV
60 print_tls_arg(struct tcb *const tcp, const kernel_ulong_t addr)
62 #ifdef HAVE_STRUCT_USER_DESC
63 # if SUPPORTED_PERSONALITIES > 1
64 if (current_personality == 1)
67 print_user_desc(tcp, tcp->u_arg[ARG_TLS], USER_DESC_BOTH);
69 # if SUPPORTED_PERSONALITIES > 1
72 #endif /* HAVE_STRUCT_USER_DESC */
74 printaddr(tcp->u_arg[ARG_TLS]);
81 const char *sep = "|";
82 kernel_ulong_t flags = tcp->u_arg[ARG_FLAGS];
83 tprints("child_stack=");
84 printaddr(tcp->u_arg[ARG_STACK]);
87 if (ARG_STACKSIZE != -1)
88 tprintf("stack_size=%#" PRI_klx ", ",
89 tcp->u_arg[ARG_STACKSIZE]);
92 if (!printflags64(clone_flags, flags & ~CSIGNAL, NULL))
94 if ((flags & CSIGNAL) != 0) {
96 printsignal(flags & CSIGNAL);
98 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
99 |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
101 if (flags & CLONE_PARENT_SETTID) {
102 tprints(", parent_tidptr=");
103 printaddr(tcp->u_arg[ARG_PTID]);
105 if (flags & CLONE_SETTLS) {
107 print_tls_arg(tcp, tcp->u_arg[ARG_TLS]);
109 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID)) {
110 tprints(", child_tidptr=");
111 printaddr(tcp->u_arg[ARG_CTID]);
114 /* TODO on syscall entry:
115 * We can clear CLONE_PTRACE here since it is an ancient hack
116 * to allow us to catch children, and we use another hack for that.
117 * But CLONE_PTRACE can conceivably be used by malicious programs
118 * to subvert us. By clearing this bit, we can defend against it:
119 * in untraced execution, CLONE_PTRACE should have no effect.
121 * We can also clear CLONE_UNTRACED, since it allows to start
122 * children outside of our control. At the moment
123 * I'm trying to figure out whether there is a *legitimate*
124 * use of this flag which we should respect.
131 printfd(tcp, tcp->u_arg[0]);
133 printxval(setns_types, tcp->u_arg[1], "CLONE_NEW???");
140 printflags64(unshare_flags, tcp->u_arg[0], "CLONE_???");