blob: 39eb54035dc04b7737d2121ab30a49cf4e5ab3c6 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Richard Henderson (rth@tamu.edu).
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20/* clone() is even more special than fork() as it mucks with stacks
21 and invokes a function in the right context after its all over. */
22
23#include <asm/errno.h>
24#include <sys/syscall.h>
25#include "NM_Macros.S"
26
27/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
28
29 .text
30 .align 2
31 .globl clone
32 .type clone,@function
33
34clone:
35 save %sp,-16
36
37 MOVIP %l0, -EINVAL
38 /* sanity check arguments */
39 skprnz %i0 /* no NULL function pointers */
40 br CLONE_ERROR_LABEL
41 mov %o0, %i2
42
43 skprnz %i1 /* no NULL stack pointers */
44 br CLONE_ERROR_LABEL
45 mov %o1, %i1
46
47 /* Do the system call */
48 MOVIP %g1, __NR_clone
49 trap 63
50
51 /* if ret >=0? */
52 cmpi %o0, 0
53 skps cc_pl
54 br CLONE_ERROR_LABEL
55 mov %l0, %o0
56
57 /* Start thread */
58 skprz %o1
59 br __thread_start
60 nop
61 mov %i0, %o0
62 ret
63 restore
64
65CLONE_ERROR_LABEL:
66 neg %l0
67 MOVIA %g1, __errno_location@h
68 call %g1
69 nop
70 st [%o0], %l0 /* store errno */
71
72 xor %i0, %i0
73 dec %i0 /* retval=-1 */
74 ret
75 restore
76
77 .size clone, .-clone
78
79 .type __thread_start,@function
80
81__thread_start:
82 call %i0
83 mov %o0, %i3
84 MOVIA %g1, _exit@h
85 call %g1
86 nop
87
88 .size __thread_start, .-__thread_start