summaryrefslogtreecommitdiffhomepage
path: root/src/thread/nt32/clone.c
blob: f5ad5f8f903827bc87461de37b5c9c0f903df6d2 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <syscall.h>

/* take advantage of i686 vararg abi */
#define  __clone ____clone
#include "pthread_impl.h"
#undef   __clone

struct pt_regs {
	unsigned long	ebx;
	unsigned long	ecx;
	unsigned long	edx;
	unsigned long	esi;
	unsigned long	edi;
	unsigned long	ebp;
	unsigned long	eax;
	unsigned long	xds;
	unsigned long	xes;
	unsigned long	xfs;
	unsigned long	xgs;
	unsigned long	orig_eax;
	unsigned long	eip;
	unsigned long	xcs;
	unsigned long	eflags;
	unsigned long	esp;
	unsigned long	xss;
	unsigned long	sbase;
	unsigned long	slimit;
	unsigned long	sbottom;
};

typedef long __sys_clone(
	unsigned long	flags,
	void *		child_stack,
	void *		ptid,
	void *		ctid,
	struct pt_regs *regs);

extern unsigned long ** __syscall_vtbl;

int __clone(
	__entry_point *	fn,
	void *		child_stack,
	int		flags,
	void *		arg,
	int *		ptid,
	void *		pthread_self_addr,
	int *		ctid)
{
	struct pt_regs	regs;
	__sys_clone *	pfn_clone;
	pthread_t	pthread;

	regs.eip = (unsigned long)fn;
	regs.ecx = (unsigned long)arg;
	regs.edx = (unsigned long)pthread_self_addr;

	pfn_clone = (__sys_clone *)(__syscall_vtbl[SYS_clone]);

	pthread      = (pthread_t)pthread_self_addr;
	regs.sbase   = (unsigned long)pthread->stack;
	regs.slimit  = regs.sbase  - pthread->stack_size;
	regs.sbottom = regs.slimit - pthread->guard_size;

	return (int)pfn_clone(
		flags,
		child_stack,
		ptid,
		ctid,
		&regs);
}