clone.S 2.1 KB

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