1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* Copyright (c) 2021 SUSE LLC 3 * Richard Palethorpe <rpalethorpe@suse.com> 4 */ 5 6 #define TST_NO_DEFAULT_MAIN 7 8 #include <stddef.h> 9 10 #include "tst_test.h" 11 #include "lapi/clone.h" 12 tst_clone(const struct tst_clone_args * tst_args)13pid_t tst_clone(const struct tst_clone_args *tst_args) 14 { 15 struct clone_args args = { 16 .flags = tst_args->flags, 17 .exit_signal = tst_args->exit_signal, 18 }; 19 int flags; 20 pid_t pid = -1; 21 22 tst_flush(); 23 24 errno = ENOSYS; 25 if (__NR_clone3 != __LTP__NR_INVALID_SYSCALL) 26 pid = syscall(__NR_clone3, &args, sizeof(args)); 27 28 if (pid == -1 && errno != ENOSYS) 29 return -1; 30 31 if (pid != -1) 32 return pid; 33 34 flags = args.exit_signal | args.flags; 35 36 #ifdef __s390x__ 37 pid = syscall(__NR_clone, NULL, flags); 38 #else 39 pid = syscall(__NR_clone, flags, NULL); 40 #endif 41 42 if (pid == -1) 43 return -2; 44 45 return pid; 46 } 47