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_STRUCT_CLONE_ARGS 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 #endif 30 31 #ifndef HAVE_CLONE3 clone3(struct clone_args * args,size_t size)32static inline int clone3(struct clone_args *args, size_t size) 33 { 34 return tst_syscall(__NR_clone3, args, size); 35 } 36 #endif 37 38 #ifndef CLONE_PIDFD 39 #define CLONE_PIDFD 0x00001000 /* set if a pidfd should be placed in parent */ 40 #endif 41 clone3_supported_by_kernel(void)42static inline void clone3_supported_by_kernel(void) 43 { 44 if ((tst_kvercmp(5, 3, 0)) < 0) { 45 /* Check if the syscall is backported on an older kernel */ 46 TEST(syscall(__NR_clone3, NULL, 0)); 47 if (TST_RET == -1 && TST_ERR == ENOSYS) 48 tst_brk(TCONF, "Test not supported on kernel version < v5.3"); 49 } 50 } 51 52 #endif /* LAPI_CLONE_H__ */ 53