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