s390: Add the clone3 wrapper
[glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / clone3.S
blobbbe75ce893a7ce72e490ccb0c6da6fe3a0b1b6e9
1 /* The clone3 syscall wrapper.  Linux/s390x version.
2    Copyright (C) 2023 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
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.
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.
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/>.  */
20 #include <sysdep.h>
21 #define _ERRNO_H        1
22 #include <bits/errno.h>
24 /* The userland implementation is:
25    int clone3 (struct clone_args *cl_args, size_t size,
26                int (*func)(void *arg), void *arg);
28    the kernel entry is:
29    int clone3 (struct clone_args *cl_args, size_t size);
31    The parameters are passed in registers from userland:
32    r2: cl_args
33    r3: size
34    r4: func
35    r5: arg  */
37         .text
38 ENTRY(__clone3)
39         /* Sanity check args.  */
40         ltr     %r2, %r2
41         je      error
42         ltr     %r4, %r4
43         je      error
45         /* Do the system call, the kernel expects:
46            r1: system call number
47            r2: cl_args
48            r3: size  */
49         lhi     %r1, SYS_ify(clone3)
50         svc     0
51         ltr     %r2,%r2                 /* check return code */
52         jz      thread_start
53         jm      SYSCALL_ERROR_LABEL
54         br      %r14
55 error:
56         lhi     %r2,-EINVAL
57         j       SYSCALL_ERROR_LABEL
58 PSEUDO_END (__clone3)
60         .align 16
61         .type thread_start, %function
62 thread_start:
63         cfi_startproc
64         /* Mark r14 as undefined in order to stop unwinding here.  */
65         cfi_undefined (r14)
67         /* func is in gpr 4, arg in gpr 5.  */
68         lr      %r2, %r5
69         ahi     %r15, -96
70         xc      0(4,%r15),0(%r15)
71         basr    %r14, %r4
73         DO_CALL (exit, 1)
74         cfi_endproc
75         ASM_SIZE_DIRECTIVE (thread_start)
77 libc_hidden_def (__clone3)
78 weak_alias (__clone3, clone3)