|
Packit |
6c4009 |
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* clone() is even more special than fork() as it mucks with stacks
|
|
Packit |
6c4009 |
and invokes a function in the right context after its all over. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
#define _ERRNO_H 1
|
|
Packit |
6c4009 |
#include <bits/errno.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* int clone(int (*fn)(void *arg), x0
|
|
Packit |
6c4009 |
void *child_stack, x1
|
|
Packit |
6c4009 |
int flags, x2
|
|
Packit |
6c4009 |
void *arg, x3
|
|
Packit |
6c4009 |
pid_t *ptid, x4
|
|
Packit |
6c4009 |
struct user_desc *tls, x5
|
|
Packit |
6c4009 |
pid_t *ctid); x6
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
ENTRY(__clone)
|
|
Packit |
6c4009 |
DELOUSE (0)
|
|
Packit |
6c4009 |
DELOUSE (1)
|
|
Packit |
6c4009 |
DELOUSE (2)
|
|
Packit |
6c4009 |
DELOUSE (3)
|
|
Packit |
6c4009 |
DELOUSE (4)
|
|
Packit |
6c4009 |
DELOUSE (5)
|
|
Packit |
6c4009 |
DELOUSE (6)
|
|
Packit |
6c4009 |
/* Save args for the child. */
|
|
Packit |
6c4009 |
mov x10, x0
|
|
Packit |
6c4009 |
mov x11, x2
|
|
Packit |
6c4009 |
mov x12, x3
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Sanity check args. */
|
|
Packit |
6c4009 |
mov x0, #-EINVAL
|
|
Packit |
6c4009 |
cbz x10, .Lsyscall_error
|
|
Packit |
6c4009 |
cbz x1, .Lsyscall_error
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Do the system call. */
|
|
Packit |
6c4009 |
/* X0:flags, x1:newsp, x2:parenttidptr, x3:newtls, x4:childtid. */
|
|
Packit |
6c4009 |
mov x0, x2 /* flags */
|
|
Packit |
6c4009 |
/* New sp is already in x1. */
|
|
Packit |
6c4009 |
mov x2, x4 /* ptid */
|
|
Packit |
6c4009 |
mov x3, x5 /* tls */
|
|
Packit |
6c4009 |
mov x4, x6 /* ctid */
|
|
Packit |
6c4009 |
mov x8, #SYS_ify(clone)
|
|
Packit |
6c4009 |
svc 0x0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cmp x0, #0
|
|
Packit |
6c4009 |
beq thread_start
|
|
Packit |
6c4009 |
blt .Lsyscall_error
|
|
Packit |
6c4009 |
RET
|
|
Packit |
6c4009 |
PSEUDO_END (__clone)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.align 4
|
|
Packit |
6c4009 |
.type thread_start, %function
|
|
Packit |
6c4009 |
thread_start:
|
|
Packit |
6c4009 |
cfi_startproc
|
|
Packit |
6c4009 |
cfi_undefined (x30)
|
|
Packit |
6c4009 |
mov x29, 0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Pick the function arg and execute. */
|
|
Packit |
6c4009 |
mov x0, x12
|
|
Packit |
6c4009 |
blr x10
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We are done, pass the return value through x0. */
|
|
Packit |
6c4009 |
mov x8, #SYS_ify(exit)
|
|
Packit |
6c4009 |
svc 0x0
|
|
Packit |
6c4009 |
cfi_endproc
|
|
Packit |
6c4009 |
.size thread_start, .-thread_start
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
libc_hidden_def (__clone)
|
|
Packit |
6c4009 |
weak_alias (__clone, clone)
|