blob: 161007d6be3aa8fa63c9695a556d70ac490592de [file] [log] [blame] [raw]
Igor Sysoev7d66b1f2004-10-05 15:39:18 +00001
2/*
3 * Copyright (C) Igor Sysoev
4 */
5
6
Igor Sysoev7d66b1f2004-10-05 15:39:18 +00007#include <sys/syscall.h>
8#include <machine/asm.h>
9
10/*
11 * rfork_thread(3) - rfork_thread(flags, stack, func, arg);
12 */
13
14#define KERNCALL int $0x80
15
16ENTRY(rfork_thread)
17 push %ebp
18 mov %esp, %ebp
19 push %esi
20
Igor Sysoev49563fd2005-01-25 12:25:58 +000021 mov 12(%ebp), %esi # the thread stack address
Igor Sysoev7d66b1f2004-10-05 15:39:18 +000022
23 sub $4, %esi
24 mov 20(%ebp), %eax # the thread argument
25 mov %eax, (%esi)
26
27 sub $4, %esi
Igor Sysoev49563fd2005-01-25 12:25:58 +000028 mov 16(%ebp), %eax # the thread start address
Igor Sysoev7d66b1f2004-10-05 15:39:18 +000029 mov %eax, (%esi)
30
31 push 8(%ebp) # rfork(2) flags
32 push $0
33 mov $SYS_rfork, %eax
34 KERNCALL
35 jc error
36
37 cmp $0, %edx
38 jne child
39
40parent:
41 add $8, %esp
42 pop %esi
Igor Sysoev49563fd2005-01-25 12:25:58 +000043 leave
Igor Sysoev7d66b1f2004-10-05 15:39:18 +000044 ret
45
46child:
47 mov %esi, %esp
48 pop %eax
49 call *%eax # call a thread start address ...
50 add $4, %esp
51
52 push %eax
53 push $0
54 mov $SYS_exit, %eax # ... and exit(2) after a thread would return
55 KERNCALL
56
57error:
58 add $8, %esp
59 pop %esi
Igor Sysoev49563fd2005-01-25 12:25:58 +000060 leave
Igor Sysoev7d66b1f2004-10-05 15:39:18 +000061 PIC_PROLOGUE
62
63 /* libc's cerror: jmp PIC_PLT(HIDENAME(cerror)) */
64
65 push %eax
66 call PIC_PLT(CNAME(__error))
67 pop %ecx
68 PIC_EPILOGUE
69 mov %ecx, (%eax)
70 mov $-1, %eax
71 mov $-1, %edx
72 ret