summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/microblaze/clone.c
blob: d92100865575b2ae283a289a4e0f4815617f1dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (C) 2004 Atmel Corporation
 *
 * This file is subject to the terms and conditions of the GNU Lesser General
 * Public License.  See the file "COPYING.LIB" in the main directory of this
 * archive for more details.
 */
#include <sched.h>
#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>

int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...)
{
	int rval = -EINVAL;
	if (fn && child_stack)
		rval = INTERNAL_SYSCALL(clone, 0, 2, flags, child_stack);

	if (rval == 0)
	{
		int exitCode = fn(arg);
		rval = INTERNAL_SYSCALL(exit, 0, 1, exitCode);
	}

	return rval;
}

#ifdef __NR_clone2
int
__clone2(int (*fn)(void *arg), void *child_stack, size_t stack_size,
	 int flags, void *arg, ...)
{
	int rval = -EINVAL;
	if (fn && child_stack)
	{
		rval = INTERNAL_SYSCALL(clone2, 0, 3, flags, child_stack, stack_size);
	}

	if (rval == 0)
	{
		int exitCode = fn(arg);
		rval = INTERNAL_SYSCALL(exit, 0, 1, exitCode);
	}

	return rval;
}
#endif