xref: /freebsd/sys/compat/linux/linux_fork.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
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 
26 #ifndef _LINUX_FORK_H_
27 #define _LINUX_FORK_H_
28 
29 #define	LINUX_CLONE_VM			0x00000100
30 #define	LINUX_CLONE_FS			0x00000200
31 #define	LINUX_CLONE_FILES		0x00000400
32 #define	LINUX_CLONE_SIGHAND		0x00000800
33 #define	LINUX_CLONE_PIDFD		0x00001000	/* since Linux 5.2 */
34 #define	LINUX_CLONE_PTRACE		0x00002000
35 #define	LINUX_CLONE_VFORK		0x00004000
36 #define	LINUX_CLONE_PARENT		0x00008000
37 #define	LINUX_CLONE_THREAD		0x00010000
38 #define	LINUX_CLONE_NEWNS		0x00020000	/* New mount NS */
39 #define	LINUX_CLONE_SYSVSEM		0x00040000
40 #define	LINUX_CLONE_SETTLS		0x00080000
41 #define	LINUX_CLONE_PARENT_SETTID	0x00100000
42 #define	LINUX_CLONE_CHILD_CLEARTID	0x00200000
43 #define	LINUX_CLONE_DETACHED		0x00400000	/* Unused */
44 #define	LINUX_CLONE_UNTRACED		0x00800000
45 #define	LINUX_CLONE_CHILD_SETTID	0x01000000
46 #define	LINUX_CLONE_NEWCGROUP		0x02000000	/* New cgroup NS */
47 #define	LINUX_CLONE_NEWUTS		0x04000000
48 #define	LINUX_CLONE_NEWIPC		0x08000000
49 #define	LINUX_CLONE_NEWUSER		0x10000000
50 #define	LINUX_CLONE_NEWPID		0x20000000
51 #define	LINUX_CLONE_NEWNET		0x40000000
52 #define	LINUX_CLONE_IO			0x80000000
53 
54 /* Flags for the clone3() syscall. */
55 #define	LINUX_CLONE_CLEAR_SIGHAND	0x100000000ULL
56 #define	LINUX_CLONE_INTO_CGROUP		0x200000000ULL
57 #define	LINUX_CLONE_NEWTIME		0x00000080
58 
59 #define	LINUX_CLONE_LEGACY_FLAGS	0xffffffffULL
60 
61 #define	LINUX_CSIGNAL			0x000000ff
62 
63 #if defined(_KERNEL)
64 /*
65  * User-space clone3 args layout.
66  */
67 struct l_user_clone_args {
68 	uint64_t flags;
69 	uint64_t pidfd;
70 	uint64_t child_tid;
71 	uint64_t parent_tid;
72 	uint64_t exit_signal;
73 	uint64_t stack;
74 	uint64_t stack_size;
75 	uint64_t tls;
76 	uint64_t set_tid;
77 	uint64_t set_tid_size;
78 	uint64_t cgroup;
79 };
80 
81 /*
82  * Kernel clone3 args layout.
83  */
84 struct l_clone_args {
85 	uint64_t flags;
86 	l_int *child_tid;
87 	l_int *parent_tid;
88 	l_int exit_signal;
89 	l_ulong stack;
90 	l_ulong stack_size;
91 	l_ulong tls;
92 };
93 
94 #define	LINUX_CLONE_ARGS_SIZE_VER0	64
95 
96 int linux_set_upcall(struct thread *, register_t);
97 int linux_set_cloned_tls(struct thread *, void *);
98 void linux_thread_detach(struct thread *);
99 #endif /* defined(_KERNEL) */
100 
101 #endif /* _LINUX_FORK_H_ */
102