1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _CLONE3_SELFTESTS_H
4 #define _CLONE3_SELFTESTS_H
8 #include <linux/sched.h>
9 #include <linux/types.h>
14 #include "../kselftest.h"
16 #define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))
18 #ifndef CLONE_INTO_CGROUP
19 #define CLONE_INTO_CGROUP 0x200000000ULL /* Clone into a specific cgroup given the right permissions. */
23 #define __NR_clone3 -1
29 __aligned_u64 child_tid
;
30 __aligned_u64 parent_tid
;
31 __aligned_u64 exit_signal
;
33 __aligned_u64 stack_size
;
35 #ifndef CLONE_ARGS_SIZE_VER0
36 #define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
38 __aligned_u64 set_tid
;
39 __aligned_u64 set_tid_size
;
40 #ifndef CLONE_ARGS_SIZE_VER1
41 #define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */
44 #ifndef CLONE_ARGS_SIZE_VER2
45 #define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */
49 static pid_t
sys_clone3(struct __clone_args
*args
, size_t size
)
53 return syscall(__NR_clone3
, args
, size
);
56 static inline void test_clone3_supported(void)
59 struct __clone_args args
= {};
62 ksft_exit_skip("clone3() syscall is not supported\n");
64 /* Set to something that will always cause EINVAL. */
65 args
.exit_signal
= -1;
66 pid
= sys_clone3(&args
, sizeof(args
));
73 "Managed to create child process with invalid exit_signal\n");
77 ksft_exit_skip("clone3() syscall is not supported\n");
79 ksft_print_msg("clone3() syscall supported\n");
82 #endif /* _CLONE3_SELFTESTS_H */