• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/sched.h"
12 
tst_clone(const struct tst_clone_args * tst_args)13 pid_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 		.cgroup = tst_args->cgroup,
19 	};
20 	int flags;
21 	pid_t pid = -1;
22 
23 	tst_flush();
24 
25 	errno = ENOSYS;
26 	if (__NR_clone3 != __LTP__NR_INVALID_SYSCALL)
27 		pid = syscall(__NR_clone3, &args, sizeof(args));
28 
29 	if (pid == -1 && errno != ENOSYS)
30 		return -1;
31 
32 	if (pid != -1)
33 		return pid;
34 
35 	flags = args.exit_signal | args.flags;
36 
37 #ifdef __s390x__
38 	pid = syscall(__NR_clone, NULL, flags);
39 #else
40 	pid = syscall(__NR_clone, flags, NULL);
41 #endif
42 
43 	if (pid == -1)
44 		return -2;
45 
46 	return pid;
47 }
48