]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sh/clone.S
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sh / clone.S
CommitLineData
2b778ceb 1/* Copyright (C) 1999-2021 Free Software Foundation, Inc.
3846ef75
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
3846ef75
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
3846ef75 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
3846ef75
UD
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 <sysdep.h>
22#define _ERRNO_H 1
23#include <bits/errno.h>
2da9a6a1 24#include <tcb-offsets.h>
0d3b7a19 25
2a051a7d
UD
26/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
27 pid_t *ptid, void *tls, pid_t *ctid); */
3846ef75 28
2da9a6a1 29 .text
3846ef75
UD
30ENTRY(__clone)
31 /* sanity check arguments. */
32 tst r4, r4
84c23a3d 33 bt/s 0f
3846ef75 34 tst r5, r5
84c23a3d
RM
35 bf 1f
360:
bbd17455 37 bra .Lsyscall_error
84c23a3d 38 mov #-EINVAL,r0
3846ef75
UD
391:
40 /* insert the args onto the new stack */
41 mov.l r7, @-r5
42 /* save the function pointer as the 0th element */
43 mov.l r4, @-r5
44
45 /* do the system call */
46 mov r6, r4
2a051a7d
UD
47 mov.l @r15, r6
48 mov.l @(8,r15), r7
49 mov.l @(4,r15), r0
876f9634 50 mov #+SYS_ify(clone), r3
2a051a7d 51 trapa #0x15
3846ef75
UD
52 mov r0, r1
53 mov #-12, r2
54 shad r2, r1
55 not r1, r1 // r1=0 means r0 = -1 to -4095
56 tst r1, r1 // i.e. error in linux
bbd17455 57 bf .Lclone_end
9c84384c 58.Lsyscall_error:
bbd17455
UD
59 SYSCALL_ERROR_HANDLER
60.Lclone_end:
3846ef75 61 tst r0, r0
bbd17455
UD
62 bt 2f
63.Lpseudo_end:
3846ef75
UD
64 rts
65 nop
bbd17455 662:
2da9a6a1
UD
67 /* terminate the stack frame */
68 mov #0, r14
c579f48e 69
3846ef75
UD
70 /* thread starts */
71 mov.l @r15, r1
72 jsr @r1
73 mov.l @(4,r15), r4
74
75 /* we are done, passing the return value through r0 */
554e3d51 76 mov r0, r4
3f823e87
AZ
77 mov #+SYS_ify(exit), r3
78 trapa #0x15
3846ef75
UD
79 .align 2
80.LG:
81 .long _GLOBAL_OFFSET_TABLE_
82.L3:
83 .long PLTJMP(C_SYMBOL_NAME(_exit))
84PSEUDO_END (__clone)
85
9ff72da4 86libc_hidden_def (__clone)
3846ef75 87weak_alias (__clone, clone)