1/* The clone3 syscall wrapper. Linux/s390x version.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#include <sysdep.h>
21#define _ERRNO_H 1
22#include <bits/errno.h>
23
24/* The userland implementation is:
25 int clone3 (struct clone_args *cl_args, size_t size,
26 int (*func)(void *arg), void *arg);
27
28 the kernel entry is:
29 int clone3 (struct clone_args *cl_args, size_t size);
30
31 The parameters are passed in registers from userland:
32 r2: cl_args
33 r3: size
34 r4: func
35 r5: arg */
36
37 .text
38ENTRY(__clone3)
39 /* Sanity check args. */
40 ltgr %r2, %r2
41 je error
42 ltgr %r4, %r4
43 je error
44
45 /* Do the system call, the kernel expects:
46 r1: system call number
47 r2: cl_args
48 r3: size */
49 lghi %r1, SYS_ify(clone3)
50 svc 0
51 ltgr %r2,%r2 /* check return code */
52 jz thread_start
53 jgm SYSCALL_ERROR_LABEL
54 br %r14
55error:
56 lghi %r2,-EINVAL
57 jg SYSCALL_ERROR_LABEL
58PSEUDO_END (__clone3)
59
60 .align 16
61 .type thread_start, %function
62thread_start:
63 cfi_startproc
64 /* Mark r14 as undefined in order to stop unwinding here. */
65 cfi_undefined (r14)
66
67 /* func is in gpr 4, arg in gpr 5. */
68 lgr %r2, %r5
69 aghi %r15, -160
70 xc 0(8,%r15),0(%r15)
71 basr %r14, %r4
72
73 DO_CALL (exit, 1)
74 cfi_endproc
75 ASM_SIZE_DIRECTIVE (thread_start)
76
77libc_hidden_def (__clone3)
78weak_alias (__clone3, clone3)
79

source code of glibc/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S