1 /* SPDX-License-Identifier: GPL-2.0-or-later 2 * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com> 3 */ 4 5 #ifndef TST_CLONE_H__ 6 #define TST_CLONE_H__ 7 8 #include <sched.h> 9 10 #ifdef TST_TEST_H__ 11 12 /* The parts of clone3's clone_args we support */ 13 struct tst_clone_args { 14 uint64_t flags; 15 uint64_t exit_signal; 16 uint64_t cgroup; 17 }; 18 19 /* clone3 with fallbacks to clone when possible. Be aware that it 20 * returns -1 if clone3 fails (except ENOSYS), but -2 if clone fails. 21 * 22 * Without CLONE_VM this acts like fork so you may want to set 23 * tst_test.forks_child (safe_clone requires this). 24 * 25 * You should set exit_signal to SIGCHLD for 26 * tst_reap_children. Otherwise you must call wait with the 27 * appropriate parameters. 28 */ 29 pid_t tst_clone(const struct tst_clone_args *args); 30 31 pid_t safe_clone(const char *file, const int lineno, 32 const struct tst_clone_args *args); 33 34 /* "Safe" version of tst_clone */ 35 #define SAFE_CLONE(args) safe_clone(__FILE__, __LINE__, args) 36 37 #endif /* TST_TEST_H__ */ 38 39 /* Functions from lib/cloner.c */ 40 int ltp_clone(unsigned long flags, int (*fn)(void *arg), void *arg, 41 size_t stack_size, void *stack); 42 int ltp_clone7(unsigned long flags, int (*fn)(void *arg), void *arg, 43 size_t stack_size, void *stack, ...); 44 void *ltp_alloc_stack(size_t size); 45 46 #define clone(...) (use_the_ltp_clone_functions__do_not_use_clone) 47 48 #endif /* TST_CLONE_H__ */ 49