clone.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (C) 1997-2017 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson (rth@tamu.edu).
  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 <asm/errno.h>
  17. #include <asm/unistd.h>
  18. #include <sysdep.h>
  19. #define CLONE_VM 0x00000100
  20. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  21. pid_t *ptid, void *tls, pid_t *ctid); */
  22. .register %g2,#scratch
  23. .register %g3,#scratch
  24. .text
  25. ENTRY (__clone)
  26. save %sp, -192, %sp
  27. cfi_def_cfa_register(%fp)
  28. cfi_window_save
  29. cfi_register(%o7, %i7)
  30. /* sanity check arguments */
  31. brz,pn %i0, 99f /* fn non-NULL? */
  32. mov %i0, %g2
  33. brz,pn %i1, 99f /* child_stack non-NULL? */
  34. mov %i2, %o0 /* clone flags */
  35. /* The child_stack is the top of the stack, allocate one
  36. whole stack frame from that as this is what the kernel
  37. expects. Also, subtract STACK_BIAS. */
  38. sub %i1, 192 + 0x7ff, %o1
  39. mov %i3, %g3
  40. mov %i4,%o2 /* PTID */
  41. mov %i5,%o3 /* TLS */
  42. ldx [%fp+0x7ff+176],%o4 /* CTID */
  43. /* Do the system call */
  44. set __NR_clone, %g1
  45. ta 0x6d
  46. bcs,pn %xcc, 98f
  47. nop
  48. brnz,pn %o1, __thread_start
  49. nop
  50. jmpl %i7 + 8, %g0
  51. restore %o0, %g0, %o0
  52. 99: mov EINVAL, %o0
  53. 98: call __errno_location
  54. mov %o0, %i0
  55. st %i0, [%o0]
  56. jmpl %i7 + 8, %g0
  57. restore %g0,-1,%o0
  58. END(__clone)
  59. .type __thread_start,@function
  60. __thread_start:
  61. mov %g0, %fp /* terminate backtrace */
  62. call %g2
  63. mov %g3,%o0
  64. call HIDDEN_JUMPTARGET(_exit),0
  65. nop
  66. .size __thread_start, .-__thread_start
  67. libc_hidden_def(__clone)
  68. weak_alias(__clone, clone)