clone.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 1996-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* clone() is even more special than fork() as it mucks with stacks
  15. and invokes a function in the right context after its all over. */
  16. #include <sysdep.h>
  17. #define _ERRNO_H 1
  18. #include <bits/errno.h>
  19. /* int clone(int (*fn)(void *arg), x0
  20. void *child_stack, x1
  21. int flags, x2
  22. void *arg, x3
  23. pid_t *ptid, x4
  24. struct user_desc *tls, x5
  25. pid_t *ctid); x6
  26. */
  27. .text
  28. ENTRY(__clone)
  29. DELOUSE (0)
  30. DELOUSE (1)
  31. DELOUSE (2)
  32. DELOUSE (3)
  33. DELOUSE (4)
  34. DELOUSE (5)
  35. DELOUSE (6)
  36. /* Save args for the child. */
  37. mov x10, x0
  38. mov x11, x2
  39. mov x12, x3
  40. /* Sanity check args. */
  41. mov x0, #-EINVAL
  42. cbz x10, .Lsyscall_error
  43. cbz x1, .Lsyscall_error
  44. /* Do the system call. */
  45. /* X0:flags, x1:newsp, x2:parenttidptr, x3:newtls, x4:childtid. */
  46. mov x0, x2 /* flags */
  47. /* New sp is already in x1. */
  48. mov x2, x4 /* ptid */
  49. mov x3, x5 /* tls */
  50. mov x4, x6 /* ctid */
  51. mov x8, #SYS_ify(clone)
  52. svc 0x0
  53. cmp x0, #0
  54. beq thread_start
  55. blt .Lsyscall_error
  56. RET
  57. PSEUDO_END (__clone)
  58. .align 4
  59. .type thread_start, %function
  60. thread_start:
  61. cfi_startproc
  62. cfi_undefined (x30)
  63. mov x29, 0
  64. /* Pick the function arg and execute. */
  65. mov x0, x12
  66. blr x10
  67. /* We are done, pass the return value through x0. */
  68. mov x8, #SYS_ify(exit)
  69. svc 0x0
  70. cfi_endproc
  71. .size thread_start, .-thread_start
  72. libc_hidden_def (__clone)
  73. weak_alias (__clone, clone)