xref: /freebsd/sys/compat/linux/linux_fork.h (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1 /*-
2  * Copyright (c) 2021 Dmitry Chagin <dchagin@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #ifndef _LINUX_FORK_H_
29 #define _LINUX_FORK_H_
30 
31 #define	LINUX_CLONE_VM			0x00000100
32 #define	LINUX_CLONE_FS			0x00000200
33 #define	LINUX_CLONE_FILES		0x00000400
34 #define	LINUX_CLONE_SIGHAND		0x00000800
35 #define	LINUX_CLONE_PIDFD		0x00001000	/* since Linux 5.2 */
36 #define	LINUX_CLONE_PTRACE		0x00002000
37 #define	LINUX_CLONE_VFORK		0x00004000
38 #define	LINUX_CLONE_PARENT		0x00008000
39 #define	LINUX_CLONE_THREAD		0x00010000
40 #define	LINUX_CLONE_NEWNS		0x00020000	/* New mount NS */
41 #define	LINUX_CLONE_SYSVSEM		0x00040000
42 #define	LINUX_CLONE_SETTLS		0x00080000
43 #define	LINUX_CLONE_PARENT_SETTID	0x00100000
44 #define	LINUX_CLONE_CHILD_CLEARTID	0x00200000
45 #define	LINUX_CLONE_DETACHED		0x00400000	/* Unused */
46 #define	LINUX_CLONE_UNTRACED		0x00800000
47 #define	LINUX_CLONE_CHILD_SETTID	0x01000000
48 #define	LINUX_CLONE_NEWCGROUP		0x02000000	/* New cgroup NS */
49 #define	LINUX_CLONE_NEWUTS		0x04000000
50 #define	LINUX_CLONE_NEWIPC		0x08000000
51 #define	LINUX_CLONE_NEWUSER		0x10000000
52 #define	LINUX_CLONE_NEWPID		0x20000000
53 #define	LINUX_CLONE_NEWNET		0x40000000
54 #define	LINUX_CLONE_IO			0x80000000
55 
56 /* Flags for the clone3() syscall. */
57 #define	LINUX_CLONE_CLEAR_SIGHAND	0x100000000ULL
58 #define	LINUX_CLONE_INTO_CGROUP		0x200000000ULL
59 #define	LINUX_CLONE_NEWTIME		0x00000080
60 
61 #define	LINUX_CLONE_LEGACY_FLAGS	0xffffffffULL
62 
63 #define	LINUX_CSIGNAL			0x000000ff
64 
65 /*
66  * User-space clone3 args layout.
67  */
68 struct l_user_clone_args {
69 	uint64_t flags;
70 	uint64_t pidfd;
71 	uint64_t child_tid;
72 	uint64_t parent_tid;
73 	uint64_t exit_signal;
74 	uint64_t stack;
75 	uint64_t stack_size;
76 	uint64_t tls;
77 	uint64_t set_tid;
78 	uint64_t set_tid_size;
79 	uint64_t cgroup;
80 };
81 
82 /*
83  * Kernel clone3 args layout.
84  */
85 struct l_clone_args {
86 	uint64_t flags;
87 	l_int *child_tid;
88 	l_int *parent_tid;
89 	l_int exit_signal;
90 	l_ulong stack;
91 	l_ulong stack_size;
92 	l_ulong tls;
93 };
94 
95 #define	LINUX_CLONE_ARGS_SIZE_VER0	64
96 
97 int linux_set_upcall(struct thread *, register_t);
98 int linux_set_cloned_tls(struct thread *, void *);
99 void linux_thread_detach(struct thread *);
100 
101 #endif /* _LINUX_FORK_H_ */
102