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