blob: 086adc6859ab835af473d7c89b172acbf858b3e6 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
2
3 The GNU C Library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
7
8 The GNU C Library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public
14 License along with the GNU C Library; see the file COPYING.LIB. If not,
15 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. */
17
18/* clone() is even more special than fork() as it mucks with stacks
19 and invokes a function in the right context after its all over. */
20
21#include <sys/syscall.h>
22
23#warning "This file contains a hardcoded constant for SYS_clone"
24
25.section .rodata
26 .align 2
27.LC0: .long 120 /* SYS_clone */
28.align 4
29.text
30.type clone,@function
31.globl clone;
32clone:
33 .word 0x0040
34 /* subl2 $8, %sp */
35 movl 4(%ap), %r1
36 movl 8(%ap), %r0
37 mcoml $21, %r6
38
39 /* Sanity check args. */
40 tstl %r1
41 jeql CLONE_ERROR_LABEL
42 tstl %r0
43 jeql CLONE_ERROR_LABEL
44
45 /* Need to setup the child stack the same as the parent. */
46 subl2 $24, %r0
47 movl 16(%ap), 20(%r0)
48 movl %r1, 16(%r0)
49 movl %r0, %r1
50 addl2 $16, %r1
51 movl %r1, 12(%r0)
52
53 /* Do the system call. */
54 pushl %ap
55 pushl %r0
56 pushl 12(%ap)
57 pushl $0x2
58 movl %sp, %ap
59 chmk .LC0 /* %r0 .LC0 -4(%fp) -8(%fp) */
60 addl2 $12, %sp
61 movl (%sp)+, %ap
62 movl %r0, %r6
63 jneq CLONE_ERROR_LABEL
64
65 movl $0, %fp
66 pushl 4(%ap)
67 movl (%r1), %r0
68 calls $1, (%r0)
69 pushl %r0
70 calls $1, HIDDEN_JUMPTARGET(_exit)
71
72CLONE_ERROR_LABEL:
73 cmpl %r6, $-126 /* -ENOKEY?!?! Fuck, this must be wrong! FIXME */
74 jlequ CLONE_RETURN_LABEL
75 calls $0, __errno_location
76 mnegl %r6, (%r0)
77 mcoml $0, %r6
78 movl %r6, %r0
79 ret
80
81CLONE_RETURN_LABEL:
82 ret
83
84.size clone,.-clone
85