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 14 #include "config.h" 15 #include "lapi/syscalls.h" 16 17 #ifndef HAVE_CLONE3 18 struct clone_args { 19 uint64_t __attribute__((aligned(8))) flags; 20 uint64_t __attribute__((aligned(8))) pidfd; 21 uint64_t __attribute__((aligned(8))) child_tid; 22 uint64_t __attribute__((aligned(8))) parent_tid; 23 uint64_t __attribute__((aligned(8))) exit_signal; 24 uint64_t __attribute__((aligned(8))) stack; 25 uint64_t __attribute__((aligned(8))) stack_size; 26 uint64_t __attribute__((aligned(8))) tls; 27 }; 28 clone3(struct clone_args * args,size_t size)29int clone3(struct clone_args *args, size_t size) 30 { 31 return tst_syscall(__NR_clone3, args, size); 32 } 33 #endif 34 35 #ifndef CLONE_PIDFD 36 #define CLONE_PIDFD 0x00001000 /* set if a pidfd should be placed in parent */ 37 #endif 38 clone3_supported_by_kernel(void)39void clone3_supported_by_kernel(void) 40 { 41 if ((tst_kvercmp(5, 3, 0)) < 0) { 42 /* Check if the syscall is backported on an older kernel */ 43 TEST(syscall(__NR_clone3, NULL, 0)); 44 if (TST_RET == -1 && TST_ERR == ENOSYS) 45 tst_brk(TCONF, "Test not supported on kernel version < v5.3"); 46 } 47 } 48 49 #endif /* LAPI_CLONE_H__ */ 50