• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Linaro Limited. All rights reserved.
4  * Author: Viresh Kumar <viresh.kumar@linaro.org>
5  */
6 
7 #ifndef LAPI_CLONE_H__
8 #define LAPI_CLONE_H__
9 
10 #include <sys/syscall.h>
11 #include <linux/types.h>
12 #include <sched.h>
13 #include <stdint.h>
14 
15 #include "config.h"
16 #include "lapi/syscalls.h"
17 
18 #ifndef HAVE_CLONE3
19 struct clone_args {
20 	uint64_t __attribute__((aligned(8))) flags;
21 	uint64_t __attribute__((aligned(8))) pidfd;
22 	uint64_t __attribute__((aligned(8))) child_tid;
23 	uint64_t __attribute__((aligned(8))) parent_tid;
24 	uint64_t __attribute__((aligned(8))) exit_signal;
25 	uint64_t __attribute__((aligned(8))) stack;
26 	uint64_t __attribute__((aligned(8))) stack_size;
27 	uint64_t __attribute__((aligned(8))) tls;
28 };
29 
clone3(struct clone_args * args,size_t size)30 static inline int clone3(struct clone_args *args, size_t size)
31 {
32 	return tst_syscall(__NR_clone3, args, size);
33 }
34 #endif
35 
36 #ifndef CLONE_PIDFD
37 #define CLONE_PIDFD	0x00001000	/* set if a pidfd should be placed in parent */
38 #endif
39 
40 #ifndef CLONE_NEWUSER
41 # define CLONE_NEWUSER	0x10000000
42 #endif
43 
clone3_supported_by_kernel(void)44 static inline void clone3_supported_by_kernel(void)
45 {
46 	long ret;
47 
48 	if ((tst_kvercmp(5, 3, 0)) < 0) {
49 		/* Check if the syscall is backported on an older kernel */
50 		ret = syscall(__NR_clone3, NULL, 0);
51 		if (ret == -1 && errno == ENOSYS)
52 			tst_brk(TCONF, "Test not supported on kernel version < v5.3");
53 	}
54 }
55 
56 #endif /* LAPI_CLONE_H__ */
57